target-arm: add Security Extensions for CPUs
v9 cover target-arm: add Security Extensions for CPUs
Version 9 of the ARM processor security extension (TrustZone) support. This patchset includes changes to support the processor security extensions on ARMv7 aarch32 with hooks for later enabling v8 aarch64/32.
Summary of changes from v8 -> v9
- Squashed patch 18 into 17
- Reverted async unmask table fix
- Fixed EL table values
- Removed ARM_CP_SECSTATE_TEST macro
- Updated cpreg hashing and macro arg order so secstate follows is64
- Fixed issuese in add_cpreg_to_hash()
- Reowrked define_one_arm_cp_reg_with_opaque() secure case handling
- Cleaned up CP reg definitions
- Added SDER32_EL2, DACR32_EL2, & IFSR32_EL2 defs
- Removed v8 check in arm_cpu_reset()
- Rearranged cpsr_write() so mask filtering occurs before mode switch
- Added TCR CP reg struct and usage
- Broke up CONTEXTIDR and FCSEIDR CP reg defs into secure/non-secure instances.
- Added missing MAIR endianness support
- Fixed comments
Fabian Aggeler (19):
target-arm: add banked register accessors
target-arm: add CPREG secure state support
target-arm: insert AArch32 cpregs twice into hashtable
target-arm: move AArch32 SCR into security reglist
target-arm: implement IRQ/FIQ routing to Monitor mode
target-arm: add NSACR register
target-arm: add MVBAR support
target-arm: add SCTLR_EL3 and make SCTLR banked
target-arm: respect SCR.FW, SCR.AW and SCTLR.NMFI
target-arm: make CSSELR banked
target-arm: make TTBR0/1 banked
target-arm: make TTBCR banked
target-arm: make DACR banked
target-arm: make IFSR banked
target-arm: make DFSR banked
target-arm: make IFAR/DFAR banked
target-arm: make PAR banked
target-arm: make c13 cp regs banked (FCSEIDR, ...)
target-arm: add cpu feature EL3 to CPUs with Security Extensions
Greg Bellows (6):
target-arm: extend async excp masking
target-arm: add async excp target_el function
target-arm: add secure state bit to CPREG hash
target-arm: add SDER definition
target-arm: make VBAR banked
target-arm: make MAIR0/1 banked
Sergey Fedorov (1):
target-arm: add non-secure Translation Block flag
hw/arm/pxa2xx.c | 6 +- linux-user/aarch64/target_cpu.h | 2 +- linux-user/arm/target_cpu.h | 2 +- linux-user/main.c | 2 +- target-arm/cpu.c | 14 +- target-arm/cpu.h | 377 ++++++++++++++++++---- target-arm/helper.c | 682 ++++++++++++++++++++++++++++++---------- target-arm/internals.h | 6 +- target-arm/op_helper.c | 4 +- target-arm/translate.c | 15 +- target-arm/translate.h | 1 + 11 files changed, 869 insertions(+), 242 deletions(-)
--
1.8.3.2
PATCH v9 1/26 target-arm: extend async excp masking
This patch extends arm_excp_unmasked() to use lookup tables for determining whether IRQ and FIQ exceptions are masked. The lookup tables are based on the ARMv8 and ARMv7 specification physical interrupt masking tables.
If EL3 is using AArch64 IRQ/FIQ masking is ignored in all exception levels other than EL3 if SCR.{FIQ|IRQ} is set to 1 (routed to EL3).
---
v8 -> v9
- Undo the use of tables for exception masking and instead go with simplified logic based on the target EL lookup.
- Remove the masking tables
v7 -> v8
- Add IRQ and FIQ exeception masking lookup tables.
- Rewrite patch to use lookup tables for determining whether an excpetion is masked or not.
v5 -> v6
- Globally change Aarch# to AArch#
- Fixed comment termination
v4 -> v5
- Merge with v4 patch 10
--- target-arm/cpu.h | 79 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 26 deletions(-)
target-arm/cpu.h +53 -26
@@ -1247,39 +1247,51 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)CPUARMState *env = cs->env_ptr;unsigned int cur_el =arm_current_el (env);unsigned int target_el =arm_excp_target_el (cs, excp_idx); -/* FIXME: Use actual secure state. */ -bool secure = false; -/* If in EL1/0, Physical IRQ routing to EL2 only happens from NS state. */ -bool irq_can_hyp = !secure && cur_el <2 && target_el ==2 ; -/* ARMv7-M interrupt return works by loading a magic value -* into the PC. On real hardware the load causes the -* return to occur. The qemu implementation performs the -* jump normally, then does the exception return when the -* CPU tries to execute code at the magic address. -* This will cause the magic PC value to be pushed to -* the stack if an interrupt occurred at the wrong time. -* We avoid this by disabling interrupts when -* pc contains a magic address. +bool secure =arm_is_secure (env); +uint32_t scr; +uint32_t hcr; +bool pstate_unmasked; +int8_t unmasked =0 ; +bool is_aa64 =arm_el_is_aa64 (env,3 ); + +/* Don't take exceptions if they target a lower EL. +* This check should catch any exceptions that would not be taken but left +* pending. */ -bool irq_unmasked = !(env->daif &PSTATE_I ) - && (!IS_M (env) || env->regs[15 ] <0xfffffff0 ); - -/* Don't take exceptions if they target a lower EL. */ if (cur_el > target_el) {return false; }switch (excp_idx) {case EXCP_FIQ : -if (irq_can_hyp && (env->cp15.hcr_el2 &HCR_FMO )) { -return true; - } -return !(env->daif &PSTATE_F ); +/* If FIQs are routed to EL3 or EL2 then there are cases where we +* override the CPSR.F in determining if the exception is masked or +* not. If neither of these are set then we fall back to the CPSR.F +* setting otherwise we further assess the state below. +*/ + hcr = (env->cp15.hcr_el2 &HCR_FMO ); + scr = (env->cp15.scr_el3 &SCR_FIQ ); + +/* When EL3 is 32-bit, the SCR.FW bit controls whether the CPSR.F bit +* masks FIQ interrupts when taken in non-secure state. If SCR.FW is +* set then FIQs can be masked by CPSR.F when non-secure but only +* when FIQs are only routed to EL3. +*/ + scr &= is_aa64 || !((env->cp15.scr_el3 &SCR_FW ) && !hcr); + pstate_unmasked = !(env->daif &PSTATE_F ); +break ; +case EXCP_IRQ : -if (irq_can_hyp && (env->cp15.hcr_el2 &HCR_IMO )) { -return true; - } -return irq_unmasked; +/* When EL3 execution state is 32-bit, if HCR.IMO is set then we may +* override the CPSR.I masking when in non-secure state. The SCR.IRQ +* setting has already been taken into consideration when setting the +* target EL, so it does not have a further affect here. +*/ + hcr = is_aa64 || (env->cp15.hcr_el2 &HCR_IMO ); + scr = false; + pstate_unmasked = !(env->daif &PSTATE_I ); +break ; +case EXCP_VFIQ :if (!secure && !(env->cp15.hcr_el2 &HCR_FMO )) {/* VFIQs are only taken when hypervized and non-secure. */
@@ -1291,10 +1303,25 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)/* VIRQs are only taken when hypervized and non-secure. */ return false; } -return irq_unmasked; +return !(env->daif &PSTATE_I ) && + (!IS_M (env) || env->regs[15 ] <0xfffffff0 );default :g_assert_not_reached (); } + +/* Use the target EL, current execution state and SCR/HCR settings to +* determine whether the corresponding CPSR bit is used to mask the +* interrupt. +*/ +if ((target_el > cur_el) && (target_el !=1 ) && (scr || hcr) && + (is_aa64 || !secure)) { + unmasked =1 ; + } + +/* The PSTATE bits only mask the interrupt if we have not overriden the +* ability above. +*/ +return unmasked || pstate_unmasked; }static inline CPUARMState *cpu_init (const char *cpu_model)
Signature · 1 line
1.8.3.2
Re: [Qemu-devel] [PATCH v9 01/26] target-arm: extend async excp masking
Quoted 42 lines · Greg Bellows
This patch extends
arm_excp_unmasked()to use lookup tables for determining whether IRQ and FIQ exceptions are masked. The lookup tables are based on the ARMv8 and ARMv7 specification physical interrupt masking tables.If EL3 is using AArch64 IRQ/FIQ masking is ignored in all exception levels other than EL3 if SCR.{FIQ|IRQ} is set to 1 (routed to EL3).
Signed-off-by Greg Bellows <[email protected]>---
v8 -> v9
- Undo the use of tables for exception masking and instead go with simplified logic based on the target EL lookup.
- Remove the masking tablesv7 -> v8
- Add IRQ and FIQ exeception masking lookup tables.
- Rewrite patch to use lookup tables for determining whether an excpetion is masked or not.v5 -> v6
- Globally change Aarch# to AArch#
- Fixed comment terminationv4 -> v5
- Merge with v4 patch 10--- target-arm/cpu.h | 79 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 26 deletions(-)target-arm/cpu.h +0
-3@@ -1247,39 +1247,51 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)CPUARMState *env = cs->env_ptr;unsigned int cur_el =arm_current_el (env);unsigned int target_el =arm_excp_target_el (cs, excp_idx); -/* FIXME: Use actual secure state. */ -bool secure = false; -/* If in EL1/0, Physical IRQ routing to EL2 only happens from NS state. */
target-arm/cpu.h static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx) · line 1262
Quoted 10 lines
target-arm/cpu.h +0
-10-bool irq_can_hyp = !secure && cur_el <2 && target_el ==2 ; -/* ARMv7-M interrupt return works by loading a magic value -* into the PC. On real hardware the load causes the -* return to occur. The qemu implementation performs the -* jump normally, then does the exception return when the -* CPU tries to execute code at the magic address. -* This will cause the magic PC value to be pushed to -* the stack if an interrupt occurred at the wrong time. -* We avoid this by disabling interrupts when -* pc contains a magic address.
I did suggest you based this on the M profile patches; you'll find this doesn't apply to current master I think.
thanks
-- PMM
Re: [Qemu-devel] [PATCH v9 01/26] target-arm: extend async excp masking
Yeah I wanted to get out what I had after all the patches. I am planning to rebar tomorrow.
Greg
Quoted 68 lines · Peter Maydell
Quoted 1 line · Greg Bellows
This patch extends
arm_excp_unmasked()to use lookup tables fordetermining
Quoted 1 line
whether IRQ and FIQ exceptions are masked. The lookup tables are based
on the
Quoted 3 lines
ARMv8 and ARMv7 specification physical interrupt masking tables.
If EL3 is using AArch64 IRQ/FIQ masking is ignored in all exception
levels
Quoted 8 lines
other than EL3 if SCR.{FIQ|IRQ} is set to 1 (routed to EL3).
Signed-off-by Greg Bellows <[email protected]>---
v8 -> v9
- Undo the use of tables for exception masking and instead go withsimplified
Quoted 6 lines
logic based on the target EL lookup.
- Remove the masking tablesv7 -> v8
- Add IRQ and FIQ exeception masking lookup tables.
- Rewrite patch to use lookup tables for determining whether anexcpetion is
Quoted 10 lines
masked or not.
v5 -> v6
- Globally change Aarch# to AArch#
- Fixed comment terminationv4 -> v5
- Merge with v4 patch 10--- target-arm/cpu.h | 79+++++++++++++++++++++++++++++++++++++-------------------
target-arm/cpu.h static inline bool arm_excp_unmasked(CPUState
Quoted 7 lines
1 file changed, 53 insertions(+), 26 deletions(-)target-arm/cpu.h +0
-0@@ -1247,39 +1247,51 @@ static inline bool arm_excp_unmasked(CPUState*cs, unsigned int
excp_idx)target-arm/cpu.h static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)
Quoted 6 lines
target-arm/cpu.h +0
-3CPUARMState *env = cs->env_ptr;unsigned int cur_el =arm_current_el (env);unsigned int target_el =arm_excp_target_el (cs, excp_idx); -/* FIXME: Use actual secure state. */ -bool secure = false; -/* If in EL1/0, Physical IRQ routing to EL2 only happens from NS state. */
target-arm/cpu.h static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx) · line 1262
Quoted 10 lines
target-arm/cpu.h +0
-10-bool irq_can_hyp = !secure && cur_el <2 && target_el ==2 ; -/* ARMv7-M interrupt return works by loading a magic value -* into the PC. On real hardware the load causes the -* return to occur. The qemu implementation performs the -* jump normally, then does the exception return when the -* CPU tries to execute code at the magic address. -* This will cause the magic PC value to be pushed to -* the stack if an interrupt occurred at the wrong time. -* We avoid this by disabling interrupts when -* pc contains a magic address. I did suggest you based this on the M profile patches; you'll find this doesn't apply to current master I think.
thanks
-- PMM
PATCH v9 2/26 target-arm: add async excp target_el function
In reply to Greg BellowsAdds a dedicated function and a lookup table for determining the target exception level of IRQ and FIQ exceptions. The lookup table is taken from the ARMv7 and ARMv8 specification exception routing tables.
---
v8 -> v9
- Fixed target_el_table in correct 32-bit secure values
- Expanded comment on target_el_table untaken exception handling
- Fixed minor issues
v7 -> v8
- Added target EL lookup table
- Rework arm_phys_excp_target_el to use an EL lookup table rather than conditionals.
v5 -> v6
- Removed unneeded arm_phys_excp_target_el() function prototype.
- Removed unneeded arm_phys_excp_target_el() USER_ONLY function.
- Fixed up arm_phys_excp_target_el() function definition to be static.
- Globally replace Aarch# with AArch#
v4 -> v5
- Simplify target EL function including removal of mode which was unused
- Merged with patch that plugs in the use of the function
v3 -> v4
- Fixed arm_phys_excp_target_el() 0/0/0 case to return excp_mode when EL<2 rather than ABORT.
--- target-arm/helper.c | 116 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 97 insertions(+), 19 deletions(-)
target-arm/helper.c +97 -19
@@ -3761,6 +3761,101 @@ void switch_mode(CPUARMState *env, int mode) env->spsr = env->banked_spsr[i]; } +/* Physical Interrupt Target EL Lookup Table +* +* [ From ARM ARM section G1.13.4 (Table G1-15) ] +* +* The below multi-dimensional table is used for looking up the target +* exception level given numerous condition criteria. Specifically, the +* target EL is based on SCR and HCR routing controls as well as the +* currently executing EL and secure state. +* +* Dimensions: +* target_el_table[2][2][2][2][2][4] +* | | | | | +--- Current EL +* | | | | +------ Non-secure(0)/Secure(1) +* | | | +--------- HCR mask override +* | | +------------ SCR exec state control +* | +--------------- SCR mask override +* +------------------ 32-bit(0)/64-bit(1) EL3 +* +* The table values are as such: +* 0-3 = EL0-EL3 +* -1 = Cannot occur +* +* The ARM ARM target EL table includes entries indicating that an "exception +* is not taken". The two cases where this is applicable are: +* 1) An exception is taken from EL3 but the SCR does not have the exception +* routed to EL3. +* 2) An exception is taken from EL2 but the HCR does not have the exception +* routed to EL2. +* In these two cases, the below table contain a target of EL1. This value is +* returned as it is expected that the consumer of the table data will check +* for "target EL >= current EL" to ensure the exception is not taken. +* +* SCR HCR +* 64 EA AMO From +* BIT IRQ IMO Non-secure Secure +* EL3 FIQ RW FMO EL0 EL1 EL2 EL3 EL0 EL1 EL2 EL3 +*/ +const int8_t target_el_table[2 ][2 ][2 ][2 ][2 ][4 ] = { + {{{{/* 0 0 0 0 */ {1 ,1 ,2 ,-1 },{3 ,-1 ,-1 ,3 },}, + {/* 0 0 0 1 */ {2 ,2 ,2 ,-1 },{3 ,-1 ,-1 ,3 },},}, + {{/* 0 0 1 0 */ {1 ,1 ,2 ,-1 },{3 ,-1 ,-1 ,3 },}, + {/* 0 0 1 1 */ {2 ,2 ,2 ,-1 },{3 ,-1 ,-1 ,3 },},},}, + {{{/* 0 1 0 0 */ {3 ,3 ,3 ,-1 },{3 ,-1 ,-1 ,3 },}, + {/* 0 1 0 1 */ {3 ,3 ,3 ,-1 },{3 ,-1 ,-1 ,3 },},}, + {{/* 0 1 1 0 */ {3 ,3 ,3 ,-1 },{3 ,-1 ,-1 ,3 },}, + {/* 0 1 1 1 */ {3 ,3 ,3 ,-1 },{3 ,-1 ,-1 ,3 },},},},}, + {{{{/* 1 0 0 0 */ {1 ,1 ,2 ,-1 },{1 ,1 ,-1 ,1 },}, + {/* 1 0 0 1 */ {2 ,2 ,2 ,-1 },{1 ,1 ,-1 ,1 },},}, + {{/* 1 0 1 0 */ {1 ,1 ,1 ,-1 },{1 ,1 ,-1 ,1 },}, + {/* 1 0 1 1 */ {2 ,2 ,2 ,-1 },{1 ,1 ,-1 ,1 },},},}, + {{{/* 1 1 0 0 */ {3 ,3 ,3 ,-1 },{3 ,3 ,-1 ,3 },}, + {/* 1 1 0 1 */ {3 ,3 ,3 ,-1 },{3 ,3 ,-1 ,3 },},}, + {{/* 1 1 1 0 */ {3 ,3 ,3 ,-1 },{3 ,3 ,-1 ,3 },}, + {/* 1 1 1 1 */ {3 ,3 ,3 ,-1 },{3 ,3 ,-1 ,3 },},},},}, +}; + +/* +* Determine the target EL for physical exceptions +*/ +static inline uint32_t arm_phys_excp_target_el (CPUState *cs,uint32_t excp_idx, +uint32_t cur_el,bool secure) +{ +CPUARMState *env = cs->env_ptr; +int rw = ((env->cp15.scr_el3 &SCR_RW ) ==SCR_RW ); +int scr; +int hcr; +int target_el; +int is64 =arm_el_is_aa64 (env,3 ); + +switch (excp_idx) { +case EXCP_IRQ : + scr = ((env->cp15.scr_el3 &SCR_IRQ ) ==SCR_IRQ ); + hcr = ((env->cp15.hcr_el2 &HCR_IMO ) ==HCR_IMO ); +break ; +case EXCP_FIQ : + scr = ((env->cp15.scr_el3 &SCR_FIQ ) ==SCR_FIQ ); + hcr = ((env->cp15.hcr_el2 &HCR_FMO ) ==HCR_FMO ); +break ; +default : + scr = ((env->cp15.scr_el3 &SCR_EA ) ==SCR_EA ); + hcr = ((env->cp15.hcr_el2 &HCR_AMO ) ==HCR_AMO ); +break ; + }; + +/* If HCR.TGE is set then HCR is treated as being 1 */ + hcr |= ((env->cp15.hcr_el2 &HCR_TGE ) ==HCR_TGE ); + +/* Perform a table-lookup for the target EL given the current state */ + target_el = target_el_table[is64][scr][rw][hcr][secure][cur_el]; + +assert (target_el >0 ); + +return target_el; +} +/* * Determine the target EL for a given exception type. */
@@ -3770,13 +3865,7 @@ unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx)CPUARMState *env = &cpu->env;unsigned int cur_el =arm_current_el (env);unsigned int target_el; -/* FIXME: Use actual secure state. */ -bool secure = false; - -if (!env->aarch64) { -/* TODO: Add EL2 and 3 exception handling for AArch32. */ -return 1 ; - } +bool secure =arm_is_secure (env);switch (excp_idx) {case EXCP_HVC :
@@ -3788,19 +3877,8 @@ unsigned int arm_excp_target_el(CPUState *cs, unsigned int excp_idx)break ;case EXCP_FIQ :case EXCP_IRQ : - { -const uint64_t hcr_mask = excp_idx ==EXCP_FIQ ?HCR_FMO :HCR_IMO ; -const uint32_t scr_mask = excp_idx ==EXCP_FIQ ?SCR_FIQ :SCR_IRQ ; - - target_el =1 ; -if (!secure && (env->cp15.hcr_el2 & hcr_mask)) { - target_el =2 ; - } -if (env->cp15.scr_el3 & scr_mask) { - target_el =3 ; - } + target_el =arm_phys_excp_target_el (cs, excp_idx, cur_el, secure);break ; - }case EXCP_VIRQ :case EXCP_VFIQ : target_el =1 ;
Signature · 1 line
1.8.3.2
PATCH v9 3/26 target-arm: add banked register accessors
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
If EL3 is in AArch32 state certain cp registers are banked (secure and non-secure instance). When reading or writing to coprocessor registers the following macros can be used.
- A32_BANKED macros are used for choosing the banked register based on provided input security argument. This macro is used to choose the bank during translation of MRC/MCR instructions that are dependent on something other than the current secure state.
- A32_BANKED_CURRENT macros are used for choosing the banked register based on current secure state. This is NOT to be used for choosing the bank used during translation as it breaks monitor mode.
If EL3 is operating in AArch64 state coprocessor registers are not banked anymore. The macros use the non-secure instance (_ns) in this case, which is architecturally mapped to the AArch64 EL register.
---
v7 -> v8
- Move use_secure_reg() function to the TBFLAG patch.
v5 -> v6
- Converted macro USE_SECURE_REG() into inlince function use_secure_reg()
- Globally replace Aarch# with AArch#
v4 -> v5
- Cleaned-up macros to try and alleviate misuse. Made A32_BANKED macros take secure arg indicator rather than relying on USE_SECURE_REG. Incorporated the A32_BANKED macros into the A32_BANKED_CURRENT. CURRENT is now the only one that automatically chooses based on current secure state.
--- target-arm/cpu.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
target-arm/cpu.h +27 -0
@@ -817,6 +817,33 @@ static inline bool arm_el_is_aa64(CPUARMState *env, int el)return arm_feature (env,ARM_FEATURE_AARCH64 ); } +/* Macros for accessing a specified CP register bank */ +#define A32_BANKED_REG_GET (_env, _regname, _secure) \ + ((_secure) ? (_env)->cp15._regname##_s : (_env)->cp15._regname##_ns) + +#define A32_BANKED_REG_SET (_env, _regname, _secure, _val) \ + do { \ + if (_secure) { \ + (_env)->cp15._regname##_s = (_val); \ + } else { \ + (_env)->cp15._regname##_ns = (_val); \ + } \ + } while (0) + +/* Macros for automatically accessing a specific CP register bank depending on +* the current secure state of the system. These macros are not intended for +* supporting instruction translation reads/writes as these are dependent +* solely on the SCR.NS bit and not the mode. +*/ +#define A32_BANKED_CURRENT_REG_GET (_env, _regname) \ + A32_BANKED_REG_GET((_env), _regname, \ + ((!arm_el_is_aa64((_env), 3) && arm_is_secure(_env)))) + +#define A32_BANKED_CURRENT_REG_SET (_env, _regname, _val) \ + A32_BANKED_REG_SET((_env), _regname, \ + ((!arm_el_is_aa64((_env), 3) && arm_is_secure(_env))), \ + (_val)) +void arm_cpu_list (FILE *f,fprintf_function cpu_fprintf);unsigned int arm_excp_target_el (CPUState *cs,unsigned int excp_idx);
Signature · 1 line
1.8.3.2
PATCH v9 4/26 target-arm: add non-secure Translation Block flag
In reply to Greg BellowsFrom: Sergey Fedorov <[email protected]>
This patch is based on idea found in patch atgit://github.com/jowinter/qemu-trustzone.gitf3d955c6c0ed8c46bc0eb10b634201032a651dd2 by
Johannes Winter <[email protected]>.
The TBFLAG captures the SCR NS secure state at the time when a TB is created so the correct bank is accessed on system register accesses.
---
v7 -> v8
- Moved and renamed use_secure_reg() to this patch. New name is access_secure_reg().
- Fixed function comment
v5 -> v6
- Removed 64-bit NS TBFLAG macros as they are not needed
- Added comment on DisasContext ns field
- Replaced use of USE_SECURE_REG with use_secure_reg
v4 -> v5
- Merge changes
- Fixed issue where TB secure state flag was incorrectly being set based on secure state rather than NS setting. This caused an issue where monitor mode MRC/MCR accesses were always secure rather than being based on NS bit setting.
- Added separate 64/32 TB secure state flags
- Unconditionalized the setting of the DC ns bit
- Removed IS_NS macro and replaced with direct usage.
--- target-arm/cpu.h | 27 +++++++++++++++++++++++++++ target-arm/translate.c | 1 + target-arm/translate.h | 1 + 3 files changed, 29 insertions(+)
target-arm/cpu.h +27 -0
@@ -817,6 +817,22 @@ static inline bool arm_el_is_aa64(CPUARMState *env, int el)return arm_feature (env,ARM_FEATURE_AARCH64 ); } +/* Function for determing whether guest cp register reads and writes should +* access the secure or non-secure bank of a cp register. When EL3 is +* operating in AArch32 state, the NS-bit determines whether the secure +* instance of a cp register should be used. When EL3 is AArch64 (or if +* it doesn't exist at all) then there is no register banking, and all +* accesses are to the non-secure version. +*/ +static inline bool access_secure_reg (CPUARMState *env) +{ +bool ret = (arm_feature (env,ARM_FEATURE_EL3 ) && + !arm_el_is_aa64 (env,3 ) && + !(env->cp15.scr_el3 &SCR_NS )); + +return ret; +} +/* Macros for accessing a specified CP register bank */ #define A32_BANKED_REG_GET (_env, _regname, _secure) \ ((_secure) ? (_env)->cp15._regname##_s : (_env)->cp15._regname##_ns)
@@ -1468,6 +1484,12 @@ static inline bool arm_singlestep_active(CPUARMState *env)*/ #define ARM_TBFLAG_XSCALE_CPAR_SHIFT 20#define ARM_TBFLAG_XSCALE_CPAR_MASK (3 << ARM_TBFLAG_XSCALE_CPAR_SHIFT) +/* Indicates whether cp register reads and writes by guest code should access +* the secure or nonsecure bank of banked registers; note that this is not +* the same thing as the current security state of the processor! +*/ +#define ARM_TBFLAG_NS_SHIFT 22 +#define ARM_TBFLAG_NS_MASK (1 << ARM_TBFLAG_NS_SHIFT)/* Bit usage when in AArch64 state */ #define ARM_TBFLAG_AA64_EL_SHIFT 0
@@ -1512,6 +1534,8 @@ static inline bool arm_singlestep_active(CPUARMState *env) (((F) & ARM_TBFLAG_AA64_SS_ACTIVE_MASK) >> ARM_TBFLAG_AA64_SS_ACTIVE_SHIFT)#define ARM_TBFLAG_AA64_PSTATE_SS (F ) \ (((F) & ARM_TBFLAG_AA64_PSTATE_SS_MASK) >> ARM_TBFLAG_AA64_PSTATE_SS_SHIFT) +#define ARM_TBFLAG_NS (F ) \ + (((F) & ARM_TBFLAG_NS_MASK) >> ARM_TBFLAG_NS_SHIFT)static inline void cpu_get_tb_cpu_state (CPUARMState *env,target_ulong *pc,target_ulong *cs_base,int *flags)
@@ -1561,6 +1585,9 @@ static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc,if (privmode) { *flags |=ARM_TBFLAG_PRIV_MASK ; } +if (!(access_secure_reg (env))) { + *flags |=ARM_TBFLAG_NS_MASK ; + }if (env->vfp.xregs[ARM_VFP_FPEXC ] & (1 <<30 ) ||arm_el_is_aa64 (env,1 )) { *flags |=ARM_TBFLAG_VFPEN_MASK ;
target-arm/translate.c +1 -0
@@ -11005,6 +11005,7 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,#if !defined(CONFIG_USER_ONLY ) dc->user = (ARM_TBFLAG_PRIV (tb->flags) ==0 );#endif + dc->ns =ARM_TBFLAG_NS (tb->flags); dc->cpacr_fpen =ARM_TBFLAG_CPACR_FPEN (tb->flags); dc->vfp_enabled =ARM_TBFLAG_VFPEN (tb->flags); dc->vec_len =ARM_TBFLAG_VECLEN (tb->flags);
target-arm/translate.h +1 -0
@@ -20,6 +20,7 @@ typedef struct DisasContext {#if !defined(CONFIG_USER_ONLY )int user;#endif +bool ns;/* Use non-secure CPREG bank on access */ bool cpacr_fpen;/* FP enabled via CPACR.FPEN */ bool vfp_enabled;/* FP enabled via FPSCR.EN */ int vec_len;
Signature · 1 line
1.8.3.2
PATCH v9 5/26 target-arm: add CPREG secure state support
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
Prepare ARMCPRegInfo to support specifying two fieldoffsets per register definition. This will allow us to keep one register definition for banked registers (different offsets for secure/ non-secure world).
Also added secure state tracking field and flags. This allows for identification of the register info secure state.
---
v8 -> v9
- Removed ARM_CP_SECSTATE_TEST macro
- Replaced dropped comment
v7 -> v8
- Break up the fieldoffset union to avoid need for sometimes overwriting one bank when updating fieldoffset. This also removes the need for the #define short-cut introduced in v7.
v6 -> v7
- Add naming for fieldoffset fields and macros for accessing. This was needed to overcome issues with the GCC-4.4 compiler.
v5 -> v6
- Separate out secure CPREG flags
- Add convenience macro for testing flags
- Removed extraneous newline
- Move add_cpreg_to_hashtable() functionality to a later commit for which it is dependent on.
- Added comment explaining fieldoffset padding
v4 -> v5
- Added ARM CP register secure and non-secure bank flags
- Added setting of secure and non-secure flags furing registration
--- target-arm/cpu.h | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-)
target-arm/cpu.h +34 -2
@@ -993,6 +993,21 @@ enum { ARM_CP_STATE_BOTH = 2, }; +/* ARM CP register secure state flags. These flags identify security state +* attributes for a given CP register entry. +* The existence of both or neither secure and non-secure flags indicates that +* the register has both a secure and non-secure hash entry. A single one of +* these flags causes the register to only be hashed for the specified +* security state. +* Although definitions may have any combination of the S/NS bits, each +* registered entry will only have one to identify whether the entry is secure +* or non-secure. +*/ +enum { +ARM_CP_SECSTATE_S = (1 <<0 ),/* bit[0]: Secure state register */ +ARM_CP_SECSTATE_NS = (1 <<1 ),/* bit[1]: Non-secure state register */ +}; +/* Return true if cptype is a valid type field. This is used to try to * catch errors where the sentinel has been accidentally left off the end * of a list of registers.
@@ -1127,6 +1142,8 @@ struct ARMCPRegInfo {int type;/* Access rights: PL*_[RW] */ int access; +/* Security state: ARM_CP_SECSTATE_* bits/values */ +int secure;/* The opaque pointer passed to define_arm_cp_regs_with_opaque() when * this register was defined: can be used to hand data through to the * register read/write functions, since they are passed the ARMCPRegInfo*.
@@ -1136,12 +1153,27 @@ struct ARMCPRegInfo {* fieldoffset is non-zero, the reset value of the register. */ uint64_t resetvalue; -/* Offset of the field in CPUARMState for this register. This is not -* needed if either: +/* Offset of the field in CPUARMState for this register. +* +* This is not needed if either: * 1. type is ARM_CP_CONST or one of the ARM_CP_SPECIALs * 2. both readfn and writefn are specified */ ptrdiff_t fieldoffset;/* offsetof(CPUARMState, field) */ + +/* Offsets of the secure and non-secure fields in CPUARMState for the +* register if it is banked. These fields are only used during the static +* registration of a register. During hashing the bank associated +* with a given security state is copied to fieldoffset which is used from +* there on out. +* +* It is expected that register definitions use either fieldoffset or +* bank_fieldoffsets in the definition but not both. It is also expected +* that both bank offsets are set when defining a banked register. This +* use indicates that a register is banked. +*/ +ptrdiff_t bank_fieldoffsets[2 ]; +/* Function for making any access checks for this register in addition to * those specified by the 'access' permissions bits. If NULL, no extra * checks required. The access check is performed at runtime, not at
Signature · 1 line
1.8.3.2
PATCH v9 6/26 target-arm: add secure state bit to CPREG hash
In reply to Greg BellowsAdded additional NS-bit to CPREG hash encoding. Updated hash lookup locations to specify hash bit currently set to non-secure.
---
v8 -> v9
- Fixed CP_REG_NS_MASK
- Changed ENCODE_CP_REG argument order so ns follows is64
- Replaced use of CP_REG_NS_MASK with CP_REG_NS_SHIFT
- Changed add_cpreg_to_hashtable argument order so ns follows is64
- Replaced use of SCR_NS with ARM_CP_SECSTATE_NS on registration
- Undid global replace of Aarch# with AArch# in translate.c
v5 -> v6
- Globally replace Aarch# with AArch#
--- target-arm/cpu.h | 25 ++++++++++++++++++++----- target-arm/helper.c | 7 ++++--- target-arm/translate.c | 14 +++++++++----- 3 files changed, 33 insertions(+), 13 deletions(-)
target-arm/cpu.h +20 -5
@@ -879,6 +879,7 @@ void armv7m_nvic_complete_irq(void *opaque, int irq);* Crn, Crm, opc1, opc2 fields * 32 or 64 bit register (ie is it accessed via MRC/MCR * or via MRRC/MCRR?) +* non-secure/secure bank (AArch32 only) * We allow 4 bits for opc1 because MRRC/MCRR have a 4 bit field. * (In this case crn and opc2 should be zero.) * For AArch64, there is no 32/64 bit size distinction;
@@ -896,9 +897,16 @@ void armv7m_nvic_complete_irq(void *opaque, int irq);#define CP_REG_AA64_SHIFT 28#define CP_REG_AA64_MASK (1 << CP_REG_AA64_SHIFT) -#define ENCODE_CP_REG (cp, is64, crn, crm, opc1, opc2) \ - (((cp) << 16) | ((is64) << 15) | ((crn) << 11) | \ - ((crm) << 7) | ((opc1) << 3) | (opc2)) +/* To enable banking of coprocessor registers depending on ns-bit we +* add a bit to distinguish between secure and non-secure cpregs in the +* hashtable. +*/ +#define CP_REG_NS_SHIFT 29 +#define CP_REG_NS_MASK (1 << CP_REG_NS_SHIFT) + +#define ENCODE_CP_REG (cp, is64, ns, crn, crm, opc1, opc2) \ + ((ns) << CP_REG_NS_SHIFT | ((cp) << 16) | ((is64) << 15) | \ + ((crn) << 11) | ((crm) << 7) | ((opc1) << 3) | (opc2))#define ENCODE_AA64_CP_REG (cp, crn, crm, op0, op1, op2) \ (CP_REG_AA64_MASK | \
@@ -917,8 +925,15 @@ static inline uint32_t kvm_to_cpreg_id(uint64_t kvmid)uint32_t cpregid = kvmid;if ((kvmid &CP_REG_ARCH_MASK ) ==CP_REG_ARM64 ) { cpregid |=CP_REG_AA64_MASK ; - }else if ((kvmid &CP_REG_SIZE_MASK ) ==CP_REG_SIZE_U64 ) { - cpregid |= (1 <<15 ); + }else { +if ((kvmid &CP_REG_SIZE_MASK ) ==CP_REG_SIZE_U64 ) { + cpregid |= (1 <<15 ); + } + +/* KVM is always non-secure so add the NS flag on AArch32 register +* entries. +*/ + cpregid |=1 <<CP_REG_NS_SHIFT ; }return cpregid; }
target-arm/helper.c +4 -3
@@ -3287,7 +3287,7 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) }static void add_cpreg_to_hashtable (ARMCPU *cpu,const ARMCPRegInfo *r, -void *opaque,int state, +void *opaque,int state,int secstate,int crm,int opc1,int opc2) {/* Private utility function for define_one_arm_cp_reg_with_opaque():
@@ -3296,6 +3296,7 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r,uint32_t *key =g_new (uint32_t,1 );ARMCPRegInfo *r2 =g_memdup (r,sizeof (ARMCPRegInfo));int is64 = (r->type &ARM_CP_64BIT ) ?1 :0 ; +int ns = (r->secure &ARM_CP_SECSTATE_NS ) ?1 :0 ;if (r->state ==ARM_CP_STATE_BOTH && state ==ARM_CP_STATE_AA32 ) {/* The AArch32 view of a shared register sees the lower 32 bits * of a 64 bit backing field. It is not migratable as the AArch64
@@ -3327,7 +3328,7 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, *key =ENCODE_AA64_CP_REG (r2->cp, r2->crn, crm, r2->opc0, opc1, opc2); }else { - *key =ENCODE_CP_REG (r2->cp, is64, r2->crn, crm, opc1, opc2); + *key =ENCODE_CP_REG (r2->cp, is64, ns, r2->crn, crm, opc1, opc2); }if (opaque) { r2->opaque = opaque;
@@ -3477,7 +3478,7 @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,continue ; }add_cpreg_to_hashtable (cpu, r, opaque, state, - crm, opc1, opc2); +ARM_CP_SECSTATE_NS , crm, opc1, opc2); } } }
target-arm/translate.c +9 -5
@@ -7074,7 +7074,7 @@ static int disas_coproc_insn(CPUARMState * env, DisasContext *s, uint32_t insn) rt = (insn >>12 ) &0xf ; ri =get_arm_cp_reginfo (s->cp_regs, -ENCODE_CP_REG (cpnum, is64, crn, crm, opc1, opc2)); +ENCODE_CP_REG (cpnum, is64, s->ns, crn, crm, opc1, opc2));if (ri) {/* Check access permissions */ if (!cp_access_ok (s->current_el, ri, isread)) {
@@ -7264,12 +7264,16 @@ static int disas_coproc_insn(CPUARMState * env, DisasContext *s, uint32_t insn)*/ if (is64) {qemu_log_mask (LOG_UNIMP ,"%s access to unsupported AArch32 " -"64 bit system register cp:%d opc1: %d crm:%d\n" , - isread ?"read" :"write" , cpnum, opc1, crm); +"64 bit system register cp:%d opc1: %d crm:%d " +"(%s)\n" , + isread ?"read" :"write" , cpnum, opc1, crm, + s->ns ?"non-secure" :"secure" ); }else {qemu_log_mask (LOG_UNIMP ,"%s access to unsupported AArch32 " -"system register cp:%d opc1:%d crn:%d crm:%d opc2:%d\n" , - isread ?"read" :"write" , cpnum, opc1, crn, crm, opc2); +"system register cp:%d opc1:%d crn:%d crm:%d opc2:%d " +"(%s)\n" , + isread ?"read" :"write" , cpnum, opc1, crn, crm, opc2, + s->ns ?"non-secure" :"secure" ); }return 1 ;
Signature · 1 line
1.8.3.2
PATCH v9 7/26 target-arm: insert AArch32 cpregs twice into hashtable
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
Prepare for cp register banking by inserting every cp register twice, once for secure world and once for non-secure world.
---
v8 -> v9
- Fixed setting of secure field in add_cpreg_to_hashtable so it uses secstate and happens in all cases.
- Fixed check for disabling of migration to only occur on duplicately defined reginfos.
- Fixed comment on disabling migration and reset and eliminated crn special case.
- Reworked define_one_arm_cp_reg_with_opaque() secure case handling.
v7 -> v8
- Updated define registers asserts to allow either a non-zero fieldoffset or non-zero bank_fieldoffsets.
- Updated CP register hashing to always set the register fieldoffset when banked register offsets are specified.
v5 -> v6
- Fixed NS-bit number in the CPREG hash lookup from 27 to 29.
- Switched to dedicated CPREG secure flags.
- Fixed disablement of reset and migration of common 32/64-bit registers.
- Globally replace Aarch# with AArch#
v4 -> v5
- Added use of ARM CP secure/non-secure bank flags during register processing in define_one_arm_cp_reg_with_opaque(). We now only register the specified bank if only one flag is specified, otherwise we register both a secure and non-secure instance.
--- target-arm/helper.c | 98 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 81 insertions(+), 17 deletions(-)
target-arm/helper.c +81 -17
@@ -3296,23 +3296,59 @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r,uint32_t *key =g_new (uint32_t,1 );ARMCPRegInfo *r2 =g_memdup (r,sizeof (ARMCPRegInfo));int is64 = (r->type &ARM_CP_64BIT ) ?1 :0 ; -int ns = (r->secure &ARM_CP_SECSTATE_NS ) ?1 :0 ; -if (r->state ==ARM_CP_STATE_BOTH && state ==ARM_CP_STATE_AA32 ) { -/* The AArch32 view of a shared register sees the lower 32 bits -* of a 64 bit backing field. It is not migratable as the AArch64 -* view handles that. AArch64 also handles reset. -* We assume it is a cp15 register if the .cp field is left unset. +int ns = (secstate &ARM_CP_SECSTATE_NS ) ?1 :0 ; + +/* Reset the secure state to the specific incoming state. This is +* necessary as the register may have been defined with both states. +*/ + r2->secure = secstate; + +if (r->bank_fieldoffsets[0 ] && r->bank_fieldoffsets[1 ]) { +/* Register is banked (using both entries in array). +* Overwriting fieldoffset as the array is only used to define +* banked registers but later only fieldoffset is used. */ -if (r2->cp ==0 ) { - r2->cp =15 ; + r2->fieldoffset = r->bank_fieldoffsets[ns]; + } + +if (state ==ARM_CP_STATE_AA32 ) { +if (r->bank_fieldoffsets[0 ] && r->bank_fieldoffsets[1 ]) { +/* If the register is banked then we don't need to migrate or +* reset the 32-bit instance in certain cases: +* +* 1) If the register has both 32-bit and 64-bit instances then we +* can count on the 64-bit instance taking care of the +* non-secure bank. +* 2) If ARMv8 is enabled then we can count on a 64-bit version +* taking care of the secure bank. This requires that separate +* 32 and 64-bit definitions are provided. +*/ +if ((r->state ==ARM_CP_STATE_BOTH && ns) || + (arm_feature (&cpu->env,ARM_FEATURE_V8 ) && !ns)) { + r2->type |=ARM_CP_NO_MIGRATE ; + r2->resetfn = arm_cp_reset_ignore; + } + }else if ((secstate != r->secure) && !ns) { +/* The register is not banked so we only want to allow migration of +* the non-secure instance. +*/ + r2->type |=ARM_CP_NO_MIGRATE ; + r2->resetfn = arm_cp_reset_ignore; } - r2->type |=ARM_CP_NO_MIGRATE ; - r2->resetfn = arm_cp_reset_ignore; + +if (r->state ==ARM_CP_STATE_BOTH ) { +/* We assume it is a cp15 register if the .cp field is left unset. +*/ +if (r2->cp ==0 ) { + r2->cp =15 ; + } +#ifdef HOST_WORDS_BIGENDIAN -if (r2->fieldoffset) { - r2->fieldoffset +=sizeof (uint32_t ); - } +if (r2->fieldoffset) { + r2->fieldoffset +=sizeof (uint32_t ); + }#endif + } }if (state ==ARM_CP_STATE_AA64 ) {/* To allow abbreviation of ARMCPRegInfo
@@ -3461,10 +3497,14 @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,*/ if (!(r->type & (ARM_CP_SPECIAL |ARM_CP_CONST ))) {if (r->access &PL3_R ) { -assert (r->fieldoffset || r->readfn); +assert ((r->fieldoffset || + (r->bank_fieldoffsets[0 ] && r->bank_fieldoffsets[1 ])) || + r->readfn); }if (r->access &PL3_W ) { -assert (r->fieldoffset || r->writefn); +assert ((r->fieldoffset || + (r->bank_fieldoffsets[0 ] && r->bank_fieldoffsets[1 ])) || + r->writefn); } }/* Bad type field probably means missing sentinel at end of reg list */
@@ -3477,8 +3517,32 @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,if (r->state != state && r->state !=ARM_CP_STATE_BOTH ) {continue ; } -add_cpreg_to_hashtable (cpu, r, opaque, state, -ARM_CP_SECSTATE_NS , crm, opc1, opc2); +if (state ==ARM_CP_STATE_AA32 ) { +/* Under AArch32 CP registers can be common +* (same for secure and non-secure world) or banked. +*/ +switch (r->secure) { +case ARM_CP_SECSTATE_S : +case ARM_CP_SECSTATE_NS : +add_cpreg_to_hashtable (cpu, r, opaque, state, + r->secure, crm, opc1, opc2); +break ; +default : +add_cpreg_to_hashtable (cpu, r, opaque, state, +ARM_CP_SECSTATE_S , + crm, opc1, opc2); +add_cpreg_to_hashtable (cpu, r, opaque, state, +ARM_CP_SECSTATE_NS , + crm, opc1, opc2); +break ; + } + }else { +/* AArch64 registers get mapped to non-secure instance +* of AArch32 */ +add_cpreg_to_hashtable (cpu, r, opaque, state, +ARM_CP_SECSTATE_NS , + crm, opc1, opc2); + } } } }
Signature · 1 line
1.8.3.2
PATCH v9 8/26 target-arm: move AArch32 SCR into security reglist
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
Define a new ARM CP register info list for the ARMv7 Security Extension feature. Register that list only for ARM cores with Security Extension/EL3 support. Moving AArch32 SCR into Security Extension register group.
---
v7 -> v8
- Fix SCR register fieldoffset to be offsetoflow32.
- Rename v7_el3_cp_reginfo to el3_cp_reginfo and remove v7 feature check when defining. This allows all common v7/8 secure CP regs to be registered together leaving the v8_el3_cp_reginfo to only v8 specific EL3 registers.
- Move SCR_EL3 into el3_cp_reginfo.
v4 -> v5
- Added reset value on SCR_EL3
- Squashed SCR Migration fix (previously patch 33)
This patch adds code to mark duplicate CP register registrations as NO_MIGRATE to avoid duplicate migrations.
v3 -> v4
- Renamed security_cp_reginfo to v7_el3_cp_reginfo
- Conditionalized define on whether v7 or v8 were enabled
--- target-arm/helper.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
target-arm/helper.c +13 -6
@@ -898,9 +898,6 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .access = PL1_RW, .writefn = vbar_write, .fieldoffset = offsetof(CPUARMState, cp15.vbar_el[1]), .resetvalue = 0 }, - { .name = "SCR", .cp = 15, .crn = 1, .crm = 1, .opc1 = 0, .opc2 = 0, - .access = PL1_RW, .fieldoffset = offsetoflow32(CPUARMState, cp15.scr_el3), - .resetvalue = 0, .writefn = scr_write }, { .name = "CCSIDR", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .crn = 0, .crm = 0, .opc1 = 1, .opc2 = 0, .access = PL1_R, .readfn = ccsidr_read, .type = ARM_CP_NO_MIGRATE },
@@ -2335,11 +2332,18 @@ static const ARMCPRegInfo v8_el3_cp_reginfo[] = { .access = PL3_RW, .writefn = vbar_write, .fieldoffset = offsetof(CPUARMState, cp15.vbar_el[3]), .resetvalue = 0 }, + REGINFO_SENTINEL +}; + +static const ARMCPRegInfo el3_cp_reginfo[] = { { .name ="SCR_EL3" , .state =ARM_CP_STATE_AA64 , - .type = ARM_CP_NO_MIGRATE, .opc0 =3 , .opc1 =6 , .crn =1 , .crm =1 , .opc2 =0 , .access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.scr_el3), - .writefn = scr_write }, + .resetvalue =0 , .writefn = scr_write }, + { .name ="SCR" , .type =ARM_CP_NO_MIGRATE , + .cp =15 , .opc1 =0 , .crn =1 , .crm =1 , .opc2 =0 , + .access =PL3_RW , .fieldoffset =offsetoflow32 (CPUARMState, cp15.scr_el3), + .resetfn = arm_cp_reset_ignore, .writefn = scr_write },REGINFO_SENTINEL };
@@ -2960,7 +2964,10 @@ void register_cp_regs_for_features(ARMCPU *cpu) } }if (arm_feature (env,ARM_FEATURE_EL3 )) { -define_arm_cp_regs (cpu, v8_el3_cp_reginfo); +if (arm_feature (env,ARM_FEATURE_V8 )) { +define_arm_cp_regs (cpu, v8_el3_cp_reginfo); + } +define_arm_cp_regs (cpu, el3_cp_reginfo); }if (arm_feature (env,ARM_FEATURE_MPU )) {/* These are the MPU registers prior to PMSAv6. Any new
Signature · 1 line
1.8.3.2
PATCH v9 9/26 target-arm: implement IRQ/FIQ routing to Monitor mode
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
SCR.{IRQ/FIQ} bits allow to route IRQ/FIQ exceptions to monitor CPU mode. When taking IRQ exception to monitor mode FIQ exception is additionally masked.
--- target-arm/helper.c | 9 +++++++++ 1 file changed, 9 insertions(+)
target-arm/helper.c +9 -0
@@ -4233,12 +4233,21 @@ void arm_cpu_do_interrupt(CPUState *cs)/* Disable IRQ and imprecise data aborts. */ mask =CPSR_A |CPSR_I ; offset =4 ; +if (env->cp15.scr_el3 &SCR_IRQ ) { +/* IRQ routed to monitor mode */ + new_mode =ARM_CPU_MODE_MON ; + mask |=CPSR_F ; + }break ;case EXCP_FIQ : new_mode =ARM_CPU_MODE_FIQ ; addr =0x1c ;/* Disable FIQ, IRQ and imprecise data aborts. */ mask =CPSR_A |CPSR_I |CPSR_F ; +if (env->cp15.scr_el3 &SCR_FIQ ) { +/* FIQ routed to monitor mode */ + new_mode =ARM_CPU_MODE_MON ; + } offset =4 ;break ;case EXCP_SMC :
Signature · 1 line
1.8.3.2
PATCH v9 10/26 target-arm: add NSACR register
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
Implements NSACR register with corresponding read/write functions for ARMv7 and ARMv8.
---
v8 -> v9
- Removed unused NSACR constants
- Added TODO for trapping secure EL1 accesses to NSACR
- Change NSACR access from PL3_RW to PL3_W
- Fixed declaration order of the NSACR register components
v7 -> v8
- Update naming from c1_nsacr to nsacr to match other registers being changed.
- Remove NSACR read/write functions
v4 -> v5
- Changed to use renamed arm_current_el()
--- target-arm/cpu.h | 1 + target-arm/helper.c | 4 ++++ 2 files changed, 5 insertions(+)
target-arm/cpu.h +1 -0
@@ -181,6 +181,7 @@ typedef struct CPUARMState {uint64_t c1_sys;/* System control register. */ uint64_t c1_coproc;/* Coprocessor access register. */ uint32_t c1_xscaleauxcr;/* XScale auxiliary control register. */ +uint32_t nsacr;/* Non-secure access control register. */ uint64_t ttbr0_el1;/* MMU translation table base 0. */ uint64_t ttbr1_el1;/* MMU translation table base 1. */ uint64_t c2_control;/* MMU translation table base control. */
target-arm/helper.c +4 -0
@@ -2344,6 +2344,10 @@ static const ARMCPRegInfo el3_cp_reginfo[] = { .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 0, .access = PL3_RW, .fieldoffset = offsetoflow32(CPUARMState, cp15.scr_el3), .resetfn = arm_cp_reset_ignore, .writefn = scr_write }, +/* TODO: Implement NSACR trapping of secure EL1 accesses to EL3 */ + { .name = "NSACR", .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 2, + .access = PL3_W | PL1_R, .resetvalue = 0, + .fieldoffset = offsetof(CPUARMState, cp15.nsacr) }, REGINFO_SENTINEL };
Signature · 1 line
1.8.3.2
PATCH v9 11/26 target-arm: add SDER definition
In reply to Greg BellowsAdded CP register defintions for SDER and SDER32_EL3 as well as cp15.sder for register storage.
---
v8 -> v9
- Fixed declaration order of the SDER register components
v7 -> v8
- Added SDER32_EL3 register definition
- Changed sder name from c1_sder to sder
- Changed sder from uint32_t to uint64_t.
--- target-arm/cpu.h | 1 + target-arm/helper.c | 8 ++++++++ 2 files changed, 9 insertions(+)
target-arm/cpu.h +1 -0
@@ -181,6 +181,7 @@ typedef struct CPUARMState {uint64_t c1_sys;/* System control register. */ uint64_t c1_coproc;/* Coprocessor access register. */ uint32_t c1_xscaleauxcr;/* XScale auxiliary control register. */ +uint64_t sder;/* Secure debug enable register. */ uint32_t nsacr;/* Non-secure access control register. */ uint64_t ttbr0_el1;/* MMU translation table base 0. */ uint64_t ttbr1_el1;/* MMU translation table base 1. */
target-arm/helper.c +8 -0
@@ -2344,6 +2344,14 @@ static const ARMCPRegInfo el3_cp_reginfo[] = { .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 0, .access = PL3_RW, .fieldoffset = offsetoflow32(CPUARMState, cp15.scr_el3), .resetfn = arm_cp_reset_ignore, .writefn = scr_write }, + { .name = "SDER32_EL3", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 1, .opc2 = 1, + .access = PL3_RW, .resetvalue = 0, + .fieldoffset = offsetof(CPUARMState, cp15.sder) }, + { .name = "SDER", + .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 1, + .access = PL3_RW, .resetvalue = 0, + .fieldoffset = offsetoflow32(CPUARMState, cp15.sder) }, /* TODO: Implement NSACR trapping of secure EL1 accesses to EL3 */ { .name = "NSACR", .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 2, .access = PL3_W | PL1_R, .resetvalue = 0,
Signature · 1 line
1.8.3.2
PATCH v9 12/26 target-arm: add MVBAR support
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
Use MVBAR register as exception vector base address for exceptions taken to CPU monitor mode.
---
v8 -> v9
- Fixed declaration order of the MVBAR register components
v7 -> v8
- Changed the mvbar cp15 storage from uint64_t to uint32_t
--- target-arm/cpu.h | 1 + target-arm/helper.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-)
target-arm/cpu.h +1 -0
@@ -211,6 +211,7 @@ typedef struct CPUARMState {uint32_t c9_pminten;/* perf monitor interrupt enables */ uint64_t mair_el1;uint64_t vbar_el[4 ];/* vector base address register */ +uint32_t mvbar;/* (monitor) vector base address register */ uint32_t c13_fcse;/* FCSE PID. */ uint64_t contextidr_el1;/* Context ID. */ uint64_t tpidr_el0;/* User RW Thread register. */
target-arm/helper.c +9 -6
@@ -2356,6 +2356,9 @@ static const ARMCPRegInfo el3_cp_reginfo[] = { { .name = "NSACR", .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 2, .access = PL3_W | PL1_R, .resetvalue = 0, .fieldoffset = offsetof(CPUARMState, cp15.nsacr) }, + { .name = "MVBAR", .cp = 15, .opc1 = 0, .crn = 12, .crm = 0, .opc2 = 1, + .access = PL3_RW, .writefn = vbar_write, .resetvalue = 0, + .fieldoffset = offsetof(CPUARMState, cp15.mvbar) }, REGINFO_SENTINEL };
@@ -4272,16 +4275,16 @@ void arm_cpu_do_interrupt(CPUState *cs)cpu_abort (cs,"Unhandled exception 0x%x\n" , cs->exception_index);return ;/* Never happens. Keep compiler happy. */ } -/* High vectors. */ -if (env->cp15.c1_sys &SCTLR_V ) { -/* when enabled, base address cannot be remapped. */ + +if (new_mode ==ARM_CPU_MODE_MON ) { + addr += env->cp15.mvbar; + }else if (env->cp15.c1_sys &SCTLR_V ) { +/* High vectors. When enabled, base address cannot be remapped. */ addr +=0xffff0000 ; }else {/* ARM v7 architectures provide a vector base address register to remap * the interrupt vector table. -* This register is only followed in non-monitor mode, and has a secure -* and un-secure copy. Since the cpu is always in a un-secure operation -* and is never in monitor mode this feature is always active. +* This register is only followed in non-monitor mode, and is banked. * Note: only bits 31:5 are valid. */ addr += env->cp15.vbar_el[1 ];
--
1.8.3.2
PATCH v9 13/26 target-arm: add SCTLR_EL3 and make SCTLR banked
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
Implements SCTLR_EL3 and uses secure/non-secure instance when needed.
---
v8 -> v9
- Remove the v8 check in arm_cpu_reset when setting regs[15]
- Fix SCTLR definition component order
v5 -> v6
- Changed _el field variants to be array based
- Consolidate SCTLR and SCTLR_EL1 reginfo entries
--- hw/arm/pxa2xx.c | 2 +- target-arm/cpu.c | 8 ++++-- target-arm/cpu.h | 10 ++++++- target-arm/helper.c | 72 +++++++++++++++++++++++++++++--------------------- target-arm/op_helper.c | 2 +- 5 files changed, 59 insertions(+), 35 deletions(-)
hw/arm/pxa2xx.c +1 -1
@@ -273,7 +273,7 @@ static void pxa2xx_pwrmode_write(CPUARMState *env, const ARMCPRegInfo *ri,case 3 : s->cpu->env.uncached_cpsr =ARM_CPU_MODE_SVC ; s->cpu->env.daif =PSTATE_A |PSTATE_F |PSTATE_I ; - s->cpu->env.cp15.c1_sys =0 ; + s->cpu->env.cp15.sctlr_ns =0 ; s->cpu->env.cp15.c1_coproc =0 ; s->cpu->env.cp15.ttbr0_el1 =0 ; s->cpu->env.cp15.c3 =0 ;
target-arm/cpu.c +6 -2
@@ -109,7 +109,7 @@ static void arm_cpu_reset(CPUState *s)#if defined(CONFIG_USER_ONLY ) env->pstate = PSTATE_MODE_EL0t;/* Userspace expects access to DC ZVA, CTL_EL0 and the cache ops */ - env->cp15.c1_sys |=SCTLR_UCT |SCTLR_UCI |SCTLR_DZE ; + env->cp15.sctlr_el[1 ] |=SCTLR_UCT |SCTLR_UCI |SCTLR_DZE ;/* and to the FP/Neon instructions */ env->cp15.c1_coproc =deposit64 (env->cp15.c1_coproc,20 ,2 ,3 );#else
@@ -167,7 +167,11 @@ static void arm_cpu_reset(CPUState *s) env->thumb = initial_pc &1 ; } -if (env->cp15.c1_sys &SCTLR_V ) { +/* AArch32 has a hard highvec setting of 0xFFFF0000. If we are currently +* executing as AArch32 then check if highvecs are enabled and +* adjust the PC accordingly. +*/ +if (A32_BANKED_CURRENT_REG_GET (env, sctlr) &SCTLR_V ) { env->regs[15 ] =0xFFFF0000 ; }
target-arm/cpu.h +9 -1
@@ -178,7 +178,15 @@ typedef struct CPUARMState {struct {uint32_t c0_cpuid;uint64_t c0_cssel;/* Cache size selection. */ -uint64_t c1_sys;/* System control register. */ +union {/* System control register. */ +struct { +uint64_t _unused_sctlr; +uint64_t sctlr_ns; +uint64_t hsctlr; +uint64_t sctlr_s; + }; +uint64_t sctlr_el[4 ]; + };uint64_t c1_coproc;/* Coprocessor access register. */ uint32_t c1_xscaleauxcr;/* XScale auxiliary control register. */ uint64_t sder;/* Secure debug enable register. */
target-arm/helper.c +42 -30
159 lines not on this page · raw message
target-arm/op_helper.c +1 -1
@@ -361,7 +361,7 @@ void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm)* Note that SPSel is never OK from EL0; we rely on handle_msr_i() * to catch that case at translate time. */ -if (arm_current_el (env) ==0 && !(env->cp15.c1_sys &SCTLR_UMA )) { +if (arm_current_el (env) ==0 && !(env->cp15.sctlr_el[1 ] &SCTLR_UMA )) {raise_exception (env,EXCP_UDEF ); }
Signature · 1 line
1.8.3.2
PATCH v9 14/26 target-arm: respect SCR.FW, SCR.AW and SCTLR.NMFI
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
Add checks of SCR AW/FW bits when performing writes of CPSR. These SCR bits are used to control whether the CPSR masking bits can be adjusted from non-secure state.
---
v8 -> v9
- Move cpsr_write mask filtering above mode switch.
- Replace conditional checks removed in v8.
v7 -> v8
- Fixed incorrect use of env->uncached_cpsr A/I/F to use env->daif instead.
- Removed incorrect statement about SPSR to CPSR copies being affected by SCR.AW/FW.
- Fix typo in comment.
- Simpified cpsr_write logic
v3 -> v4
- Fixed up conditions for ignoring CPSR.A/F updates by isolating to v7 and checking for the existence of EL3 and non-existence of EL2.
--- target-arm/helper.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-)
target-arm/helper.c +57 -2
@@ -3644,6 +3644,8 @@ uint32_t cpsr_read(CPUARMState *env)void cpsr_write (CPUARMState *env,uint32_t val,uint32_t mask) { +uint32_t changed_daif; +if (mask &CPSR_NZCV ) { env->ZF = (~val) &CPSR_Z ; env->NF = val;
@@ -3666,8 +3668,57 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) env->GE = (val >>16 ) &0xf ; } - env->daif &= ~(CPSR_AIF & mask); - env->daif |= val &CPSR_AIF & mask; +/* In a V7 implementation that includes the security extensions but does +* not include Virtualization Extensions the SCR.FW and SCR.AW bits control +* whether non-secure software is allowed to change the CPSR_F and CPSR_A +* bits respectively. +* +* In a V8 implementation, it is permitted for privileged software to +* change the CPSR A/F bits regardless of the SCR.AW/FW bits. +*/ +if (!arm_feature (env,ARM_FEATURE_V8 ) && +arm_feature (env,ARM_FEATURE_EL3 ) && + !arm_feature (env,ARM_FEATURE_EL2 ) && + !arm_is_secure (env)) { + + changed_daif = (env->daif ^ val) & mask; + +if (changed_daif &CPSR_A ) { +/* Check to see if we are allowed to change the masking of async +* abort exceptions from a non-secure state. +*/ +if (!(env->cp15.scr_el3 &SCR_AW )) { +qemu_log_mask (LOG_GUEST_ERROR , +"Ignoring attempt to switch CPSR_A flag from " +"non-secure world with SCR.AW bit clear\n" ); + mask &= ~CPSR_A ; + } + } + +if (changed_daif &CPSR_F ) { +/* Check to see if we are allowed to change the masking of FIQ +* exceptions from a non-secure state. +*/ +if (!(env->cp15.scr_el3 &SCR_FW )) { +qemu_log_mask (LOG_GUEST_ERROR , +"Ignoring attempt to switch CPSR_F flag from " +"non-secure world with SCR.FW bit clear\n" ); + mask &= ~CPSR_F ; + } + +/* Check whether non-maskable FIQ (NMFI) support is enabled. +* If this bit is set software is not allowed to mask +* FIQs, but is allowed to set CPSR_F to 0. +*/ +if ((A32_BANKED_CURRENT_REG_GET (env, sctlr) &SCTLR_NMFI ) && + (val &CPSR_F )) { +qemu_log_mask (LOG_GUEST_ERROR , +"Ignoring attempt to enable CPSR_F flag " +"(non-maskable FIQ [NMFI] support enabled)\n" ); + mask &= ~CPSR_F ; + } + } + }if ((env->uncached_cpsr ^ val) & mask &CPSR_M ) {if (bad_mode_switch (env, val &CPSR_M )) {
@@ -3680,6 +3731,10 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)switch_mode (env, val &CPSR_M ); } } + + env->daif &= ~(CPSR_AIF & mask); + env->daif |= val &CPSR_AIF & mask; + mask &= ~CACHED_CPSR_BITS ; env->uncached_cpsr = (env->uncached_cpsr & ~mask) | (val & mask); }
Signature · 1 line
1.8.3.2
PATCH v9 15/26 target-arm: make CSSELR banked
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
Rename CSSELR (cache size selection register) and add secure instance (AArch32).
---
v8 -> v9
- Replaced call to ARM_CP_SECSTATE_TEST with direct access
v7 -> v8
- Fix CSSELR CP register definition to use .opc0 rather than .cp.
v5 -> v6
- Changed _el field variants to be array based
- Switch to use distinct CPREG secure flags.
- Merged CSSELR and CSSELR_EL1 reginfo entries
v4 -> v5
- Changed to use the CCSIDR cpreg bank flag to select the csselr bank instead of the A32_BANKED macro. This more accurately uses the secure state bank matching the CCSIDR.
--- target-arm/cpu.h | 10 +++++++++- target-arm/helper.c | 14 +++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-)
target-arm/cpu.h +9 -1
@@ -177,7 +177,15 @@ typedef struct CPUARMState {/* System control coprocessor (cp15) */ struct { uint32_t c0_cpuid; - uint64_t c0_cssel; /* Cache size selection. */ + union { /* Cache size selection */ + struct { + uint64_t _unused_csselr0; + uint64_t csselr_ns; + uint64_t _unused_csselr1; + uint64_t csselr_s; + }; + uint64_t csselr_el[4]; + }; union { /* System control register. */ struct { uint64_t _unused_sctlr;
target-arm/helper.c +11 -3
@@ -776,7 +776,14 @@ static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)static uint64_t ccsidr_read (CPUARMState *env,const ARMCPRegInfo *ri) {ARMCPU *cpu =arm_env_get_cpu (env); -return cpu->ccsidr[env->cp15.c0_cssel]; + +/* Acquire the CSSELR index from the bank corresponding to the CCSIDR +* bank +*/ +uint32_t index =A32_BANKED_REG_GET (env, csselr, + ri->secure &ARM_CP_SECSTATE_S ); + +return cpu->ccsidr[index]; } static void csselr_write(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -903,8 +910,9 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { .access = PL1_R, .readfn = ccsidr_read, .type = ARM_CP_NO_MIGRATE }, { .name = "CSSELR", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .crn = 0, .crm = 0, .opc1 = 2, .opc2 = 0, - .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c0_cssel), - .writefn = csselr_write, .resetvalue = 0 }, + .access = PL1_RW, .writefn = csselr_write, .resetvalue = 0, + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.csselr_s), + offsetof(CPUARMState, cp15.csselr_ns) } },/* Auxiliary ID register: this actually has an IMPDEF value but for now * just RAZ for all cores: */
Signature · 1 line
1.8.3.2
PATCH v9 16/26 target-arm: make TTBR0/1 banked
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
Adds secure and non-secure bank register suport for TTBR0 and TTBR1. Changes include adding secure and non-secure instances of ttbr0 and ttbr1 as well as a CP register definition for TTBR0_EL3. Added a union containing both EL based array fields and secure and non-secure fields mapped to them. Updated accesses to use A32_BANKED_CURRENT_REG_GET macro.
---
v8 -> v9
- Fixed naming of TTBR0/1 and defined with opc0 instead of cp
- Removed get_phys_addr_lpae() AArch64 EL3 support.
- Remove stray whitespace change in pxa2xx.c
v5 -> v6
- Changed _el field variants to be array based
- Merged TTBR# and TTBR#_EL1 reginfo entries
- Globally replace Aarch# with AArch#
--- hw/arm/pxa2xx.c | 2 +- target-arm/cpu.h | 20 ++++++++++++++++++-- target-arm/helper.c | 37 +++++++++++++++++++++++++------------ 3 files changed, 44 insertions(+), 15 deletions(-)
hw/arm/pxa2xx.c +1 -1
@@ -275,7 +275,7 @@ static void pxa2xx_pwrmode_write(CPUARMState *env, const ARMCPRegInfo *ri, s->cpu->env.daif =PSTATE_A |PSTATE_F |PSTATE_I ; s->cpu->env.cp15.sctlr_ns =0 ; s->cpu->env.cp15.c1_coproc =0 ; - s->cpu->env.cp15.ttbr0_el1 =0 ; + s->cpu->env.cp15.ttbr0_el[1 ] =0 ; s->cpu->env.cp15.c3 =0 ; s->pm_regs[PSSR >>2 ] |=0x8 ;/* Set STS */ s->pm_regs[RCSR >>2 ] |=0x8 ;/* Set GPR */
target-arm/cpu.h +18 -2
@@ -199,8 +199,24 @@ typedef struct CPUARMState {uint32_t c1_xscaleauxcr;/* XScale auxiliary control register. */ uint64_t sder;/* Secure debug enable register. */ uint32_t nsacr;/* Non-secure access control register. */ -uint64_t ttbr0_el1;/* MMU translation table base 0. */ -uint64_t ttbr1_el1;/* MMU translation table base 1. */ +union {/* MMU translation table base 0. */ +struct { +uint64_t _unused_ttbr0_0; +uint64_t ttbr0_ns; +uint64_t _unused_ttbr0_1; +uint64_t ttbr0_s; + }; +uint64_t ttbr0_el[4 ]; + }; +union {/* MMU translation table base 1. */ +struct { +uint64_t _unused_ttbr1_0; +uint64_t ttbr1_ns; +uint64_t _unused_ttbr1_1; +uint64_t ttbr1_s; + }; +uint64_t ttbr1_el[4 ]; + };uint64_t c2_control;/* MMU translation table base control. */ uint32_t c2_mask;/* MMU translation table base selection mask. */ uint32_t c2_base_mask;/* MMU translation table base 0 mask. */
target-arm/helper.c +25 -12
@@ -1646,13 +1646,15 @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = { .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[1]), .resetvalue = 0, }, { .name = "TTBR0_EL1", .state = ARM_CP_STATE_BOTH, - .opc0 = 3, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 0, - .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.ttbr0_el1), - .writefn = vmsa_ttbr_write, .resetvalue = 0 }, + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 0, .opc2 = 0, + .access = PL1_RW, .writefn = vmsa_ttbr_write, .resetvalue = 0, + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ttbr0_s), + offsetof(CPUARMState, cp15.ttbr0_ns) } }, { .name = "TTBR1_EL1", .state = ARM_CP_STATE_BOTH, - .opc0 = 3, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 1, - .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.ttbr1_el1), - .writefn = vmsa_ttbr_write, .resetvalue = 0 }, + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 0, .opc2 = 1, + .access = PL1_RW, .writefn = vmsa_ttbr_write, .resetvalue = 0, + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ttbr1_s), + offsetof(CPUARMState, cp15.ttbr1_ns) } }, { .name = "TCR_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 2, .access = PL1_RW, .writefn = vmsa_tcr_el1_write,
@@ -1883,11 +1885,13 @@ static const ARMCPRegInfo lpae_cp_reginfo[] = { .fieldoffset = offsetof(CPUARMState, cp15.par_el1), .resetvalue = 0 }, { .name = "TTBR0", .cp = 15, .crm = 2, .opc1 = 0, .access = PL1_RW, .type = ARM_CP_64BIT | ARM_CP_NO_MIGRATE, - .fieldoffset = offsetof(CPUARMState, cp15.ttbr0_el1), + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ttbr0_s), + offsetof(CPUARMState, cp15.ttbr0_ns) }, .writefn = vmsa_ttbr_write, .resetfn = arm_cp_reset_ignore }, { .name = "TTBR1", .cp = 15, .crm = 2, .opc1 = 1, .access = PL1_RW, .type = ARM_CP_64BIT | ARM_CP_NO_MIGRATE, - .fieldoffset = offsetof(CPUARMState, cp15.ttbr1_el1), + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ttbr1_s), + offsetof(CPUARMState, cp15.ttbr1_ns) }, .writefn = vmsa_ttbr_write, .resetfn = arm_cp_reset_ignore }, REGINFO_SENTINEL };
@@ -2341,6 +2345,10 @@ static const ARMCPRegInfo v8_el3_cp_reginfo[] = { .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 0, .opc2 = 0, .access = PL3_RW, .raw_writefn = raw_write, .writefn = sctlr_write, .fieldoffset = offsetof(CPUARMState, cp15.sctlr_el[3]) }, + { .name = "TTBR0_EL3", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 6, .crn = 2, .crm = 0, .opc2 = 0, + .access = PL3_RW, .writefn = vmsa_ttbr_write, .resetvalue = 0, + .fieldoffset = offsetof(CPUARMState, cp15.ttbr0_el[3]) }, { .name = "ELR_EL3", .state = ARM_CP_STATE_AA64, .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 6, .crn = 4, .crm = 0, .opc2 = 1,
@@ -4443,18 +4451,23 @@ static inline int check_ap(CPUARMState *env, int ap, int domain_prot,static bool get_level1_table_address (CPUARMState *env,uint32_t *table,uint32_t address) { +/* We only get here if EL1 is running in AArch32. If EL3 is running in +* AArch32 there is a secure and non-secure instance of the translation +* table registers. +*/ if (address & env->cp15.c2_mask) {if ((env->cp15.c2_control &TTBCR_PD1 )) {/* Translation table walk disabled for TTBR1 */ return false; } - *table = env->cp15.ttbr1_el1 &0xffffc000 ; + *table =A32_BANKED_CURRENT_REG_GET (env, ttbr1) &0xffffc000 ; }else {if ((env->cp15.c2_control &TTBCR_PD0 )) {/* Translation table walk disabled for TTBR0 */ return false; } - *table = env->cp15.ttbr0_el1 & env->cp15.c2_base_mask; + *table =A32_BANKED_CURRENT_REG_GET (env, ttbr0) & + env->cp15.c2_base_mask; } *table |= (address >>18 ) &0x3ffc ;return true;
@@ -4759,7 +4772,7 @@ static int get_phys_addr_lpae(CPUARMState *env, target_ulong address,* we will always flush the TLB any time the ASID is changed). */ if (ttbr_select ==0 ) { - ttbr = env->cp15.ttbr0_el1; + ttbr =A32_BANKED_CURRENT_REG_GET (env, ttbr0); epd =extract32 (env->cp15.c2_control,7 ,1 ); tsz = t0sz;
@@ -4771,7 +4784,7 @@ static int get_phys_addr_lpae(CPUARMState *env, target_ulong address, granule_sz =11 ; } }else { - ttbr = env->cp15.ttbr1_el1; + ttbr =A32_BANKED_CURRENT_REG_GET (env, ttbr1); epd =extract32 (env->cp15.c2_control,23 ,1 ); tsz = t1sz;
Signature · 1 line
1.8.3.2
PATCH v9 17/26 target-arm: make TTBCR banked
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
Adds secure and non-secure bank register suport for TTBCR.
Added new struct to compartmentalize the TCR data and masks. Removed old tcr/ttbcr data and added a 4 element array of the new structs in cp15. This allows for one entry per EL. Added a CP register definition for TCR_EL3.
---
v8 -> v9
- Removed get_phys_addr_lpae() AArch64 EL3 support.
- Replaced calls to ARM_CP_SECSTATE_TEST with direct access
- Reorganized the TCR data into a common TCR struct.
- Added raw_ptr() utility function for acquiring the TCR pointer from a reginfo
- Replaced accesses to tcr to use the new struct and utility function.
- Removed uses of A32_BANKED_CURRENT_REG_GET/SET with tcr
v5 -> v6
- Changed _el field variants to be array based
- Switch to use distinct CPREG secure flags
v4 -> v5
- Changed c2_mask updates to use the TTBCR cpreg bank flag for selcting the secure bank instead of the A32_BANKED_CURRENT macro. This more accurately chooses the correct bank matching that of the TTBCR being accessed.
--- target-arm/cpu.h | 11 +++++--- target-arm/helper.c | 72 ++++++++++++++++++++++++++++++++------------------ target-arm/internals.h | 6 ++--- 3 files changed, 58 insertions(+), 31 deletions(-)
target-arm/cpu.h +8 -3
@@ -120,6 +120,12 @@ typedef struct ARMGenericTimer {#define GTIMER_VIRT 1#define NUM_GTIMERS 2 +typedef struct { +uint64_t raw_tcr; +uint32_t mask; +uint32_t base_mask; +}TCR ; + typedef struct CPUARMState { /* Regs for current mode. */ uint32_t regs[16];
@@ -217,9 +223,8 @@ typedef struct CPUARMState { };uint64_t ttbr1_el[4 ]; }; -uint64_t c2_control;/* MMU translation table base control. */ -uint32_t c2_mask;/* MMU translation table base selection mask. */ -uint32_t c2_base_mask;/* MMU translation table base 0 mask. */ +/* MMU translation table base control. */ +TCR tcr_el[4 ];uint32_t c2_data;/* MPU data cachable bits. */ uint32_t c2_insn;/* MPU instruction cachable bits. */ uint32_t c3;/* MMU domain access control register
target-arm/helper.c +47 -25
177 lines not on this page · raw message
target-arm/internals.h +3 -3
@@ -153,9 +153,9 @@ static inline void update_spsel(CPUARMState *env, uint32_t imm)*/ static inline bool extended_addresses_enabled (CPUARMState *env) { -return arm_el_is_aa64 (env,1 ) - || ((arm_feature (env,ARM_FEATURE_LPAE ) - && (env->cp15.c2_control &TTBCR_EAE ))); +TCR *tcr = &env->cp15.tcr_el[arm_is_secure (env) ?3 :1 ]; +return arm_el_is_aa64 (env,1 ) || + (arm_feature (env,ARM_FEATURE_LPAE ) && (tcr->raw_tcr &TTBCR_EAE )); }/* Valid Syndrome Register EC field values */
Signature · 1 line
1.8.3.2
PATCH v9 18/26 target-arm: make DACR banked
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
When EL3 is running in AArch32 (or ARMv7 with Security Extensions) DACR has a secure and a non-secure instance. Adds definition for DACR32_EL2.
---
v8 -> v9
- Added definition for DACR32_EL2
- Changed dacr cp15 fields to uint64_t
--- hw/arm/pxa2xx.c | 2 +- target-arm/cpu.h | 13 +++++++++++-- target-arm/helper.c | 28 ++++++++++++++++++---------- 3 files changed, 30 insertions(+), 13 deletions(-)
hw/arm/pxa2xx.c +1 -1
@@ -276,7 +276,7 @@ static void pxa2xx_pwrmode_write(CPUARMState *env, const ARMCPRegInfo *ri, s->cpu->env.cp15.sctlr_ns =0 ; s->cpu->env.cp15.c1_coproc =0 ; s->cpu->env.cp15.ttbr0_el[1 ] =0 ; - s->cpu->env.cp15.c3 =0 ; + s->cpu->env.cp15.dacr_ns =0 ; s->pm_regs[PSSR >>2 ] |=0x8 ;/* Set STS */ s->pm_regs[RCSR >>2 ] |=0x8 ;/* Set GPR */
target-arm/cpu.h +11 -2
@@ -227,8 +227,17 @@ typedef struct CPUARMState {TCR tcr_el[4 ];uint32_t c2_data;/* MPU data cachable bits. */ uint32_t c2_insn;/* MPU instruction cachable bits. */ -uint32_t c3;/* MMU domain access control register -MPU write buffer control. */ +union {/* MMU domain access control register +* MPU write buffer control. +*/ +struct { +uint64_t dacr_ns; +uint64_t dacr_s; + }; +struct { +uint64_t dacr32_el2; + }; + };uint32_t pmsav5_data_ap;/* PMSAv5 MPU data access permissions */ uint32_t pmsav5_insn_ap;/* PMSAv5 MPU insn access permissions */ uint64_t hcr_el2;/* Hypervisor configuration register */
target-arm/helper.c +18 -10
@@ -440,10 +440,12 @@ static const ARMCPRegInfo not_v8_cp_reginfo[] = {* definitions that don't use CP_ANY wildcards (mostly in v8_cp_reginfo[]). */ /* MMU Domain access control / MPU write buffer control */ - { .name = "DACR", .cp = 15, - .crn = 3, .crm = CP_ANY, .opc1 = CP_ANY, .opc2 = CP_ANY, - .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c3), - .resetvalue = 0, .writefn = dacr_write, .raw_writefn = raw_write, }, + { .name = "DACR", + .cp = 15, .opc1 = CP_ANY, .crn = 3, .crm = CP_ANY, .opc2 = CP_ANY, + .access = PL1_RW, .resetvalue = 0, + .writefn = dacr_write, .raw_writefn = raw_write, + .bank_fieldoffsets = { offsetoflow32(CPUARMState, cp15.dacr_s), + offsetoflow32(CPUARMState, cp15.dacr_ns) } },/* ??? This covers not just the impdef TLB lockdown registers but also * some v7VMSA registers relating to TEX remap, so it is overly broad. */
@@ -2257,10 +2259,11 @@ static const ARMCPRegInfo v8_cp_reginfo[] = { { .name = "DCCISW", .cp = 15, .opc1 = 0, .crn = 7, .crm = 14, .opc2 = 2, .type = ARM_CP_NOP, .access = PL1_W }, /* MMU Domain access control / MPU write buffer control */ - { .name = "DACR", .cp = 15, - .opc1 = 0, .crn = 3, .crm = 0, .opc2 = 0, - .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c3), - .resetvalue = 0, .writefn = dacr_write, .raw_writefn = raw_write, }, + { .name = "DACR", .cp = 15, .opc1 = 0, .crn = 3, .crm = 0, .opc2 = 0, + .access = PL1_RW, .resetvalue = 0, + .writefn = dacr_write, .raw_writefn = raw_write, + .bank_fieldoffsets = { offsetoflow32(CPUARMState, cp15.dacr_s), + offsetoflow32(CPUARMState, cp15.dacr_ns) } }, { .name = "ELR_EL1", .state = ARM_CP_STATE_AA64, .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 0, .crn = 4, .crm = 0, .opc2 = 1,
@@ -2330,6 +2333,11 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = { .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 0, .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.hcr_el2), .writefn = hcr_write }, + { .name = "DACR32_EL2", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 4, .crn = 3, .crm = 0, .opc2 = 0, + .access = PL2_RW, .resetvalue = 0, + .writefn = dacr_write, .raw_writefn = raw_write, + .fieldoffset = offsetof(CPUARMState, cp15.dacr32_el2) }, { .name = "ELR_EL2", .state = ARM_CP_STATE_AA64, .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 4, .crn = 4, .crm = 0, .opc2 = 1,
@@ -4518,7 +4526,7 @@ static int get_phys_addr_v5(CPUARMState *env, uint32_t address, int access_type, desc =ldl_phys (cs->as, table); type = (desc &3 ); domain = (desc >>5 ) &0x0f ; - domain_prot = (env->cp15.c3 >> (domain *2 )) &3 ; + domain_prot = (A32_BANKED_CURRENT_REG_GET (env, dacr) >> (domain *2 )) &3 ;if (type ==0 ) {/* Section translation fault. */ code =5 ;
@@ -4630,7 +4638,7 @@ static int get_phys_addr_v6(CPUARMState *env, uint32_t address, int access_type,/* Page or Section. */ domain = (desc >>5 ) &0x0f ; } - domain_prot = (env->cp15.c3 >> (domain *2 )) &3 ; + domain_prot = (A32_BANKED_CURRENT_REG_GET (env, dacr) >> (domain *2 )) &3 ;if (domain_prot ==0 || domain_prot ==2 ) {if (type !=1 ) { code =9 ;/* Section domain fault. */
Signature · 1 line
1.8.3.2
PATCH v9 19/26 target-arm: make IFSR banked
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
When EL3 is running in AArch32 (or ARMv7 with Security Extensions) IFSR has a secure and a non-secure instance. Adds IFSR32_EL2 definition and storage.
---
v8 -> v9
- Added definition for IFSR32_EL2
- Changed ifsr cp15 fields to uint64_t
--- target-arm/cpu.h | 10 +++++++++- target-arm/helper.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-)
target-arm/cpu.h +9 -1
@@ -242,7 +242,15 @@ typedef struct CPUARMState {uint32_t pmsav5_insn_ap;/* PMSAv5 MPU insn access permissions */ uint64_t hcr_el2;/* Hypervisor configuration register */ uint64_t scr_el3;/* Secure configuration register. */ -uint32_t ifsr_el2;/* Fault status registers. */ +union {/* Fault status registers. */ +struct { +uint64_t ifsr_ns; +uint64_t ifsr_s; + }; +struct { +uint64_t ifsr32_el2; + }; + };uint64_t esr_el[4 ];uint32_t c6_region[8 ];/* MPU base/size registers. */ uint64_t far_el[4 ];/* Fault address registers. */
target-arm/helper.c +9 -4
@@ -1654,8 +1654,9 @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = { .fieldoffset = offsetoflow32(CPUARMState, cp15.esr_el[1]), .resetfn = arm_cp_reset_ignore, }, { .name = "IFSR", .cp = 15, .crn = 5, .crm = 0, .opc1 = 0, .opc2 = 1, - .access = PL1_RW, - .fieldoffset = offsetof(CPUARMState, cp15.ifsr_el2), .resetvalue = 0, }, + .access = PL1_RW, .resetvalue = 0, + .bank_fieldoffsets = { offsetoflow32(CPUARMState, cp15.ifsr_s), + offsetoflow32(CPUARMState, cp15.ifsr_ns) } }, { .name = "ESR_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .crn = 5, .crm = 2, .opc1 = 0, .opc2 = 0, .access = PL1_RW,
@@ -2347,6 +2348,10 @@ static const ARMCPRegInfo v8_el2_cp_reginfo[] = { .type = ARM_CP_NO_MIGRATE, .opc0 = 3, .opc1 = 4, .crn = 5, .crm = 2, .opc2 = 0, .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.esr_el[2]) }, + { .name = "IFSR32_EL2", .state = ARM_CP_STATE_AA64, + .opc0 = 3, .opc1 = 4, .crn = 5, .crm = 0, .opc2 = 1, + .access = PL2_RW, .resetvalue = 0, + .fieldoffset = offsetof(CPUARMState, cp15.ifsr32_el2) }, { .name = "FAR_EL2", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 4, .crn = 6, .crm = 0, .opc2 = 0, .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.far_el[2]) },
@@ -4324,11 +4329,11 @@ void arm_cpu_do_interrupt(CPUState *cs) env->exception.fsr =2 ;/* Fall through to prefetch abort. */ case EXCP_PREFETCH_ABORT : - env->cp15.ifsr_el2 = env->exception.fsr; +A32_BANKED_CURRENT_REG_SET (env, ifsr, env->exception.fsr); env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],32 ,32 , env->exception.vaddress);qemu_log_mask (CPU_LOG_INT ,"...with IFSR 0x%x IFAR 0x%x\n" , - env->cp15.ifsr_el2, (uint32_t )env->exception.vaddress); + env->exception.fsr, (uint32_t )env->exception.vaddress); new_mode =ARM_CPU_MODE_ABT ; addr =0x0c ; mask =CPSR_A |CPSR_I ;
Signature · 1 line
1.8.3.2
PATCH v9 20/26 target-arm: make DFSR banked
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
When EL3 is running in AArch32 (or ARMv7 with Security Extensions) DFSR has a secure and a non-secure instance.
---
v3 -> v4
- Reverted esr/dfsr back to array-based notation as a union with v7 naming.
--- target-arm/cpu.h | 10 +++++++++- target-arm/helper.c | 7 ++++--- 2 files changed, 13 insertions(+), 4 deletions(-)
target-arm/cpu.h +9 -1
@@ -251,7 +251,15 @@ typedef struct CPUARMState {uint64_t ifsr32_el2; }; }; -uint64_t esr_el[4 ]; +union { +struct { +uint64_t _unused_dfsr; +uint64_t dfsr_ns; +uint64_t hsr; +uint64_t dfsr_s; + }; +uint64_t esr_el[4 ]; + };uint32_t c6_region[8 ];/* MPU base/size registers. */ uint64_t far_el[4 ];/* Fault address registers. */ uint64_t par_el1;/* Translation result. */
target-arm/helper.c +4 -3
@@ -1651,7 +1651,8 @@ static void vmsa_ttbr_write(CPUARMState *env, const ARMCPRegInfo *ri,static const ARMCPRegInfo vmsa_cp_reginfo[] = { { .name ="DFSR" , .cp =15 , .crn =5 , .crm =0 , .opc1 =0 , .opc2 =0 , .access =PL1_RW , .type =ARM_CP_NO_MIGRATE , - .fieldoffset =offsetoflow32 (CPUARMState, cp15.esr_el[1 ]), + .bank_fieldoffsets = {offsetoflow32 (CPUARMState, cp15.dfsr_s), +offsetoflow32 (CPUARMState, cp15.dfsr_ns) }, .resetfn = arm_cp_reset_ignore, }, { .name ="IFSR" , .cp =15 , .crn =5 , .crm =0 , .opc1 =0 , .opc2 =1 , .access =PL1_RW , .resetvalue =0 ,
@@ -4340,11 +4341,11 @@ void arm_cpu_do_interrupt(CPUState *cs) offset =4 ;break ;case EXCP_DATA_ABORT : - env->cp15.esr_el[1 ] = env->exception.fsr; +A32_BANKED_CURRENT_REG_SET (env, dfsr, env->exception.fsr); env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],0 ,32 , env->exception.vaddress);qemu_log_mask (CPU_LOG_INT ,"...with DFSR 0x%x DFAR 0x%x\n" , - (uint32_t )env->cp15.esr_el[1 ], + env->exception.fsr, (uint32_t )env->exception.vaddress); new_mode =ARM_CPU_MODE_ABT ; addr =0x10 ;
Signature · 1 line
1.8.3.2
PATCH v9 21/26 target-arm: make IFAR/DFAR banked
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
When EL3 is running in AArch32 (or ARMv7 with Security Extensions) IFAR and DFAR have a secure and a non-secure instance.
---
v8 -> v9
- Reordered CP register component order
- Removed extra semicolon
v3 -> v4
- Revert to array-based notation of far_el in combination with v7 naming
--- target-arm/cpu.c | 2 +- target-arm/cpu.h | 19 ++++++++++++++++++- target-arm/helper.c | 16 +++++++++------- 3 files changed, 28 insertions(+), 9 deletions(-)
target-arm/cpu.c +1 -1
@@ -525,7 +525,7 @@ static void arm1026_initfn(Object *obj)ARMCPRegInfo ifar = { .name ="IFAR" , .cp =15 , .crn =6 , .crm =0 , .opc1 =0 , .opc2 =1 , .access =PL1_RW , - .fieldoffset =offsetofhigh32 (CPUARMState, cp15.far_el[1 ]), + .fieldoffset = offsetof(CPUARMState, cp15.ifar_ns), .resetvalue =0 };define_one_arm_cp_reg (cpu, &ifar);
target-arm/cpu.h +18 -1
@@ -261,7 +261,24 @@ typedef struct CPUARMState {uint64_t esr_el[4 ]; };uint32_t c6_region[8 ];/* MPU base/size registers. */ -uint64_t far_el[4 ];/* Fault address registers. */ +union {/* Fault address registers. */ +struct { +uint64_t _unused_far0; +#ifdef HOST_WORDS_BIGENDIAN +uint32_t ifar_ns; +uint32_t dfar_ns; +uint32_t ifar_s; +uint32_t dfar_s; +#else +uint32_t dfar_ns; +uint32_t ifar_ns; +uint32_t dfar_s; +uint32_t ifar_s; +#endif +uint64_t _unused_far3; + }; +uint64_t far_el[4 ]; + };uint64_t par_el1;/* Translation result. */ uint32_t c9_insn;/* Cache lockdown registers. */ uint32_t c9_data;
target-arm/helper.c +9 -7
@@ -559,7 +559,8 @@ static const ARMCPRegInfo v6_cp_reginfo[] = { .access = PL0_W, .type = ARM_CP_NOP }, { .name = "IFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 2, .access = PL1_RW, - .fieldoffset = offsetofhigh32(CPUARMState, cp15.far_el[1]), + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ifar_s), + offsetof(CPUARMState, cp15.ifar_ns) }, .resetvalue = 0, }, /* Watchpoint Fault Address Register : should actually only be present * for 1136, 1176, 11MPCore.
@@ -1682,11 +1683,14 @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = { .resetfn = arm_cp_reset_ignore, .raw_writefn = vmsa_ttbcr_raw_write, .bank_fieldoffsets = { offsetoflow32(CPUARMState, cp15.tcr_el[3]), offsetoflow32(CPUARMState, cp15.tcr_el[1])} }, -/* 64-bit FAR; this entry also gives us the AArch32 DFAR */ - { .name = "FAR_EL1", .state = ARM_CP_STATE_BOTH, + { .name = "FAR_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 0, .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.far_el[1]), .resetvalue = 0, }, + { .name = "DFAR", .cp = 15, .opc1 = 0, .crn = 6, .crm = 0, .opc2 = 0, + .access = PL1_RW, .resetvalue = 0, + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.dfar_s), + offsetof(CPUARMState, cp15.dfar_ns) } },REGINFO_SENTINEL };
@@ -4331,8 +4335,7 @@ void arm_cpu_do_interrupt(CPUState *cs)/* Fall through to prefetch abort. */ case EXCP_PREFETCH_ABORT :A32_BANKED_CURRENT_REG_SET (env, ifsr, env->exception.fsr); - env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],32 ,32 , - env->exception.vaddress); +A32_BANKED_CURRENT_REG_SET (env, ifar, env->exception.vaddress);qemu_log_mask (CPU_LOG_INT ,"...with IFSR 0x%x IFAR 0x%x\n" , env->exception.fsr, (uint32_t )env->exception.vaddress); new_mode =ARM_CPU_MODE_ABT ;
@@ -4342,8 +4345,7 @@ void arm_cpu_do_interrupt(CPUState *cs)break ;case EXCP_DATA_ABORT :A32_BANKED_CURRENT_REG_SET (env, dfsr, env->exception.fsr); - env->cp15.far_el[1 ] =deposit64 (env->cp15.far_el[1 ],0 ,32 , - env->exception.vaddress); +A32_BANKED_CURRENT_REG_SET (env, dfar, env->exception.vaddress);qemu_log_mask (CPU_LOG_INT ,"...with DFSR 0x%x DFAR 0x%x\n" , env->exception.fsr, (uint32_t )env->exception.vaddress);
Signature · 1 line
1.8.3.2
PATCH v9 22/26 target-arm: make PAR banked
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
When EL3 is running in AArch32 (or ARMv7 with Security Extensions) PAR has a secure and a non-secure instance.
---
v8 -> v9
- Cleaned-up ats_write() to only call A32_BANKED_CURRENT_REG_SET() once at the endof the function.
- Revert unnecessary CPreg definition changes
v5 -> v6
- Changed _el field variants to be array based
v3 -> v4
- Fix par union/structure definition
--- target-arm/cpu.h | 10 +++++++++- target-arm/helper.c | 23 +++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-)
target-arm/cpu.h +9 -1
@@ -279,7 +279,15 @@ typedef struct CPUARMState { };uint64_t far_el[4 ]; }; -uint64_t par_el1;/* Translation result. */ +union {/* Translation result. */ +struct { +uint64_t _unused_par_0; +uint64_t par_ns; +uint64_t _unused_par_1; +uint64_t par_s; + }; +uint64_t par_el[4 ]; + };uint32_t c9_insn;/* Cache lockdown registers. */ uint32_t c9_data;uint64_t c9_pmcr;/* performance monitor control register */
target-arm/helper.c +13 -10
@@ -1404,6 +1404,7 @@ static void ats_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)int prot;int ret, is_user = ri->opc2 &2 ;int access_type = ri->opc2 &1 ; +uint64_t par64; ret =get_phys_addr (env, value, access_type, is_user, &phys_addr, &prot, &page_size);
@@ -1412,7 +1413,7 @@ static void ats_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)* translation table format, but with WnR always clear. * Convert it to a 64-bit PAR. */ -uint64_t par64 = (1 <<11 );/* LPAE bit always set */ + par64 = (1 <<11 );/* LPAE bit always set */ if (ret ==0 ) { par64 |= phys_addr & ~0xfffULL ;/* We don't set the ATTR or SH fields in the PAR. */
@@ -1424,7 +1425,6 @@ static void ats_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)* fault. */ } - env->cp15.par_el1 = par64; }else {/* ret is a DFSR/IFSR value for the short descriptor * translation table format (with WnR always clear).
@@ -1434,23 +1434,25 @@ static void ats_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)/* We do not set any attribute bits in the PAR */ if (page_size == (1 <<24 ) &&arm_feature (env,ARM_FEATURE_V7 )) { - env->cp15.par_el1 = (phys_addr &0xff000000 ) |1 <<1 ; + par64 = (phys_addr &0xff000000 ) | (1 <<1 ); }else { - env->cp15.par_el1 = phys_addr &0xfffff000 ; + par64 = phys_addr &0xfffff000 ; } }else { - env->cp15.par_el1 = ((ret & (1 <<10 )) >>5 ) | - ((ret & (1 <<12 )) >>6 ) | - ((ret &0xf ) <<1 ) |1 ; + par64 = ((ret & (1 <<10 )) >>5 ) | ((ret & (1 <<12 )) >>6 ) | + ((ret &0xf ) <<1 ) |1 ; } } + +A32_BANKED_CURRENT_REG_SET (env, par, par64); }#endif static const ARMCPRegInfo vapa_cp_reginfo[] = { { .name ="PAR" , .cp =15 , .crn =7 , .crm =4 , .opc1 =0 , .opc2 =0 , .access =PL1_RW , .resetvalue =0 , - .fieldoffset =offsetoflow32 (CPUARMState, cp15.par_el1), + .bank_fieldoffsets = {offsetoflow32 (CPUARMState, cp15.par_s), +offsetoflow32 (CPUARMState, cp15.par_ns) }, .writefn = par_write }, #ifndef CONFIG_USER_ONLY { .name ="ATS" , .cp =15 , .crn =7 , .crm =8 , .opc1 =0 , .opc2 =CP_ANY ,
@@ -1903,8 +1905,9 @@ static const ARMCPRegInfo lpae_cp_reginfo[] = { .access = PL1_RW, .type = ARM_CP_CONST | ARM_CP_OVERRIDE, .resetvalue = 0 }, { .name = "PAR", .cp = 15, .crm = 7, .opc1 = 0, - .access = PL1_RW, .type = ARM_CP_64BIT, - .fieldoffset = offsetof(CPUARMState, cp15.par_el1), .resetvalue = 0 }, + .access = PL1_RW, .type = ARM_CP_64BIT, .resetvalue = 0, + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.par_s), + offsetof(CPUARMState, cp15.par_ns)} }, { .name = "TTBR0", .cp = 15, .crm = 2, .opc1 = 0, .access = PL1_RW, .type = ARM_CP_64BIT | ARM_CP_NO_MIGRATE, .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ttbr0_s),
Signature · 1 line
1.8.3.2
PATCH v9 23/26 target-arm: make VBAR banked
In reply to Greg BellowsWhen EL3 is running in Aarch32 (or ARMv7 with Security Extensions) VBAR has a secure and a non-secure instance, which are mapped to VBAR_EL1 and VBAR_EL3.
---
v8 -> v9
- Revert unnecessary CPreg definition changes
v5 -> v6
- Changed _el field variants to be array based
- Merged VBAR and VBAR_EL1 reginfo entries
v3 -> v4
- Fix vbar union/structure definition
- Revert back to array-based vbar definition combined with v7 naming
--- target-arm/cpu.h | 10 +++++++++- target-arm/helper.c | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-)
target-arm/cpu.h +9 -1
@@ -297,7 +297,15 @@ typedef struct CPUARMState {uint32_t c9_pmuserenr;/* perf monitor user enable */ uint32_t c9_pminten;/* perf monitor interrupt enables */ uint64_t mair_el1; -uint64_t vbar_el[4 ];/* vector base address register */ +union {/* vector base address register */ +struct { +uint64_t _unused_vbar; +uint64_t vbar_ns; +uint64_t hvbar; +uint64_t vbar_s; + }; +uint64_t vbar_el[4 ]; + };uint32_t mvbar;/* (monitor) vector base address register */ uint32_t c13_fcse;/* FCSE PID. */ uint64_t contextidr_el1;/* Context ID. */
target-arm/helper.c +3 -2
@@ -911,7 +911,8 @@ static const ARMCPRegInfo v7_cp_reginfo[] = { { .name = "VBAR", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .crn = 12, .crm = 0, .opc1 = 0, .opc2 = 0, .access = PL1_RW, .writefn = vbar_write, - .fieldoffset = offsetof(CPUARMState, cp15.vbar_el[1]), + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.vbar_s), + offsetof(CPUARMState, cp15.vbar_ns) }, .resetvalue = 0 }, { .name = "CCSIDR", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .crn = 0, .crm = 0, .opc1 = 1, .opc2 = 0,
@@ -4402,7 +4403,7 @@ void arm_cpu_do_interrupt(CPUState *cs)* This register is only followed in non-monitor mode, and is banked. * Note: only bits 31:5 are valid. */ - addr += env->cp15.vbar_el[1 ]; + addr +=A32_BANKED_CURRENT_REG_GET (env, vbar); }if ((env->uncached_cpsr &CPSR_M ) ==ARM_CPU_MODE_MON ) {
Signature · 1 line
1.8.3.2
PATCH v9 24/26 target-arm: make c13 cp regs banked (FCSEIDR, ...)
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
When EL3 is running in AArch32 (or ARMv7 with Security Extensions) FCSEIDR, CONTEXTIDR, TPIDRURW, TPIDRURO and TPIDRPRW have a secure and a non-secure instance.
---
v8 -> v9
- Changed contextidr structure definition to have 4 uint64_t fields.
- Broke up secure/non-secure CONTEXTIDR defs so the secure instance can be properly migrated and reset.
- Broke up secure/non-secure FCSEIDR defs.
- Reversed CP register field reordering
- Reversed white-space changes
v6 -> v7
- Fix linux-user/arm/target-cpu.h to use array based tpidr_el.
- Fix linux-user/main.c to use array based tpidrro_el.
- Remove tab identified by checkpatch failure.
- FIx linux-user/aarch64/target_cpu.h to use array based tpidr_el.
v5 -> v6
- Changed _el field variants to be array based
- Rework data layout for correct aliasing
- Merged CONTEXTIDR and CONTEXTIDR_EL1 reginfo entries
v3 -> v4
- Fix tpidrprw mapping
--- linux-user/aarch64/target_cpu.h | 2 +- linux-user/arm/target_cpu.h | 2 +- linux-user/main.c | 2 +- target-arm/cpu.h | 36 +++++++++++++++++++++---- target-arm/helper.c | 58 ++++++++++++++++++++++++++++++++--------- target-arm/op_helper.c | 2 +- 6 files changed, 80 insertions(+), 22 deletions(-)
linux-user/aarch64/target_cpu.h +1 -1
@@ -32,7 +32,7 @@ static inline void cpu_set_tls(CPUARMState *env, target_ulong newtls)/* Note that AArch64 Linux keeps the TLS pointer in TPIDR; this is * different from AArch32 Linux, which uses TPIDRRO. */ - env->cp15.tpidr_el0 = newtls; + env->cp15.tpidr_el[0] = newtls; }#endif
linux-user/arm/target_cpu.h +1 -1
@@ -29,7 +29,7 @@ static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp)static inline void cpu_set_tls (CPUARMState *env,target_ulong newtls) { - env->cp15.tpidrro_el0 = newtls; + env->cp15.tpidrro_el[0 ] = newtls; }#endif
linux-user/main.c +1 -1
@@ -564,7 +564,7 @@ do_kernel_trap(CPUARMState *env)end_exclusive ();break ;case 0xffff0fe0 :/* __kernel_get_tls */ - env->regs[0 ] = env->cp15.tpidrro_el0; + env->regs[0 ] = env->cp15.tpidrro_el[0 ];break ;case 0xffff0f60 :/* __kernel_cmpxchg64 */ arm_kernel_cmpxchg64_helper (env);
target-arm/cpu.h +31 -5
@@ -307,11 +307,37 @@ typedef struct CPUARMState {uint64_t vbar_el[4 ]; };uint32_t mvbar;/* (monitor) vector base address register */ -uint32_t c13_fcse;/* FCSE PID. */ -uint64_t contextidr_el1;/* Context ID. */ -uint64_t tpidr_el0;/* User RW Thread register. */ -uint64_t tpidrro_el0;/* User RO Thread register. */ -uint64_t tpidr_el1;/* Privileged Thread register. */ +struct {/* FCSE PID. */ +uint32_t fcseidr_ns; +uint32_t fcseidr_s; + }; +union {/* Context ID. */ +struct { +uint64_t _unused_contextidr_0; +uint64_t contextidr_ns; +uint64_t _unused_contextidr_1; +uint64_t contextidr_s; + }; +uint64_t contextidr_el[4 ]; + }; +union {/* User RW Thread register. */ +struct { +uint64_t tpidrurw_ns; +uint64_t tpidrprw_ns; +uint64_t htpidr; +uint64_t _tpidr_el3; + }; +uint64_t tpidr_el[4 ]; + }; +/* The secure banks of these registers don't map anywhere */ +uint64_t tpidrurw_s; +uint64_t tpidrprw_s; +uint64_t tpidruro_s; + +union {/* User RO Thread register. */ +uint64_t tpidruro_ns; +uint64_t tpidrro_el[1 ]; + };uint64_t c14_cntfrq;/* Counter Frequency register */ uint64_t c14_cntkctl;/* Timer Control register */ ARMGenericTimer c14_timer[NUM_GTIMERS ];
target-arm/helper.c +45 -13
89 lines not on this page · raw message
target-arm/op_helper.c +1 -1
@@ -575,7 +575,7 @@ static bool linked_bp_matches(ARMCPU *cpu, int lbn)* short descriptor format (in which case it holds both PROCID and ASID), * since we don't implement the optional v7 context ID masking. */ - contextidr =extract64 (env->cp15.contextidr_el1,0 ,32 ); + contextidr =extract64 (env->cp15.contextidr_el[1 ],0 ,32 );switch (bt) {case 3 :/* linked context ID match */
Signature · 1 line
1.8.3.2
PATCH v9 25/26 target-arm: make MAIR0/1 banked
In reply to Greg BellowsAdded CP register info entries for the ARMv7 MAIR0/1 secure banks.
---
v8 -> v9
- Added endianness support to the MAIR field structure definition.
v5 -> v6
- Changed _el field variants to be array based
--- target-arm/cpu.h | 21 ++++++++++++++++++++- target-arm/helper.c | 12 +++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-)
target-arm/cpu.h +20 -1
@@ -296,7 +296,26 @@ typedef struct CPUARMState {uint32_t c9_pmxevtyper;/* perf monitor event type */ uint32_t c9_pmuserenr;/* perf monitor user enable */ uint32_t c9_pminten;/* perf monitor interrupt enables */ -uint64_t mair_el1; +union {/* Memory attribute redirection */ +struct { +#ifdef HOST_WORDS_BIGENDIAN +uint64_t _unused_mair_0; +uint32_t mair1_ns; +uint32_t mair0_ns; +uint64_t _unused_mair_1; +uint32_t mair1_s; +uint32_t mair0_s; +#else +uint64_t _unused_mair_0; +uint32_t mair0_ns; +uint32_t mair1_ns; +uint64_t _unused_mair_1; +uint32_t mair0_s; +uint32_t mair1_s; +#endif + }; +uint64_t mair_el[4 ]; + }; union { /* vector base address register */ struct { uint64_t _unused_vbar;
target-arm/helper.c +9 -3
@@ -965,20 +965,26 @@ static const ARMCPRegInfo v7_cp_reginfo[] = {*/ { .name = "MAIR_EL1", .state = ARM_CP_STATE_AA64, .opc0 = 3, .opc1 = 0, .crn = 10, .crm = 2, .opc2 = 0, - .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el1), + .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el[1]), .resetvalue = 0 },/* For non-long-descriptor page tables these are PRRR and NMRR; * regardless they still act as reads-as-written for QEMU. * The override is necessary because of the overly-broad TLB_LOCKDOWN * definition. */ +/* MAIR0/1 are defined seperately from their 64-bit counterpart which +* allows them to assign the correct fieldoffset based on the endianness +* handled in the field definitions. +*/ { .name = "MAIR0", .state = ARM_CP_STATE_AA32, .type = ARM_CP_OVERRIDE, .cp = 15, .opc1 = 0, .crn = 10, .crm = 2, .opc2 = 0, .access = PL1_RW, - .fieldoffset = offsetoflow32(CPUARMState, cp15.mair_el1), + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.mair0_s), + offsetof(CPUARMState, cp15.mair0_ns) }, .resetfn = arm_cp_reset_ignore }, { .name = "MAIR1", .state = ARM_CP_STATE_AA32, .type = ARM_CP_OVERRIDE, .cp = 15, .opc1 = 0, .crn = 10, .crm = 2, .opc2 = 1, .access = PL1_RW, - .fieldoffset = offsetofhigh32(CPUARMState, cp15.mair_el1), + .bank_fieldoffsets = { offsetof(CPUARMState, cp15.mair1_s), + offsetof(CPUARMState, cp15.mair1_ns) }, .resetfn = arm_cp_reset_ignore }, { .name = "ISR_EL1", .state = ARM_CP_STATE_BOTH, .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 1, .opc2 = 0,
Signature · 1 line
1.8.3.2
PATCH v9 26/26 target-arm: add cpu feature EL3 to CPUs with Security Extensions
In reply to Greg BellowsFrom: Fabian Aggeler <[email protected]>
Set ARM_FEATURE_EL3 feature for CPUs that implement Security Extensions.
--- target-arm/cpu.c | 4 ++++ 1 file changed, 4 insertions(+)
target-arm/cpu.c +4 -0
@@ -613,6 +613,7 @@ static void arm1176_initfn(Object *obj)set_feature (&cpu->env,ARM_FEATURE_DUMMY_C15_REGS );set_feature (&cpu->env,ARM_FEATURE_CACHE_DIRTY_REG );set_feature (&cpu->env,ARM_FEATURE_CACHE_BLOCK_OPS ); +set_feature (&cpu->env,ARM_FEATURE_EL3 ); cpu->midr =0x410fb767 ; cpu->reset_fpsid =0x410120b5 ; cpu->mvfr0 =0x11111111 ;
@@ -699,6 +700,7 @@ static void cortex_a8_initfn(Object *obj)set_feature (&cpu->env,ARM_FEATURE_NEON );set_feature (&cpu->env,ARM_FEATURE_THUMB2EE );set_feature (&cpu->env,ARM_FEATURE_DUMMY_C15_REGS ); +set_feature (&cpu->env,ARM_FEATURE_EL3 ); cpu->midr =0x410fc080 ; cpu->reset_fpsid =0x410330c0 ; cpu->mvfr0 =0x11110222 ;
@@ -766,6 +768,7 @@ static void cortex_a9_initfn(Object *obj)set_feature (&cpu->env,ARM_FEATURE_VFP_FP16 );set_feature (&cpu->env,ARM_FEATURE_NEON );set_feature (&cpu->env,ARM_FEATURE_THUMB2EE ); +set_feature (&cpu->env,ARM_FEATURE_EL3 );/* Note that A9 supports the MP extensions even for * A9UP and single-core A9MP (which are both different * and valid configurations; we don't model A9UP).
@@ -833,6 +836,7 @@ static void cortex_a15_initfn(Object *obj)set_feature (&cpu->env,ARM_FEATURE_DUMMY_C15_REGS );set_feature (&cpu->env,ARM_FEATURE_CBAR_RO );set_feature (&cpu->env,ARM_FEATURE_LPAE ); +set_feature (&cpu->env,ARM_FEATURE_EL3 ); cpu->kvm_target =QEMU_KVM_ARM_TARGET_CORTEX_A15 ; cpu->midr =0x412fc0f1 ; cpu->reset_fpsid =0x410430f0 ;
Signature · 1 line
1.8.3.2