Improve OS/2 hack - save full segment (including hidden part) and not only selector value

This commit is contained in:
Stanislav Shwartsman 2006-02-28 20:29:03 +00:00
parent a527b2cfca
commit 9b3be40d88
3 changed files with 21 additions and 27 deletions

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////
// $Id: call_far.cc,v 1.7 2005-12-12 19:44:06 sshwarts Exp $
// $Id: call_far.cc,v 1.8 2006-02-28 20:29:03 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -265,11 +265,6 @@ BX_CPU_C::call_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp)
BX_DEBUG(("CALL GATE TO MORE PRIVILEGE LEVEL"));
// Help for OS/2
BX_CPU_THIS_PTR except_chk = 1;
BX_CPU_THIS_PTR except_cs = BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value;
BX_CPU_THIS_PTR except_ss = BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value;
// get new SS selector for new privilege level from TSS
get_SS_ESP_from_TSS(cs_descriptor.dpl, &SS_for_cpl_x, &ESP_for_cpl_x);
@ -316,7 +311,7 @@ BX_CPU_C::call_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp)
exception(BX_SS_EXCEPTION, SS_for_cpl_x & 0xfffc, 0);
}
if ( cs_descriptor.u.segment.d_b )
if (cs_descriptor.u.segment.d_b)
// new stack must have room for parameters plus 16 bytes
room_needed = 16;
else
@ -336,13 +331,13 @@ BX_CPU_C::call_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp)
// new stack must have room for parameters plus return info
// else #SS(SS selector)
if ( !can_push(&ss_descriptor, ESP_for_cpl_x, room_needed) ) {
if (!can_push(&ss_descriptor, ESP_for_cpl_x, room_needed)) {
BX_INFO(("call_protected: stack doesn't have room"));
exception(BX_SS_EXCEPTION, SS_for_cpl_x & 0xfffc, 0);
}
// new eIP must be in code segment limit else #GP(0)
if ( new_EIP > cs_descriptor.u.segment.limit_scaled ) {
if (new_EIP > cs_descriptor.u.segment.limit_scaled) {
BX_ERROR(("call_protected: EIP not within CS limits"));
exception(BX_GP_EXCEPTION, 0, 0);
}
@ -357,7 +352,7 @@ BX_CPU_C::call_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp)
// save return CS:eIP to be pushed on new stack
return_CS = BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value;
if ( cs_descriptor.u.segment.d_b )
if (cs_descriptor.u.segment.d_b)
return_EIP = EIP;
else
return_EIP = IP;
@ -375,6 +370,11 @@ BX_CPU_C::call_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp)
}
}
// Help for OS/2
BX_CPU_THIS_PTR except_chk = 1;
BX_CPU_THIS_PTR except_cs = BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS];
BX_CPU_THIS_PTR except_ss = BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS];
/* load new SS:SP value from TSS */
/* load SS descriptor */
load_ss(&ss_selector, &ss_descriptor, ss_descriptor.dpl);

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: cpu.h,v 1.264 2006-02-28 19:50:08 sshwarts Exp $
// $Id: cpu.h,v 1.265 2006-02-28 20:29:03 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -1168,8 +1168,8 @@ public: // for now...
bx_address save_esp;
// This help for OS/2
bx_bool except_chk;
Bit16u except_cs;
Bit16u except_ss;
bx_segment_reg_t except_cs;
bx_segment_reg_t except_ss;
// Boundaries of current page, based on EIP
bx_address eipPageBias;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: exception.cc,v 1.74 2006-02-24 09:49:03 sshwarts Exp $
// $Id: exception.cc,v 1.75 2006-02-28 20:29:03 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -864,13 +864,6 @@ void BX_CPU_C::exception(unsigned vector, Bit16u error_code, bx_bool is_INT)
longjmp(BX_CPU_THIS_PTR jmp_buf_env, 1); // go back to main decode loop
}
if (BX_CPU_THIS_PTR except_chk) // FIXME: Help with OS/2
{
if (vector != BX_PF_EXCEPTION) {
BX_ERROR(("exception(): except_chk is ON not for #PF !"));
}
}
// note: fault-class exceptions _except_ #DB set RF in
// eflags image.
@ -953,12 +946,6 @@ void BX_CPU_C::exception(unsigned vector, Bit16u error_code, bx_bool is_INT)
exception_type = BX_ET_CONTRIBUTORY;
break;
case BX_PF_EXCEPTION: // page fault
if (BX_CPU_THIS_PTR except_chk) // FIXME: Help with OS/2
{
BX_CPU_THIS_PTR except_chk = 0;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value = BX_CPU_THIS_PTR except_cs;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value = BX_CPU_THIS_PTR except_ss;
}
push_error = 1;
exception_class = BX_EXCEPTION_CLASS_FAULT;
exception_type = BX_ET_PAGE_FAULT;
@ -1010,6 +997,13 @@ void BX_CPU_C::exception(unsigned vector, Bit16u error_code, bx_bool is_INT)
RIP = BX_CPU_THIS_PTR prev_eip;
RSP = BX_CPU_THIS_PTR prev_esp;
if (BX_CPU_THIS_PTR except_chk) // FIXME: Help with OS/2
{
BX_CPU_THIS_PTR except_chk = 0;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS] = BX_CPU_THIS_PTR except_cs;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS] = BX_CPU_THIS_PTR except_ss;
}
if (vector != BX_DB_EXCEPTION) BX_CPU_THIS_PTR assert_RF();
}