2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2007-11-30 11:49:12 +03:00
|
|
|
// $Id: segment_ctrl_pro.cc,v 1.77 2007-11-30 08:49:12 sshwarts Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2001-04-10 06:20:02 +04:00
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2007-11-18 02:28:33 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-05-24 22:46:34 +04:00
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
2001-04-10 05:04:59 +04:00
|
|
|
#include "bochs.h"
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "cpu.h"
|
merge in BRANCH-io-cleanup.
To see the commit logs for this use either cvsweb or
cvs update -r BRANCH-io-cleanup and then 'cvs log' the various files.
In general this provides a generic interface for logging.
logfunctions:: is a class that is inherited by some classes, and also
. allocated as a standalone global called 'genlog'. All logging uses
. one of the ::info(), ::error(), ::ldebug(), ::panic() methods of this
. class through 'BX_INFO(), BX_ERROR(), BX_DEBUG(), BX_PANIC()' macros
. respectively.
.
. An example usage:
. BX_INFO(("Hello, World!\n"));
iofunctions:: is a class that is allocated once by default, and assigned
as the iofunction of each logfunctions instance. It is this class that
maintains the file descriptor and other output related code, at this
point using vfprintf(). At some future point, someone may choose to
write a gui 'console' for bochs to which messages would be redirected
simply by assigning a different iofunction class to the various logfunctions
objects.
More cleanup is coming, but this works for now. If you want to see alot
of debugging output, in main.cc, change onoff[LOGLEV_DEBUG]=0 to =1.
Comments, bugs, flames, to me: todd@fries.net
2001-05-15 18:49:57 +04:00
|
|
|
#define LOG_THIS BX_CPU_THIS_PTR
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(2)
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_C::load_seg_reg(bx_segment_reg_t *seg, Bit16u new_value)
|
|
|
|
{
|
2005-02-24 22:50:36 +03:00
|
|
|
if (protected_mode())
|
|
|
|
{
|
|
|
|
if (seg == &BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS])
|
|
|
|
{
|
2007-09-25 20:11:32 +04:00
|
|
|
bx_selector_t ss_selector;
|
|
|
|
bx_descriptor_t descriptor;
|
|
|
|
Bit32u dword1, dword2;
|
|
|
|
|
|
|
|
parse_selector(new_value, &ss_selector);
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
if ((new_value & 0xfffc) == 0) { /* null selector */
|
2005-02-24 22:50:36 +03:00
|
|
|
#if BX_SUPPORT_X86_64
|
2007-09-25 20:11:32 +04:00
|
|
|
// allow SS = 0 in 64 bit mode only with cpl != 3 and rpl=cpl
|
|
|
|
if (Is64BitMode() && CPL != 3 && ss_selector.rpl == CPL) {
|
2005-02-24 22:50:36 +03:00
|
|
|
seg->selector.index = 0;
|
|
|
|
seg->selector.ti = 0;
|
|
|
|
seg->selector.rpl = 0;
|
|
|
|
seg->selector.value = 0;
|
|
|
|
seg->cache.valid = 0; /* invalidate null selector */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2007-09-25 20:11:32 +04:00
|
|
|
BX_ERROR(("load_seg_reg(SS): loading null selector"));
|
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc, 0);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-11-05 14:39:26 +03:00
|
|
|
fetch_raw_descriptor(&ss_selector, &dword1, &dword2, BX_GP_EXCEPTION);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* selector's RPL must = CPL, else #GP(selector) */
|
2005-11-05 14:39:26 +03:00
|
|
|
if (ss_selector.rpl != CPL) {
|
2006-02-22 23:58:16 +03:00
|
|
|
BX_ERROR(("load_seg_reg(SS): rpl != CPL"));
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc, 0);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
parse_descriptor(dword1, dword2, &descriptor);
|
|
|
|
|
|
|
|
if (descriptor.valid==0) {
|
2006-02-22 23:58:16 +03:00
|
|
|
BX_ERROR(("load_seg_reg(SS): valid bit cleared"));
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc, 0);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* AR byte must indicate a writable data segment else #GP(selector) */
|
2006-06-12 20:58:27 +04:00
|
|
|
if (descriptor.segment==0 || IS_CODE_SEGMENT(descriptor.type) ||
|
|
|
|
IS_DATA_SEGMENT_WRITEABLE(descriptor.type) == 0)
|
2005-02-02 00:17:57 +03:00
|
|
|
{
|
2006-02-22 23:58:16 +03:00
|
|
|
BX_ERROR(("load_seg_reg(SS): not writable data segment"));
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc, 0);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* DPL in the AR byte must equal CPL else #GP(selector) */
|
|
|
|
if (descriptor.dpl != CPL) {
|
2006-02-22 23:58:16 +03:00
|
|
|
BX_ERROR(("load_seg_reg(SS): dpl != CPL"));
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc, 0);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* segment must be marked PRESENT else #SS(selector) */
|
2005-07-11 00:32:32 +04:00
|
|
|
if (! IS_PRESENT(descriptor)) {
|
2006-02-22 23:58:16 +03:00
|
|
|
BX_ERROR(("load_seg_reg(SS): not present"));
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(BX_SS_EXCEPTION, new_value & 0xfffc, 0);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* load SS with selector, load SS cache with descriptor */
|
2005-11-05 14:39:26 +03:00
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector = ss_selector;
|
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache = descriptor;
|
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.valid = 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* now set accessed bit in descriptor */
|
|
|
|
dword2 |= 0x0100;
|
2005-11-05 14:39:26 +03:00
|
|
|
if (ss_selector.ti == 0) { /* GDT */
|
|
|
|
access_linear(BX_CPU_THIS_PTR gdtr.base + ss_selector.index*8 + 4, 4, 0,
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_WRITE, &dword2);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else { /* LDT */
|
2006-08-31 22:18:17 +04:00
|
|
|
access_linear(BX_CPU_THIS_PTR ldtr.cache.u.system.base + ss_selector.index*8 + 4, 4, 0,
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_WRITE, &dword2);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
return;
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2002-10-17 02:10:07 +04:00
|
|
|
else if ( (seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS]) ||
|
|
|
|
(seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES])
|
2001-04-10 05:04:59 +04:00
|
|
|
#if BX_CPU_LEVEL >= 3
|
2002-10-17 02:10:07 +04:00
|
|
|
|| (seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS]) ||
|
|
|
|
(seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS])
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2005-02-02 00:17:57 +03:00
|
|
|
)
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
bx_descriptor_t descriptor;
|
2005-11-05 14:39:26 +03:00
|
|
|
bx_selector_t selector;
|
2001-04-10 05:04:59 +04:00
|
|
|
Bit32u dword1, dword2;
|
|
|
|
|
|
|
|
if ((new_value & 0xfffc) == 0) { /* null selector */
|
|
|
|
seg->selector.index = 0;
|
|
|
|
seg->selector.ti = 0;
|
|
|
|
seg->selector.rpl = 0;
|
|
|
|
seg->selector.value = 0;
|
|
|
|
seg->cache.valid = 0; /* invalidate null selector */
|
|
|
|
return;
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-11-05 14:39:26 +03:00
|
|
|
parse_selector(new_value, &selector);
|
|
|
|
fetch_raw_descriptor(&selector, &dword1, &dword2, BX_GP_EXCEPTION);
|
2001-04-10 05:04:59 +04:00
|
|
|
parse_descriptor(dword1, dword2, &descriptor);
|
|
|
|
|
|
|
|
if (descriptor.valid==0) {
|
2007-11-30 11:49:12 +03:00
|
|
|
BX_ERROR(("load_seg_reg(%s, 0x%04x): invalid segment", strseg(seg), new_value));
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc, 0);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* AR byte must indicate data or readable code segment else #GP(selector) */
|
2006-06-12 20:58:27 +04:00
|
|
|
if (descriptor.segment==0 || (IS_CODE_SEGMENT(descriptor.type) &&
|
|
|
|
IS_CODE_SEGMENT_READABLE(descriptor.type) == 0))
|
2005-02-02 00:17:57 +03:00
|
|
|
{
|
2007-11-30 11:49:12 +03:00
|
|
|
BX_ERROR(("load_seg_reg(%s, 0x%04x): not data or readable code", strseg(seg), new_value));
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc, 0);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* If data or non-conforming code, then both the RPL and the CPL
|
|
|
|
* must be less than or equal to DPL in AR byte else #GP(selector) */
|
2006-06-12 20:58:27 +04:00
|
|
|
if (IS_DATA_SEGMENT(descriptor.type) ||
|
|
|
|
IS_CODE_SEGMENT_NON_CONFORMING(descriptor.type))
|
2005-02-02 00:17:57 +03:00
|
|
|
{
|
2005-11-05 14:39:26 +03:00
|
|
|
if ((selector.rpl > descriptor.dpl) || (CPL > descriptor.dpl)) {
|
2007-11-30 11:49:12 +03:00
|
|
|
BX_ERROR(("load_seg_reg(%s, 0x%04x): RPL & CPL must be <= DPL", strseg(seg), new_value));
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc, 0);
|
|
|
|
}
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* segment must be marked PRESENT else #NP(selector) */
|
2005-07-11 00:32:32 +04:00
|
|
|
if (! IS_PRESENT(descriptor)) {
|
2007-11-30 11:49:12 +03:00
|
|
|
BX_ERROR(("load_seg_reg(%s, 0x%04x): segment not present", strseg(seg), new_value));
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(BX_NP_EXCEPTION, new_value & 0xfffc, 0);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
/* load segment register with selector */
|
|
|
|
/* load segment register-cache with descriptor */
|
2005-11-05 14:39:26 +03:00
|
|
|
seg->selector = selector;
|
|
|
|
seg->cache = descriptor;
|
|
|
|
seg->cache.valid = 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2002-09-16 21:00:16 +04:00
|
|
|
/* now set accessed bit in descriptor */
|
|
|
|
/* wmr: don't bother if it's already set (thus allowing */
|
2001-11-13 08:11:41 +03:00
|
|
|
/* GDT to be in read-only pages like real hdwe does) */
|
2002-09-16 21:00:16 +04:00
|
|
|
|
|
|
|
if (!(dword2 & 0x0100)) {
|
2001-11-13 08:11:41 +03:00
|
|
|
dword2 |= 0x0100;
|
2005-11-05 14:39:26 +03:00
|
|
|
if (selector.ti == 0) { /* GDT */
|
|
|
|
access_linear(BX_CPU_THIS_PTR gdtr.base + selector.index*8 + 4, 4, 0,
|
2001-11-13 08:11:41 +03:00
|
|
|
BX_WRITE, &dword2);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-11-13 08:11:41 +03:00
|
|
|
else { /* LDT */
|
2006-08-31 22:18:17 +04:00
|
|
|
access_linear(BX_CPU_THIS_PTR ldtr.cache.u.system.base + selector.index*8 + 4, 4, 0,
|
2002-09-16 21:00:16 +04:00
|
|
|
BX_WRITE, &dword2);
|
|
|
|
}
|
2001-11-13 08:11:41 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("load_seg_reg(): invalid segment register passed!"));
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
}
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-11-08 01:45:25 +03:00
|
|
|
/* real or v8086 mode */
|
2005-03-12 21:38:56 +03:00
|
|
|
|
|
|
|
/* www.x86.org:
|
|
|
|
According to Intel, each time any segment register is loaded in real
|
|
|
|
mode, the base address is calculated as 16 times the segment value,
|
|
|
|
while the access rights and size limit attributes are given fixed,
|
|
|
|
"real-mode compatible" values. This is not true. In fact, only the CS
|
|
|
|
descriptor caches for the 286, 386, and 486 get loaded with fixed
|
|
|
|
values each time the segment register is loaded. Loading CS, or any
|
|
|
|
other segment register in real mode, on later Intel processors doesn't
|
|
|
|
change the access rights or the segment size limit attributes stored
|
|
|
|
in the descriptor cache registers. For these segments, the access
|
|
|
|
rights and segment size limit attributes from any previous setting are
|
|
|
|
honored. */
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-11-08 01:45:25 +03:00
|
|
|
seg->selector.value = new_value;
|
|
|
|
seg->selector.rpl = real_mode() ? 0 : 3;
|
|
|
|
seg->cache.valid = 1;
|
|
|
|
seg->cache.u.segment.base = new_value << 4;
|
|
|
|
seg->cache.segment = 1; /* regular segment */
|
|
|
|
seg->cache.p = 1; /* present */
|
2002-09-19 23:17:20 +04:00
|
|
|
|
2005-11-08 01:45:25 +03:00
|
|
|
if (seg == &BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS]) {
|
2006-06-12 20:58:27 +04:00
|
|
|
seg->cache.type = BX_CODE_EXEC_READ_ACCESSED;
|
2004-07-30 00:15:19 +04:00
|
|
|
#if BX_SUPPORT_ICACHE
|
2006-03-27 22:02:07 +04:00
|
|
|
BX_CPU_THIS_PTR updateFetchModeMask();
|
2007-11-21 00:22:03 +03:00
|
|
|
#endif
|
|
|
|
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
|
|
|
|
handleAlignmentCheck(); // CPL was modified
|
2002-09-19 23:17:20 +04:00
|
|
|
#endif
|
2003-05-11 02:25:55 +04:00
|
|
|
invalidate_prefetch_q();
|
2004-11-14 22:29:34 +03:00
|
|
|
}
|
2005-11-08 01:45:25 +03:00
|
|
|
else {
|
2006-06-12 20:58:27 +04:00
|
|
|
seg->cache.type = BX_DATA_READ_WRITE_ACCESSED;
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-11-08 01:45:25 +03:00
|
|
|
/* Do not modify segment limit and AR bytes when in real mode */
|
|
|
|
if (real_mode()) return;
|
|
|
|
|
|
|
|
seg->cache.dpl = 3; /* we are in v8086 mode */
|
|
|
|
seg->cache.u.segment.limit = 0xffff;
|
|
|
|
seg->cache.u.segment.limit_scaled = 0xffff;
|
|
|
|
#if BX_CPU_LEVEL >= 3
|
|
|
|
seg->cache.u.segment.g = 0; /* byte granular */
|
|
|
|
seg->cache.u.segment.d_b = 0; /* default 16bit size */
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
seg->cache.u.segment.l = 0; /* default 16bit size */
|
|
|
|
#endif
|
|
|
|
seg->cache.u.segment.avl = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-09-24 20:35:44 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2007-03-15 00:15:15 +03:00
|
|
|
void BX_CPU_C::loadSRegLMNominal(unsigned segI, unsigned selector, unsigned dpl)
|
2002-09-24 20:35:44 +04:00
|
|
|
{
|
|
|
|
bx_segment_reg_t *seg = & BX_CPU_THIS_PTR sregs[segI];
|
|
|
|
|
|
|
|
// Load a segment register in long-mode with nominal values,
|
|
|
|
// so descriptor cache values are compatible with existing checks.
|
2007-03-15 00:15:15 +03:00
|
|
|
seg->cache.u.segment.base = 0;
|
2005-07-29 10:29:57 +04:00
|
|
|
// I doubt we need limit_scaled. If we do, it should be
|
2002-09-24 20:35:44 +04:00
|
|
|
// of type bx_addr and be maxed to 64bits, not 32.
|
|
|
|
seg->cache.u.segment.limit_scaled = 0xffffffff;
|
|
|
|
seg->cache.valid = 1;
|
2007-09-25 20:11:32 +04:00
|
|
|
seg->cache.dpl = dpl;
|
2002-09-24 20:35:44 +04:00
|
|
|
|
2005-02-24 22:50:36 +03:00
|
|
|
seg->selector.value = selector;
|
2002-09-24 20:35:44 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-09 22:34:52 +03:00
|
|
|
void BX_CPU_C::validate_seg_reg(unsigned seg)
|
2005-08-02 02:06:19 +04:00
|
|
|
{
|
2005-08-03 00:20:22 +04:00
|
|
|
/*
|
|
|
|
FOR (seg = ES, DS, FS, GS)
|
|
|
|
DO
|
|
|
|
IF ((seg.attr.dpl < CPL) && ((seg.attr.type = 'data')
|
|
|
|
|| (seg.attr.type = 'non-conforming-code')))
|
|
|
|
{
|
|
|
|
seg = NULL // can't use lower dpl data segment at higher cpl
|
|
|
|
}
|
|
|
|
END
|
|
|
|
*/
|
|
|
|
|
2006-01-09 22:34:52 +03:00
|
|
|
bx_segment_reg_t *segment = &BX_CPU_THIS_PTR sregs[seg];
|
|
|
|
|
|
|
|
if (segment->cache.dpl < CPL)
|
2005-08-02 02:06:19 +04:00
|
|
|
{
|
2006-01-09 22:34:52 +03:00
|
|
|
// invalidate if data or non-conforming code segment
|
2006-06-12 20:58:27 +04:00
|
|
|
if (segment->cache.valid==0 || segment->cache.segment==0 ||
|
|
|
|
IS_DATA_SEGMENT(segment->cache.type) ||
|
|
|
|
IS_CODE_SEGMENT_NON_CONFORMING(segment->cache.type))
|
2006-01-09 22:34:52 +03:00
|
|
|
{
|
|
|
|
segment->selector.value = 0;
|
|
|
|
segment->cache.valid = 0;
|
|
|
|
}
|
2005-08-02 02:06:19 +04:00
|
|
|
}
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-01-09 22:34:52 +03:00
|
|
|
void BX_CPU_C::validate_seg_regs(void)
|
|
|
|
{
|
|
|
|
validate_seg_reg(BX_SEG_REG_ES);
|
|
|
|
validate_seg_reg(BX_SEG_REG_DS);
|
|
|
|
validate_seg_reg(BX_SEG_REG_FS);
|
|
|
|
validate_seg_reg(BX_SEG_REG_GS);
|
|
|
|
}
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#if BX_CPU_LEVEL >= 2
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(2)
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_C::parse_selector(Bit16u raw_selector, bx_selector_t *selector)
|
|
|
|
{
|
2006-04-25 19:35:26 +04:00
|
|
|
selector->value = raw_selector;
|
|
|
|
selector->index = raw_selector >> 3;
|
|
|
|
selector->ti = (raw_selector >> 2) & 0x01;
|
|
|
|
selector->rpl = raw_selector & 0x03;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2006-03-29 22:08:13 +04:00
|
|
|
#endif
|
|
|
|
|
2006-04-25 19:35:26 +04:00
|
|
|
Bit8u BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::ar_byte(const bx_descriptor_t *d)
|
|
|
|
{
|
|
|
|
if (d->valid == 0) {
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2006-06-12 20:58:27 +04:00
|
|
|
return (d->type) |
|
|
|
|
(d->segment << 4) |
|
|
|
|
(d->dpl << 5) |
|
|
|
|
(d->p << 7);
|
2006-04-25 19:35:26 +04:00
|
|
|
}
|
|
|
|
|
2006-05-27 18:02:34 +04:00
|
|
|
void BX_CPP_AttrRegparmN(2)
|
|
|
|
BX_CPU_C::set_ar_byte(bx_descriptor_t *d, Bit8u ar_byte)
|
|
|
|
{
|
|
|
|
d->p = (ar_byte >> 7) & 0x01;
|
|
|
|
d->dpl = (ar_byte >> 5) & 0x03;
|
|
|
|
d->segment = (ar_byte >> 4) & 0x01;
|
|
|
|
d->type = (ar_byte & 0x0f);
|
|
|
|
}
|
|
|
|
|
2006-04-25 19:35:26 +04:00
|
|
|
Bit32u BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::get_descriptor_l(const bx_descriptor_t *d)
|
2006-04-23 21:16:27 +04:00
|
|
|
{
|
|
|
|
Bit32u val;
|
|
|
|
|
|
|
|
if (d->valid == 0) {
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->segment) {
|
2006-08-22 23:06:03 +04:00
|
|
|
val = ((d->u.segment.base & 0xffff) << 16) | (d->u.segment.limit & 0xffff);
|
2006-04-23 21:16:27 +04:00
|
|
|
return(val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (d->type) {
|
|
|
|
case 0: // Reserved (not defined)
|
|
|
|
BX_ERROR(("#get_descriptor_l(): type %d not finished", d->type));
|
|
|
|
return(0);
|
|
|
|
|
2006-08-31 22:18:17 +04:00
|
|
|
case BX_SYS_SEGMENT_LDT:
|
2006-04-23 21:16:27 +04:00
|
|
|
case BX_SYS_SEGMENT_AVAIL_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_286_TSS:
|
2006-05-22 00:41:48 +04:00
|
|
|
case BX_SYS_SEGMENT_AVAIL_386_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_386_TSS:
|
2006-08-31 22:18:17 +04:00
|
|
|
val = ((d->u.system.base & 0xffff) << 16) | (d->u.system.limit & 0xffff);
|
2006-04-23 21:16:27 +04:00
|
|
|
return(val);
|
|
|
|
|
|
|
|
default:
|
|
|
|
BX_PANIC(("#get_descriptor_l(): type %d not finished", d->type));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-25 19:35:26 +04:00
|
|
|
Bit32u BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::get_descriptor_h(const bx_descriptor_t *d)
|
2006-04-23 21:16:27 +04:00
|
|
|
{
|
|
|
|
Bit32u val;
|
|
|
|
|
|
|
|
if (d->valid == 0) {
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->segment) {
|
|
|
|
val = (d->u.segment.base & 0xff000000) |
|
|
|
|
((d->u.segment.base >> 16) & 0x000000ff) |
|
2006-06-12 20:58:27 +04:00
|
|
|
(d->type << 8) |
|
2006-04-23 21:16:27 +04:00
|
|
|
(d->segment << 12) |
|
|
|
|
(d->dpl << 13) |
|
|
|
|
(d->p << 15) |
|
|
|
|
(d->u.segment.limit & 0xf0000) |
|
|
|
|
(d->u.segment.avl << 20) |
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
(d->u.segment.l << 21) |
|
|
|
|
#endif
|
|
|
|
(d->u.segment.d_b << 22) |
|
|
|
|
(d->u.segment.g << 23);
|
|
|
|
return(val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (d->type) {
|
|
|
|
case 0: // Reserved (not yet defined)
|
|
|
|
BX_ERROR(("#get_descriptor_h(): type %d not finished", d->type));
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
case BX_SYS_SEGMENT_AVAIL_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_286_TSS:
|
2006-08-31 22:18:17 +04:00
|
|
|
BX_ASSERT(d->u.system.g == 0);
|
|
|
|
BX_ASSERT(d->u.system.avl == 0);
|
|
|
|
// fall through
|
|
|
|
case BX_SYS_SEGMENT_LDT:
|
2006-05-22 00:41:48 +04:00
|
|
|
case BX_SYS_SEGMENT_AVAIL_386_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_386_TSS:
|
2006-08-31 22:18:17 +04:00
|
|
|
val = ((d->u.system.base >> 16) & 0xff) |
|
2006-04-23 21:16:27 +04:00
|
|
|
(d->type << 8) |
|
|
|
|
(d->dpl << 13) |
|
|
|
|
(d->p << 15) |
|
2006-08-31 22:18:17 +04:00
|
|
|
(d->u.system.limit & 0xf0000) |
|
|
|
|
(d->u.system.avl << 20) |
|
|
|
|
(d->u.system.g << 23) |
|
|
|
|
(d->u.system.base & 0xff000000);
|
2006-04-23 21:16:27 +04:00
|
|
|
return(val);
|
|
|
|
|
|
|
|
default:
|
|
|
|
BX_PANIC(("#get_descriptor_h(): type %d not finished", d->type));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-29 22:08:13 +04:00
|
|
|
#if BX_CPU_LEVEL >= 3
|
|
|
|
Bit16u BX_CPP_AttrRegparmN(1)
|
2006-04-23 21:16:27 +04:00
|
|
|
BX_CPU_C::get_segment_ar_data(const bx_descriptor_t *d) // used for SMM
|
2006-03-29 22:08:13 +04:00
|
|
|
{
|
|
|
|
Bit16u val = 0;
|
|
|
|
|
|
|
|
if (d->segment) { /* data/code segment descriptors */
|
2006-06-12 20:58:27 +04:00
|
|
|
val = (d->type) |
|
2006-03-29 22:08:13 +04:00
|
|
|
(d->segment << 4) |
|
|
|
|
(d->dpl << 5) |
|
|
|
|
(d->p << 7) |
|
|
|
|
(d->u.segment.avl << 12) |
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
(d->u.segment.l << 13) |
|
|
|
|
#endif
|
|
|
|
(d->u.segment.d_b << 14) |
|
|
|
|
(d->u.segment.g << 15);
|
|
|
|
return(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (d->type) {
|
|
|
|
case BX_SYS_SEGMENT_AVAIL_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_286_TSS:
|
2006-08-31 22:18:17 +04:00
|
|
|
BX_ASSERT(d->u.system.g == 0);
|
|
|
|
BX_ASSERT(d->u.system.avl == 0);
|
|
|
|
// fall through
|
|
|
|
case BX_SYS_SEGMENT_LDT:
|
2006-03-29 22:08:13 +04:00
|
|
|
case BX_SYS_SEGMENT_AVAIL_386_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_386_TSS:
|
2006-06-12 20:58:27 +04:00
|
|
|
val = (d->type) |
|
2006-03-29 22:08:13 +04:00
|
|
|
(d->dpl << 5) |
|
|
|
|
(d->p << 7) |
|
2006-08-31 22:18:17 +04:00
|
|
|
(d->u.system.avl << 12) |
|
|
|
|
(d->u.system.g << 15);
|
2006-03-29 22:08:13 +04:00
|
|
|
return(val);
|
|
|
|
default:
|
|
|
|
BX_PANIC(("get_segment_ar_data(): case %u unsupported", (unsigned) d->type));
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
2006-04-05 21:31:35 +04:00
|
|
|
|
|
|
|
bx_bool BX_CPU_C::set_segment_ar_data(bx_segment_reg_t *seg,
|
|
|
|
Bit16u raw_selector, bx_address base, Bit32u limit, Bit16u ar_data)
|
|
|
|
{
|
|
|
|
parse_selector(raw_selector, &seg->selector);
|
|
|
|
|
|
|
|
bx_descriptor_t *d = &seg->cache;
|
|
|
|
|
|
|
|
d->p = (ar_data >> 7) & 0x01;
|
|
|
|
d->dpl = (ar_data >> 5) & 0x03;
|
|
|
|
d->segment = (ar_data >> 4) & 0x01;
|
|
|
|
d->type = (ar_data & 0x0f);
|
|
|
|
|
|
|
|
if (d->segment) { /* data/code segment descriptors */
|
2006-06-12 20:58:27 +04:00
|
|
|
d->u.segment.g = (ar_data >> 15) & 0x01;
|
|
|
|
d->u.segment.d_b = (ar_data >> 14) & 0x01;
|
2006-04-05 21:31:35 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2006-06-12 20:58:27 +04:00
|
|
|
d->u.segment.l = (ar_data >> 13) & 0x01;
|
2006-04-05 21:31:35 +04:00
|
|
|
#endif
|
2006-06-12 20:58:27 +04:00
|
|
|
d->u.segment.avl = (ar_data >> 12) & 0x01;
|
2006-04-05 21:31:35 +04:00
|
|
|
|
2006-06-12 20:58:27 +04:00
|
|
|
d->u.segment.base = base;
|
|
|
|
d->u.segment.limit = limit;
|
2006-04-05 21:31:35 +04:00
|
|
|
|
|
|
|
if (d->u.segment.g) {
|
2006-06-12 20:58:27 +04:00
|
|
|
if (IS_DATA_SEGMENT(d->type) && IS_DATA_SEGMENT_EXPAND_DOWN(d->type))
|
2006-04-05 21:31:35 +04:00
|
|
|
d->u.segment.limit_scaled = (d->u.segment.limit << 12);
|
|
|
|
else
|
|
|
|
d->u.segment.limit_scaled = (d->u.segment.limit << 12) | 0x0fff;
|
2006-06-12 23:51:31 +04:00
|
|
|
}
|
2006-04-05 21:31:35 +04:00
|
|
|
else
|
|
|
|
d->u.segment.limit_scaled = d->u.segment.limit;
|
|
|
|
|
|
|
|
d->valid = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch(d->type) {
|
|
|
|
case BX_SYS_SEGMENT_LDT:
|
|
|
|
case BX_SYS_SEGMENT_AVAIL_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_AVAIL_386_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_386_TSS:
|
2006-05-22 00:41:48 +04:00
|
|
|
d->valid = 1;
|
2006-08-31 22:18:17 +04:00
|
|
|
d->u.system.avl = (ar_data >> 12) & 0x01;
|
|
|
|
d->u.system.g = (ar_data >> 15) & 0x01;
|
|
|
|
d->u.system.base = base;
|
|
|
|
d->u.system.limit = limit;
|
|
|
|
if (d->u.system.g)
|
|
|
|
d->u.system.limit_scaled = (d->u.system.limit << 12) | 0x0fff;
|
2006-04-05 21:31:35 +04:00
|
|
|
else
|
2006-08-31 22:18:17 +04:00
|
|
|
d->u.system.limit_scaled = (d->u.system.limit);
|
2006-04-05 21:31:35 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
BX_PANIC(("set_segment_ar_data(): case %u unsupported", (unsigned) d->type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* invalidate if null selector */
|
|
|
|
if ((raw_selector & 0xfffc) == 0) {
|
|
|
|
seg->cache.valid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return seg->cache.valid;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(3)
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_C::parse_descriptor(Bit32u dword1, Bit32u dword2, bx_descriptor_t *temp)
|
|
|
|
{
|
|
|
|
Bit8u AR_byte;
|
|
|
|
|
|
|
|
AR_byte = dword2 >> 8;
|
|
|
|
temp->p = (AR_byte >> 7) & 0x01;
|
|
|
|
temp->dpl = (AR_byte >> 5) & 0x03;
|
|
|
|
temp->segment = (AR_byte >> 4) & 0x01;
|
|
|
|
temp->type = (AR_byte & 0x0f);
|
|
|
|
temp->valid = 0; /* start out invalid */
|
|
|
|
|
|
|
|
if (temp->segment) { /* data/code segment descriptors */
|
|
|
|
temp->u.segment.limit = (dword1 & 0xffff);
|
2005-02-02 00:17:57 +03:00
|
|
|
temp->u.segment.base = (dword1 >> 16) | ((dword2 & 0xFF) << 16);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 3
|
2006-03-29 22:08:13 +04:00
|
|
|
temp->u.segment.limit |= (dword2 & 0x000F0000);
|
|
|
|
temp->u.segment.g = (dword2 & 0x00800000) > 0;
|
|
|
|
temp->u.segment.d_b = (dword2 & 0x00400000) > 0;
|
2002-09-15 06:23:12 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2006-03-29 22:08:13 +04:00
|
|
|
temp->u.segment.l = (dword2 & 0x00200000) > 0;
|
2002-09-15 06:23:12 +04:00
|
|
|
#endif
|
2006-03-29 22:08:13 +04:00
|
|
|
temp->u.segment.avl = (dword2 & 0x00100000) > 0;
|
|
|
|
temp->u.segment.base |= (dword2 & 0xFF000000);
|
2002-09-24 12:29:06 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
if (temp->u.segment.g) {
|
2006-06-12 20:58:27 +04:00
|
|
|
if (IS_DATA_SEGMENT(temp->type) && IS_DATA_SEGMENT_EXPAND_DOWN(temp->type))
|
2001-04-10 05:04:59 +04:00
|
|
|
temp->u.segment.limit_scaled = (temp->u.segment.limit << 12);
|
|
|
|
else
|
|
|
|
temp->u.segment.limit_scaled = (temp->u.segment.limit << 12) | 0x0fff;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
temp->u.segment.limit_scaled = temp->u.segment.limit;
|
|
|
|
|
|
|
|
temp->valid = 1;
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else { // system & gate segment descriptors
|
2006-03-29 22:08:13 +04:00
|
|
|
switch (temp->type) {
|
2001-04-10 05:04:59 +04:00
|
|
|
case 0: // reserved
|
|
|
|
case 8: // reserved
|
|
|
|
case 10: // reserved
|
|
|
|
case 13: // reserved
|
|
|
|
temp->valid = 0;
|
|
|
|
break;
|
2006-08-31 22:18:17 +04:00
|
|
|
|
2005-04-11 22:53:04 +04:00
|
|
|
case BX_SYS_SEGMENT_AVAIL_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_286_TSS:
|
2006-08-31 22:18:17 +04:00
|
|
|
temp->u.system.base = (dword1 >> 16) | ((dword2 & 0xff) << 16);
|
|
|
|
temp->u.system.limit = (dword1 & 0xffff);
|
|
|
|
temp->u.system.limit_scaled = temp->u.system.limit;
|
|
|
|
temp->u.system.g = 0;
|
|
|
|
temp->u.system.avl = 0;
|
2006-08-22 23:06:03 +04:00
|
|
|
temp->valid = 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
2006-08-31 22:18:17 +04:00
|
|
|
|
2005-04-11 22:53:04 +04:00
|
|
|
case BX_286_CALL_GATE:
|
|
|
|
case BX_286_INTERRUPT_GATE:
|
|
|
|
case BX_286_TRAP_GATE:
|
2007-11-06 22:17:42 +03:00
|
|
|
// 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);
|
2001-04-10 05:04:59 +04:00
|
|
|
temp->valid = 1;
|
|
|
|
break;
|
2006-08-31 22:18:17 +04:00
|
|
|
|
2005-04-11 22:53:04 +04:00
|
|
|
case BX_TASK_GATE:
|
2003-08-15 17:18:53 +04:00
|
|
|
temp->u.taskgate.tss_selector = dword1 >> 16;
|
2001-04-10 05:04:59 +04:00
|
|
|
temp->valid = 1;
|
|
|
|
break;
|
2006-08-31 22:18:17 +04:00
|
|
|
|
|
|
|
case BX_SYS_SEGMENT_LDT:
|
2005-04-11 22:53:04 +04:00
|
|
|
case BX_SYS_SEGMENT_AVAIL_386_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_386_TSS:
|
2006-08-31 22:18:17 +04:00
|
|
|
temp->u.system.base = (dword1 >> 16) |
|
2006-08-22 23:06:03 +04:00
|
|
|
((dword2 & 0xff) << 16) | (dword2 & 0xff000000);
|
2006-08-31 22:18:17 +04:00
|
|
|
temp->u.system.limit = (dword1 & 0x0000ffff) | (dword2 & 0x000f0000);
|
|
|
|
temp->u.system.g = (dword2 & 0x00800000) > 0;
|
|
|
|
temp->u.system.avl = (dword2 & 0x00100000) > 0;
|
|
|
|
if (temp->u.system.g)
|
|
|
|
temp->u.system.limit_scaled = (temp->u.system.limit << 12) | 0x0fff;
|
2001-04-10 05:04:59 +04:00
|
|
|
else
|
2006-08-31 22:18:17 +04:00
|
|
|
temp->u.system.limit_scaled = (temp->u.system.limit);
|
2001-04-10 05:04:59 +04:00
|
|
|
temp->valid = 1;
|
|
|
|
break;
|
|
|
|
|
2005-02-02 00:17:57 +03:00
|
|
|
default:
|
|
|
|
BX_PANIC(("parse_descriptor(): case %u unfinished", (unsigned) temp->type));
|
2005-04-11 22:53:04 +04:00
|
|
|
temp->valid = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(3)
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_CPU_C::load_ss(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;
|
|
|
|
|
2007-10-19 01:27:56 +04:00
|
|
|
// Add cpl to the selector value.
|
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value =
|
|
|
|
(0xfffc & BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value) | cpl;
|
|
|
|
|
2002-09-15 06:23:12 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2002-09-24 12:29:06 +04:00
|
|
|
if (BX_CPU_THIS_PTR cpu_mode == BX_MODE_LONG_64) {
|
2007-03-15 00:15:15 +03:00
|
|
|
loadSRegLMNominal(BX_SEG_REG_SS, selector->value, cpl);
|
2002-09-24 18:00:10 +04:00
|
|
|
return;
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2002-09-15 06:23:12 +04:00
|
|
|
#endif
|
2006-06-12 20:58:27 +04:00
|
|
|
if ((BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value & 0xfffc) == 0)
|
2002-09-24 18:00:10 +04:00
|
|
|
BX_PANIC(("load_ss(): null selector passed"));
|
2002-09-15 06:23:12 +04:00
|
|
|
|
2006-06-12 20:58:27 +04:00
|
|
|
if (!BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.valid) {
|
2002-09-24 18:00:10 +04:00
|
|
|
BX_PANIC(("load_ss(): invalid selector/descriptor passed."));
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2002-09-24 12:29:06 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#if BX_CPU_LEVEL >= 2
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(3)
|
2006-03-22 23:47:11 +03:00
|
|
|
BX_CPU_C::fetch_raw_descriptor(const bx_selector_t *selector,
|
2005-12-12 22:44:06 +03:00
|
|
|
Bit32u *dword1, Bit32u *dword2, unsigned exception_no)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2006-08-22 23:06:03 +04:00
|
|
|
Bit32u index = selector->index;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
if (selector->ti == 0) { /* GDT */
|
2006-08-22 23:06:03 +04:00
|
|
|
if ((index*8 + 7) > BX_CPU_THIS_PTR gdtr.limit) {
|
2005-07-20 05:26:47 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor: GDT: index (%x)%x > limit (%x)",
|
2006-08-25 23:56:03 +04:00
|
|
|
index*8 + 7, index, BX_CPU_THIS_PTR gdtr.limit));
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(exception_no, selector->value & 0xfffc, 0);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2006-08-22 23:06:03 +04:00
|
|
|
bx_address offset = BX_CPU_THIS_PTR gdtr.base + index*8;
|
2006-04-05 21:31:35 +04:00
|
|
|
access_linear(offset, 4, 0, BX_READ, dword1);
|
|
|
|
access_linear(offset + 4, 4, 0, BX_READ, dword2);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else { /* LDT */
|
|
|
|
if (BX_CPU_THIS_PTR ldtr.cache.valid==0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("fetch_raw_descriptor: LDTR.valid=0"));
|
2007-11-24 17:22:34 +03:00
|
|
|
debug(BX_CPU_THIS_PTR prev_rip);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2006-08-31 22:18:17 +04:00
|
|
|
if ((index*8 + 7) > BX_CPU_THIS_PTR ldtr.cache.u.system.limit_scaled) {
|
2004-05-11 01:05:51 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor: LDT: index (%x)%x > limit (%x)",
|
2006-08-31 22:18:17 +04:00
|
|
|
index*8 + 7, index, BX_CPU_THIS_PTR ldtr.cache.u.system.limit_scaled));
|
2001-04-10 05:04:59 +04:00
|
|
|
exception(exception_no, selector->value & 0xfffc, 0);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2006-08-31 22:18:17 +04:00
|
|
|
bx_address offset = BX_CPU_THIS_PTR ldtr.cache.u.system.base + index*8;
|
2006-04-05 21:31:35 +04:00
|
|
|
access_linear(offset, 4, 0, BX_READ, dword1);
|
|
|
|
access_linear(offset + 4, 4, 0, BX_READ, dword2);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
bx_bool BX_CPP_AttrRegparmN(3)
|
2006-03-22 23:47:11 +03:00
|
|
|
BX_CPU_C::fetch_raw_descriptor2(const bx_selector_t *selector, Bit32u *dword1, Bit32u *dword2)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2006-08-22 23:06:03 +04:00
|
|
|
Bit32u index = selector->index;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
if (selector->ti == 0) { /* GDT */
|
2006-08-22 23:06:03 +04:00
|
|
|
if ((index*8 + 7) > BX_CPU_THIS_PTR gdtr.limit)
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
2006-08-22 23:06:03 +04:00
|
|
|
bx_address offset = BX_CPU_THIS_PTR gdtr.base + index*8;
|
2006-04-05 21:31:35 +04:00
|
|
|
access_linear(offset, 4, 0, BX_READ, dword1);
|
|
|
|
access_linear(offset + 4, 4, 0, BX_READ, dword2);
|
2001-04-10 05:04:59 +04:00
|
|
|
return(1);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else { /* LDT */
|
2005-07-20 05:26:47 +04:00
|
|
|
if (BX_CPU_THIS_PTR ldtr.cache.valid==0) {
|
|
|
|
BX_PANIC(("fetch_raw_descriptor2: LDTR.valid=0"));
|
|
|
|
return(0);
|
|
|
|
}
|
2006-08-31 22:18:17 +04:00
|
|
|
if ((index*8 + 7) > BX_CPU_THIS_PTR ldtr.cache.u.system.limit_scaled)
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0);
|
2006-08-31 22:18:17 +04:00
|
|
|
bx_address offset = BX_CPU_THIS_PTR ldtr.cache.u.system.base + index*8;
|
2006-04-05 21:31:35 +04:00
|
|
|
access_linear(offset, 4, 0, BX_READ, dword1);
|
|
|
|
access_linear(offset + 4, 4, 0, BX_READ, dword2);
|
2001-04-10 05:04:59 +04:00
|
|
|
return(1);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-08-02 22:44:20 +04:00
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
2006-03-22 23:47:11 +03:00
|
|
|
void BX_CPU_C::fetch_raw_descriptor64(const bx_selector_t *selector,
|
2005-12-12 22:44:06 +03:00
|
|
|
Bit32u *dword1, Bit32u *dword2, Bit32u *dword3, unsigned exception_no)
|
2005-08-02 22:44:20 +04:00
|
|
|
{
|
2006-08-22 23:06:03 +04:00
|
|
|
Bit32u index = selector->index;
|
2006-03-22 23:47:11 +03:00
|
|
|
Bit32u dword4;
|
|
|
|
|
2005-08-02 22:44:20 +04:00
|
|
|
if (selector->ti == 0) { /* GDT */
|
2006-08-22 23:06:03 +04:00
|
|
|
if ((index*8 + 15) > BX_CPU_THIS_PTR gdtr.limit) {
|
2005-08-02 22:44:20 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor64: GDT: index (%x)%x > limit (%x)",
|
2006-08-25 23:56:03 +04:00
|
|
|
index*8 + 15, index, BX_CPU_THIS_PTR gdtr.limit));
|
2005-08-02 22:44:20 +04:00
|
|
|
exception(exception_no, selector->value & 0xfffc, 0);
|
|
|
|
}
|
2006-08-22 23:06:03 +04:00
|
|
|
bx_address offset = BX_CPU_THIS_PTR gdtr.base + index*8;
|
2006-04-05 21:31:35 +04:00
|
|
|
access_linear(offset, 4, 0, BX_READ, dword1);
|
|
|
|
access_linear(offset + 4, 4, 0, BX_READ, dword2);
|
|
|
|
access_linear(offset + 8, 4, 0, BX_READ, dword3);
|
|
|
|
access_linear(offset + 12, 4, 0, BX_READ, &dword4);
|
2005-08-02 22:44:20 +04:00
|
|
|
}
|
|
|
|
else { /* LDT */
|
|
|
|
if (BX_CPU_THIS_PTR ldtr.cache.valid==0) {
|
|
|
|
BX_PANIC(("fetch_raw_descriptor: LDTR.valid=0"));
|
2007-11-24 17:22:34 +03:00
|
|
|
debug(BX_CPU_THIS_PTR prev_rip);
|
2005-08-02 22:44:20 +04:00
|
|
|
}
|
2006-08-31 22:18:17 +04:00
|
|
|
if ((index*8 + 15) > BX_CPU_THIS_PTR ldtr.cache.u.system.limit_scaled) {
|
2005-08-02 22:44:20 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor64: LDT: index (%x)%x > limit (%x)",
|
2006-08-31 22:18:17 +04:00
|
|
|
index*8 + 15, index, BX_CPU_THIS_PTR ldtr.cache.u.system.limit_scaled));
|
2005-08-02 22:44:20 +04:00
|
|
|
exception(exception_no, selector->value & 0xfffc, 0);
|
|
|
|
}
|
2006-08-31 22:18:17 +04:00
|
|
|
bx_address offset = BX_CPU_THIS_PTR ldtr.cache.u.system.base + index*8;
|
2006-04-05 21:31:35 +04:00
|
|
|
access_linear(offset, 4, 0, BX_READ, dword1);
|
|
|
|
access_linear(offset + 4, 4, 0, BX_READ, dword2);
|
|
|
|
access_linear(offset + 8, 4, 0, BX_READ, dword3);
|
|
|
|
access_linear(offset + 12, 4, 0, BX_READ, &dword4);
|
2006-03-22 23:47:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dword4 != 0) {
|
|
|
|
BX_ERROR(("fetch_raw_descriptor64: extended attributes DWORD4 != 0"));
|
|
|
|
exception(BX_GP_EXCEPTION, selector->value & 0xfffc, 0);
|
2005-08-02 22:44:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|