Skip to content

Commit 2beb051

Browse files
committed
target/arm: Move arm_current_el() and arm_el_is_aa64() to internals.h
The functions arm_current_el() and arm_el_is_aa64() are used only in target/arm and in hw/intc/arm_gicv3_cpuif.c. They're functions that query internal state of the CPU. Move them out of cpu.h and into internals.h. This means we need to include internals.h in arm_gicv3_cpuif.c, but this is justifiable because that file is implementing the GICv3 CPU interface, which really is part of the CPU proper; we just ended up implementing it in code in hw/intc/ for historical reasons. The motivation for this move is that we'd like to change arm_el_is_aa64() to add a condition that uses cpu_isar_feature(); but we don't want to include cpu-features.h in cpu.h. Signed-off-by: Peter Maydell <[email protected]> Reviewed-by: Richard Henderson <[email protected]>
1 parent fefc122 commit 2beb051

File tree

4 files changed

+69
-66
lines changed

4 files changed

+69
-66
lines changed

hw/intc/arm_gicv3_cpuif.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "cpu.h"
2323
#include "target/arm/cpregs.h"
2424
#include "target/arm/cpu-features.h"
25+
#include "target/arm/internals.h"
2526
#include "system/tcg.h"
2627
#include "system/qtest.h"
2728

target/arm/arch_dump.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "elf.h"
2424
#include "system/dump.h"
2525
#include "cpu-features.h"
26+
#include "internals.h"
2627

2728
/* struct user_pt_regs from arch/arm64/include/uapi/asm/ptrace.h */
2829
struct aarch64_user_regs {

target/arm/cpu.h

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,39 +2635,6 @@ uint64_t arm_hcr_el2_eff_secstate(CPUARMState *env, ARMSecuritySpace space);
26352635
uint64_t arm_hcr_el2_eff(CPUARMState *env);
26362636
uint64_t arm_hcrx_el2_eff(CPUARMState *env);
26372637

2638-
/* Return true if the specified exception level is running in AArch64 state. */
2639-
static inline bool arm_el_is_aa64(CPUARMState *env, int el)
2640-
{
2641-
/* This isn't valid for EL0 (if we're in EL0, is_a64() is what you want,
2642-
* and if we're not in EL0 then the state of EL0 isn't well defined.)
2643-
*/
2644-
assert(el >= 1 && el <= 3);
2645-
bool aa64 = arm_feature(env, ARM_FEATURE_AARCH64);
2646-
2647-
/* The highest exception level is always at the maximum supported
2648-
* register width, and then lower levels have a register width controlled
2649-
* by bits in the SCR or HCR registers.
2650-
*/
2651-
if (el == 3) {
2652-
return aa64;
2653-
}
2654-
2655-
if (arm_feature(env, ARM_FEATURE_EL3) &&
2656-
((env->cp15.scr_el3 & SCR_NS) || !(env->cp15.scr_el3 & SCR_EEL2))) {
2657-
aa64 = aa64 && (env->cp15.scr_el3 & SCR_RW);
2658-
}
2659-
2660-
if (el == 2) {
2661-
return aa64;
2662-
}
2663-
2664-
if (arm_is_el2_enabled(env)) {
2665-
aa64 = aa64 && (env->cp15.hcr_el2 & HCR_RW);
2666-
}
2667-
2668-
return aa64;
2669-
}
2670-
26712638
/*
26722639
* Function for determining whether guest cp register reads and writes should
26732640
* access the secure or non-secure bank of a cp register. When EL3 is
@@ -2699,39 +2666,6 @@ static inline bool arm_v7m_is_handler_mode(CPUARMState *env)
26992666
return env->v7m.exception != 0;
27002667
}
27012668

2702-
/* Return the current Exception Level (as per ARMv8; note that this differs
2703-
* from the ARMv7 Privilege Level).
2704-
*/
2705-
static inline int arm_current_el(CPUARMState *env)
2706-
{
2707-
if (arm_feature(env, ARM_FEATURE_M)) {
2708-
return arm_v7m_is_handler_mode(env) ||
2709-
!(env->v7m.control[env->v7m.secure] & 1);
2710-
}
2711-
2712-
if (is_a64(env)) {
2713-
return extract32(env->pstate, 2, 2);
2714-
}
2715-
2716-
switch (env->uncached_cpsr & 0x1f) {
2717-
case ARM_CPU_MODE_USR:
2718-
return 0;
2719-
case ARM_CPU_MODE_HYP:
2720-
return 2;
2721-
case ARM_CPU_MODE_MON:
2722-
return 3;
2723-
default:
2724-
if (arm_is_secure(env) && !arm_el_is_aa64(env, 3)) {
2725-
/* If EL3 is 32-bit then all secure privileged modes run in
2726-
* EL3
2727-
*/
2728-
return 3;
2729-
}
2730-
2731-
return 1;
2732-
}
2733-
}
2734-
27352669
/**
27362670
* write_list_to_cpustate
27372671
* @cpu: ARMCPU

target/arm/internals.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,73 @@ static inline FloatRoundMode arm_rmode_to_sf(ARMFPRounding rmode)
392392
return arm_rmode_to_sf_map[rmode];
393393
}
394394

395+
/* Return true if the specified exception level is running in AArch64 state. */
396+
static inline bool arm_el_is_aa64(CPUARMState *env, int el)
397+
{
398+
/*
399+
* This isn't valid for EL0 (if we're in EL0, is_a64() is what you want,
400+
* and if we're not in EL0 then the state of EL0 isn't well defined.)
401+
*/
402+
assert(el >= 1 && el <= 3);
403+
bool aa64 = arm_feature(env, ARM_FEATURE_AARCH64);
404+
405+
/*
406+
* The highest exception level is always at the maximum supported
407+
* register width, and then lower levels have a register width controlled
408+
* by bits in the SCR or HCR registers.
409+
*/
410+
if (el == 3) {
411+
return aa64;
412+
}
413+
414+
if (arm_feature(env, ARM_FEATURE_EL3) &&
415+
((env->cp15.scr_el3 & SCR_NS) || !(env->cp15.scr_el3 & SCR_EEL2))) {
416+
aa64 = aa64 && (env->cp15.scr_el3 & SCR_RW);
417+
}
418+
419+
if (el == 2) {
420+
return aa64;
421+
}
422+
423+
if (arm_is_el2_enabled(env)) {
424+
aa64 = aa64 && (env->cp15.hcr_el2 & HCR_RW);
425+
}
426+
427+
return aa64;
428+
}
429+
430+
/*
431+
* Return the current Exception Level (as per ARMv8; note that this differs
432+
* from the ARMv7 Privilege Level).
433+
*/
434+
static inline int arm_current_el(CPUARMState *env)
435+
{
436+
if (arm_feature(env, ARM_FEATURE_M)) {
437+
return arm_v7m_is_handler_mode(env) ||
438+
!(env->v7m.control[env->v7m.secure] & 1);
439+
}
440+
441+
if (is_a64(env)) {
442+
return extract32(env->pstate, 2, 2);
443+
}
444+
445+
switch (env->uncached_cpsr & 0x1f) {
446+
case ARM_CPU_MODE_USR:
447+
return 0;
448+
case ARM_CPU_MODE_HYP:
449+
return 2;
450+
case ARM_CPU_MODE_MON:
451+
return 3;
452+
default:
453+
if (arm_is_secure(env) && !arm_el_is_aa64(env, 3)) {
454+
/* If EL3 is 32-bit then all secure privileged modes run in EL3 */
455+
return 3;
456+
}
457+
458+
return 1;
459+
}
460+
}
461+
395462
static inline bool arm_cpu_data_is_big_endian_a32(CPUARMState *env,
396463
bool sctlr_b)
397464
{

0 commit comments

Comments
 (0)