Int type vm_level is more meaningful than pointer type sys_state, and it is easy to get current mode from value of vm_level.
Here replace sys_state with vm_level, and use vm_level directly. Signed-off-by: Bibo Mao <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> --- target/loongarch/cpu.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h index 5cc2370da2..277fc4f475 100644 --- a/target/loongarch/cpu.h +++ b/target/loongarch/cpu.h @@ -429,7 +429,7 @@ typedef struct CPUArchState { /* Fields up to this point are cleared by a CPU reset */ struct {} end_reset_fields; - CPUSysState sys_states[1]; + CPUSysState sys_states[VM_LEVELS]; uint32_t cpucfg[21]; uint32_t pv_features; uint64_t vendor_id; @@ -440,7 +440,7 @@ typedef struct CPUArchState { AddressSpace *address_space_iocsr; uint32_t mp_state; #endif - CPUSysState *sys_state; + int vm_level; unsigned int irq_nr; } CPULoongArchState; @@ -510,12 +510,14 @@ struct LoongArchCPUClass { static inline CPUSysState *env_sys(CPULoongArchState *env) { - return env->sys_state; + return &env->sys_states[env->vm_level]; } static inline void set_sys(CPULoongArchState *env, int vm_level) { - env->sys_state = &env->sys_states[vm_level]; + if (vm_level >= 0 && vm_level < VM_LEVELS) { + env->vm_level = vm_level; + } } static inline CPUTimerState *env_timer(CPULoongArchState *env) -- 2.54.0
