Eliminate can_pop function - with bugfix in retf
This commit is contained in:
parent
3c7949948b
commit
d24a274909
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: cpu.h,v 1.460 2008-04-19 22:29:43 sshwarts Exp $
|
||||
// $Id: cpu.h,v 1.461 2008-04-23 17:25:21 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2001 MandrakeSoft S.A.
|
||||
@ -3030,7 +3030,6 @@ public: // for now...
|
||||
BX_SMF void push_64(Bit64u value64) BX_CPP_AttrRegparmN(1);
|
||||
BX_SMF Bit64u pop_64(void);
|
||||
#endif
|
||||
BX_SMF bx_bool can_pop(Bit32u bytes) BX_CPP_AttrRegparmN(1);
|
||||
BX_SMF void sanity_checks(void);
|
||||
BX_SMF void assert_checks(void);
|
||||
BX_SMF void enter_system_management_mode(void);
|
||||
|
@ -1,5 +1,5 @@
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// $Id: ret_far.cc,v 1.16 2008-04-20 21:44:13 sshwarts Exp $
|
||||
// $Id: ret_far.cc,v 1.17 2008-04-23 17:25:21 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2005 Stanislav Shwartsman
|
||||
@ -62,20 +62,20 @@ BX_CPU_C::return_protected(bxInstruction_c *i, Bit16u pop_bytes)
|
||||
|
||||
#if BX_SUPPORT_X86_64
|
||||
if (i->os64L()) {
|
||||
return_RIP = read_virtual_qword(BX_SEG_REG_SS, temp_RSP);
|
||||
raw_cs_selector = (Bit16u) read_virtual_qword(BX_SEG_REG_SS, temp_RSP + 8);
|
||||
return_RIP = read_virtual_qword(BX_SEG_REG_SS, temp_RSP);
|
||||
stack_param_offset = 16;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (i->os32L()) {
|
||||
return_RIP = read_virtual_dword(BX_SEG_REG_SS, temp_RSP);
|
||||
raw_cs_selector = (Bit16u) read_virtual_dword(BX_SEG_REG_SS, temp_RSP + 4);
|
||||
return_RIP = read_virtual_dword(BX_SEG_REG_SS, temp_RSP);
|
||||
stack_param_offset = 8;
|
||||
}
|
||||
else {
|
||||
return_RIP = read_virtual_word(BX_SEG_REG_SS, temp_RSP);
|
||||
raw_cs_selector = read_virtual_word(BX_SEG_REG_SS, temp_RSP + 2);
|
||||
return_RIP = read_virtual_word(BX_SEG_REG_SS, temp_RSP);
|
||||
stack_param_offset = 4;
|
||||
}
|
||||
|
||||
@ -109,12 +109,6 @@ BX_CPU_C::return_protected(bxInstruction_c *i, Bit16u pop_bytes)
|
||||
{
|
||||
BX_DEBUG(("return_protected: return to SAME PRIVILEGE LEVEL"));
|
||||
|
||||
// top word on stack must be within stack limits, else #SS(0)
|
||||
if (! can_pop(stack_param_offset + pop_bytes)) {
|
||||
BX_ERROR(("return_protected: top word not in stack limits"));
|
||||
exception(BX_SS_EXCEPTION, 0, 0);
|
||||
}
|
||||
|
||||
branch_far64(&cs_selector, &cs_descriptor, return_RIP, CPL);
|
||||
|
||||
#if BX_SUPPORT_X86_64
|
||||
@ -124,7 +118,7 @@ BX_CPU_C::return_protected(bxInstruction_c *i, Bit16u pop_bytes)
|
||||
#endif
|
||||
{
|
||||
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b)
|
||||
ESP += stack_param_offset + pop_bytes;
|
||||
RSP = ESP + stack_param_offset + pop_bytes;
|
||||
else
|
||||
SP += stack_param_offset + pop_bytes;
|
||||
}
|
||||
@ -145,34 +139,16 @@ BX_CPU_C::return_protected(bxInstruction_c *i, Bit16u pop_bytes)
|
||||
|
||||
#if BX_SUPPORT_X86_64
|
||||
if (i->os64L()) {
|
||||
/* top 32+immediate bytes on stack must be within stack limits, else #SS(0) */
|
||||
if (! can_pop(32 + pop_bytes)) {
|
||||
BX_ERROR(("return_protected: 32 bytes not within stack limits"));
|
||||
exception(BX_SS_EXCEPTION, 0, 0);
|
||||
}
|
||||
|
||||
raw_ss_selector = read_virtual_word (BX_SEG_REG_SS, temp_RSP + 24 + pop_bytes);
|
||||
return_RSP = read_virtual_qword(BX_SEG_REG_SS, temp_RSP + 16 + pop_bytes);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (i->os32L()) {
|
||||
/* top 16+immediate bytes on stack must be within stack limits, else #SS(0) */
|
||||
if (! can_pop(16 + pop_bytes)) {
|
||||
BX_ERROR(("return_protected: 16 bytes not within stack limits"));
|
||||
exception(BX_SS_EXCEPTION, 0, 0);
|
||||
}
|
||||
|
||||
raw_ss_selector = read_virtual_word (BX_SEG_REG_SS, temp_RSP + 12 + pop_bytes);
|
||||
return_RSP = read_virtual_dword(BX_SEG_REG_SS, temp_RSP + 8 + pop_bytes);
|
||||
}
|
||||
else {
|
||||
/* top 8+immediate bytes on stack must be within stack limits, else #SS(0) */
|
||||
if (! can_pop(8 + pop_bytes)) {
|
||||
BX_ERROR(("return_protected: 8 bytes not within stack limits"));
|
||||
exception(BX_SS_EXCEPTION, 0, 0);
|
||||
}
|
||||
|
||||
raw_ss_selector = read_virtual_word(BX_SEG_REG_SS, temp_RSP + 6 + pop_bytes);
|
||||
return_RSP = read_virtual_word(BX_SEG_REG_SS, temp_RSP + 4 + pop_bytes);
|
||||
}
|
||||
@ -235,11 +211,12 @@ BX_CPU_C::return_protected(bxInstruction_c *i, Bit16u pop_bytes)
|
||||
load_ss(&ss_selector, &ss_descriptor, cs_selector.rpl);
|
||||
|
||||
#if BX_SUPPORT_X86_64
|
||||
if (StackAddrSize64()) RSP = return_RSP + pop_bytes;
|
||||
if (StackAddrSize64())
|
||||
RSP = return_RSP + pop_bytes;
|
||||
else
|
||||
#endif
|
||||
if (ss_descriptor.u.segment.d_b)
|
||||
ESP = (Bit32u) return_RSP + pop_bytes;
|
||||
RSP = (Bit32u) return_RSP + pop_bytes;
|
||||
else
|
||||
SP = (Bit16u) return_RSP + pop_bytes;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: stack16.cc,v 1.37 2008-04-05 17:51:55 sshwarts Exp $
|
||||
// $Id: stack16.cc,v 1.38 2008-04-23 17:25:21 sshwarts Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2001 MandrakeSoft S.A.
|
||||
@ -177,26 +177,26 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::PUSHAD16(bxInstruction_c *i)
|
||||
|
||||
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b)
|
||||
{
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 2), AX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 4), CX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 6), DX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 8), BX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 10), temp_SP);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 12), BP);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 14), SI);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP - 16), DI);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 2), AX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 4), CX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 6), DX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 8), BX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 10), temp_SP);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 12), BP);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 14), SI);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP - 16), DI);
|
||||
ESP -= 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP - 2), AX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP - 4), CX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP - 6), DX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP - 8), BX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP - 10), temp_SP);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP - 12), BP);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP - 14), SI);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP - 16), DI);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP - 2), AX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP - 4), CX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP - 6), DX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP - 8), BX);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP - 10), temp_SP);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP - 12), BP);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP - 14), SI);
|
||||
write_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP - 16), DI);
|
||||
SP -= 16;
|
||||
}
|
||||
}
|
||||
@ -208,25 +208,25 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::POPAD16(bxInstruction_c *i)
|
||||
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b)
|
||||
{
|
||||
Bit32u temp_ESP = ESP;
|
||||
di = read_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 0));
|
||||
si = read_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 2));
|
||||
bp = read_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 4));
|
||||
bx = read_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 8));
|
||||
dx = read_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 10));
|
||||
cx = read_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 12));
|
||||
ax = read_virtual_word(BX_SEG_REG_SS, (Bit32u) (temp_ESP + 14));
|
||||
di = read_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 0));
|
||||
si = read_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 2));
|
||||
bp = read_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 4));
|
||||
bx = read_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 8));
|
||||
dx = read_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 10));
|
||||
cx = read_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 12));
|
||||
ax = read_virtual_word(BX_SEG_REG_SS, (Bit32u)(temp_ESP + 14));
|
||||
ESP += 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
Bit16u temp_SP = SP;
|
||||
di = read_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP + 0));
|
||||
si = read_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP + 2));
|
||||
bp = read_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP + 4));
|
||||
bx = read_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP + 8));
|
||||
dx = read_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP + 10));
|
||||
cx = read_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP + 12));
|
||||
ax = read_virtual_word(BX_SEG_REG_SS, (Bit16u) (temp_SP + 14));
|
||||
di = read_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP + 0));
|
||||
si = read_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP + 2));
|
||||
bp = read_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP + 4));
|
||||
bx = read_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP + 8));
|
||||
dx = read_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP + 10));
|
||||
cx = read_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP + 12));
|
||||
ax = read_virtual_word(BX_SEG_REG_SS, (Bit16u)(temp_SP + 14));
|
||||
SP += 16;
|
||||
}
|
||||
|
||||
@ -239,60 +239,3 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::POPAD16(bxInstruction_c *i)
|
||||
AX = ax;
|
||||
}
|
||||
#endif
|
||||
|
||||
bx_bool BX_CPP_AttrRegparmN(1) BX_CPU_C::can_pop(Bit32u bytes)
|
||||
{
|
||||
Bit32u temp_ESP, expand_down_limit;
|
||||
|
||||
#if BX_SUPPORT_X86_64
|
||||
if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64) {
|
||||
return(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.d_b) { /* Big bit set: use ESP */
|
||||
temp_ESP = ESP;
|
||||
expand_down_limit = 0xFFFFFFFF;
|
||||
}
|
||||
else { /* Big bit clear: use SP */
|
||||
temp_ESP = SP;
|
||||
expand_down_limit = 0xFFFF;
|
||||
}
|
||||
|
||||
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.valid==0) {
|
||||
BX_ERROR(("can_pop(): SS invalidated"));
|
||||
return(0); /* never gets here */
|
||||
}
|
||||
|
||||
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.p==0) {
|
||||
BX_ERROR(("can_pop(): SS.p = 0"));
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (IS_DATA_SEGMENT_EXPAND_DOWN(BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.type)) { /* expand down */
|
||||
if (temp_ESP == expand_down_limit) {
|
||||
BX_PANIC(("can_pop(): found SP=ffff"));
|
||||
return(0);
|
||||
}
|
||||
if (((expand_down_limit - temp_ESP) + 1) >= bytes)
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
else { /* normal (expand-up) segment */
|
||||
if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.limit_scaled==0) {
|
||||
BX_ERROR(("can_pop(): SS.limit = 0"));
|
||||
return(0);
|
||||
}
|
||||
if (temp_ESP == expand_down_limit) {
|
||||
BX_ERROR(("can_pop(): found SP=ffff"));
|
||||
return(0);
|
||||
}
|
||||
if (temp_ESP > BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.limit_scaled) {
|
||||
BX_ERROR(("can_pop(): eSP > SS.limit"));
|
||||
return(0);
|
||||
}
|
||||
if (((BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.u.segment.limit_scaled - temp_ESP) + 1) >= bytes)
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user