Skip to content

Commit

Permalink
introduce get_efer_allow_mask function to avoid placing that code dir…
Browse files Browse the repository at this point in the history
…ectly in init.cc
  • Loading branch information
Stanislav Shwartsman committed Nov 17, 2023
1 parent 9bda4eb commit a3fe8c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
1 change: 1 addition & 0 deletions bochs/cpu/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -4388,6 +4388,7 @@ class BOCHSAPI BX_CPU_C : public logfunctions {
#endif
#if BX_CPU_LEVEL >= 5
BX_SMF bool SetEFER(bx_address val) BX_CPP_AttrRegparmN(1);
BX_SMF Bit32u get_efer_allow_mask(void);
#endif

BX_SMF bx_address read_CR0(void);
Expand Down
27 changes: 27 additions & 0 deletions bochs/cpu/crregs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,33 @@ void BX_CPU_C::xsave_xrestor_init(void)
#endif
}

#if BX_CPU_LEVEL >= 5

Bit32u BX_CPU_C::get_efer_allow_mask(void)
{
Bit32u efer_allowed_mask = 0;

if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_NX))
efer_allowed_mask |= BX_EFER_NXE_MASK;
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SYSCALL_SYSRET_LEGACY))
efer_allowed_mask |= BX_EFER_SCE_MASK;
#if BX_SUPPORT_X86_64
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_LONG_MODE)) {
efer_allowed_mask |= (BX_EFER_SCE_MASK | BX_EFER_LME_MASK | BX_EFER_LMA_MASK);
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_FFXSR))
efer_allowed_mask |= BX_EFER_FFXSR_MASK;
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SVM))
efer_allowed_mask |= BX_EFER_SVME_MASK;
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_TCE))
efer_allowed_mask |= BX_EFER_TCE_MASK;
}
#endif

return efer_allowed_mask;
}

#endif

Bit32u BX_CPU_C::get_xcr0_allow_mask(void)
{
Bit32u allowMask = 0x3;
Expand Down
21 changes: 3 additions & 18 deletions bochs/cpu/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,6 @@ void BX_CPU_C::param_restore(bx_param_c *param, Bit64s val)

void BX_CPU_C::after_restore_state(void)
{
handleCpuContextChange();

BX_CPU_THIS_PTR prev_rip = RIP;

if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_IA32_REAL) CPL = 0;
Expand All @@ -672,6 +670,8 @@ void BX_CPU_C::after_restore_state(void)
set_PKeys(BX_CPU_THIS_PTR pkru, BX_CPU_THIS_PTR pkrs);
#endif

handleCpuContextChange();

assert_checks();
debug(RIP);
}
Expand Down Expand Up @@ -912,22 +912,7 @@ void BX_CPU_C::reset(unsigned source)
#endif

BX_CPU_THIS_PTR efer.set32(0);
BX_CPU_THIS_PTR efer_suppmask = 0;
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_NX))
BX_CPU_THIS_PTR efer_suppmask |= BX_EFER_NXE_MASK;
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SYSCALL_SYSRET_LEGACY))
BX_CPU_THIS_PTR efer_suppmask |= BX_EFER_SCE_MASK;
#if BX_SUPPORT_X86_64
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_LONG_MODE)) {
BX_CPU_THIS_PTR efer_suppmask |= (BX_EFER_SCE_MASK | BX_EFER_LME_MASK | BX_EFER_LMA_MASK);
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_FFXSR))
BX_CPU_THIS_PTR efer_suppmask |= BX_EFER_FFXSR_MASK;
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_SVM))
BX_CPU_THIS_PTR efer_suppmask |= BX_EFER_SVME_MASK;
if (BX_CPUID_SUPPORT_ISA_EXTENSION(BX_ISA_TCE))
BX_CPU_THIS_PTR efer_suppmask |= BX_EFER_TCE_MASK;
}
#endif
BX_CPU_THIS_PTR efer_suppmask = get_efer_allow_mask();

BX_CPU_THIS_PTR msr.star = 0;
#if BX_SUPPORT_X86_64
Expand Down

0 comments on commit a3fe8c2

Please sign in to comment.