merge gate286 and gate386 in descriptor.h

This commit is contained in:
Stanislav Shwartsman 2007-11-06 19:17:42 +00:00
parent 494189e822
commit cfca3fdb8b
5 changed files with 46 additions and 70 deletions

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////
// $Id: call_far.cc,v 1.20 2007-10-19 12:40:18 sshwarts Exp $
// $Id: call_far.cc,v 1.21 2007-11-06 19:17:42 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -208,16 +208,9 @@ BX_CPU_C::call_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp)
case BX_286_CALL_GATE:
case BX_386_CALL_GATE:
// examine code segment selector in call gate descriptor
if (gate_descriptor.type == BX_286_CALL_GATE) {
BX_DEBUG(("call_protected: CALL 16bit call gate"));
dest_selector = gate_descriptor.u.gate286.dest_selector;
new_EIP = gate_descriptor.u.gate286.dest_offset;
}
else {
BX_DEBUG(("call_protected: CALL 32bit call gate"));
dest_selector = gate_descriptor.u.gate386.dest_selector;
new_EIP = gate_descriptor.u.gate386.dest_offset;
}
BX_DEBUG(("call_protected: call gate"));
dest_selector = gate_descriptor.u.gate.dest_selector;
new_EIP = gate_descriptor.u.gate.dest_offset;
// selector must not be null else #GP(0)
if ( (dest_selector & 0xfffc) == 0 ) {
@ -257,7 +250,7 @@ BX_CPU_C::call_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp)
Bit32u ESP_for_cpl_x;
bx_selector_t ss_selector;
bx_descriptor_t ss_descriptor;
unsigned room_needed, param_count;
unsigned room_needed;
Bit16u return_SS, return_CS;
Bit32u return_ESP, return_EIP;
Bit16u parameter_word[32];
@ -319,16 +312,13 @@ BX_CPU_C::call_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp)
// new stack must have room for parameters plus 8 bytes
room_needed = 8;
if (gate_descriptor.type==BX_286_CALL_GATE) {
// get word count from call gate, mask to 5 bits
param_count = gate_descriptor.u.gate286.word_count & 0x1f;
// get word count from call gate, mask to 5 bits
unsigned param_count = gate_descriptor.u.gate.param_count & 0x1f;
if (gate_descriptor.type==BX_286_CALL_GATE)
room_needed += param_count*2;
}
else {
// get word count from call gate, mask to 5 bits
param_count = gate_descriptor.u.gate386.dword_count & 0x1f;
else
room_needed += param_count*4;
}
// new stack must have room for parameters plus return info
// else #SS(SS selector)
@ -472,7 +462,7 @@ BX_CPU_C::call_gate64(bx_selector_t *gate_selector)
fetch_raw_descriptor64(gate_selector, &dword1, &dword2, &dword3, BX_GP_EXCEPTION);
parse_descriptor(dword1, dword2, &gate_descriptor);
Bit16u dest_selector = gate_descriptor.u.gate386.dest_selector;
Bit16u dest_selector = gate_descriptor.u.gate.dest_selector;
// selector must not be null else #GP(0)
if ( (dest_selector & 0xfffc) == 0 ) {
BX_ERROR(("call_gate64: selector in gate null"));
@ -486,7 +476,7 @@ BX_CPU_C::call_gate64(bx_selector_t *gate_selector)
parse_descriptor(dword1, dword2, &cs_descriptor);
// find the RIP in the gate_descriptor
Bit64u new_RIP = gate_descriptor.u.gate386.dest_offset;
Bit64u new_RIP = gate_descriptor.u.gate.dest_offset;
new_RIP |= ((Bit64u)dword3 << 32);
// AR byte of selected descriptor must indicate code segment,

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: descriptor.h,v 1.19 2007-10-15 22:07:52 sshwarts Exp $
// $Id: descriptor.h,v 1.20 2007-11-06 19:17:42 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007 Stanislav Shwartsman
@ -124,19 +124,11 @@ union {
#endif
} segment;
struct {
Bit8u word_count; /* 5bits (0..31) #words to copy from caller's stack
* to called procedure's stack. (call gates only)*/
Bit16u dest_selector;
Bit16u dest_offset;
} gate286;
#if BX_CPU_LEVEL >= 3
struct {
Bit8u dword_count; /* 5bits (0..31) #dwords to copy from caller's stack
* to called procedure's stack. (call gates only) */
Bit8u param_count; /* 5bits (0..31) #words/dword to copy from caller's
* stack to called procedure's stack. */
Bit16u dest_selector;
Bit32u dest_offset;
} gate386;
#endif
} gate;
struct { /* type 5: Task Gate Descriptor */
Bit16u tss_selector; /* TSS segment selector */
} taskgate;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: exception.cc,v 1.94 2007-10-19 12:40:19 sshwarts Exp $
// $Id: exception.cc,v 1.95 2007-11-06 19:17:42 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -116,11 +116,11 @@ void BX_CPU_C::long_mode_int(Bit8u vector, bx_bool is_INT, bx_bool is_error_code
exception(BX_NP_EXCEPTION, vector*16 + 2, 0);
}
Bit16u gate_dest_selector = gate_descriptor.u.gate386.dest_selector;
Bit64u gate_dest_offset = ((Bit64u)dword3 << 32) +
gate_descriptor.u.gate386.dest_offset;
Bit16u gate_dest_selector = gate_descriptor.u.gate.dest_selector;
Bit64u gate_dest_offset = ((Bit64u)dword3 << 32) |
gate_descriptor.u.gate.dest_offset;
unsigned ist = gate_descriptor.u.gate386.dword_count & 0x7;
unsigned ist = gate_descriptor.u.gate.param_count & 0x7;
// examine CS selector and descriptor given in gate descriptor
// selector must be non-null else #GP(EXT)
@ -405,14 +405,8 @@ void BX_CPU_C::protected_mode_int(Bit8u vector, bx_bool is_INT, bx_bool is_error
case BX_286_TRAP_GATE:
case BX_386_INTERRUPT_GATE:
case BX_386_TRAP_GATE:
if (gate_descriptor.type >= 14) { // 386 gate
gate_dest_selector = gate_descriptor.u.gate386.dest_selector;
gate_dest_offset = gate_descriptor.u.gate386.dest_offset;
}
else { // 286 gate
gate_dest_selector = gate_descriptor.u.gate286.dest_selector;
gate_dest_offset = gate_descriptor.u.gate286.dest_offset;
}
gate_dest_selector = gate_descriptor.u.gate.dest_selector;
gate_dest_offset = gate_descriptor.u.gate.dest_offset;
// examine CS selector and descriptor given in gate descriptor
// selector must be non-null else #GP(EXT)

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////
// $Id: jmp_far.cc,v 1.8 2006-10-04 19:08:40 sshwarts Exp $
// $Id: jmp_far.cc,v 1.9 2007-11-06 19:17:42 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -201,7 +201,7 @@ BX_CPU_C::jmp_call_gate16(bx_descriptor_t *gate_descriptor)
// examine selector to code segment given in call gate descriptor
// selector must not be null, else #GP(0)
Bit16u gate_cs_raw = gate_descriptor->u.gate286.dest_selector;
Bit16u gate_cs_raw = gate_descriptor->u.gate.dest_selector;
if ((gate_cs_raw & 0xfffc) == 0) {
BX_ERROR(("jump_protected: CS selector null"));
@ -216,7 +216,7 @@ BX_CPU_C::jmp_call_gate16(bx_descriptor_t *gate_descriptor)
// check code-segment descriptor
check_cs(&gate_cs_descriptor, gate_cs_raw, 0, CPL);
Bit16u temp_IP = gate_descriptor->u.gate286.dest_offset;
Bit16u temp_IP = gate_descriptor->u.gate.dest_offset;
branch_far32(&gate_cs_selector, &gate_cs_descriptor, temp_IP, CPL);
}
@ -232,7 +232,7 @@ BX_CPU_C::jmp_call_gate32(bx_descriptor_t *gate_descriptor)
// examine selector to code segment given in call gate descriptor
// selector must not be null, else #GP(0)
Bit16u gate_cs_raw = gate_descriptor->u.gate386.dest_selector;
Bit16u gate_cs_raw = gate_descriptor->u.gate.dest_selector;
if ((gate_cs_raw & 0xfffc) == 0) {
BX_ERROR(("jump_protected: CS selector null"));
@ -247,7 +247,7 @@ BX_CPU_C::jmp_call_gate32(bx_descriptor_t *gate_descriptor)
// check code-segment descriptor
check_cs(&gate_cs_descriptor, gate_cs_raw, 0, CPL);
Bit32u temp_EIP = gate_descriptor->u.gate386.dest_offset;
Bit32u temp_EIP = gate_descriptor->u.gate.dest_offset;
branch_far32(&gate_cs_selector, &gate_cs_descriptor, temp_EIP, CPL);
}
@ -266,7 +266,7 @@ BX_CPU_C::jmp_call_gate64(bx_selector_t *gate_selector)
fetch_raw_descriptor64(gate_selector, &dword1, &dword2, &dword3, BX_GP_EXCEPTION);
parse_descriptor(dword1, dword2, &gate_descriptor);
Bit16u dest_selector = gate_descriptor.u.gate386.dest_selector;
Bit16u dest_selector = gate_descriptor.u.gate.dest_selector;
// selector must not be null else #GP(0)
if ( (dest_selector & 0xfffc) == 0 ) {
BX_ERROR(("call_gate64: selector in gate null"));
@ -280,7 +280,7 @@ BX_CPU_C::jmp_call_gate64(bx_selector_t *gate_selector)
parse_descriptor(dword1, dword2, &cs_descriptor);
// find the RIP in the gate_descriptor
Bit64u new_RIP = gate_descriptor.u.gate386.dest_offset;
Bit64u new_RIP = gate_descriptor.u.gate.dest_offset;
new_RIP |= ((Bit64u)dword3 << 32);
// AR byte of selected descriptor must indicate code segment,

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: segment_ctrl_pro.cc,v 1.72 2007-10-18 21:27:56 sshwarts Exp $
// $Id: segment_ctrl_pro.cc,v 1.73 2007-11-06 19:17:42 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -591,10 +591,21 @@ BX_CPU_C::parse_descriptor(Bit32u dword1, Bit32u dword2, bx_descriptor_t *temp)
case BX_286_CALL_GATE:
case BX_286_INTERRUPT_GATE:
case BX_286_TRAP_GATE:
/* word count only used for call gate */
temp->u.gate286.word_count = dword2 & 0x1f;
temp->u.gate286.dest_selector = dword1 >> 16;
temp->u.gate286.dest_offset = dword1 & 0xffff;
// param count only used for call gate
temp->u.gate.param_count = dword2 & 0x1f;
temp->u.gate.dest_selector = dword1 >> 16;
temp->u.gate.dest_offset = dword1 & 0xffff;
temp->valid = 1;
break;
case BX_386_CALL_GATE:
case BX_386_INTERRUPT_GATE:
case BX_386_TRAP_GATE:
// param count only used for call gate
temp->u.gate.param_count = dword2 & 0x1f;
temp->u.gate.dest_selector = dword1 >> 16;
temp->u.gate.dest_offset = (dword2 & 0xffff0000) |
(dword1 & 0x0000ffff);
temp->valid = 1;
break;
@ -618,17 +629,6 @@ BX_CPU_C::parse_descriptor(Bit32u dword1, Bit32u dword2, bx_descriptor_t *temp)
temp->valid = 1;
break;
case BX_386_CALL_GATE:
case BX_386_INTERRUPT_GATE:
case BX_386_TRAP_GATE:
// word count only used for call gate
temp->u.gate386.dword_count = dword2 & 0x1f;
temp->u.gate386.dest_selector = dword1 >> 16;
temp->u.gate386.dest_offset = (dword2 & 0xffff0000) |
(dword1 & 0x0000ffff);
temp->valid = 1;
break;
default:
BX_PANIC(("parse_descriptor(): case %u unfinished", (unsigned) temp->type));
temp->valid = 0;