These changes are from Peter Tattam

- fix load_ss, remove load_ss_null
- change the "#if KPL64Hacks" around msr stuff into "#if BX_IGNORE_BAD_MSR"
- remove "#if KPL64Hacks" from BX_CPU_C::can_push
- segment_ctrl_pro.cc: bug fix to ss == null handling in 64 bit mode

Modified: cpu/cpu.h cpu/ctrl_xfer_pro.cc cpu/exception.cc
cpu/proc_ctrl.cc cpu/segment_ctrl_pro.cc cpu/stack_pro.cc
This commit is contained in:
Bryce Denney 2002-09-24 08:29:06 +00:00
parent 3b011766fa
commit de0e58c2c5
6 changed files with 76 additions and 76 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: cpu.h,v 1.74 2002-09-24 00:44:55 kevinlawton Exp $
// $Id: cpu.h,v 1.75 2002-09-24 08:29:05 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -2494,9 +2494,6 @@ union {
BX_SMF void load_ldtr(bx_selector_t *selector, bx_descriptor_t *descriptor);
BX_SMF void load_cs(bx_selector_t *selector, bx_descriptor_t *descriptor, Bit8u cpl);
BX_SMF void load_ss(bx_selector_t *selector, bx_descriptor_t *descriptor, Bit8u cpl);
#if BX_SUPPORT_X86_64
BX_SMF void load_ss_null(bx_selector_t *selector, bx_descriptor_t *descriptor, Bit8u cpl);
#endif
BX_SMF void fetch_raw_descriptor(bx_selector_t *selector,
Bit32u *dword1, Bit32u *dword2, Bit8u exception);
BX_SMF void load_seg_reg(bx_segment_reg_t *seg, Bit16u new_value);

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: ctrl_xfer_pro.cc,v 1.17 2002-09-24 00:44:55 kevinlawton Exp $
// $Id: ctrl_xfer_pro.cc,v 1.18 2002-09-24 08:29:05 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -1637,30 +1637,32 @@ if ( (raw_ss_selector & 0xfffc) == 0 ) {
parse_descriptor(dword1, dword2, &ss_descriptor);
/* AR byte must indicate a writable data segment,
* else #GP(SS selector) */
if ( ss_descriptor.valid==0 ||
ss_descriptor.segment==0 ||
ss_descriptor.u.segment.executable ||
ss_descriptor.u.segment.r_w==0 ) {
BX_PANIC(("iret: SS AR byte not writable code segment"));
exception(BX_GP_EXCEPTION, raw_ss_selector & 0xfffc, 0);
return;
}
if (raw_ss_selector != 0) {
/* AR byte must indicate a writable data segment,
* else #GP(SS selector) */
if ( ss_descriptor.valid==0 ||
ss_descriptor.segment==0 ||
ss_descriptor.u.segment.executable ||
ss_descriptor.u.segment.r_w==0 ) {
BX_PANIC(("iret: SS AR byte not writable code segment"));
exception(BX_GP_EXCEPTION, raw_ss_selector & 0xfffc, 0);
return;
}
/* stack segment DPL must equal the RPL of the return CS selector,
* else #GP(SS selector) */
if ( ss_descriptor.dpl != cs_selector.rpl ) {
BX_PANIC(("iret: SS.dpl != CS selector RPL"));
exception(BX_GP_EXCEPTION, raw_ss_selector & 0xfffc, 0);
return;
}
/* stack segment DPL must equal the RPL of the return CS selector,
* else #GP(SS selector) */
if ( ss_descriptor.dpl != cs_selector.rpl ) {
BX_PANIC(("iret: SS.dpl != CS selector RPL"));
exception(BX_GP_EXCEPTION, raw_ss_selector & 0xfffc, 0);
return;
}
/* SS must be present, else #NP(SS selector) */
if ( ss_descriptor.p==0 ) {
BX_PANIC(("iret: SS not present!"));
exception(BX_NP_EXCEPTION, raw_ss_selector & 0xfffc, 0);
return;
/* SS must be present, else #NP(SS selector) */
if ( ss_descriptor.p==0 ) {
BX_PANIC(("iret: SS not present!"));
exception(BX_NP_EXCEPTION, raw_ss_selector & 0xfffc, 0);
return;
}
}
#if KPL64Hacks

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: exception.cc,v 1.17 2002-09-23 15:26:05 bdenney Exp $
// $Id: exception.cc,v 1.18 2002-09-24 08:29:05 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -236,7 +236,7 @@ BX_CPU_THIS_PTR save_esp = ESP;
// load new RSP values from TSS
load_ss_null(&ss_selector, &ss_descriptor, cs_descriptor.dpl);
load_ss(&ss_selector, &ss_descriptor, cs_descriptor.dpl);
RSP = RSP_for_cpl_x;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: proc_ctrl.cc,v 1.48 2002-09-24 00:44:56 kevinlawton Exp $
// $Id: proc_ctrl.cc,v 1.49 2002-09-24 08:29:06 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -1775,13 +1775,14 @@ BX_CPU_C::RDMSR(bxInstruction_c *i)
#endif // #if BX_SUPPORT_X86_64
default:
#if KPL64Hacks
BX_INFO(("RDMSR: Unknown register %#x", ECX));
return;
#if BX_IGNORE_BAD_MSR
BX_ERROR(("RDMSR: Unknown register %#x", ECX));
return;
#else
BX_PANIC(("RDMSR: Unknown register %#x", ECX));
#endif
goto do_exception;
#endif
}
#endif /* BX_CPU_LEVEL >= 5 */
@ -1880,13 +1881,14 @@ BX_CPU_C::WRMSR(bxInstruction_c *i)
#endif // #if BX_SUPPORT_X86_64
default:
#if KPL64Hacks
BX_INFO(("WRMSR: Unknown register %#x", ECX));
return;
#if BX_IGNORE_BAD_MSR
BX_ERROR(("WRMSR: Unknown register %#x", ECX));
return;
#else
BX_PANIC(("WRMSR: Unknown register %#x", ECX));
#endif
goto do_exception;
#endif
}
#endif /* BX_CPU_LEVEL >= 5 */

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: segment_ctrl_pro.cc,v 1.15 2002-09-24 00:44:56 kevinlawton Exp $
// $Id: segment_ctrl_pro.cc,v 1.16 2002-09-24 08:29:06 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -34,6 +34,13 @@
#define LOG_THIS BX_CPU_THIS_PTR
#define INIT_64_DESCRIPTOR(descriptor) \
{ \
(descriptor).u.segment.base = 0; \
(descriptor).u.segment.limit_scaled = 0xffffffff; \
(descriptor).valid = 1; \
}
void
@ -337,6 +344,12 @@ BX_CPU_C::load_seg_reg(bx_segment_reg_t *seg, Bit16u new_value)
BX_CPU_THIS_PTR iCache.createFetchModeMask(BX_CPU_THIS);
#endif
#if BX_SUPPORT_X86_64
if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64) {
INIT_64_DESCRIPTOR(seg->cache);
}
#endif
}
else { /* SS, DS, ES, FS, GS */
seg->selector.value = new_value;
@ -355,8 +368,6 @@ BX_CPU_C::load_seg_reg(bx_segment_reg_t *seg, Bit16u new_value)
}
#if BX_CPU_LEVEL >= 2
void
BX_CPU_C::parse_selector(Bit16u raw_selector, bx_selector_t *selector)
@ -400,6 +411,12 @@ BX_CPU_C::parse_descriptor(Bit32u dword1, Bit32u dword2, bx_descriptor_t *temp)
#endif
temp->u.segment.avl = (dword2 & 0x00100000) > 0;
temp->u.segment.base |= (dword2 & 0xFF000000);
#if BX_SUPPORT_X86_64
if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64) {
INIT_64_DESCRIPTOR(*temp);
}
#endif
if (temp->u.segment.g) {
if ( (temp->u.segment.executable==0) && (temp->u.segment.c_ed) )
temp->u.segment.limit_scaled = (temp->u.segment.limit << 12);
@ -526,6 +543,7 @@ BX_CPU_C::load_cs(bx_selector_t *selector, bx_descriptor_t *descriptor,
if (BX_CPU_THIS_PTR msr.lma) {
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.l) {
BX_CPU_THIS_PTR cpu_mode = BX_MODE_LONG_64;
INIT_64_DESCRIPTOR(BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache);
}
else {
BX_CPU_THIS_PTR cpu_mode = BX_MODE_LONG_COMPAT;
@ -546,37 +564,20 @@ BX_CPU_C::load_ss(bx_selector_t *selector, bx_descriptor_t *descriptor, Bit8u cp
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache = *descriptor;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.rpl = cpl;
if ( (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value & 0xfffc) == 0 )
BX_PANIC(("load_ss(): null selector passed"));
if ( !BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.valid ) {
BX_PANIC(("load_ss(): invalid selector/descriptor passed."));
}
}
#if BX_SUPPORT_X86_64
void
BX_CPU_C::load_ss_null(bx_selector_t *selector, bx_descriptor_t *descriptor, Bit8u cpl)
{
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector = *selector;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache = *descriptor;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.rpl = cpl;
#if KPL64Hacks
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.valid = 1;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.p = 1;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.segment = 1;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.executable = 0;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.c_ed = 0;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.r_w = 1;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.a = 1;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.base = 0;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.l = 1;
if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64) {
INIT_64_DESCRIPTOR(BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache);
}
else{
#endif
if ( (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value & 0xfffc) == 0 )
BX_PANIC(("load_ss(): null selector passed"));
if ( !BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.valid ) {
BX_PANIC(("load_ss(): invalid selector/descriptor passed."));
}
}
}
#endif
#if BX_CPU_LEVEL >= 2
void

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: stack_pro.cc,v 1.8 2002-09-24 00:44:56 kevinlawton Exp $
// $Id: stack_pro.cc,v 1.9 2002-09-24 08:29:06 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -242,10 +242,9 @@ BX_CPU_C::pop_64(Bit64u *value64_ptr)
BX_CPU_C::can_push(bx_descriptor_t *descriptor, Bit32u esp, Bit32u bytes)
{
#if BX_SUPPORT_X86_64
#if KPL64Hacks
if ( BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64 )
return(1); // SS segment is ignore in long mode, to my knowlege. (KPL)
#endif
if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64) {
return(1);
}
#endif
if ( real_mode() ) { /* code not needed ??? */
@ -336,10 +335,9 @@ BX_CPU_C::can_pop(Bit32u bytes)
Bit32u temp_ESP, expand_down_limit;
#if BX_SUPPORT_X86_64
#if KPL64Hacks
if ( BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64 )
return(1); // SS segment is ignore in long mode, to my knowlege. (KPL)
#endif
if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64) {
return(1);
}
#endif
/* ??? */