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