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

« back to all changes in this revision

Viewing changes to .pc/ubuntu/arm64/0026-target-arm-A64-provide-functions-for-accessing-FPCR-.patch/target-arm/cpu.h

  • 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
 * ARM virtual CPU header
 
3
 *
 
4
 *  Copyright (c) 2003 Fabrice Bellard
 
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
#ifndef CPU_ARM_H
 
20
#define CPU_ARM_H
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include "kvm-consts.h"
 
25
 
 
26
#if defined(TARGET_AARCH64)
 
27
  /* AArch64 definitions */
 
28
#  define TARGET_LONG_BITS 64
 
29
#  define ELF_MACHINE EM_AARCH64
 
30
#else
 
31
#  define TARGET_LONG_BITS 32
 
32
#  define ELF_MACHINE EM_ARM
 
33
#endif
 
34
 
 
35
#define CPUArchState struct CPUARMState
 
36
 
 
37
#include "qemu-common.h"
 
38
#include "exec/cpu-defs.h"
 
39
 
 
40
#include "fpu/softfloat.h"
 
41
 
 
42
#define TARGET_HAS_ICE 1
 
43
 
 
44
#define EXCP_UDEF            1   /* undefined instruction */
 
45
#define EXCP_SWI             2   /* software interrupt */
 
46
#define EXCP_PREFETCH_ABORT  3
 
47
#define EXCP_DATA_ABORT      4
 
48
#define EXCP_IRQ             5
 
49
#define EXCP_FIQ             6
 
50
#define EXCP_BKPT            7
 
51
#define EXCP_EXCEPTION_EXIT  8   /* Return from v7M exception.  */
 
52
#define EXCP_KERNEL_TRAP     9   /* Jumped to kernel code page.  */
 
53
#define EXCP_STREX          10
 
54
#define EXCP_SMC            11   /* secure monitor call */
 
55
 
 
56
#define ARMV7M_EXCP_RESET   1
 
57
#define ARMV7M_EXCP_NMI     2
 
58
#define ARMV7M_EXCP_HARD    3
 
59
#define ARMV7M_EXCP_MEM     4
 
60
#define ARMV7M_EXCP_BUS     5
 
61
#define ARMV7M_EXCP_USAGE   6
 
62
#define ARMV7M_EXCP_SVC     11
 
63
#define ARMV7M_EXCP_DEBUG   12
 
64
#define ARMV7M_EXCP_PENDSV  14
 
65
#define ARMV7M_EXCP_SYSTICK 15
 
66
 
 
67
/* ARM-specific interrupt pending bits.  */
 
68
#define CPU_INTERRUPT_FIQ   CPU_INTERRUPT_TGT_EXT_1
 
69
 
 
70
/* Meanings of the ARMCPU object's two inbound GPIO lines */
 
71
#define ARM_CPU_IRQ 0
 
72
#define ARM_CPU_FIQ 1
 
73
 
 
74
typedef void ARMWriteCPFunc(void *opaque, int cp_info,
 
75
                            int srcreg, int operand, uint32_t value);
 
76
typedef uint32_t ARMReadCPFunc(void *opaque, int cp_info,
 
77
                               int dstreg, int operand);
 
78
 
 
79
struct arm_boot_info;
 
80
 
 
81
#define NB_MMU_MODES 2
 
82
 
 
83
/* We currently assume float and double are IEEE single and double
 
84
   precision respectively.
 
85
   Doing runtime conversions is tricky because VFP registers may contain
 
86
   integer values (eg. as the result of a FTOSI instruction).
 
87
   s<2n> maps to the least significant half of d<n>
 
88
   s<2n+1> maps to the most significant half of d<n>
 
89
 */
 
90
 
 
91
/* CPU state for each instance of a generic timer (in cp15 c14) */
 
92
typedef struct ARMGenericTimer {
 
93
    uint64_t cval; /* Timer CompareValue register */
 
94
    uint32_t ctl; /* Timer Control register */
 
95
} ARMGenericTimer;
 
96
 
 
97
#define GTIMER_PHYS 0
 
98
#define GTIMER_VIRT 1
 
99
#define NUM_GTIMERS 2
 
100
 
 
101
/* Scale factor for generic timers, ie number of ns per tick.
 
102
 * This gives a 62.5MHz timer.
 
103
 */
 
104
#define GTIMER_SCALE 16
 
105
 
 
106
typedef struct CPUARMState {
 
107
    /* Regs for current mode.  */
 
108
    uint32_t regs[16];
 
109
 
 
110
    /* 32/64 switch only happens when taking and returning from
 
111
     * exceptions so the overlap semantics are taken care of then
 
112
     * instead of having a complicated union.
 
113
     */
 
114
    /* Regs for A64 mode.  */
 
115
    uint64_t xregs[32];
 
116
    uint64_t pc;
 
117
    /* PSTATE isn't an architectural register for ARMv8. However, it is
 
118
     * convenient for us to assemble the underlying state into a 32 bit format
 
119
     * identical to the architectural format used for the SPSR. (This is also
 
120
     * what the Linux kernel's 'pstate' field in signal handlers and KVM's
 
121
     * 'pstate' register are.) Of the PSTATE bits:
 
122
     *  NZCV are kept in the split out env->CF/VF/NF/ZF, (which have the same
 
123
     *    semantics as for AArch32, as described in the comments on each field)
 
124
     *  nRW (also known as M[4]) is kept, inverted, in env->aarch64
 
125
     *  all other bits are stored in their correct places in env->pstate
 
126
     */
 
127
    uint32_t pstate;
 
128
    uint32_t aarch64; /* 1 if CPU is in aarch64 state; inverse of PSTATE.nRW */
 
129
 
 
130
    /* Frequently accessed CPSR bits are stored separately for efficiency.
 
131
       This contains all the other bits.  Use cpsr_{read,write} to access
 
132
       the whole CPSR.  */
 
133
    uint32_t uncached_cpsr;
 
134
    uint32_t spsr;
 
135
 
 
136
    /* Banked registers.  */
 
137
    uint32_t banked_spsr[7];
 
138
    uint32_t banked_r13[7];
 
139
    uint32_t banked_r14[7];
 
140
 
 
141
    /* These hold r8-r12.  */
 
142
    uint32_t usr_regs[5];
 
143
    uint32_t fiq_regs[5];
 
144
 
 
145
    /* cpsr flag cache for faster execution */
 
146
    uint32_t CF; /* 0 or 1 */
 
147
    uint32_t VF; /* V is the bit 31. All other bits are undefined */
 
148
    uint32_t NF; /* N is bit 31. All other bits are undefined.  */
 
149
    uint32_t ZF; /* Z set if zero.  */
 
150
    uint32_t QF; /* 0 or 1 */
 
151
    uint32_t GE; /* cpsr[19:16] */
 
152
    uint32_t thumb; /* cpsr[5]. 0 = arm mode, 1 = thumb mode. */
 
153
    uint32_t condexec_bits; /* IT bits.  cpsr[15:10,26:25].  */
 
154
 
 
155
    /* System control coprocessor (cp15) */
 
156
    struct {
 
157
        uint32_t c0_cpuid;
 
158
        uint32_t c0_cssel; /* Cache size selection.  */
 
159
        uint32_t c1_sys; /* System control register.  */
 
160
        uint32_t c1_coproc; /* Coprocessor access register.  */
 
161
        uint32_t c1_xscaleauxcr; /* XScale auxiliary control register.  */
 
162
        uint32_t c1_scr; /* secure config register.  */
 
163
        uint32_t c1_sedbg; /* Secure debug enable register. */
 
164
        uint32_t c1_nseac; /* Non-secure access control register. */
 
165
        uint32_t c2_base0; /* MMU translation table base 0.  */
 
166
        uint32_t c2_base0_hi; /* MMU translation table base 0, high 32 bits */
 
167
        uint32_t c2_base1; /* MMU translation table base 0.  */
 
168
        uint32_t c2_base1_hi; /* MMU translation table base 1, high 32 bits */
 
169
        uint32_t c2_control; /* MMU translation table base control.  */
 
170
        uint32_t c2_mask; /* MMU translation table base selection mask.  */
 
171
        uint32_t c2_base_mask; /* MMU translation table base 0 mask. */
 
172
        uint32_t c2_data; /* MPU data cachable bits.  */
 
173
        uint32_t c2_insn; /* MPU instruction cachable bits.  */
 
174
        uint32_t c3; /* MMU domain access control register
 
175
                        MPU write buffer control.  */
 
176
        uint32_t c5_insn; /* Fault status registers.  */
 
177
        uint32_t c5_data;
 
178
        uint32_t c6_region[8]; /* MPU base/size registers.  */
 
179
        uint32_t c6_insn; /* Fault address registers.  */
 
180
        uint32_t c6_data;
 
181
        uint32_t c7_par;  /* Translation result. */
 
182
        uint32_t c7_par_hi;  /* Translation result, high 32 bits */
 
183
        uint32_t c9_insn; /* Cache lockdown registers.  */
 
184
        uint32_t c9_data;
 
185
        uint32_t c9_pmcr; /* performance monitor control register */
 
186
        uint32_t c9_pmcnten; /* perf monitor counter enables */
 
187
        uint32_t c9_pmovsr; /* perf monitor overflow status */
 
188
        uint32_t c9_pmxevtyper; /* perf monitor event type */
 
189
        uint32_t c9_pmuserenr; /* perf monitor user enable */
 
190
        uint32_t c9_pminten; /* perf monitor interrupt enables */
 
191
        uint32_t c12_vbar; /* vector base address register */
 
192
        uint32_t c12_mvbar; /* monitor vector base address register. */
 
193
        uint32_t c13_fcse; /* FCSE PID.  */
 
194
        uint32_t c13_context; /* Context ID.  */
 
195
        uint32_t c13_tls1; /* User RW Thread register.  */
 
196
        uint32_t c13_tls2; /* User RO Thread register.  */
 
197
        uint32_t c13_tls3; /* Privileged Thread register.  */
 
198
        uint32_t c14_cntfrq; /* Counter Frequency register */
 
199
        uint32_t c14_cntkctl; /* Timer Control register */
 
200
        ARMGenericTimer c14_timer[NUM_GTIMERS];
 
201
        uint32_t c15_cpar; /* XScale Coprocessor Access Register */
 
202
        uint32_t c15_ticonfig; /* TI925T configuration byte.  */
 
203
        uint32_t c15_i_max; /* Maximum D-cache dirty line index.  */
 
204
        uint32_t c15_i_min; /* Minimum D-cache dirty line index.  */
 
205
        uint32_t c15_threadid; /* TI debugger thread-ID.  */
 
206
        uint32_t c15_config_base_address; /* SCU base address.  */
 
207
        uint32_t c15_diagnostic; /* diagnostic register */
 
208
        uint32_t c15_power_diagnostic;
 
209
        uint32_t c15_power_control; /* power control */
 
210
    } cp15;
 
211
 
 
212
    /* System registers (AArch64) */
 
213
    struct {
 
214
        uint64_t tpidr_el0;
 
215
    } sr;
 
216
 
 
217
    struct {
 
218
        uint32_t other_sp;
 
219
        uint32_t vecbase;
 
220
        uint32_t basepri;
 
221
        uint32_t control;
 
222
        int current_sp;
 
223
        int exception;
 
224
        int pending_exception;
 
225
    } v7m;
 
226
 
 
227
    /* Thumb-2 EE state.  */
 
228
    uint32_t teecr;
 
229
    uint32_t teehbr;
 
230
 
 
231
    /* VFP coprocessor state.  */
 
232
    struct {
 
233
        /* VFP/Neon register state. Note that the mapping between S, D and Q
 
234
         * views of the register bank differs between AArch64 and AArch32:
 
235
         * In AArch32:
 
236
         *  Qn = regs[2n+1]:regs[2n]
 
237
         *  Dn = regs[n]
 
238
         *  Sn = regs[n/2] bits 31..0 for even n, and bits 63..32 for odd n
 
239
         * (and regs[32] to regs[63] are inaccessible)
 
240
         * In AArch64:
 
241
         *  Qn = regs[2n+1]:regs[2n]
 
242
         *  Dn = regs[2n]
 
243
         *  Sn = regs[2n] bits 31..0
 
244
         * This corresponds to the architecturally defined mapping between
 
245
         * the two execution states, and means we do not need to explicitly
 
246
         * map these registers when changing states.
 
247
         */
 
248
        float64 regs[64];
 
249
 
 
250
        uint32_t xregs[16];
 
251
        /* We store these fpcsr fields separately for convenience.  */
 
252
        int vec_len;
 
253
        int vec_stride;
 
254
 
 
255
        /* scratch space when Tn are not sufficient.  */
 
256
        uint32_t scratch[8];
 
257
 
 
258
        /* fp_status is the "normal" fp status. standard_fp_status retains
 
259
         * values corresponding to the ARM "Standard FPSCR Value", ie
 
260
         * default-NaN, flush-to-zero, round-to-nearest and is used by
 
261
         * any operations (generally Neon) which the architecture defines
 
262
         * as controlled by the standard FPSCR value rather than the FPSCR.
 
263
         *
 
264
         * To avoid having to transfer exception bits around, we simply
 
265
         * say that the FPSCR cumulative exception flags are the logical
 
266
         * OR of the flags in the two fp statuses. This relies on the
 
267
         * only thing which needs to read the exception flags being
 
268
         * an explicit FPSCR read.
 
269
         */
 
270
        float_status fp_status;
 
271
        float_status standard_fp_status;
 
272
    } vfp;
 
273
    uint32_t exclusive_addr;
 
274
    uint32_t exclusive_val;
 
275
    uint32_t exclusive_high;
 
276
#if defined(CONFIG_USER_ONLY)
 
277
    uint32_t exclusive_test;
 
278
    uint32_t exclusive_info;
 
279
#endif
 
280
 
 
281
    /* iwMMXt coprocessor state.  */
 
282
    struct {
 
283
        uint64_t regs[16];
 
284
        uint64_t val;
 
285
 
 
286
        uint32_t cregs[16];
 
287
    } iwmmxt;
 
288
 
 
289
    /* For mixed endian mode.  */
 
290
    bool bswap_code;
 
291
 
 
292
#if defined(CONFIG_USER_ONLY)
 
293
    /* For usermode syscall translation.  */
 
294
    int eabi;
 
295
#endif
 
296
 
 
297
    CPU_COMMON
 
298
 
 
299
    /* These fields after the common ones so they are preserved on reset.  */
 
300
 
 
301
    /* Internal CPU feature flags.  */
 
302
    uint64_t features;
 
303
 
 
304
    void *nvic;
 
305
    const struct arm_boot_info *boot_info;
 
306
} CPUARMState;
 
307
 
 
308
#include "cpu-qom.h"
 
309
 
 
310
ARMCPU *cpu_arm_init(const char *cpu_model);
 
311
void arm_translate_init(void);
 
312
void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu);
 
313
int cpu_arm_exec(CPUARMState *s);
 
314
int bank_number(int mode);
 
315
void switch_mode(CPUARMState *, int);
 
316
uint32_t do_arm_semihosting(CPUARMState *env);
 
317
 
 
318
static inline bool is_a64(CPUARMState *env)
 
319
{
 
320
    return env->aarch64;
 
321
}
 
322
 
 
323
/* you can call this signal handler from your SIGBUS and SIGSEGV
 
324
   signal handlers to inform the virtual CPU of exceptions. non zero
 
325
   is returned if the signal was handled by the virtual CPU.  */
 
326
int cpu_arm_signal_handler(int host_signum, void *pinfo,
 
327
                           void *puc);
 
328
int cpu_arm_handle_mmu_fault (CPUARMState *env, target_ulong address, int rw,
 
329
                              int mmu_idx);
 
330
#define cpu_handle_mmu_fault cpu_arm_handle_mmu_fault
 
331
 
 
332
#define CPSR_M (0x1fU)
 
333
#define CPSR_T (1U << 5)
 
334
#define CPSR_F (1U << 6)
 
335
#define CPSR_I (1U << 7)
 
336
#define CPSR_A (1U << 8)
 
337
#define CPSR_E (1U << 9)
 
338
#define CPSR_IT_2_7 (0xfc00U)
 
339
#define CPSR_GE (0xfU << 16)
 
340
#define CPSR_RESERVED (0xfU << 20)
 
341
#define CPSR_J (1U << 24)
 
342
#define CPSR_IT_0_1 (3U << 25)
 
343
#define CPSR_Q (1U << 27)
 
344
#define CPSR_V (1U << 28)
 
345
#define CPSR_C (1U << 29)
 
346
#define CPSR_Z (1U << 30)
 
347
#define CPSR_N (1U << 31)
 
348
#define CPSR_NZCV (CPSR_N | CPSR_Z | CPSR_C | CPSR_V)
 
349
 
 
350
#define CPSR_IT (CPSR_IT_0_1 | CPSR_IT_2_7)
 
351
#define CACHED_CPSR_BITS (CPSR_T | CPSR_GE | CPSR_IT | CPSR_Q | CPSR_NZCV)
 
352
/* Bits writable in user mode.  */
 
353
#define CPSR_USER (CPSR_NZCV | CPSR_Q | CPSR_GE)
 
354
/* Execution state bits.  MRS read as zero, MSR writes ignored.  */
 
355
#define CPSR_EXEC (CPSR_T | CPSR_IT | CPSR_J)
 
356
 
 
357
/* Bit definitions for ARMv8 SPSR (PSTATE) format.
 
358
 * Only these are valid when in AArch64 mode; in
 
359
 * AArch32 mode SPSRs are basically CPSR-format.
 
360
 */
 
361
#define PSTATE_M (0xFU)
 
362
#define PSTATE_nRW (1U << 4)
 
363
#define PSTATE_F (1U << 6)
 
364
#define PSTATE_I (1U << 7)
 
365
#define PSTATE_A (1U << 8)
 
366
#define PSTATE_D (1U << 9)
 
367
#define PSTATE_IL (1U << 20)
 
368
#define PSTATE_SS (1U << 21)
 
369
#define PSTATE_V (1U << 28)
 
370
#define PSTATE_C (1U << 29)
 
371
#define PSTATE_Z (1U << 30)
 
372
#define PSTATE_N (1U << 31)
 
373
#define PSTATE_NZCV (PSTATE_N | PSTATE_Z | PSTATE_C | PSTATE_V)
 
374
#define CACHED_PSTATE_BITS (PSTATE_NZCV)
 
375
/* Mode values for AArch64 */
 
376
#define PSTATE_MODE_EL3h 13
 
377
#define PSTATE_MODE_EL3t 12
 
378
#define PSTATE_MODE_EL2h 9
 
379
#define PSTATE_MODE_EL2t 8
 
380
#define PSTATE_MODE_EL1h 5
 
381
#define PSTATE_MODE_EL1t 4
 
382
#define PSTATE_MODE_EL0t 0
 
383
 
 
384
/* Return the current PSTATE value. For the moment we don't support 32<->64 bit
 
385
 * interprocessing, so we don't attempt to sync with the cpsr state used by
 
386
 * the 32 bit decoder.
 
387
 */
 
388
static inline uint32_t pstate_read(CPUARMState *env)
 
389
{
 
390
    int ZF;
 
391
 
 
392
    ZF = (env->ZF == 0);
 
393
    return (env->NF & 0x80000000) | (ZF << 30)
 
394
        | (env->CF << 29) | ((env->VF & 0x80000000) >> 3)
 
395
        | env->pstate;
 
396
}
 
397
 
 
398
static inline void pstate_write(CPUARMState *env, uint32_t val)
 
399
{
 
400
    env->ZF = (~val) & PSTATE_Z;
 
401
    env->NF = val;
 
402
    env->CF = (val >> 29) & 1;
 
403
    env->VF = (val << 3) & 0x80000000;
 
404
    env->pstate = val & ~CACHED_PSTATE_BITS;
 
405
}
 
406
 
 
407
/* Return the current CPSR value.  */
 
408
uint32_t cpsr_read(CPUARMState *env);
 
409
/* Set the CPSR.  Note that some bits of mask must be all-set or all-clear.  */
 
410
void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask);
 
411
 
 
412
/* Return the current xPSR value.  */
 
413
static inline uint32_t xpsr_read(CPUARMState *env)
 
414
{
 
415
    int ZF;
 
416
    ZF = (env->ZF == 0);
 
417
    return (env->NF & 0x80000000) | (ZF << 30)
 
418
        | (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | (env->QF << 27)
 
419
        | (env->thumb << 24) | ((env->condexec_bits & 3) << 25)
 
420
        | ((env->condexec_bits & 0xfc) << 8)
 
421
        | env->v7m.exception;
 
422
}
 
423
 
 
424
/* Set the xPSR.  Note that some bits of mask must be all-set or all-clear.  */
 
425
static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
 
426
{
 
427
    if (mask & CPSR_NZCV) {
 
428
        env->ZF = (~val) & CPSR_Z;
 
429
        env->NF = val;
 
430
        env->CF = (val >> 29) & 1;
 
431
        env->VF = (val << 3) & 0x80000000;
 
432
    }
 
433
    if (mask & CPSR_Q)
 
434
        env->QF = ((val & CPSR_Q) != 0);
 
435
    if (mask & (1 << 24))
 
436
        env->thumb = ((val & (1 << 24)) != 0);
 
437
    if (mask & CPSR_IT_0_1) {
 
438
        env->condexec_bits &= ~3;
 
439
        env->condexec_bits |= (val >> 25) & 3;
 
440
    }
 
441
    if (mask & CPSR_IT_2_7) {
 
442
        env->condexec_bits &= 3;
 
443
        env->condexec_bits |= (val >> 8) & 0xfc;
 
444
    }
 
445
    if (mask & 0x1ff) {
 
446
        env->v7m.exception = val & 0x1ff;
 
447
    }
 
448
}
 
449
 
 
450
/* Return the current FPSCR value.  */
 
451
uint32_t vfp_get_fpscr(CPUARMState *env);
 
452
void vfp_set_fpscr(CPUARMState *env, uint32_t val);
 
453
 
 
454
enum arm_cpu_mode {
 
455
  ARM_CPU_MODE_USR = 0x10,
 
456
  ARM_CPU_MODE_FIQ = 0x11,
 
457
  ARM_CPU_MODE_IRQ = 0x12,
 
458
  ARM_CPU_MODE_SVC = 0x13,
 
459
  ARM_CPU_MODE_SMC = 0x16,
 
460
  ARM_CPU_MODE_ABT = 0x17,
 
461
  ARM_CPU_MODE_UND = 0x1b,
 
462
  ARM_CPU_MODE_SYS = 0x1f
 
463
};
 
464
 
 
465
/* VFP system registers.  */
 
466
#define ARM_VFP_FPSID   0
 
467
#define ARM_VFP_FPSCR   1
 
468
#define ARM_VFP_MVFR1   6
 
469
#define ARM_VFP_MVFR0   7
 
470
#define ARM_VFP_FPEXC   8
 
471
#define ARM_VFP_FPINST  9
 
472
#define ARM_VFP_FPINST2 10
 
473
 
 
474
/* iwMMXt coprocessor control registers.  */
 
475
#define ARM_IWMMXT_wCID         0
 
476
#define ARM_IWMMXT_wCon         1
 
477
#define ARM_IWMMXT_wCSSF        2
 
478
#define ARM_IWMMXT_wCASF        3
 
479
#define ARM_IWMMXT_wCGR0        8
 
480
#define ARM_IWMMXT_wCGR1        9
 
481
#define ARM_IWMMXT_wCGR2        10
 
482
#define ARM_IWMMXT_wCGR3        11
 
483
 
 
484
/* If adding a feature bit which corresponds to a Linux ELF
 
485
 * HWCAP bit, remember to update the feature-bit-to-hwcap
 
486
 * mapping in linux-user/elfload.c:get_elf_hwcap().
 
487
 */
 
488
enum arm_features {
 
489
    ARM_FEATURE_VFP,
 
490
    ARM_FEATURE_AUXCR,  /* ARM1026 Auxiliary control register.  */
 
491
    ARM_FEATURE_XSCALE, /* Intel XScale extensions.  */
 
492
    ARM_FEATURE_IWMMXT, /* Intel iwMMXt extension.  */
 
493
    ARM_FEATURE_V6,
 
494
    ARM_FEATURE_V6K,
 
495
    ARM_FEATURE_V7,
 
496
    ARM_FEATURE_THUMB2,
 
497
    ARM_FEATURE_MPU,    /* Only has Memory Protection Unit, not full MMU.  */
 
498
    ARM_FEATURE_VFP3,
 
499
    ARM_FEATURE_VFP_FP16,
 
500
    ARM_FEATURE_NEON,
 
501
    ARM_FEATURE_THUMB_DIV, /* divide supported in Thumb encoding */
 
502
    ARM_FEATURE_M, /* Microcontroller profile.  */
 
503
    ARM_FEATURE_OMAPCP, /* OMAP specific CP15 ops handling.  */
 
504
    ARM_FEATURE_THUMB2EE,
 
505
    ARM_FEATURE_V7MP,    /* v7 Multiprocessing Extensions */
 
506
    ARM_FEATURE_V4T,
 
507
    ARM_FEATURE_V5,
 
508
    ARM_FEATURE_STRONGARM,
 
509
    ARM_FEATURE_VAPA, /* cp15 VA to PA lookups */
 
510
    ARM_FEATURE_ARM_DIV, /* divide supported in ARM encoding */
 
511
    ARM_FEATURE_VFP4, /* VFPv4 (implies that NEON is v2) */
 
512
    ARM_FEATURE_GENERIC_TIMER,
 
513
    ARM_FEATURE_MVFR, /* Media and VFP Feature Registers 0 and 1 */
 
514
    ARM_FEATURE_DUMMY_C15_REGS, /* RAZ/WI all of cp15 crn=15 */
 
515
    ARM_FEATURE_CACHE_TEST_CLEAN, /* 926/1026 style test-and-clean ops */
 
516
    ARM_FEATURE_CACHE_DIRTY_REG, /* 1136/1176 cache dirty status register */
 
517
    ARM_FEATURE_CACHE_BLOCK_OPS, /* v6 optional cache block operations */
 
518
    ARM_FEATURE_MPIDR, /* has cp15 MPIDR */
 
519
    ARM_FEATURE_PXN, /* has Privileged Execute Never bit */
 
520
    ARM_FEATURE_LPAE, /* has Large Physical Address Extension */
 
521
    ARM_FEATURE_V8,
 
522
    ARM_FEATURE_AARCH64, /* supports 64 bit mode */
 
523
    ARM_FEATURE_TRUSTZONE, /* TrustZone Security Extensions. */
 
524
};
 
525
 
 
526
static inline int arm_feature(CPUARMState *env, int feature)
 
527
{
 
528
    return (env->features & (1ULL << feature)) != 0;
 
529
}
 
530
 
 
531
void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 
532
 
 
533
/* Interface between CPU and Interrupt controller.  */
 
534
void armv7m_nvic_set_pending(void *opaque, int irq);
 
535
int armv7m_nvic_acknowledge_irq(void *opaque);
 
536
void armv7m_nvic_complete_irq(void *opaque, int irq);
 
537
 
 
538
/* Interface for defining coprocessor registers.
 
539
 * Registers are defined in tables of arm_cp_reginfo structs
 
540
 * which are passed to define_arm_cp_regs().
 
541
 */
 
542
 
 
543
/* When looking up a coprocessor register we look for it
 
544
 * via an integer which encodes all of:
 
545
 *  coprocessor number
 
546
 *  Crn, Crm, opc1, opc2 fields
 
547
 *  32 or 64 bit register (ie is it accessed via MRC/MCR
 
548
 *    or via MRRC/MCRR?)
 
549
 * We allow 4 bits for opc1 because MRRC/MCRR have a 4 bit field.
 
550
 * (In this case crn and opc2 should be zero.)
 
551
 */
 
552
#define ENCODE_CP_REG(cp, is64, crn, crm, opc1, opc2)   \
 
553
    (((cp) << 16) | ((is64) << 15) | ((crn) << 11) |    \
 
554
     ((crm) << 7) | ((opc1) << 3) | (opc2))
 
555
 
 
556
/* Convert a full 64 bit KVM register ID to the truncated 32 bit
 
557
 * version used as a key for the coprocessor register hashtable
 
558
 */
 
559
static inline uint32_t kvm_to_cpreg_id(uint64_t kvmid)
 
560
{
 
561
    uint32_t cpregid = kvmid;
 
562
    if ((kvmid & CP_REG_SIZE_MASK) == CP_REG_SIZE_U64) {
 
563
        cpregid |= (1 << 15);
 
564
    }
 
565
    return cpregid;
 
566
}
 
567
 
 
568
/* Convert a truncated 32 bit hashtable key into the full
 
569
 * 64 bit KVM register ID.
 
570
 */
 
571
static inline uint64_t cpreg_to_kvm_id(uint32_t cpregid)
 
572
{
 
573
    uint64_t kvmid = cpregid & ~(1 << 15);
 
574
    if (cpregid & (1 << 15)) {
 
575
        kvmid |= CP_REG_SIZE_U64 | CP_REG_ARM;
 
576
    } else {
 
577
        kvmid |= CP_REG_SIZE_U32 | CP_REG_ARM;
 
578
    }
 
579
    return kvmid;
 
580
}
 
581
 
 
582
/* ARMCPRegInfo type field bits. If the SPECIAL bit is set this is a
 
583
 * special-behaviour cp reg and bits [15..8] indicate what behaviour
 
584
 * it has. Otherwise it is a simple cp reg, where CONST indicates that
 
585
 * TCG can assume the value to be constant (ie load at translate time)
 
586
 * and 64BIT indicates a 64 bit wide coprocessor register. SUPPRESS_TB_END
 
587
 * indicates that the TB should not be ended after a write to this register
 
588
 * (the default is that the TB ends after cp writes). OVERRIDE permits
 
589
 * a register definition to override a previous definition for the
 
590
 * same (cp, is64, crn, crm, opc1, opc2) tuple: either the new or the
 
591
 * old must have the OVERRIDE bit set.
 
592
 * NO_MIGRATE indicates that this register should be ignored for migration;
 
593
 * (eg because any state is accessed via some other coprocessor register).
 
594
 * IO indicates that this register does I/O and therefore its accesses
 
595
 * need to be surrounded by gen_io_start()/gen_io_end(). In particular,
 
596
 * registers which implement clocks or timers require this.
 
597
 */
 
598
#define ARM_CP_SPECIAL 1
 
599
#define ARM_CP_CONST 2
 
600
#define ARM_CP_64BIT 4
 
601
#define ARM_CP_SUPPRESS_TB_END 8
 
602
#define ARM_CP_OVERRIDE 16
 
603
#define ARM_CP_NO_MIGRATE 32
 
604
#define ARM_CP_IO 64
 
605
#define ARM_CP_NOP (ARM_CP_SPECIAL | (1 << 8))
 
606
#define ARM_CP_WFI (ARM_CP_SPECIAL | (2 << 8))
 
607
#define ARM_LAST_SPECIAL ARM_CP_WFI
 
608
/* Used only as a terminator for ARMCPRegInfo lists */
 
609
#define ARM_CP_SENTINEL 0xffff
 
610
/* Mask of only the flag bits in a type field */
 
611
#define ARM_CP_FLAG_MASK 0x7f
 
612
 
 
613
/* Return true if cptype is a valid type field. This is used to try to
 
614
 * catch errors where the sentinel has been accidentally left off the end
 
615
 * of a list of registers.
 
616
 */
 
617
static inline bool cptype_valid(int cptype)
 
618
{
 
619
    return ((cptype & ~ARM_CP_FLAG_MASK) == 0)
 
620
        || ((cptype & ARM_CP_SPECIAL) &&
 
621
            ((cptype & ~ARM_CP_FLAG_MASK) <= ARM_LAST_SPECIAL));
 
622
}
 
623
 
 
624
/* Access rights:
 
625
 * We define bits for Read and Write access for what rev C of the v7-AR ARM ARM
 
626
 * defines as PL0 (user), PL1 (fiq/irq/svc/abt/und/sys, ie privileged), and
 
627
 * PL2 (hyp). The other level which has Read and Write bits is Secure PL1
 
628
 * (ie any of the privileged modes in Secure state, or Monitor mode).
 
629
 * If a register is accessible in one privilege level it's always accessible
 
630
 * in higher privilege levels too. Since "Secure PL1" also follows this rule
 
631
 * (ie anything visible in PL2 is visible in S-PL1, some things are only
 
632
 * visible in S-PL1) but "Secure PL1" is a bit of a mouthful, we bend the
 
633
 * terminology a little and call this PL3.
 
634
 *
 
635
 * If access permissions for a register are more complex than can be
 
636
 * described with these bits, then use a laxer set of restrictions, and
 
637
 * do the more restrictive/complex check inside a helper function.
 
638
 */
 
639
#define PL3_R 0x80
 
640
#define PL3_W 0x40
 
641
#define PL2_R (0x20 | PL3_R)
 
642
#define PL2_W (0x10 | PL3_W)
 
643
#define PL1_R (0x08 | PL2_R)
 
644
#define PL1_W (0x04 | PL2_W)
 
645
#define PL0_R (0x02 | PL1_R)
 
646
#define PL0_W (0x01 | PL1_W)
 
647
 
 
648
#define PL3_RW (PL3_R | PL3_W)
 
649
#define PL2_RW (PL2_R | PL2_W)
 
650
#define PL1_RW (PL1_R | PL1_W)
 
651
#define PL0_RW (PL0_R | PL0_W)
 
652
 
 
653
static inline int arm_current_pl(CPUARMState *env)
 
654
{
 
655
    if ((env->uncached_cpsr & 0x1f) == ARM_CPU_MODE_USR) {
 
656
        return 0;
 
657
    }
 
658
    /* We don't currently implement the Virtualization or TrustZone
 
659
     * extensions, so PL2 and PL3 don't exist for us.
 
660
     */
 
661
    return 1;
 
662
}
 
663
 
 
664
typedef struct ARMCPRegInfo ARMCPRegInfo;
 
665
 
 
666
/* Access functions for coprocessor registers. These should return
 
667
 * 0 on success, or one of the EXCP_* constants if access should cause
 
668
 * an exception (in which case *value is not written).
 
669
 */
 
670
typedef int CPReadFn(CPUARMState *env, const ARMCPRegInfo *opaque,
 
671
                     uint64_t *value);
 
672
typedef int CPWriteFn(CPUARMState *env, const ARMCPRegInfo *opaque,
 
673
                      uint64_t value);
 
674
/* Hook function for register reset */
 
675
typedef void CPResetFn(CPUARMState *env, const ARMCPRegInfo *opaque);
 
676
 
 
677
#define CP_ANY 0xff
 
678
 
 
679
/* Definition of an ARM coprocessor register */
 
680
struct ARMCPRegInfo {
 
681
    /* Name of register (useful mainly for debugging, need not be unique) */
 
682
    const char *name;
 
683
    /* Location of register: coprocessor number and (crn,crm,opc1,opc2)
 
684
     * tuple. Any of crm, opc1 and opc2 may be CP_ANY to indicate a
 
685
     * 'wildcard' field -- any value of that field in the MRC/MCR insn
 
686
     * will be decoded to this register. The register read and write
 
687
     * callbacks will be passed an ARMCPRegInfo with the crn/crm/opc1/opc2
 
688
     * used by the program, so it is possible to register a wildcard and
 
689
     * then behave differently on read/write if necessary.
 
690
     * For 64 bit registers, only crm and opc1 are relevant; crn and opc2
 
691
     * must both be zero.
 
692
     */
 
693
    uint8_t cp;
 
694
    uint8_t crn;
 
695
    uint8_t crm;
 
696
    uint8_t opc1;
 
697
    uint8_t opc2;
 
698
    /* Register type: ARM_CP_* bits/values */
 
699
    int type;
 
700
    /* Access rights: PL*_[RW] */
 
701
    int access;
 
702
    /* The opaque pointer passed to define_arm_cp_regs_with_opaque() when
 
703
     * this register was defined: can be used to hand data through to the
 
704
     * register read/write functions, since they are passed the ARMCPRegInfo*.
 
705
     */
 
706
    void *opaque;
 
707
    /* Value of this register, if it is ARM_CP_CONST. Otherwise, if
 
708
     * fieldoffset is non-zero, the reset value of the register.
 
709
     */
 
710
    uint64_t resetvalue;
 
711
    /* Offset of the field in CPUARMState for this register. This is not
 
712
     * needed if either:
 
713
     *  1. type is ARM_CP_CONST or one of the ARM_CP_SPECIALs
 
714
     *  2. both readfn and writefn are specified
 
715
     */
 
716
    ptrdiff_t fieldoffset; /* offsetof(CPUARMState, field) */
 
717
    /* Function for handling reads of this register. If NULL, then reads
 
718
     * will be done by loading from the offset into CPUARMState specified
 
719
     * by fieldoffset.
 
720
     */
 
721
    CPReadFn *readfn;
 
722
    /* Function for handling writes of this register. If NULL, then writes
 
723
     * will be done by writing to the offset into CPUARMState specified
 
724
     * by fieldoffset.
 
725
     */
 
726
    CPWriteFn *writefn;
 
727
    /* Function for doing a "raw" read; used when we need to copy
 
728
     * coprocessor state to the kernel for KVM or out for
 
729
     * migration. This only needs to be provided if there is also a
 
730
     * readfn and it makes an access permission check.
 
731
     */
 
732
    CPReadFn *raw_readfn;
 
733
    /* Function for doing a "raw" write; used when we need to copy KVM
 
734
     * kernel coprocessor state into userspace, or for inbound
 
735
     * migration. This only needs to be provided if there is also a
 
736
     * writefn and it makes an access permission check or masks out
 
737
     * "unwritable" bits or has write-one-to-clear or similar behaviour.
 
738
     */
 
739
    CPWriteFn *raw_writefn;
 
740
    /* Function for resetting the register. If NULL, then reset will be done
 
741
     * by writing resetvalue to the field specified in fieldoffset. If
 
742
     * fieldoffset is 0 then no reset will be done.
 
743
     */
 
744
    CPResetFn *resetfn;
 
745
};
 
746
 
 
747
/* Macros which are lvalues for the field in CPUARMState for the
 
748
 * ARMCPRegInfo *ri.
 
749
 */
 
750
#define CPREG_FIELD32(env, ri) \
 
751
    (*(uint32_t *)((char *)(env) + (ri)->fieldoffset))
 
752
#define CPREG_FIELD64(env, ri) \
 
753
    (*(uint64_t *)((char *)(env) + (ri)->fieldoffset))
 
754
 
 
755
#define REGINFO_SENTINEL { .type = ARM_CP_SENTINEL }
 
756
 
 
757
void define_arm_cp_regs_with_opaque(ARMCPU *cpu,
 
758
                                    const ARMCPRegInfo *regs, void *opaque);
 
759
void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
 
760
                                       const ARMCPRegInfo *regs, void *opaque);
 
761
static inline void define_arm_cp_regs(ARMCPU *cpu, const ARMCPRegInfo *regs)
 
762
{
 
763
    define_arm_cp_regs_with_opaque(cpu, regs, 0);
 
764
}
 
765
static inline void define_one_arm_cp_reg(ARMCPU *cpu, const ARMCPRegInfo *regs)
 
766
{
 
767
    define_one_arm_cp_reg_with_opaque(cpu, regs, 0);
 
768
}
 
769
const ARMCPRegInfo *get_arm_cp_reginfo(ARMCPU *cpu, uint32_t encoded_cp);
 
770
 
 
771
/* CPWriteFn that can be used to implement writes-ignored behaviour */
 
772
int arm_cp_write_ignore(CPUARMState *env, const ARMCPRegInfo *ri,
 
773
                        uint64_t value);
 
774
/* CPReadFn that can be used for read-as-zero behaviour */
 
775
int arm_cp_read_zero(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t *value);
 
776
 
 
777
static inline bool cp_access_ok(CPUARMState *env,
 
778
                                const ARMCPRegInfo *ri, int isread)
 
779
{
 
780
    return (ri->access >> ((arm_current_pl(env) * 2) + isread)) & 1;
 
781
}
 
782
 
 
783
/**
 
784
 * write_list_to_cpustate
 
785
 * @cpu: ARMCPU
 
786
 *
 
787
 * For each register listed in the ARMCPU cpreg_indexes list, write
 
788
 * its value from the cpreg_values list into the ARMCPUState structure.
 
789
 * This updates TCG's working data structures from KVM data or
 
790
 * from incoming migration state.
 
791
 *
 
792
 * Returns: true if all register values were updated correctly,
 
793
 * false if some register was unknown or could not be written.
 
794
 * Note that we do not stop early on failure -- we will attempt
 
795
 * writing all registers in the list.
 
796
 */
 
797
bool write_list_to_cpustate(ARMCPU *cpu);
 
798
 
 
799
/**
 
800
 * write_cpustate_to_list:
 
801
 * @cpu: ARMCPU
 
802
 *
 
803
 * For each register listed in the ARMCPU cpreg_indexes list, write
 
804
 * its value from the ARMCPUState structure into the cpreg_values list.
 
805
 * This is used to copy info from TCG's working data structures into
 
806
 * KVM or for outbound migration.
 
807
 *
 
808
 * Returns: true if all register values were read correctly,
 
809
 * false if some register was unknown or could not be read.
 
810
 * Note that we do not stop early on failure -- we will attempt
 
811
 * reading all registers in the list.
 
812
 */
 
813
bool write_cpustate_to_list(ARMCPU *cpu);
 
814
 
 
815
/* Does the core conform to the the "MicroController" profile. e.g. Cortex-M3.
 
816
   Note the M in older cores (eg. ARM7TDMI) stands for Multiply. These are
 
817
   conventional cores (ie. Application or Realtime profile).  */
 
818
 
 
819
#define IS_M(env) arm_feature(env, ARM_FEATURE_M)
 
820
 
 
821
#define ARM_CPUID_TI915T      0x54029152
 
822
#define ARM_CPUID_TI925T      0x54029252
 
823
 
 
824
#if defined(CONFIG_USER_ONLY)
 
825
#define TARGET_PAGE_BITS 12
 
826
#else
 
827
/* The ARM MMU allows 1k pages.  */
 
828
/* ??? Linux doesn't actually use these, and they're deprecated in recent
 
829
   architecture revisions.  Maybe a configure option to disable them.  */
 
830
#define TARGET_PAGE_BITS 10
 
831
#endif
 
832
 
 
833
#if defined(TARGET_AARCH64)
 
834
#  define TARGET_PHYS_ADDR_SPACE_BITS 48
 
835
#  define TARGET_VIRT_ADDR_SPACE_BITS 64
 
836
#else
 
837
#  define TARGET_PHYS_ADDR_SPACE_BITS 40
 
838
#  define TARGET_VIRT_ADDR_SPACE_BITS 32
 
839
#endif
 
840
 
 
841
static inline CPUARMState *cpu_init(const char *cpu_model)
 
842
{
 
843
    ARMCPU *cpu = cpu_arm_init(cpu_model);
 
844
    if (cpu) {
 
845
        return &cpu->env;
 
846
    }
 
847
    return NULL;
 
848
}
 
849
 
 
850
#define cpu_exec cpu_arm_exec
 
851
#define cpu_gen_code cpu_arm_gen_code
 
852
#define cpu_signal_handler cpu_arm_signal_handler
 
853
#define cpu_list arm_cpu_list
 
854
 
 
855
/* MMU modes definitions */
 
856
#define MMU_MODE0_SUFFIX _kernel
 
857
#define MMU_MODE1_SUFFIX _user
 
858
#define MMU_USER_IDX 1
 
859
static inline int cpu_mmu_index (CPUARMState *env)
 
860
{
 
861
    return (env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_USR ? 1 : 0;
 
862
}
 
863
 
 
864
#include "exec/cpu-all.h"
 
865
 
 
866
/* Bit usage in the TB flags field: bit 31 indicates whether we are
 
867
 * in 32 or 64 bit mode. The meaning of the other bits depends on that.
 
868
 */
 
869
#define ARM_TBFLAG_AARCH64_STATE_SHIFT 31
 
870
#define ARM_TBFLAG_AARCH64_STATE_MASK  (1U << ARM_TBFLAG_AARCH64_STATE_SHIFT)
 
871
 
 
872
/* Bit usage when in AArch32 state: */
 
873
#define ARM_TBFLAG_THUMB_SHIFT      0
 
874
#define ARM_TBFLAG_THUMB_MASK       (1 << ARM_TBFLAG_THUMB_SHIFT)
 
875
#define ARM_TBFLAG_VECLEN_SHIFT     1
 
876
#define ARM_TBFLAG_VECLEN_MASK      (0x7 << ARM_TBFLAG_VECLEN_SHIFT)
 
877
#define ARM_TBFLAG_VECSTRIDE_SHIFT  4
 
878
#define ARM_TBFLAG_VECSTRIDE_MASK   (0x3 << ARM_TBFLAG_VECSTRIDE_SHIFT)
 
879
#define ARM_TBFLAG_PRIV_SHIFT       6
 
880
#define ARM_TBFLAG_PRIV_MASK        (1 << ARM_TBFLAG_PRIV_SHIFT)
 
881
#define ARM_TBFLAG_VFPEN_SHIFT      7
 
882
#define ARM_TBFLAG_VFPEN_MASK       (1 << ARM_TBFLAG_VFPEN_SHIFT)
 
883
#define ARM_TBFLAG_CONDEXEC_SHIFT   8
 
884
#define ARM_TBFLAG_CONDEXEC_MASK    (0xff << ARM_TBFLAG_CONDEXEC_SHIFT)
 
885
#define ARM_TBFLAG_BSWAP_CODE_SHIFT 16
 
886
#define ARM_TBFLAG_BSWAP_CODE_MASK  (1 << ARM_TBFLAG_BSWAP_CODE_SHIFT)
 
887
 
 
888
/* Bit usage when in AArch64 state: currently no bits defined */
 
889
 
 
890
/* some convenience accessor macros */
 
891
#define ARM_TBFLAG_AARCH64_STATE(F) \
 
892
    (((F) & ARM_TBFLAG_AARCH64_STATE_MASK) >> ARM_TBFLAG_AARCH64_STATE_SHIFT)
 
893
#define ARM_TBFLAG_THUMB(F) \
 
894
    (((F) & ARM_TBFLAG_THUMB_MASK) >> ARM_TBFLAG_THUMB_SHIFT)
 
895
#define ARM_TBFLAG_VECLEN(F) \
 
896
    (((F) & ARM_TBFLAG_VECLEN_MASK) >> ARM_TBFLAG_VECLEN_SHIFT)
 
897
#define ARM_TBFLAG_VECSTRIDE(F) \
 
898
    (((F) & ARM_TBFLAG_VECSTRIDE_MASK) >> ARM_TBFLAG_VECSTRIDE_SHIFT)
 
899
#define ARM_TBFLAG_PRIV(F) \
 
900
    (((F) & ARM_TBFLAG_PRIV_MASK) >> ARM_TBFLAG_PRIV_SHIFT)
 
901
#define ARM_TBFLAG_VFPEN(F) \
 
902
    (((F) & ARM_TBFLAG_VFPEN_MASK) >> ARM_TBFLAG_VFPEN_SHIFT)
 
903
#define ARM_TBFLAG_CONDEXEC(F) \
 
904
    (((F) & ARM_TBFLAG_CONDEXEC_MASK) >> ARM_TBFLAG_CONDEXEC_SHIFT)
 
905
#define ARM_TBFLAG_BSWAP_CODE(F) \
 
906
    (((F) & ARM_TBFLAG_BSWAP_CODE_MASK) >> ARM_TBFLAG_BSWAP_CODE_SHIFT)
 
907
 
 
908
static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc,
 
909
                                        target_ulong *cs_base, int *flags)
 
910
{
 
911
    if (is_a64(env)) {
 
912
        *pc = env->pc;
 
913
        *flags = ARM_TBFLAG_AARCH64_STATE_MASK;
 
914
    } else {
 
915
        int privmode;
 
916
        *pc = env->regs[15];
 
917
        *flags = (env->thumb << ARM_TBFLAG_THUMB_SHIFT)
 
918
            | (env->vfp.vec_len << ARM_TBFLAG_VECLEN_SHIFT)
 
919
            | (env->vfp.vec_stride << ARM_TBFLAG_VECSTRIDE_SHIFT)
 
920
            | (env->condexec_bits << ARM_TBFLAG_CONDEXEC_SHIFT)
 
921
            | (env->bswap_code << ARM_TBFLAG_BSWAP_CODE_SHIFT);
 
922
        if (arm_feature(env, ARM_FEATURE_M)) {
 
923
            privmode = !((env->v7m.exception == 0) && (env->v7m.control & 1));
 
924
        } else {
 
925
            privmode = (env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_USR;
 
926
        }
 
927
        if (privmode) {
 
928
            *flags |= ARM_TBFLAG_PRIV_MASK;
 
929
        }
 
930
        if (env->vfp.xregs[ARM_VFP_FPEXC] & (1 << 30)) {
 
931
            *flags |= ARM_TBFLAG_VFPEN_MASK;
 
932
        }
 
933
    }
 
934
 
 
935
    *cs_base = 0;
 
936
}
 
937
 
 
938
static inline bool cpu_has_work(CPUState *cpu)
 
939
{
 
940
    return cpu->interrupt_request &
 
941
        (CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD | CPU_INTERRUPT_EXITTB);
 
942
}
 
943
 
 
944
#include "exec/exec-all.h"
 
945
 
 
946
static inline void cpu_pc_from_tb(CPUARMState *env, TranslationBlock *tb)
 
947
{
 
948
    if (ARM_TBFLAG_AARCH64_STATE(tb->flags)) {
 
949
        env->pc = tb->pc;
 
950
    } else {
 
951
        env->regs[15] = tb->pc;
 
952
    }
 
953
}
 
954
 
 
955
/* Load an instruction and return it in the standard little-endian order */
 
956
static inline uint32_t arm_ldl_code(CPUARMState *env, target_ulong addr,
 
957
                                    bool do_swap)
 
958
{
 
959
    uint32_t insn = cpu_ldl_code(env, addr);
 
960
    if (do_swap) {
 
961
        return bswap32(insn);
 
962
    }
 
963
    return insn;
 
964
}
 
965
 
 
966
/* Ditto, for a halfword (Thumb) instruction */
 
967
static inline uint16_t arm_lduw_code(CPUARMState *env, target_ulong addr,
 
968
                                     bool do_swap)
 
969
{
 
970
    uint16_t insn = cpu_lduw_code(env, addr);
 
971
    if (do_swap) {
 
972
        return bswap16(insn);
 
973
    }
 
974
    return insn;
 
975
}
 
976
 
 
977
#endif