2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2009-01-17 21:56:25 +03:00
|
|
|
// $Id: segment_ctrl_pro.cc,v 1.107 2009-01-17 18:56:25 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
|
2009-01-16 21:18:59 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 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) {
|
2008-05-06 23:45:17 +04:00
|
|
|
load_null_selector(seg);
|
2005-02-24 22:50:36 +03:00
|
|
|
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 */
|
2008-01-20 20:46:02 +03:00
|
|
|
if (!(dword2 & 0x0100)) {
|
|
|
|
dword2 |= 0x0100;
|
|
|
|
if (ss_selector.ti == 0) { /* GDT */
|
2008-03-29 21:18:08 +03:00
|
|
|
access_write_linear(BX_CPU_THIS_PTR gdtr.base + ss_selector.index*8 + 4, 4, 0, &dword2);
|
2008-01-20 20:46:02 +03:00
|
|
|
}
|
|
|
|
else { /* LDT */
|
2008-03-29 21:18:08 +03:00
|
|
|
access_write_linear(BX_CPU_THIS_PTR ldtr.cache.u.system.base + ss_selector.index*8 + 4, 4, 0, &dword2);
|
2008-01-20 20:46:02 +03:00
|
|
|
}
|
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
|
|
|
}
|
2008-02-16 01:05:43 +03: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
|
2008-02-16 01:05:43 +03: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 */
|
2008-05-06 23:45:17 +04:00
|
|
|
load_null_selector(seg);
|
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-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) */
|
2008-02-03 00:46:54 +03:00
|
|
|
if (descriptor.segment==0 || (IS_CODE_SEGMENT(descriptor.type) &&
|
2006-06-12 20:58:27 +04:00
|
|
|
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 */
|
2008-02-03 00:46:54 +03:00
|
|
|
/* 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 */
|
2008-03-29 21:18:08 +03:00
|
|
|
access_write_linear(BX_CPU_THIS_PTR gdtr.base + selector.index*8 + 4, 4, 0, &dword2);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2001-11-13 08:11:41 +03:00
|
|
|
else { /* LDT */
|
2008-03-29 21:18:08 +03:00
|
|
|
access_write_linear(BX_CPU_THIS_PTR ldtr.cache.u.system.base + selector.index*8 + 4, 4, 0, &dword2);
|
2002-09-16 21:00:16 +04:00
|
|
|
}
|
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 */
|
2008-08-15 21:39:22 +04:00
|
|
|
seg->cache.type = BX_DATA_READ_WRITE_ACCESSED;
|
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]) {
|
2008-05-27 01:46:39 +04:00
|
|
|
invalidate_prefetch_q();
|
2008-08-03 23:53:09 +04:00
|
|
|
updateFetchModeMask();
|
2007-11-21 00:22:03 +03:00
|
|
|
#if BX_CPU_LEVEL >= 4 && BX_SUPPORT_ALIGNMENT_CHECK
|
|
|
|
handleAlignmentCheck(); // CPL was modified
|
2002-09-19 23:17:20 +04:00
|
|
|
#endif
|
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 */
|
2008-05-05 01:25:16 +04:00
|
|
|
/* Support for big real mode */
|
2005-11-08 01:45:25 +03:00
|
|
|
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
|
2008-05-06 23:45:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::load_null_selector(bx_segment_reg_t *seg)
|
|
|
|
{
|
|
|
|
seg->selector.index = 0;
|
|
|
|
seg->selector.ti = 0;
|
|
|
|
seg->selector.rpl = 0;
|
|
|
|
seg->selector.value = 0;
|
|
|
|
|
|
|
|
seg->cache.valid = 0; /* invalidate null selector */
|
|
|
|
seg->cache.p = 0;
|
|
|
|
seg->cache.dpl = 0;
|
|
|
|
seg->cache.segment = 1; /* data/code segment */
|
|
|
|
seg->cache.type = 0;
|
|
|
|
|
|
|
|
seg->cache.u.segment.base = 0;
|
|
|
|
seg->cache.u.segment.limit = 0;
|
|
|
|
seg->cache.u.segment.limit_scaled = 0;
|
|
|
|
seg->cache.u.segment.g = 0;
|
|
|
|
seg->cache.u.segment.d_b = 0;
|
|
|
|
seg->cache.u.segment.avl = 0;
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
seg->cache.u.segment.l = 0;
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
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;
|
2002-09-24 20:35:44 +04:00
|
|
|
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
|
|
|
|
|
2008-04-20 02:29:44 +04:00
|
|
|
BX_CPP_INLINE 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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2006-04-25 19:35:26 +04:00
|
|
|
Bit8u BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::ar_byte(const bx_descriptor_t *d)
|
|
|
|
{
|
2009-01-17 21:56:25 +03:00
|
|
|
if (d->valid == 0) return(0);
|
2006-04-25 19:35:26 +04:00
|
|
|
|
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;
|
|
|
|
|
2009-01-17 21:56:25 +03:00
|
|
|
//if (d->valid == 0) return(0);
|
2006-04-23 21:16:27 +04:00
|
|
|
|
|
|
|
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:
|
2009-01-17 21:56:25 +03:00
|
|
|
BX_ERROR(("#get_descriptor_l(): type %d not finished", d->type));
|
2006-04-23 21:16:27 +04:00
|
|
|
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;
|
|
|
|
|
2009-01-17 21:56:25 +03:00
|
|
|
//if (d->valid == 0) return(0);
|
2006-04-23 21:16:27 +04:00
|
|
|
|
|
|
|
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:
|
2009-01-17 21:56:25 +03:00
|
|
|
BX_ERROR(("#get_descriptor_h(): type %d not finished", d->type));
|
2006-04-23 21:16:27 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-29 22:08:13 +04:00
|
|
|
#if BX_CPU_LEVEL >= 3
|
2008-12-06 21:01:00 +03:00
|
|
|
bx_bool BX_CPU_C::set_segment_ar_data(bx_segment_reg_t *seg, bx_bool valid,
|
2008-12-06 21:52:02 +03:00
|
|
|
Bit16u raw_selector, bx_address base, Bit32u limit_scaled, Bit16u ar_data)
|
2006-04-05 21:31:35 +04:00
|
|
|
{
|
|
|
|
parse_selector(raw_selector, &seg->selector);
|
|
|
|
|
|
|
|
bx_descriptor_t *d = &seg->cache;
|
|
|
|
|
2008-09-12 01:54:57 +04:00
|
|
|
d->p = (ar_data >> 7) & 0x1;
|
|
|
|
d->dpl = (ar_data >> 5) & 0x3;
|
|
|
|
d->segment = (ar_data >> 4) & 0x1;
|
2006-04-05 21:31:35 +04:00
|
|
|
d->type = (ar_data & 0x0f);
|
|
|
|
|
2008-12-06 21:01:00 +03:00
|
|
|
d->valid = valid;
|
2008-09-12 01:54:57 +04:00
|
|
|
|
2006-04-05 21:31:35 +04:00
|
|
|
if (d->segment) { /* data/code segment descriptors */
|
2008-09-12 01:54:57 +04:00
|
|
|
d->u.segment.g = (ar_data >> 15) & 0x1;
|
|
|
|
d->u.segment.d_b = (ar_data >> 14) & 0x1;
|
2006-04-05 21:31:35 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
2008-09-12 01:54:57 +04:00
|
|
|
d->u.segment.l = (ar_data >> 13) & 0x1;
|
2006-04-05 21:31:35 +04:00
|
|
|
#endif
|
2008-09-12 01:54:57 +04:00
|
|
|
d->u.segment.avl = (ar_data >> 12) & 0x1;
|
2006-04-05 21:31:35 +04:00
|
|
|
|
2006-06-12 20:58:27 +04:00
|
|
|
d->u.segment.base = base;
|
2008-12-06 21:52:02 +03:00
|
|
|
d->u.segment.limit_scaled = limit_scaled;
|
2006-04-05 21:31:35 +04:00
|
|
|
|
2008-04-26 01:21:46 +04:00
|
|
|
if (d->u.segment.g)
|
2008-12-06 21:52:02 +03:00
|
|
|
d->u.segment.limit = (d->u.segment.limit_scaled >> 12);
|
2006-04-05 21:31:35 +04:00
|
|
|
else
|
2008-12-06 21:52:02 +03:00
|
|
|
d->u.segment.limit = (d->u.segment.limit_scaled);
|
2006-04-05 21:31:35 +04:00
|
|
|
}
|
|
|
|
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:
|
2008-09-12 01:54:57 +04:00
|
|
|
d->u.system.avl = (ar_data >> 12) & 0x1;
|
|
|
|
d->u.system.g = (ar_data >> 15) & 0x1;
|
2006-08-31 22:18:17 +04:00
|
|
|
d->u.system.base = base;
|
2008-12-06 21:52:02 +03:00
|
|
|
d->u.system.limit_scaled = limit_scaled;
|
2006-08-31 22:18:17 +04:00
|
|
|
if (d->u.system.g)
|
2008-12-06 21:52:02 +03:00
|
|
|
d->u.system.limit = (d->u.system.limit_scaled >> 12);
|
2006-04-05 21:31:35 +04:00
|
|
|
else
|
2008-12-06 21:52:02 +03:00
|
|
|
d->u.system.limit = (d->u.system.limit_scaled);
|
2006-04-05 21:31:35 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-01-16 00:52:52 +03:00
|
|
|
BX_ERROR(("set_segment_ar_data(): case %u unsupported, valid=%d", (unsigned) d->type, d->valid));
|
2006-04-05 21:31:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-12 01:54:57 +04:00
|
|
|
return d->valid;
|
2006-04-05 21:31:35 +04:00
|
|
|
}
|
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;
|
2008-09-12 01:54:57 +04:00
|
|
|
temp->p = (AR_byte >> 7) & 0x1;
|
|
|
|
temp->dpl = (AR_byte >> 5) & 0x3;
|
|
|
|
temp->segment = (AR_byte >> 4) & 0x1;
|
|
|
|
temp->type = (AR_byte & 0xf);
|
2001-04-10 05:04:59 +04:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2008-04-26 01:21:46 +04:00
|
|
|
if (temp->u.segment.g)
|
2008-09-12 01:54:57 +04:00
|
|
|
temp->u.segment.limit_scaled = (temp->u.segment.limit << 12) | 0xfff;
|
2001-04-10 05:04:59 +04:00
|
|
|
else
|
2008-04-26 01:21:46 +04:00
|
|
|
temp->u.segment.limit_scaled = (temp->u.segment.limit);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
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_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:
|
2008-04-18 14:19:33 +04:00
|
|
|
case BX_SYS_SEGMENT_AVAIL_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_286_TSS:
|
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) |
|
2008-04-18 14:19:33 +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)
|
2008-09-12 01:54:57 +04:00
|
|
|
temp->u.system.limit_scaled = (temp->u.system.limit << 12) | 0xfff;
|
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;
|
|
|
|
|
2008-02-03 00:46:54 +03:00
|
|
|
default:
|
2005-02-02 00:17:57 +03:00
|
|
|
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)
|
|
|
|
{
|
2008-04-25 00:52:27 +04:00
|
|
|
// Add cpl to the selector value.
|
|
|
|
selector->value = (0xfffc & selector->value) | cpl;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
2008-05-05 01:25:16 +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."));
|
2002-09-24 12:29:06 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
void 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;
|
2008-01-20 23:11:17 +03:00
|
|
|
bx_address offset;
|
2008-04-20 00:00:28 +04:00
|
|
|
Bit64u raw_descriptor;
|
2006-08-22 23:06:03 +04:00
|
|
|
|
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)",
|
2008-04-26 01:21:46 +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
|
|
|
}
|
2008-01-20 23:11:17 +03:00
|
|
|
offset = BX_CPU_THIS_PTR gdtr.base + index*8;
|
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) {
|
2008-04-25 00:52:27 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor: LDTR.valid=0"));
|
|
|
|
exception(exception_no, selector->value & 0xfffc, 0);
|
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)",
|
2008-04-26 01:21:46 +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
|
|
|
}
|
2008-01-20 23:11:17 +03:00
|
|
|
offset = BX_CPU_THIS_PTR ldtr.cache.u.system.base + index*8;
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2008-01-20 23:11:17 +03:00
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
raw_descriptor = system_read_qword(offset);
|
2008-04-20 00:00:28 +04:00
|
|
|
|
|
|
|
*dword1 = GET32L(raw_descriptor);
|
|
|
|
*dword2 = GET32H(raw_descriptor);
|
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;
|
2008-01-20 23:11:17 +03:00
|
|
|
bx_address offset;
|
2008-04-20 00:00:28 +04:00
|
|
|
Bit64u raw_descriptor;
|
2006-08-22 23:06:03 +04:00
|
|
|
|
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)
|
2008-01-20 23:11:17 +03:00
|
|
|
return 0;
|
|
|
|
offset = BX_CPU_THIS_PTR gdtr.base + index*8;
|
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) {
|
2008-04-25 00:52:27 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor2: LDTR.valid=0"));
|
2008-01-20 23:11:17 +03:00
|
|
|
return 0;
|
2005-07-20 05:26:47 +04:00
|
|
|
}
|
2006-08-31 22:18:17 +04:00
|
|
|
if ((index*8 + 7) > BX_CPU_THIS_PTR ldtr.cache.u.system.limit_scaled)
|
2008-01-20 23:11:17 +03:00
|
|
|
return 0;
|
|
|
|
offset = BX_CPU_THIS_PTR ldtr.cache.u.system.base + index*8;
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2008-01-20 23:11:17 +03:00
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
raw_descriptor = system_read_qword(offset);
|
2008-04-20 00:00:28 +04:00
|
|
|
|
|
|
|
*dword1 = GET32L(raw_descriptor);
|
|
|
|
*dword2 = GET32H(raw_descriptor);
|
2008-01-20 23:11:17 +03:00
|
|
|
|
|
|
|
return 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-08-02 22:44:20 +04:00
|
|
|
|
|
|
|
#if BX_SUPPORT_X86_64
|
2008-05-25 19:53:29 +04:00
|
|
|
void BX_CPU_C::fetch_raw_descriptor_64(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;
|
2008-01-20 23:11:17 +03:00
|
|
|
bx_address offset;
|
2008-04-20 00:00:28 +04:00
|
|
|
Bit64u raw_descriptor1, raw_descriptor2;
|
2006-03-22 23:47:11 +03:00
|
|
|
|
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) {
|
2008-05-27 01:46:39 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor64: GDT: index (%x)%x > limit (%x)",
|
2008-04-26 01:21:46 +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);
|
|
|
|
}
|
2008-01-20 23:11:17 +03:00
|
|
|
offset = BX_CPU_THIS_PTR gdtr.base + index*8;
|
2005-08-02 22:44:20 +04:00
|
|
|
}
|
|
|
|
else { /* LDT */
|
|
|
|
if (BX_CPU_THIS_PTR ldtr.cache.valid==0) {
|
2008-05-27 01:46:39 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor64: LDTR.valid=0"));
|
2008-04-25 00:52:27 +04:00
|
|
|
exception(exception_no, selector->value & 0xfffc, 0);
|
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) {
|
2008-05-27 01:46:39 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor64: LDT: index (%x)%x > limit (%x)",
|
2008-04-26 01:21:46 +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);
|
|
|
|
}
|
2008-01-20 23:11:17 +03:00
|
|
|
offset = BX_CPU_THIS_PTR ldtr.cache.u.system.base + index*8;
|
2006-03-22 23:47:11 +03:00
|
|
|
}
|
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
raw_descriptor1 = system_read_qword(offset);
|
|
|
|
raw_descriptor2 = system_read_qword(offset + 8);
|
2008-01-20 23:11:17 +03:00
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
if (raw_descriptor2 & BX_CONST64(0x00001F0000000000)) {
|
2008-05-27 01:46:39 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor64: extended attributes DWORD4 TYPE != 0"));
|
2006-03-22 23:47:11 +03:00
|
|
|
exception(BX_GP_EXCEPTION, selector->value & 0xfffc, 0);
|
2005-08-02 22:44:20 +04:00
|
|
|
}
|
2008-04-20 00:00:28 +04:00
|
|
|
|
|
|
|
*dword1 = GET32L(raw_descriptor1);
|
|
|
|
*dword2 = GET32H(raw_descriptor1);
|
|
|
|
*dword3 = GET32L(raw_descriptor2);
|
2005-08-02 22:44:20 +04:00
|
|
|
}
|
|
|
|
#endif
|