2 * QEMU ARM CPU -- internal functions and types
4 * Copyright (c) 2014 Linaro Ltd
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see
18 * <http://www.gnu.org/licenses/gpl-2.0.html>
20 * This header defines functions, types, etc which need to be shared
21 * between different source files within target/arm/ but which are
22 * private to it and not required by the rest of QEMU.
25 #ifndef TARGET_ARM_INTERNALS_H
26 #define TARGET_ARM_INTERNALS_H
28 #include "hw/registerfields.h"
30 /* register banks for CPU modes */
40 static inline bool excp_is_internal(int excp
)
42 /* Return true if this exception number represents a QEMU-internal
43 * exception that will not be passed to the guest.
45 return excp
== EXCP_INTERRUPT
48 || excp
== EXCP_HALTED
49 || excp
== EXCP_EXCEPTION_EXIT
50 || excp
== EXCP_KERNEL_TRAP
51 || excp
== EXCP_SEMIHOST
;
54 /* Scale factor for generic timers, ie number of ns per tick.
55 * This gives a 62.5MHz timer.
57 #define GTIMER_SCALE 16
59 /* Bit definitions for the v7M CONTROL register */
60 FIELD(V7M_CONTROL
, NPRIV
, 0, 1)
61 FIELD(V7M_CONTROL
, SPSEL
, 1, 1)
62 FIELD(V7M_CONTROL
, FPCA
, 2, 1)
63 FIELD(V7M_CONTROL
, SFPA
, 3, 1)
65 /* Bit definitions for v7M exception return payload */
66 FIELD(V7M_EXCRET
, ES
, 0, 1)
67 FIELD(V7M_EXCRET
, RES0
, 1, 1)
68 FIELD(V7M_EXCRET
, SPSEL
, 2, 1)
69 FIELD(V7M_EXCRET
, MODE
, 3, 1)
70 FIELD(V7M_EXCRET
, FTYPE
, 4, 1)
71 FIELD(V7M_EXCRET
, DCRS
, 5, 1)
72 FIELD(V7M_EXCRET
, S
, 6, 1)
73 FIELD(V7M_EXCRET
, RES1
, 7, 25) /* including the must-be-1 prefix */
75 /* Minimum value which is a magic number for exception return */
76 #define EXC_RETURN_MIN_MAGIC 0xff000000
77 /* Minimum number which is a magic number for function or exception return
78 * when using v8M security extension
80 #define FNC_RETURN_MIN_MAGIC 0xfefffffe
82 /* We use a few fake FSR values for internal purposes in M profile.
83 * M profile cores don't have A/R format FSRs, but currently our
84 * get_phys_addr() code assumes A/R profile and reports failures via
85 * an A/R format FSR value. We then translate that into the proper
86 * M profile exception and FSR status bit in arm_v7m_cpu_do_interrupt().
87 * Mostly the FSR values we use for this are those defined for v7PMSA,
88 * since we share some of that codepath. A few kinds of fault are
89 * only for M profile and have no A/R equivalent, though, so we have
90 * to pick a value from the reserved range (which we never otherwise
91 * generate) to use for these.
92 * These values will never be visible to the guest.
94 #define M_FAKE_FSR_NSC_EXEC 0xf /* NS executing in S&NSC memory */
95 #define M_FAKE_FSR_SFAULT 0xe /* SecureFault INVTRAN, INVEP or AUVIOL */
98 * raise_exception: Raise the specified exception.
99 * Raise a guest exception with the specified value, syndrome register
100 * and target exception level. This should be called from helper functions,
101 * and never returns because we will longjump back up to the CPU main loop.
103 void QEMU_NORETURN
raise_exception(CPUARMState
*env
, uint32_t excp
,
104 uint32_t syndrome
, uint32_t target_el
);
107 * For AArch64, map a given EL to an index in the banked_spsr array.
108 * Note that this mapping and the AArch32 mapping defined in bank_number()
109 * must agree such that the AArch64<->AArch32 SPSRs have the architecturally
110 * mandated mapping between each other.
112 static inline unsigned int aarch64_banked_spsr_index(unsigned int el
)
114 static const unsigned int map
[4] = {
115 [1] = BANK_SVC
, /* EL1. */
116 [2] = BANK_HYP
, /* EL2. */
117 [3] = BANK_MON
, /* EL3. */
119 assert(el
>= 1 && el
<= 3);
123 /* Map CPU modes onto saved register banks. */
124 static inline int bank_number(int mode
)
127 case ARM_CPU_MODE_USR
:
128 case ARM_CPU_MODE_SYS
:
130 case ARM_CPU_MODE_SVC
:
132 case ARM_CPU_MODE_ABT
:
134 case ARM_CPU_MODE_UND
:
136 case ARM_CPU_MODE_IRQ
:
138 case ARM_CPU_MODE_FIQ
:
140 case ARM_CPU_MODE_HYP
:
142 case ARM_CPU_MODE_MON
:
145 g_assert_not_reached();
148 void arm_cpu_register_gdb_regs_for_features(ARMCPU
*cpu
);
149 void arm_translate_init(void);
151 enum arm_fprounding
{
160 int arm_rmode_to_sf(int rmode
);
162 static inline void aarch64_save_sp(CPUARMState
*env
, int el
)
164 if (env
->pstate
& PSTATE_SP
) {
165 env
->sp_el
[el
] = env
->xregs
[31];
167 env
->sp_el
[0] = env
->xregs
[31];
171 static inline void aarch64_restore_sp(CPUARMState
*env
, int el
)
173 if (env
->pstate
& PSTATE_SP
) {
174 env
->xregs
[31] = env
->sp_el
[el
];
176 env
->xregs
[31] = env
->sp_el
[0];
180 static inline void update_spsel(CPUARMState
*env
, uint32_t imm
)
182 unsigned int cur_el
= arm_current_el(env
);
183 /* Update PSTATE SPSel bit; this requires us to update the
184 * working stack pointer in xregs[31].
186 if (!((imm
^ env
->pstate
) & PSTATE_SP
)) {
189 aarch64_save_sp(env
, cur_el
);
190 env
->pstate
= deposit32(env
->pstate
, 0, 1, imm
);
192 /* We rely on illegal updates to SPsel from EL0 to get trapped
193 * at translation time.
195 assert(cur_el
>= 1 && cur_el
<= 3);
196 aarch64_restore_sp(env
, cur_el
);
203 * Returns the implementation defined bit-width of physical addresses.
204 * The ARMv8 reference manuals refer to this as PAMax().
206 static inline unsigned int arm_pamax(ARMCPU
*cpu
)
208 static const unsigned int pamax_map
[] = {
216 unsigned int parange
= extract32(cpu
->id_aa64mmfr0
, 0, 4);
218 /* id_aa64mmfr0 is a read-only register so values outside of the
219 * supported mappings can be considered an implementation error. */
220 assert(parange
< ARRAY_SIZE(pamax_map
));
221 return pamax_map
[parange
];
224 /* Return true if extended addresses are enabled.
225 * This is always the case if our translation regime is 64 bit,
226 * but depends on TTBCR.EAE for 32 bit.
228 static inline bool extended_addresses_enabled(CPUARMState
*env
)
230 TCR
*tcr
= &env
->cp15
.tcr_el
[arm_is_secure(env
) ? 3 : 1];
231 return arm_el_is_aa64(env
, 1) ||
232 (arm_feature(env
, ARM_FEATURE_LPAE
) && (tcr
->raw_tcr
& TTBCR_EAE
));
235 /* Valid Syndrome Register EC field values */
236 enum arm_exception_class
{
237 EC_UNCATEGORIZED
= 0x00,
239 EC_CP15RTTRAP
= 0x03,
240 EC_CP15RRTTRAP
= 0x04,
241 EC_CP14RTTRAP
= 0x05,
242 EC_CP14DTTRAP
= 0x06,
243 EC_ADVSIMDFPACCESSTRAP
= 0x07,
245 EC_CP14RRTTRAP
= 0x0c,
246 EC_ILLEGALSTATE
= 0x0e,
253 EC_SYSTEMREGISTERTRAP
= 0x18,
254 EC_SVEACCESSTRAP
= 0x19,
256 EC_INSNABORT_SAME_EL
= 0x21,
257 EC_PCALIGNMENT
= 0x22,
259 EC_DATAABORT_SAME_EL
= 0x25,
260 EC_SPALIGNMENT
= 0x26,
261 EC_AA32_FPTRAP
= 0x28,
262 EC_AA64_FPTRAP
= 0x2c,
264 EC_BREAKPOINT
= 0x30,
265 EC_BREAKPOINT_SAME_EL
= 0x31,
266 EC_SOFTWARESTEP
= 0x32,
267 EC_SOFTWARESTEP_SAME_EL
= 0x33,
268 EC_WATCHPOINT
= 0x34,
269 EC_WATCHPOINT_SAME_EL
= 0x35,
271 EC_VECTORCATCH
= 0x3a,
275 #define ARM_EL_EC_SHIFT 26
276 #define ARM_EL_IL_SHIFT 25
277 #define ARM_EL_ISV_SHIFT 24
278 #define ARM_EL_IL (1 << ARM_EL_IL_SHIFT)
279 #define ARM_EL_ISV (1 << ARM_EL_ISV_SHIFT)
281 static inline uint32_t syn_get_ec(uint32_t syn
)
283 return syn
>> ARM_EL_EC_SHIFT
;
286 /* Utility functions for constructing various kinds of syndrome value.
287 * Note that in general we follow the AArch64 syndrome values; in a
288 * few cases the value in HSR for exceptions taken to AArch32 Hyp
289 * mode differs slightly, so if we ever implemented Hyp mode then the
290 * syndrome value would need some massaging on exception entry.
291 * (One example of this is that AArch64 defaults to IL bit set for
292 * exceptions which don't specifically indicate information about the
293 * trapping instruction, whereas AArch32 defaults to IL bit clear.)
295 static inline uint32_t syn_uncategorized(void)
297 return (EC_UNCATEGORIZED
<< ARM_EL_EC_SHIFT
) | ARM_EL_IL
;
300 static inline uint32_t syn_aa64_svc(uint32_t imm16
)
302 return (EC_AA64_SVC
<< ARM_EL_EC_SHIFT
) | ARM_EL_IL
| (imm16
& 0xffff);
305 static inline uint32_t syn_aa64_hvc(uint32_t imm16
)
307 return (EC_AA64_HVC
<< ARM_EL_EC_SHIFT
) | ARM_EL_IL
| (imm16
& 0xffff);
310 static inline uint32_t syn_aa64_smc(uint32_t imm16
)
312 return (EC_AA64_SMC
<< ARM_EL_EC_SHIFT
) | ARM_EL_IL
| (imm16
& 0xffff);
315 static inline uint32_t syn_aa32_svc(uint32_t imm16
, bool is_16bit
)
317 return (EC_AA32_SVC
<< ARM_EL_EC_SHIFT
) | (imm16
& 0xffff)
318 | (is_16bit
? 0 : ARM_EL_IL
);
321 static inline uint32_t syn_aa32_hvc(uint32_t imm16
)
323 return (EC_AA32_HVC
<< ARM_EL_EC_SHIFT
) | ARM_EL_IL
| (imm16
& 0xffff);
326 static inline uint32_t syn_aa32_smc(void)
328 return (EC_AA32_SMC
<< ARM_EL_EC_SHIFT
) | ARM_EL_IL
;
331 static inline uint32_t syn_aa64_bkpt(uint32_t imm16
)
333 return (EC_AA64_BKPT
<< ARM_EL_EC_SHIFT
) | ARM_EL_IL
| (imm16
& 0xffff);
336 static inline uint32_t syn_aa32_bkpt(uint32_t imm16
, bool is_16bit
)
338 return (EC_AA32_BKPT
<< ARM_EL_EC_SHIFT
) | (imm16
& 0xffff)
339 | (is_16bit
? 0 : ARM_EL_IL
);
342 static inline uint32_t syn_aa64_sysregtrap(int op0
, int op1
, int op2
,
343 int crn
, int crm
, int rt
,
346 return (EC_SYSTEMREGISTERTRAP
<< ARM_EL_EC_SHIFT
) | ARM_EL_IL
347 | (op0
<< 20) | (op2
<< 17) | (op1
<< 14) | (crn
<< 10) | (rt
<< 5)
348 | (crm
<< 1) | isread
;
351 static inline uint32_t syn_cp14_rt_trap(int cv
, int cond
, int opc1
, int opc2
,
352 int crn
, int crm
, int rt
, int isread
,
355 return (EC_CP14RTTRAP
<< ARM_EL_EC_SHIFT
)
356 | (is_16bit
? 0 : ARM_EL_IL
)
357 | (cv
<< 24) | (cond
<< 20) | (opc2
<< 17) | (opc1
<< 14)
358 | (crn
<< 10) | (rt
<< 5) | (crm
<< 1) | isread
;
361 static inline uint32_t syn_cp15_rt_trap(int cv
, int cond
, int opc1
, int opc2
,
362 int crn
, int crm
, int rt
, int isread
,
365 return (EC_CP15RTTRAP
<< ARM_EL_EC_SHIFT
)
366 | (is_16bit
? 0 : ARM_EL_IL
)
367 | (cv
<< 24) | (cond
<< 20) | (opc2
<< 17) | (opc1
<< 14)
368 | (crn
<< 10) | (rt
<< 5) | (crm
<< 1) | isread
;
371 static inline uint32_t syn_cp14_rrt_trap(int cv
, int cond
, int opc1
, int crm
,
372 int rt
, int rt2
, int isread
,
375 return (EC_CP14RRTTRAP
<< ARM_EL_EC_SHIFT
)
376 | (is_16bit
? 0 : ARM_EL_IL
)
377 | (cv
<< 24) | (cond
<< 20) | (opc1
<< 16)
378 | (rt2
<< 10) | (rt
<< 5) | (crm
<< 1) | isread
;
381 static inline uint32_t syn_cp15_rrt_trap(int cv
, int cond
, int opc1
, int crm
,
382 int rt
, int rt2
, int isread
,
385 return (EC_CP15RRTTRAP
<< ARM_EL_EC_SHIFT
)
386 | (is_16bit
? 0 : ARM_EL_IL
)
387 | (cv
<< 24) | (cond
<< 20) | (opc1
<< 16)
388 | (rt2
<< 10) | (rt
<< 5) | (crm
<< 1) | isread
;
391 static inline uint32_t syn_fp_access_trap(int cv
, int cond
, bool is_16bit
)
393 return (EC_ADVSIMDFPACCESSTRAP
<< ARM_EL_EC_SHIFT
)
394 | (is_16bit
? 0 : ARM_EL_IL
)
395 | (cv
<< 24) | (cond
<< 20);
398 static inline uint32_t syn_sve_access_trap(void)
400 return EC_SVEACCESSTRAP
<< ARM_EL_EC_SHIFT
;
403 static inline uint32_t syn_insn_abort(int same_el
, int ea
, int s1ptw
, int fsc
)
405 return (EC_INSNABORT
<< ARM_EL_EC_SHIFT
) | (same_el
<< ARM_EL_EC_SHIFT
)
406 | ARM_EL_IL
| (ea
<< 9) | (s1ptw
<< 7) | fsc
;
409 static inline uint32_t syn_data_abort_no_iss(int same_el
,
410 int ea
, int cm
, int s1ptw
,
413 return (EC_DATAABORT
<< ARM_EL_EC_SHIFT
) | (same_el
<< ARM_EL_EC_SHIFT
)
415 | (ea
<< 9) | (cm
<< 8) | (s1ptw
<< 7) | (wnr
<< 6) | fsc
;
418 static inline uint32_t syn_data_abort_with_iss(int same_el
,
419 int sas
, int sse
, int srt
,
421 int ea
, int cm
, int s1ptw
,
425 return (EC_DATAABORT
<< ARM_EL_EC_SHIFT
) | (same_el
<< ARM_EL_EC_SHIFT
)
426 | (is_16bit
? 0 : ARM_EL_IL
)
427 | ARM_EL_ISV
| (sas
<< 22) | (sse
<< 21) | (srt
<< 16)
428 | (sf
<< 15) | (ar
<< 14)
429 | (ea
<< 9) | (cm
<< 8) | (s1ptw
<< 7) | (wnr
<< 6) | fsc
;
432 static inline uint32_t syn_swstep(int same_el
, int isv
, int ex
)
434 return (EC_SOFTWARESTEP
<< ARM_EL_EC_SHIFT
) | (same_el
<< ARM_EL_EC_SHIFT
)
435 | ARM_EL_IL
| (isv
<< 24) | (ex
<< 6) | 0x22;
438 static inline uint32_t syn_watchpoint(int same_el
, int cm
, int wnr
)
440 return (EC_WATCHPOINT
<< ARM_EL_EC_SHIFT
) | (same_el
<< ARM_EL_EC_SHIFT
)
441 | ARM_EL_IL
| (cm
<< 8) | (wnr
<< 6) | 0x22;
444 static inline uint32_t syn_breakpoint(int same_el
)
446 return (EC_BREAKPOINT
<< ARM_EL_EC_SHIFT
) | (same_el
<< ARM_EL_EC_SHIFT
)
450 static inline uint32_t syn_wfx(int cv
, int cond
, int ti
, bool is_16bit
)
452 return (EC_WFX_TRAP
<< ARM_EL_EC_SHIFT
) |
453 (is_16bit
? 0 : (1 << ARM_EL_IL_SHIFT
)) |
454 (cv
<< 24) | (cond
<< 20) | ti
;
457 /* Update a QEMU watchpoint based on the information the guest has set in the
458 * DBGWCR<n>_EL1 and DBGWVR<n>_EL1 registers.
460 void hw_watchpoint_update(ARMCPU
*cpu
, int n
);
461 /* Update the QEMU watchpoints for every guest watchpoint. This does a
462 * complete delete-and-reinstate of the QEMU watchpoint list and so is
463 * suitable for use after migration or on reset.
465 void hw_watchpoint_update_all(ARMCPU
*cpu
);
466 /* Update a QEMU breakpoint based on the information the guest has set in the
467 * DBGBCR<n>_EL1 and DBGBVR<n>_EL1 registers.
469 void hw_breakpoint_update(ARMCPU
*cpu
, int n
);
470 /* Update the QEMU breakpoints for every guest breakpoint. This does a
471 * complete delete-and-reinstate of the QEMU breakpoint list and so is
472 * suitable for use after migration or on reset.
474 void hw_breakpoint_update_all(ARMCPU
*cpu
);
476 /* Callback function for checking if a watchpoint should trigger. */
477 bool arm_debug_check_watchpoint(CPUState
*cs
, CPUWatchpoint
*wp
);
479 /* Adjust addresses (in BE32 mode) before testing against watchpoint
482 vaddr
arm_adjust_watchpoint_address(CPUState
*cs
, vaddr addr
, int len
);
484 /* Callback function for when a watchpoint or breakpoint triggers. */
485 void arm_debug_excp_handler(CPUState
*cs
);
487 #ifdef CONFIG_USER_ONLY
488 static inline bool arm_is_psci_call(ARMCPU
*cpu
, int excp_type
)
493 /* Return true if the r0/x0 value indicates that this SMC/HVC is a PSCI call. */
494 bool arm_is_psci_call(ARMCPU
*cpu
, int excp_type
);
495 /* Actually handle a PSCI call */
496 void arm_handle_psci_call(ARMCPU
*cpu
);
500 * arm_clear_exclusive: clear the exclusive monitor
502 * Clear the CPU's exclusive monitor, like the guest CLREX instruction.
504 static inline void arm_clear_exclusive(CPUARMState
*env
)
506 env
->exclusive_addr
= -1;
510 * ARMFaultType: type of an ARM MMU fault
511 * This corresponds to the v8A pseudocode's Fault enumeration,
512 * with extensions for QEMU internal conditions.
514 typedef enum ARMFaultType
{
521 ARMFault_Translation
,
522 ARMFault_AddressSize
,
523 ARMFault_SyncExternal
,
524 ARMFault_SyncExternalOnWalk
,
526 ARMFault_SyncParityOnWalk
,
527 ARMFault_AsyncParity
,
528 ARMFault_AsyncExternal
,
530 ARMFault_TLBConflict
,
533 ARMFault_ICacheMaint
,
534 ARMFault_QEMU_NSCExec
, /* v8M: NS executing in S&NSC memory */
535 ARMFault_QEMU_SFault
, /* v8M: SecureFault INVTRAN, INVEP or AUVIOL */
539 * ARMMMUFaultInfo: Information describing an ARM MMU Fault
540 * @type: Type of fault
541 * @level: Table walk level (for translation, access flag and permission faults)
542 * @domain: Domain of the fault address (for non-LPAE CPUs only)
543 * @s2addr: Address that caused a fault at stage 2
544 * @stage2: True if we faulted at stage 2
545 * @s1ptw: True if we faulted at stage 2 while doing a stage 1 page-table walk
546 * @ea: True if we should set the EA (external abort type) bit in syndrome
548 typedef struct ARMMMUFaultInfo ARMMMUFaultInfo
;
549 struct ARMMMUFaultInfo
{
560 * arm_fi_to_sfsc: Convert fault info struct to short-format FSC
561 * Compare pseudocode EncodeSDFSC(), though unlike that function
562 * we set up a whole FSR-format code including domain field and
563 * putting the high bit of the FSC into bit 10.
565 static inline uint32_t arm_fi_to_sfsc(ARMMMUFaultInfo
*fi
)
572 case ARMFault_AccessFlag
:
573 fsc
= fi
->level
== 1 ? 0x3 : 0x6;
575 case ARMFault_Alignment
:
578 case ARMFault_Permission
:
579 fsc
= fi
->level
== 1 ? 0xd : 0xf;
581 case ARMFault_Domain
:
582 fsc
= fi
->level
== 1 ? 0x9 : 0xb;
584 case ARMFault_Translation
:
585 fsc
= fi
->level
== 1 ? 0x5 : 0x7;
587 case ARMFault_SyncExternal
:
588 fsc
= 0x8 | (fi
->ea
<< 12);
590 case ARMFault_SyncExternalOnWalk
:
591 fsc
= fi
->level
== 1 ? 0xc : 0xe;
592 fsc
|= (fi
->ea
<< 12);
594 case ARMFault_SyncParity
:
597 case ARMFault_SyncParityOnWalk
:
598 fsc
= fi
->level
== 1 ? 0x40c : 0x40e;
600 case ARMFault_AsyncParity
:
603 case ARMFault_AsyncExternal
:
604 fsc
= 0x406 | (fi
->ea
<< 12);
609 case ARMFault_TLBConflict
:
612 case ARMFault_Lockdown
:
615 case ARMFault_Exclusive
:
618 case ARMFault_ICacheMaint
:
621 case ARMFault_Background
:
624 case ARMFault_QEMU_NSCExec
:
625 fsc
= M_FAKE_FSR_NSC_EXEC
;
627 case ARMFault_QEMU_SFault
:
628 fsc
= M_FAKE_FSR_SFAULT
;
631 /* Other faults can't occur in a context that requires a
632 * short-format status code.
634 g_assert_not_reached();
637 fsc
|= (fi
->domain
<< 4);
642 * arm_fi_to_lfsc: Convert fault info struct to long-format FSC
643 * Compare pseudocode EncodeLDFSC(), though unlike that function
644 * we fill in also the LPAE bit 9 of a DFSR format.
646 static inline uint32_t arm_fi_to_lfsc(ARMMMUFaultInfo
*fi
)
653 case ARMFault_AddressSize
:
656 case ARMFault_AccessFlag
:
657 fsc
= (fi
->level
& 3) | (0x2 << 2);
659 case ARMFault_Permission
:
660 fsc
= (fi
->level
& 3) | (0x3 << 2);
662 case ARMFault_Translation
:
663 fsc
= (fi
->level
& 3) | (0x1 << 2);
665 case ARMFault_SyncExternal
:
666 fsc
= 0x10 | (fi
->ea
<< 12);
668 case ARMFault_SyncExternalOnWalk
:
669 fsc
= (fi
->level
& 3) | (0x5 << 2) | (fi
->ea
<< 12);
671 case ARMFault_SyncParity
:
674 case ARMFault_SyncParityOnWalk
:
675 fsc
= (fi
->level
& 3) | (0x7 << 2);
677 case ARMFault_AsyncParity
:
680 case ARMFault_AsyncExternal
:
681 fsc
= 0x11 | (fi
->ea
<< 12);
683 case ARMFault_Alignment
:
689 case ARMFault_TLBConflict
:
692 case ARMFault_Lockdown
:
695 case ARMFault_Exclusive
:
699 /* Other faults can't occur in a context that requires a
700 * long-format status code.
702 g_assert_not_reached();
709 static inline bool arm_extabort_type(MemTxResult result
)
711 /* The EA bit in syndromes and fault status registers is an
712 * IMPDEF classification of external aborts. ARM implementations
713 * usually use this to indicate AXI bus Decode error (0) or
714 * Slave error (1); in QEMU we follow that.
716 return result
!= MEMTX_DECODE_ERROR
;
719 /* Do a page table walk and add page to TLB if possible */
720 bool arm_tlb_fill(CPUState
*cpu
, vaddr address
,
721 MMUAccessType access_type
, int mmu_idx
,
722 ARMMMUFaultInfo
*fi
);
724 /* Return true if the stage 1 translation regime is using LPAE format page
726 bool arm_s1_regime_using_lpae_format(CPUARMState
*env
, ARMMMUIdx mmu_idx
);
728 /* Raise a data fault alignment exception for the specified virtual address */
729 void arm_cpu_do_unaligned_access(CPUState
*cs
, vaddr vaddr
,
730 MMUAccessType access_type
,
731 int mmu_idx
, uintptr_t retaddr
);
733 /* arm_cpu_do_transaction_failed: handle a memory system error response
734 * (eg "no device/memory present at address") by raising an external abort
737 void arm_cpu_do_transaction_failed(CPUState
*cs
, hwaddr physaddr
,
738 vaddr addr
, unsigned size
,
739 MMUAccessType access_type
,
740 int mmu_idx
, MemTxAttrs attrs
,
741 MemTxResult response
, uintptr_t retaddr
);
743 /* Call any registered EL change hooks */
744 static inline void arm_call_pre_el_change_hook(ARMCPU
*cpu
)
746 ARMELChangeHook
*hook
, *next
;
747 QLIST_FOREACH_SAFE(hook
, &cpu
->pre_el_change_hooks
, node
, next
) {
748 hook
->hook(cpu
, hook
->opaque
);
751 static inline void arm_call_el_change_hook(ARMCPU
*cpu
)
753 ARMELChangeHook
*hook
, *next
;
754 QLIST_FOREACH_SAFE(hook
, &cpu
->el_change_hooks
, node
, next
) {
755 hook
->hook(cpu
, hook
->opaque
);
759 /* Return true if this address translation regime is secure */
760 static inline bool regime_is_secure(CPUARMState
*env
, ARMMMUIdx mmu_idx
)
763 case ARMMMUIdx_S12NSE0
:
764 case ARMMMUIdx_S12NSE1
:
765 case ARMMMUIdx_S1NSE0
:
766 case ARMMMUIdx_S1NSE1
:
769 case ARMMMUIdx_MPrivNegPri
:
770 case ARMMMUIdx_MUserNegPri
:
771 case ARMMMUIdx_MPriv
:
772 case ARMMMUIdx_MUser
:
775 case ARMMMUIdx_S1SE0
:
776 case ARMMMUIdx_S1SE1
:
777 case ARMMMUIdx_MSPrivNegPri
:
778 case ARMMMUIdx_MSUserNegPri
:
779 case ARMMMUIdx_MSPriv
:
780 case ARMMMUIdx_MSUser
:
783 g_assert_not_reached();
787 /* Return the FSR value for a debug exception (watchpoint, hardware
788 * breakpoint or BKPT insn) targeting the specified exception level.
790 static inline uint32_t arm_debug_exception_fsr(CPUARMState
*env
)
792 ARMMMUFaultInfo fi
= { .type
= ARMFault_Debug
};
793 int target_el
= arm_debug_target_el(env
);
794 bool using_lpae
= false;
796 if (target_el
== 2 || arm_el_is_aa64(env
, target_el
)) {
799 if (arm_feature(env
, ARM_FEATURE_LPAE
) &&
800 (env
->cp15
.tcr_el
[target_el
].raw_tcr
& TTBCR_EAE
)) {
806 return arm_fi_to_lfsc(&fi
);
808 return arm_fi_to_sfsc(&fi
);
812 /* Note make_memop_idx reserves 4 bits for mmu_idx, and MO_BSWAP is bit 3.
813 * Thus a TCGMemOpIdx, without any MO_ALIGN bits, fits in 8 bits.
815 #define MEMOPIDX_SHIFT 8
818 * v7m_using_psp: Return true if using process stack pointer
819 * Return true if the CPU is currently using the process stack
820 * pointer, or false if it is using the main stack pointer.
822 static inline bool v7m_using_psp(CPUARMState
*env
)
824 /* Handler mode always uses the main stack; for thread mode
825 * the CONTROL.SPSEL bit determines the answer.
826 * Note that in v7M it is not possible to be in Handler mode with
827 * CONTROL.SPSEL non-zero, but in v8M it is, so we must check both.
829 return !arm_v7m_is_handler_mode(env
) &&
830 env
->v7m
.control
[env
->v7m
.secure
] & R_V7M_CONTROL_SPSEL_MASK
;
834 * v7m_sp_limit: Return SP limit for current CPU state
835 * Return the SP limit value for the current CPU security state
838 static inline uint32_t v7m_sp_limit(CPUARMState
*env
)
840 if (v7m_using_psp(env
)) {
841 return env
->v7m
.psplim
[env
->v7m
.secure
];
843 return env
->v7m
.msplim
[env
->v7m
.secure
];
848 * aarch32_mode_name(): Return name of the AArch32 CPU mode
849 * @psr: Program Status Register indicating CPU mode
851 * Returns, for debug logging purposes, a printable representation
852 * of the AArch32 CPU mode ("svc", "usr", etc) as indicated by
853 * the low bits of the specified PSR.
855 static inline const char *aarch32_mode_name(uint32_t psr
)
857 static const char cpu_mode_names
[16][4] = {
858 "usr", "fiq", "irq", "svc", "???", "???", "mon", "abt",
859 "???", "???", "hyp", "und", "???", "???", "???", "sys"
862 return cpu_mode_names
[psr
& 0xf];