properly handle RDMSR/WRMSR of MSR_PAT when PAT feature is disabled

This commit is contained in:
Stanislav Shwartsman 2013-04-11 19:41:54 +00:00
parent f1c7d163a1
commit 025fb15461
2 changed files with 22 additions and 7 deletions

View File

@ -4196,6 +4196,7 @@ public: // for now...
BX_SMF BX_CPP_INLINE int bx_cpuid_support_pae(void);
BX_SMF BX_CPP_INLINE int bx_cpuid_support_pge(void);
BX_SMF BX_CPP_INLINE int bx_cpuid_support_pse(void);
BX_SMF BX_CPP_INLINE int bx_cpuid_support_pat(void);
BX_SMF BX_CPP_INLINE int bx_cpuid_support_mmx(void);
BX_SMF BX_CPP_INLINE int bx_cpuid_support_sse(void);
BX_SMF BX_CPP_INLINE int bx_cpuid_support_sep(void);
@ -4778,6 +4779,11 @@ BX_CPP_INLINE int BX_CPU_C::bx_cpuid_support_pse(void)
return (BX_CPU_THIS_PTR cpu_extensions_bitmask & BX_CPU_PSE) != 0;
}
BX_CPP_INLINE int BX_CPU_C::bx_cpuid_support_pat(void)
{
return (BX_CPU_THIS_PTR cpu_extensions_bitmask & BX_CPU_PAT) != 0;
}
BX_CPP_INLINE int BX_CPU_C::bx_cpuid_support_pae(void)
{
return (BX_CPU_THIS_PTR cpu_extensions_bitmask & BX_CPU_PAE) != 0;

View File

@ -114,6 +114,10 @@ bx_bool BX_CPP_AttrRegparmN(2) BX_CPU_C::rdmsr(Bit32u index, Bit64u *msr)
break;
case BX_MSR_PAT:
if (! bx_cpuid_support_pat()) {
BX_ERROR(("RDMSR BX_MSR_PAT: PAT is not enabled !"));
return handle_unknown_rdmsr(index, msr);
}
val64 = BX_CPU_THIS_PTR msr.pat;
break;
@ -402,9 +406,9 @@ bx_bool isMemTypeValidMTRR(unsigned memtype)
case BX_MEMTYPE_WT:
case BX_MEMTYPE_WP:
case BX_MEMTYPE_WB:
return 1;
return BX_TRUE;
default:
return 0;
return BX_FALSE;
}
}
@ -422,9 +426,9 @@ bx_bool isValidMSR_PAT(Bit64u pat_msr)
! isMemTypeValidPAT((pat_msr >> 32) & 0xFF) ||
! isMemTypeValidPAT((pat_msr >> 40) & 0xFF) ||
! isMemTypeValidPAT((pat_msr >> 48) & 0xFF) ||
! isMemTypeValidPAT(pat_msr >> 56)) return 0;
! isMemTypeValidPAT(pat_msr >> 56)) return BX_FALSE;
return 1;
return BX_TRUE;
}
bx_bool isValidMSR_FixedMTRR(Bit64u fixed_mtrr_msr)
@ -436,9 +440,9 @@ bx_bool isValidMSR_FixedMTRR(Bit64u fixed_mtrr_msr)
! isMemTypeValidMTRR((fixed_mtrr_msr >> 32) & 0xFF) ||
! isMemTypeValidMTRR((fixed_mtrr_msr >> 40) & 0xFF) ||
! isMemTypeValidMTRR((fixed_mtrr_msr >> 48) & 0xFF) ||
! isMemTypeValidMTRR(fixed_mtrr_msr >> 56)) return 0;
! isMemTypeValidMTRR(fixed_mtrr_msr >> 56)) return BX_FALSE;
return 1;
return BX_TRUE;
}
#endif
@ -579,6 +583,11 @@ bx_bool BX_CPP_AttrRegparmN(2) BX_CPU_C::wrmsr(Bit32u index, Bit64u val_64)
break;
case BX_MSR_PAT:
if (! bx_cpuid_support_pat()) {
BX_ERROR(("WRMSR BX_MSR_PAT: PAT is not enabled !"));
return handle_unknown_wrmsr(index, val_64);
}
if (! isValidMSR_PAT(val_64)) {
BX_ERROR(("WRMSR: attempt to write invalid Memory Type to MSR_PAT"));
return 0;
@ -677,7 +686,7 @@ bx_bool BX_CPP_AttrRegparmN(2) BX_CPU_C::wrmsr(Bit32u index, Bit64u val_64)
case BX_MSR_STAR:
if ((BX_CPU_THIS_PTR efer_suppmask & BX_EFER_SCE_MASK) == 0) {
BX_ERROR(("RDMSR MSR_STAR: SYSCALL/SYSRET support not enabled !"));
BX_ERROR(("WRMSR MSR_STAR: SYSCALL/SYSRET support not enabled !"));
return handle_unknown_wrmsr(index, val_64);
}
MSR_STAR = val_64;