~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to .pc/arm64/0030-target-arm-A64-expand-decoding-skeleton-for-system-i.patch/target-arm/translate-a64.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-02-04 12:13:08 UTC
  • mfrom: (10.1.45 sid)
  • Revision ID: package-import@ubuntu.com-20140204121308-1xq92lrfs75agw2g
Tags: 1.7.0+dfsg-3ubuntu1~ppa1
* Merge 1.7.0+dfsg-3 from debian.  Remaining changes:
  - debian/patches/ubuntu:
    * expose-vmx_qemu64cpu.patch
    * linaro (omap3) and arm64 patches
    * ubuntu/target-ppc-add-stubs-for-kvm-breakpoints: fix FTBFS
      on ppc
    * ubuntu/CVE-2013-4377.patch: fix denial of service via virtio
  - debian/qemu-system-x86.modprobe: set kvm_intel nested=1 options
  - debian/control:
    * add arm64 to Architectures
    * add qemu-common and qemu-system-aarch64 packages
  - debian/qemu-system-common.install: add debian/tmp/usr/lib
  - debian/qemu-system-common.preinst: add kvm group
  - debian/qemu-system-common.postinst: remove acl placed by udev,
    and add udevadm trigger.
  - qemu-system-x86.links: add eepro100.rom, remove pxe-virtio,
    pxe-e1000 and pxe-rtl8139.
  - add qemu-system-x86.qemu-kvm.upstart and .default
  - qemu-user-static.postinst-in: remove arm64 binfmt
  - debian/rules:
    * allow parallel build
    * add aarch64 to system_targets and sys_systems
    * add qemu-kvm-spice links
    * install qemu-system-x86.modprobe
  - add debian/qemu-system-common.links for OVMF.fd link
* Remove kvm-img, kvm-nbd, kvm-ifup and kvm-ifdown symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  AArch64 translation
3
 
 *
4
 
 *  Copyright (c) 2013 Alexander Graf <agraf@suse.de>
5
 
 *
6
 
 * This library is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU Lesser General Public
8
 
 * License as published by the Free Software Foundation; either
9
 
 * version 2 of the License, or (at your option) any later version.
10
 
 *
11
 
 * This library is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
 * Lesser General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
#include <stdarg.h>
20
 
#include <stdlib.h>
21
 
#include <stdio.h>
22
 
#include <string.h>
23
 
#include <inttypes.h>
24
 
 
25
 
#include "cpu.h"
26
 
#include "tcg-op.h"
27
 
#include "qemu/log.h"
28
 
#include "translate.h"
29
 
#include "qemu/host-utils.h"
30
 
 
31
 
#include "exec/gen-icount.h"
32
 
 
33
 
#include "helper.h"
34
 
#define GEN_HELPER 1
35
 
#include "helper.h"
36
 
 
37
 
static TCGv_i64 cpu_X[32];
38
 
static TCGv_i64 cpu_pc;
39
 
static TCGv_i32 pstate;
40
 
 
41
 
static const char *regnames[] = {
42
 
    "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
43
 
    "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
44
 
    "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
45
 
    "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
46
 
};
47
 
 
48
 
/* initialize TCG globals.  */
49
 
void a64_translate_init(void)
50
 
{
51
 
    int i;
52
 
 
53
 
    cpu_pc = tcg_global_mem_new_i64(TCG_AREG0,
54
 
                                    offsetof(CPUARMState, pc),
55
 
                                    "pc");
56
 
    for (i = 0; i < 32; i++) {
57
 
        cpu_X[i] = tcg_global_mem_new_i64(TCG_AREG0,
58
 
                                          offsetof(CPUARMState, xregs[i]),
59
 
                                          regnames[i]);
60
 
    }
61
 
 
62
 
    pstate = tcg_global_mem_new_i32(TCG_AREG0,
63
 
                                    offsetof(CPUARMState, pstate),
64
 
                                    "pstate");
65
 
}
66
 
 
67
 
void aarch64_cpu_dump_state(CPUState *cs, FILE *f,
68
 
                            fprintf_function cpu_fprintf, int flags)
69
 
{
70
 
    ARMCPU *cpu = ARM_CPU(cs);
71
 
    CPUARMState *env = &cpu->env;
72
 
    uint32_t psr = pstate_read(env);
73
 
    int i;
74
 
 
75
 
    cpu_fprintf(f, "PC=%016"PRIx64"  SP=%016"PRIx64"\n",
76
 
            env->pc, env->xregs[31]);
77
 
    for (i = 0; i < 31; i++) {
78
 
        cpu_fprintf(f, "X%02d=%016"PRIx64, i, env->xregs[i]);
79
 
        if ((i % 4) == 3) {
80
 
            cpu_fprintf(f, "\n");
81
 
        } else {
82
 
            cpu_fprintf(f, " ");
83
 
        }
84
 
    }
85
 
    cpu_fprintf(f, "PSTATE=%08x (flags %c%c%c%c)\n",
86
 
                psr,
87
 
                psr & PSTATE_N ? 'N' : '-',
88
 
                psr & PSTATE_Z ? 'Z' : '-',
89
 
                psr & PSTATE_C ? 'C' : '-',
90
 
                psr & PSTATE_V ? 'V' : '-');
91
 
    cpu_fprintf(f, "\n");
92
 
}
93
 
 
94
 
void gen_a64_set_pc_im(uint64_t val)
95
 
{
96
 
    tcg_gen_movi_i64(cpu_pc, val);
97
 
}
98
 
 
99
 
static void gen_exception(int excp)
100
 
{
101
 
    TCGv_i32 tmp = tcg_temp_new_i32();
102
 
    tcg_gen_movi_i32(tmp, excp);
103
 
    gen_helper_exception(cpu_env, tmp);
104
 
    tcg_temp_free_i32(tmp);
105
 
}
106
 
 
107
 
static void gen_exception_insn(DisasContext *s, int offset, int excp)
108
 
{
109
 
    gen_a64_set_pc_im(s->pc - offset);
110
 
    gen_exception(excp);
111
 
    s->is_jmp = DISAS_EXC;
112
 
}
113
 
 
114
 
static inline bool use_goto_tb(DisasContext *s, int n, uint64_t dest)
115
 
{
116
 
    /* No direct tb linking with singlestep or deterministic io */
117
 
    if (s->singlestep_enabled || (s->tb->cflags & CF_LAST_IO)) {
118
 
        return false;
119
 
    }
120
 
 
121
 
    /* Only link tbs from inside the same guest page */
122
 
    if ((s->tb->pc & TARGET_PAGE_MASK) != (dest & TARGET_PAGE_MASK)) {
123
 
        return false;
124
 
    }
125
 
 
126
 
    return true;
127
 
}
128
 
 
129
 
static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)
130
 
{
131
 
    TranslationBlock *tb;
132
 
 
133
 
    tb = s->tb;
134
 
    if (use_goto_tb(s, n, dest)) {
135
 
        tcg_gen_goto_tb(n);
136
 
        gen_a64_set_pc_im(dest);
137
 
        tcg_gen_exit_tb((tcg_target_long)tb + n);
138
 
        s->is_jmp = DISAS_TB_JUMP;
139
 
    } else {
140
 
        gen_a64_set_pc_im(dest);
141
 
        if (s->singlestep_enabled) {
142
 
            gen_exception(EXCP_DEBUG);
143
 
        }
144
 
        tcg_gen_exit_tb(0);
145
 
        s->is_jmp = DISAS_JUMP;
146
 
    }
147
 
}
148
 
 
149
 
static void unallocated_encoding(DisasContext *s)
150
 
{
151
 
    gen_exception_insn(s, 4, EXCP_UDEF);
152
 
}
153
 
 
154
 
#define unsupported_encoding(s, insn)                                    \
155
 
    do {                                                                 \
156
 
        qemu_log_mask(LOG_UNIMP,                                         \
157
 
                      "%s:%d: unsupported instruction encoding 0x%08x "  \
158
 
                      "at pc=%016" PRIx64 "\n",                          \
159
 
                      __FILE__, __LINE__, insn, s->pc - 4);              \
160
 
        unallocated_encoding(s);                                         \
161
 
    } while (0);
162
 
 
163
 
/*
164
 
 * the instruction disassembly implemented here matches
165
 
 * the instruction encoding classifications in chapter 3 (C3)
166
 
 * of the ARM Architecture Reference Manual (DDI0487A_a)
167
 
 */
168
 
 
169
 
/* Unconditional branch (immediate) */
170
 
static void disas_uncond_b_imm(DisasContext *s, uint32_t insn)
171
 
{
172
 
    unsupported_encoding(s, insn);
173
 
}
174
 
 
175
 
/* Compare & branch (immediate) */
176
 
static void disas_comp_b_imm(DisasContext *s, uint32_t insn)
177
 
{
178
 
    unsupported_encoding(s, insn);
179
 
}
180
 
 
181
 
/* Test & branch (immediate) */
182
 
static void disas_test_b_imm(DisasContext *s, uint32_t insn)
183
 
{
184
 
    unsupported_encoding(s, insn);
185
 
}
186
 
 
187
 
/* Conditional branch (immediate) */
188
 
static void disas_cond_b_imm(DisasContext *s, uint32_t insn)
189
 
{
190
 
    unsupported_encoding(s, insn);
191
 
}
192
 
 
193
 
/* System */
194
 
static void disas_system(DisasContext *s, uint32_t insn)
195
 
{
196
 
    unsupported_encoding(s, insn);
197
 
}
198
 
 
199
 
/* Exception generation */
200
 
static void disas_exc(DisasContext *s, uint32_t insn)
201
 
{
202
 
    unsupported_encoding(s, insn);
203
 
}
204
 
 
205
 
/* Unconditional branch (register) */
206
 
static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)
207
 
{
208
 
    unsupported_encoding(s, insn);
209
 
}
210
 
 
211
 
/* C3.2 Branches, exception generating and system instructions */
212
 
static void disas_b_exc_sys(DisasContext *s, uint32_t insn)
213
 
{
214
 
    switch (extract32(insn, 25, 7)) {
215
 
    case 0x0a: case 0x0b:
216
 
    case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
217
 
        disas_uncond_b_imm(s, insn);
218
 
        break;
219
 
    case 0x1a: case 0x5a: /* Compare & branch (immediate) */
220
 
        disas_comp_b_imm(s, insn);
221
 
        break;
222
 
    case 0x1b: case 0x5b: /* Test & branch (immediate) */
223
 
        disas_test_b_imm(s, insn);
224
 
        break;
225
 
    case 0x2a: /* Conditional branch (immediate) */
226
 
        disas_cond_b_imm(s, insn);
227
 
        break;
228
 
    case 0x6a: /* Exception generation / System */
229
 
        if (insn & (1 << 24)) {
230
 
            disas_system(s, insn);
231
 
        } else {
232
 
            disas_exc(s, insn);
233
 
        }
234
 
        break;
235
 
    case 0x6b: /* Unconditional branch (register) */
236
 
        disas_uncond_b_reg(s, insn);
237
 
        break;
238
 
    default:
239
 
        unallocated_encoding(s);
240
 
        break;
241
 
    }
242
 
}
243
 
 
244
 
/* Load/store exclusive */
245
 
static void disas_ldst_excl(DisasContext *s, uint32_t insn)
246
 
{
247
 
    unsupported_encoding(s, insn);
248
 
}
249
 
 
250
 
/* Load register (literal) */
251
 
static void disas_ld_lit(DisasContext *s, uint32_t insn)
252
 
{
253
 
    unsupported_encoding(s, insn);
254
 
}
255
 
 
256
 
/* Load/store pair (all forms) */
257
 
static void disas_ldst_pair(DisasContext *s, uint32_t insn)
258
 
{
259
 
    unsupported_encoding(s, insn);
260
 
}
261
 
 
262
 
/* Load/store register (all forms) */
263
 
static void disas_ldst_reg(DisasContext *s, uint32_t insn)
264
 
{
265
 
    unsupported_encoding(s, insn);
266
 
}
267
 
 
268
 
/* AdvSIMD load/store multiple structures */
269
 
static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)
270
 
{
271
 
    unsupported_encoding(s, insn);
272
 
}
273
 
 
274
 
/* AdvSIMD load/store single structure */
275
 
static void disas_ldst_single_struct(DisasContext *s, uint32_t insn)
276
 
{
277
 
    unsupported_encoding(s, insn);
278
 
}
279
 
 
280
 
/* C3.3 Loads and stores */
281
 
static void disas_ldst(DisasContext *s, uint32_t insn)
282
 
{
283
 
    switch (extract32(insn, 24, 6)) {
284
 
    case 0x08: /* Load/store exclusive */
285
 
        disas_ldst_excl(s, insn);
286
 
        break;
287
 
    case 0x18: case 0x1c: /* Load register (literal) */
288
 
        disas_ld_lit(s, insn);
289
 
        break;
290
 
    case 0x28: case 0x29:
291
 
    case 0x2c: case 0x2d: /* Load/store pair (all forms) */
292
 
        disas_ldst_pair(s, insn);
293
 
        break;
294
 
    case 0x38: case 0x39:
295
 
    case 0x3c: case 0x3d: /* Load/store register (all forms) */
296
 
        disas_ldst_reg(s, insn);
297
 
        break;
298
 
    case 0x0c: /* AdvSIMD load/store multiple structures */
299
 
        disas_ldst_multiple_struct(s, insn);
300
 
        break;
301
 
    case 0x0d: /* AdvSIMD load/store single structure */
302
 
        disas_ldst_single_struct(s, insn);
303
 
        break;
304
 
    default:
305
 
        unallocated_encoding(s);
306
 
        break;
307
 
    }
308
 
}
309
 
 
310
 
/* PC-rel. addressing */
311
 
static void disas_pc_rel_adr(DisasContext *s, uint32_t insn)
312
 
{
313
 
    unsupported_encoding(s, insn);
314
 
}
315
 
 
316
 
/* Add/subtract (immediate) */
317
 
static void disas_add_sub_imm(DisasContext *s, uint32_t insn)
318
 
{
319
 
    unsupported_encoding(s, insn);
320
 
}
321
 
 
322
 
/* Logical (immediate) */
323
 
static void disas_logic_imm(DisasContext *s, uint32_t insn)
324
 
{
325
 
    unsupported_encoding(s, insn);
326
 
}
327
 
 
328
 
/* Move wide (immediate) */
329
 
static void disas_movw_imm(DisasContext *s, uint32_t insn)
330
 
{
331
 
    unsupported_encoding(s, insn);
332
 
}
333
 
 
334
 
/* Bitfield */
335
 
static void disas_bitfield(DisasContext *s, uint32_t insn)
336
 
{
337
 
    unsupported_encoding(s, insn);
338
 
}
339
 
 
340
 
/* Extract */
341
 
static void disas_extract(DisasContext *s, uint32_t insn)
342
 
{
343
 
    unsupported_encoding(s, insn);
344
 
}
345
 
 
346
 
/* C3.4 Data processing - immediate */
347
 
static void disas_data_proc_imm(DisasContext *s, uint32_t insn)
348
 
{
349
 
    switch (extract32(insn, 23, 6)) {
350
 
    case 0x20: case 0x21: /* PC-rel. addressing */
351
 
        disas_pc_rel_adr(s, insn);
352
 
        break;
353
 
    case 0x22: case 0x23: /* Add/subtract (immediate) */
354
 
        disas_add_sub_imm(s, insn);
355
 
        break;
356
 
    case 0x24: /* Logical (immediate) */
357
 
        disas_logic_imm(s, insn);
358
 
        break;
359
 
    case 0x25: /* Move wide (immediate) */
360
 
        disas_movw_imm(s, insn);
361
 
        break;
362
 
    case 0x26: /* Bitfield */
363
 
        disas_bitfield(s, insn);
364
 
        break;
365
 
    case 0x27: /* Extract */
366
 
        disas_extract(s, insn);
367
 
        break;
368
 
    default:
369
 
        unallocated_encoding(s);
370
 
        break;
371
 
    }
372
 
}
373
 
 
374
 
/* Logical (shifted register) */
375
 
static void disas_logic_reg(DisasContext *s, uint32_t insn)
376
 
{
377
 
    unsupported_encoding(s, insn);
378
 
}
379
 
 
380
 
/* Add/subtract (extended register) */
381
 
static void disas_add_sub_ext_reg(DisasContext *s, uint32_t insn)
382
 
{
383
 
    unsupported_encoding(s, insn);
384
 
}
385
 
 
386
 
/* Add/subtract (shifted register) */
387
 
static void disas_add_sub_reg(DisasContext *s, uint32_t insn)
388
 
{
389
 
    unsupported_encoding(s, insn);
390
 
}
391
 
 
392
 
/* Data-processing (3 source) */
393
 
static void disas_data_proc_3src(DisasContext *s, uint32_t insn)
394
 
{
395
 
    unsupported_encoding(s, insn);
396
 
}
397
 
 
398
 
/* Add/subtract (with carry) */
399
 
static void disas_adc_sbc(DisasContext *s, uint32_t insn)
400
 
{
401
 
    unsupported_encoding(s, insn);
402
 
}
403
 
 
404
 
/* Conditional compare (immediate) */
405
 
static void disas_cc_imm(DisasContext *s, uint32_t insn)
406
 
{
407
 
    unsupported_encoding(s, insn);
408
 
}
409
 
 
410
 
/* Conditional compare (register) */
411
 
static void disas_cc_reg(DisasContext *s, uint32_t insn)
412
 
{
413
 
    unsupported_encoding(s, insn);
414
 
}
415
 
 
416
 
/* Conditional select */
417
 
static void disas_cond_select(DisasContext *s, uint32_t insn)
418
 
{
419
 
    unsupported_encoding(s, insn);
420
 
}
421
 
 
422
 
/* Data-processing (1 source) */
423
 
static void disas_data_proc_1src(DisasContext *s, uint32_t insn)
424
 
{
425
 
    unsupported_encoding(s, insn);
426
 
}
427
 
 
428
 
/* Data-processing (2 source) */
429
 
static void disas_data_proc_2src(DisasContext *s, uint32_t insn)
430
 
{
431
 
    unsupported_encoding(s, insn);
432
 
}
433
 
 
434
 
/* C3.5 Data processing - register */
435
 
static void disas_data_proc_reg(DisasContext *s, uint32_t insn)
436
 
{
437
 
    switch (extract32(insn, 24, 5)) {
438
 
    case 0x0a: /* Logical (shifted register) */
439
 
        disas_logic_reg(s, insn);
440
 
        break;
441
 
    case 0x0b: /* Add/subtract */
442
 
        if (insn & (1 << 21)) { /* (extended register) */
443
 
            disas_add_sub_ext_reg(s, insn);
444
 
        } else {
445
 
            disas_add_sub_reg(s, insn);
446
 
        }
447
 
        break;
448
 
    case 0x1b: /* Data-processing (3 source) */
449
 
        disas_data_proc_3src(s, insn);
450
 
        break;
451
 
    case 0x1a:
452
 
        switch (extract32(insn, 21, 3)) {
453
 
        case 0x0: /* Add/subtract (with carry) */
454
 
            disas_adc_sbc(s, insn);
455
 
            break;
456
 
        case 0x2: /* Conditional compare */
457
 
            if (insn & (1 << 11)) { /* (immediate) */
458
 
                disas_cc_imm(s, insn);
459
 
            } else {            /* (register) */
460
 
                disas_cc_reg(s, insn);
461
 
            }
462
 
            break;
463
 
        case 0x4: /* Conditional select */
464
 
            disas_cond_select(s, insn);
465
 
            break;
466
 
        case 0x6: /* Data-processing */
467
 
            if (insn & (1 << 30)) { /* (1 source) */
468
 
                disas_data_proc_1src(s, insn);
469
 
            } else {            /* (2 source) */
470
 
                disas_data_proc_2src(s, insn);
471
 
            }
472
 
            break;
473
 
        default:
474
 
            unallocated_encoding(s);
475
 
            break;
476
 
        }
477
 
        break;
478
 
    default:
479
 
        unallocated_encoding(s);
480
 
        break;
481
 
    }
482
 
}
483
 
 
484
 
/* C3.6 Data processing - SIMD and floating point */
485
 
static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn)
486
 
{
487
 
    unsupported_encoding(s, insn);
488
 
}
489
 
 
490
 
/* C3.1 A64 instruction index by encoding */
491
 
static void disas_a64_insn(CPUARMState *env, DisasContext *s)
492
 
{
493
 
    uint32_t insn;
494
 
 
495
 
    insn = arm_ldl_code(env, s->pc, s->bswap_code);
496
 
    s->insn = insn;
497
 
    s->pc += 4;
498
 
 
499
 
    switch (extract32(insn, 25, 4)) {
500
 
    case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
501
 
        unallocated_encoding(s);
502
 
        break;
503
 
    case 0x8: case 0x9: /* Data processing - immediate */
504
 
        disas_data_proc_imm(s, insn);
505
 
        break;
506
 
    case 0xa: case 0xb: /* Branch, exception generation and system insns */
507
 
        disas_b_exc_sys(s, insn);
508
 
        break;
509
 
    case 0x4:
510
 
    case 0x6:
511
 
    case 0xc:
512
 
    case 0xe:      /* Loads and stores */
513
 
        disas_ldst(s, insn);
514
 
        break;
515
 
    case 0x5:
516
 
    case 0xd:      /* Data processing - register */
517
 
        disas_data_proc_reg(s, insn);
518
 
        break;
519
 
    case 0x7:
520
 
    case 0xf:      /* Data processing - SIMD and floating point */
521
 
        disas_data_proc_simd_fp(s, insn);
522
 
        break;
523
 
    default:
524
 
        assert(FALSE); /* all 15 cases should be handled above */
525
 
        break;
526
 
    }
527
 
}
528
 
 
529
 
void gen_intermediate_code_internal_a64(ARMCPU *cpu,
530
 
                                        TranslationBlock *tb,
531
 
                                        bool search_pc)
532
 
{
533
 
    CPUState *cs = CPU(cpu);
534
 
    CPUARMState *env = &cpu->env;
535
 
    DisasContext dc1, *dc = &dc1;
536
 
    CPUBreakpoint *bp;
537
 
    uint16_t *gen_opc_end;
538
 
    int j, lj;
539
 
    target_ulong pc_start;
540
 
    target_ulong next_page_start;
541
 
    int num_insns;
542
 
    int max_insns;
543
 
 
544
 
    pc_start = tb->pc;
545
 
 
546
 
    dc->tb = tb;
547
 
 
548
 
    gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
549
 
 
550
 
    dc->is_jmp = DISAS_NEXT;
551
 
    dc->pc = pc_start;
552
 
    dc->singlestep_enabled = cs->singlestep_enabled;
553
 
    dc->condjmp = 0;
554
 
 
555
 
    dc->aarch64 = 1;
556
 
    dc->thumb = 0;
557
 
    dc->bswap_code = 0;
558
 
    dc->condexec_mask = 0;
559
 
    dc->condexec_cond = 0;
560
 
#if !defined(CONFIG_USER_ONLY)
561
 
    dc->user = 0;
562
 
#endif
563
 
    dc->vfp_enabled = 0;
564
 
    dc->vec_len = 0;
565
 
    dc->vec_stride = 0;
566
 
 
567
 
    next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
568
 
    lj = -1;
569
 
    num_insns = 0;
570
 
    max_insns = tb->cflags & CF_COUNT_MASK;
571
 
    if (max_insns == 0) {
572
 
        max_insns = CF_COUNT_MASK;
573
 
    }
574
 
 
575
 
    gen_tb_start();
576
 
 
577
 
    tcg_clear_temp_count();
578
 
 
579
 
    do {
580
 
        if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
581
 
            QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
582
 
                if (bp->pc == dc->pc) {
583
 
                    gen_exception_insn(dc, 0, EXCP_DEBUG);
584
 
                    /* Advance PC so that clearing the breakpoint will
585
 
                       invalidate this TB.  */
586
 
                    dc->pc += 2;
587
 
                    goto done_generating;
588
 
                }
589
 
            }
590
 
        }
591
 
 
592
 
        if (search_pc) {
593
 
            j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
594
 
            if (lj < j) {
595
 
                lj++;
596
 
                while (lj < j) {
597
 
                    tcg_ctx.gen_opc_instr_start[lj++] = 0;
598
 
                }
599
 
            }
600
 
            tcg_ctx.gen_opc_pc[lj] = dc->pc;
601
 
            tcg_ctx.gen_opc_instr_start[lj] = 1;
602
 
            tcg_ctx.gen_opc_icount[lj] = num_insns;
603
 
        }
604
 
 
605
 
        if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) {
606
 
            gen_io_start();
607
 
        }
608
 
 
609
 
        if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
610
 
            tcg_gen_debug_insn_start(dc->pc);
611
 
        }
612
 
 
613
 
        disas_a64_insn(env, dc);
614
 
 
615
 
        if (tcg_check_temp_count()) {
616
 
            fprintf(stderr, "TCG temporary leak before "TARGET_FMT_lx"\n",
617
 
                    dc->pc);
618
 
        }
619
 
 
620
 
        /* Translation stops when a conditional branch is encountered.
621
 
         * Otherwise the subsequent code could get translated several times.
622
 
         * Also stop translation when a page boundary is reached.  This
623
 
         * ensures prefetch aborts occur at the right place.
624
 
         */
625
 
        num_insns++;
626
 
    } while (!dc->is_jmp && tcg_ctx.gen_opc_ptr < gen_opc_end &&
627
 
             !cs->singlestep_enabled &&
628
 
             !singlestep &&
629
 
             dc->pc < next_page_start &&
630
 
             num_insns < max_insns);
631
 
 
632
 
    if (tb->cflags & CF_LAST_IO) {
633
 
        gen_io_end();
634
 
    }
635
 
 
636
 
    if (unlikely(cs->singlestep_enabled) && dc->is_jmp != DISAS_EXC) {
637
 
        /* Note that this means single stepping WFI doesn't halt the CPU.
638
 
         * For conditional branch insns this is harmless unreachable code as
639
 
         * gen_goto_tb() has already handled emitting the debug exception
640
 
         * (and thus a tb-jump is not possible when singlestepping).
641
 
         */
642
 
        assert(dc->is_jmp != DISAS_TB_JUMP);
643
 
        if (dc->is_jmp != DISAS_JUMP) {
644
 
            gen_a64_set_pc_im(dc->pc);
645
 
        }
646
 
        gen_exception(EXCP_DEBUG);
647
 
    } else {
648
 
        switch (dc->is_jmp) {
649
 
        case DISAS_NEXT:
650
 
            gen_goto_tb(dc, 1, dc->pc);
651
 
            break;
652
 
        default:
653
 
        case DISAS_JUMP:
654
 
        case DISAS_UPDATE:
655
 
            /* indicate that the hash table must be used to find the next TB */
656
 
            tcg_gen_exit_tb(0);
657
 
            break;
658
 
        case DISAS_TB_JUMP:
659
 
        case DISAS_EXC:
660
 
        case DISAS_SWI:
661
 
            break;
662
 
        case DISAS_WFI:
663
 
            /* This is a special case because we don't want to just halt the CPU
664
 
             * if trying to debug across a WFI.
665
 
             */
666
 
            gen_helper_wfi(cpu_env);
667
 
            break;
668
 
        }
669
 
    }
670
 
 
671
 
done_generating:
672
 
    gen_tb_end(tb, num_insns);
673
 
    *tcg_ctx.gen_opc_ptr = INDEX_op_end;
674
 
 
675
 
#ifdef DEBUG_DISAS
676
 
    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
677
 
        qemu_log("----------------\n");
678
 
        qemu_log("IN: %s\n", lookup_symbol(pc_start));
679
 
        log_target_disas(env, pc_start, dc->pc - pc_start,
680
 
                         dc->thumb | (dc->bswap_code << 1));
681
 
        qemu_log("\n");
682
 
    }
683
 
#endif
684
 
    if (search_pc) {
685
 
        j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
686
 
        lj++;
687
 
        while (lj <= j) {
688
 
            tcg_ctx.gen_opc_instr_start[lj++] = 0;
689
 
        }
690
 
    } else {
691
 
        tb->size = dc->pc - pc_start;
692
 
        tb->icount = num_insns;
693
 
    }
694
 
}