- Fixed CPUID

- Merged jmp_call_gate16 and jmp_call_gate32 to single function
This commit is contained in:
Stanislav Shwartsman 2008-05-09 18:09:04 +00:00
parent 80c9b5fcbe
commit 8e7cf2bf3a
3 changed files with 25 additions and 58 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: cpu.h,v 1.471 2008-05-06 19:45:17 sshwarts Exp $
// $Id: cpu.h,v 1.472 2008-05-09 18:09:03 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -569,8 +569,8 @@ typedef struct
} bx_regs_msr_t;
#endif
#define MAX_STD_CPUID_FUNCTION 15
#define MAX_EXT_CPUID_FUNCTION 8
#define MAX_STD_CPUID_FUNCTION 14
#define MAX_EXT_CPUID_FUNCTION 9
struct cpuid_function_t {
Bit32u eax;
@ -2958,8 +2958,7 @@ public: // for now...
BX_SMF void jump_protected(bxInstruction_c *, Bit16u cs, bx_address disp) BX_CPP_AttrRegparmN(3);
BX_SMF void jmp_task_gate(bx_descriptor_t *gate_descriptor) BX_CPP_AttrRegparmN(1);
BX_SMF void jmp_call_gate16(bx_descriptor_t *gate_descriptor) BX_CPP_AttrRegparmN(1);
BX_SMF void jmp_call_gate32(bx_descriptor_t *gate_descriptor) BX_CPP_AttrRegparmN(1);
BX_SMF void jmp_call_gate(bx_descriptor_t *gate_descriptor) BX_CPP_AttrRegparmN(1);
#if BX_SUPPORT_X86_64
BX_SMF void jmp_call_gate64(bx_selector_t *selector) BX_CPP_AttrRegparmN(1);
#endif

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: cpuid.cc,v 1.67 2008-04-04 12:23:19 sshwarts Exp $
// $Id: cpuid.cc,v 1.68 2008-05-09 18:09:04 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007 Stanislav Shwartsman
@ -299,7 +299,7 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::CPUID(bxInstruction_c *i)
RCX = BX_CPU_THIS_PTR cpuid_ext_function[function].ecx;
RDX = BX_CPU_THIS_PTR cpuid_ext_function[function].edx;
#if BX_SUPPORT_APIC
if (EAX == 1) {
if (function == 1) {
// if MSR_APICBASE APIC Global Enable bit has been cleared,
// the CPUID feature flag for the APIC is set to 0.
if ((BX_CPU_THIS_PTR msr.apicbase & 0x800) == 0)
@ -710,7 +710,7 @@ void BX_CPU_C::set_cpuid_defaults(void)
// ------------------------------------------------------
// CPUID function 0x00000007
cpuid = &(BX_CPU_THIS_PTR cpuid_std_function[7]);
cpuid = &(BX_CPU_THIS_PTR cpuid_ext_function[7]);
cpuid->eax = 0;
cpuid->ebx = 0;

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////////////////
// $Id: jmp_far.cc,v 1.14 2008-04-26 19:41:28 sshwarts Exp $
// $Id: jmp_far.cc,v 1.15 2008-05-09 18:09:04 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2005 Stanislav Shwartsman
@ -112,9 +112,9 @@ BX_CPU_C::jump_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp)
case BX_SYS_SEGMENT_AVAIL_386_TSS:
if (descriptor.type==BX_SYS_SEGMENT_AVAIL_286_TSS)
BX_DEBUG(("jump to 286 TSS"));
BX_DEBUG(("jump_protected: jump to 286 TSS"));
else
BX_DEBUG(("jump to 386 TSS"));
BX_DEBUG(("jump_protected: jump to 386 TSS"));
// SWITCH_TASKS _without_ nesting to TSS
task_switch(&selector, &descriptor, BX_TASK_FROM_JUMP, dword1, dword2);
@ -126,16 +126,13 @@ BX_CPU_C::jump_protected(bxInstruction_c *i, Bit16u cs_raw, bx_address disp)
}
return;
case BX_286_CALL_GATE:
jmp_call_gate16(&descriptor);
return;
case BX_TASK_GATE:
jmp_task_gate(&descriptor);
return;
case BX_286_CALL_GATE:
case BX_386_CALL_GATE:
jmp_call_gate32(&descriptor);
jmp_call_gate(&descriptor);
return;
default: // can't get here
@ -160,7 +157,7 @@ BX_CPU_C::jmp_task_gate(bx_descriptor_t *gate_descriptor)
parse_selector(raw_tss_selector, &tss_selector);
if (tss_selector.ti) {
BX_ERROR(("jump_protected: tss_selector.ti=1"));
BX_ERROR(("jmp_task_gate: tss_selector.ti=1"));
exception(BX_GP_EXCEPTION, raw_tss_selector & 0xfffc, 0);
}
@ -172,19 +169,19 @@ BX_CPU_C::jmp_task_gate(bx_descriptor_t *gate_descriptor)
parse_descriptor(dword1, dword2, &tss_descriptor);
if (tss_descriptor.valid==0 || tss_descriptor.segment) {
BX_ERROR(("jump_protected: TSS selector points to bad TSS"));
BX_ERROR(("jmp_task_gate: TSS selector points to bad TSS"));
exception(BX_GP_EXCEPTION, raw_tss_selector & 0xfffc, 0);
}
if (tss_descriptor.type!=BX_SYS_SEGMENT_AVAIL_286_TSS &&
tss_descriptor.type!=BX_SYS_SEGMENT_AVAIL_386_TSS)
{
BX_ERROR(("jump_protected: TSS selector points to bad TSS"));
BX_ERROR(("jmp_task_gate: TSS selector points to bad TSS"));
exception(BX_GP_EXCEPTION, raw_tss_selector & 0xfffc, 0);
}
// task state segment must be present, else #NP(tss selector)
if (! IS_PRESENT(tss_descriptor)) {
BX_ERROR(("jump_protected: TSS descriptor.p == 0"));
BX_ERROR(("jmp_task_gate: TSS descriptor.p == 0"));
exception(BX_NP_EXCEPTION, raw_tss_selector & 0xfffc, 0);
}
@ -198,57 +195,29 @@ BX_CPU_C::jmp_task_gate(bx_descriptor_t *gate_descriptor)
temp_eIP = IP;
if (temp_eIP > BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.limit_scaled) {
BX_ERROR(("jump_protected: EIP > CS.limit"));
BX_ERROR(("jmp_task_gate: EIP > CS.limit"));
exception(BX_GP_EXCEPTION, 0, 0);
}
}
void BX_CPP_AttrRegparmN(1)
BX_CPU_C::jmp_call_gate16(bx_descriptor_t *gate_descriptor)
BX_CPU_C::jmp_call_gate(bx_descriptor_t *gate_descriptor)
{
bx_selector_t gate_cs_selector;
bx_descriptor_t gate_cs_descriptor;
Bit32u dword1, dword2;
BX_DEBUG(("jump_protected: JUMP TO 286 CALL GATE"));
if (gate_descriptor->type==BX_286_CALL_GATE)
BX_DEBUG(("jmp_call_gate: jump to 286 CALL GATE"));
else
BX_DEBUG(("jmp_call_gate: jump to 386 CALL GATE"));
// 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.gate.dest_selector;
if ((gate_cs_raw & 0xfffc) == 0) {
BX_ERROR(("jump_protected: CS selector null"));
exception(BX_GP_EXCEPTION, 0, 0);
}
parse_selector(gate_cs_raw, &gate_cs_selector);
// selector must be within its descriptor table limits else #GP(CS selector)
fetch_raw_descriptor(&gate_cs_selector, &dword1, &dword2, BX_GP_EXCEPTION);
parse_descriptor(dword1, dword2, &gate_cs_descriptor);
// check code-segment descriptor
check_cs(&gate_cs_descriptor, gate_cs_raw, 0, CPL);
Bit16u temp_IP = gate_descriptor->u.gate.dest_offset;
branch_far32(&gate_cs_selector, &gate_cs_descriptor, temp_IP, CPL);
}
void BX_CPP_AttrRegparmN(1)
BX_CPU_C::jmp_call_gate32(bx_descriptor_t *gate_descriptor)
{
bx_selector_t gate_cs_selector;
bx_descriptor_t gate_cs_descriptor;
Bit32u dword1, dword2;
BX_DEBUG(("jump_protected: JUMP TO 386 CALL GATE"));
// 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.gate.dest_selector;
if ((gate_cs_raw & 0xfffc) == 0) {
BX_ERROR(("jump_protected: CS selector null"));
BX_ERROR(("jmp_call_gate: CS selector null"));
exception(BX_GP_EXCEPTION, 0, 0);
}
@ -261,7 +230,6 @@ BX_CPU_C::jmp_call_gate32(bx_descriptor_t *gate_descriptor)
check_cs(&gate_cs_descriptor, gate_cs_raw, 0, CPL);
Bit32u temp_EIP = gate_descriptor->u.gate.dest_offset;
branch_far32(&gate_cs_selector, &gate_cs_descriptor, temp_EIP, CPL);
}
@ -301,7 +269,7 @@ BX_CPU_C::jmp_call_gate64(bx_selector_t *gate_selector)
if (cs_descriptor.valid==0 || cs_descriptor.segment==0 ||
IS_DATA_SEGMENT(cs_descriptor.type))
{
BX_ERROR(("jmp_call_gate64: not code segment in call gate 64"));
BX_ERROR(("jmp_call_gate64: not code segment in 64-bit call gate"));
exception(BX_GP_EXCEPTION, dest_selector & 0xfffc, 0);
}
@ -309,7 +277,7 @@ BX_CPU_C::jmp_call_gate64(bx_selector_t *gate_selector)
// to 64-bit code segments, else #GP(selector)
if (! IS_LONG64_SEGMENT(cs_descriptor) || cs_descriptor.u.segment.d_b)
{
BX_ERROR(("jmp_call_gate64: not 64-bit code segment in call gate 64"));
BX_ERROR(("jmp_call_gate64: not 64-bit code segment in 64-bit call gate"));
exception(BX_GP_EXCEPTION, dest_selector & 0xfffc, 0);
}