2009-07-27 17:28:25 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 00:54:04 +03:00
|
|
|
// $Id$
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2015-01-25 23:55:10 +03:00
|
|
|
// Copyright (C) 2001-2015 The Bochs Project
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// 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
|
2009-11-30 00:01:26 +03:00
|
|
|
if (long64_mode() && CPL != 3 && ss_selector.rpl == CPL) {
|
2009-10-13 00:50:14 +04:00
|
|
|
load_null_selector(seg, new_value);
|
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"));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc);
|
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"));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc);
|
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"));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc);
|
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"));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc);
|
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"));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc);
|
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"));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(BX_SS_EXCEPTION, new_value & 0xfffc);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-07-27 09:52:28 +04:00
|
|
|
touch_segment(&ss_selector, &descriptor);
|
|
|
|
|
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;
|
2015-01-25 23:55:10 +03:00
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.valid = SegValidCache;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2012-03-25 15:54:32 +04:00
|
|
|
invalidate_stack_cache();
|
|
|
|
|
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]) ||
|
2010-05-02 19:11:39 +04:00
|
|
|
(seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES]) ||
|
|
|
|
(seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS]) ||
|
2008-02-16 01:05:43 +03:00
|
|
|
(seg==&BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS])
|
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 */
|
2009-10-13 00:50:14 +04:00
|
|
|
load_null_selector(seg, new_value);
|
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));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc);
|
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));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc);
|
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));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(BX_GP_EXCEPTION, new_value & 0xfffc);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
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));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(BX_NP_EXCEPTION, new_value & 0xfffc);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-07-27 09:52:28 +04:00
|
|
|
touch_segment(&selector, &descriptor);
|
|
|
|
|
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;
|
2015-01-25 23:55:10 +03:00
|
|
|
seg->cache.valid = SegValidCache;
|
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;
|
2015-01-25 23:55:10 +03:00
|
|
|
seg->cache.valid = SegValidCache;
|
2005-11-08 01:45:25 +03:00
|
|
|
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
|
|
|
|
2009-03-10 23:01:56 +03:00
|
|
|
/* Do not modify segment limit and AR bytes when in real mode */
|
|
|
|
/* Support for big real mode */
|
|
|
|
if (!real_mode()) {
|
2009-08-30 09:03:04 +04:00
|
|
|
seg->cache.type = BX_DATA_READ_WRITE_ACCESSED;
|
2009-03-10 23:01:56 +03:00
|
|
|
seg->cache.dpl = 3; /* we are in v8086 mode */
|
|
|
|
seg->cache.u.segment.limit_scaled = 0xffff;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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();
|
2010-04-22 21:51:37 +04:00
|
|
|
updateFetchModeMask(/* CS reloaded */);
|
2012-03-25 23:07:17 +04:00
|
|
|
#if BX_CPU_LEVEL >= 4
|
2010-04-22 21:51:37 +04:00
|
|
|
handleAlignmentCheck(/* CPL change */);
|
2002-09-19 23:17:20 +04:00
|
|
|
#endif
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2012-03-25 15:54:32 +04:00
|
|
|
|
|
|
|
if (seg == &BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS])
|
|
|
|
invalidate_stack_cache();
|
2008-05-06 23:45:17 +04:00
|
|
|
}
|
|
|
|
|
2009-10-13 00:50:14 +04:00
|
|
|
void BX_CPP_AttrRegparmN(2)
|
|
|
|
BX_CPU_C::load_null_selector(bx_segment_reg_t *seg, unsigned value)
|
2008-05-06 23:45:17 +04:00
|
|
|
{
|
2009-10-13 00:50:14 +04:00
|
|
|
BX_ASSERT((value & 0xfffc) == 0);
|
|
|
|
|
2008-05-06 23:45:17 +04:00
|
|
|
seg->selector.index = 0;
|
|
|
|
seg->selector.ti = 0;
|
2009-10-13 00:50:14 +04:00
|
|
|
seg->selector.rpl = BX_SELECTOR_RPL(value);
|
|
|
|
seg->selector.value = value;
|
2008-05-06 23:45:17 +04:00
|
|
|
|
|
|
|
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_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
|
2012-03-25 15:54:32 +04:00
|
|
|
|
|
|
|
invalidate_stack_cache();
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-12-27 19:38:09 +03:00
|
|
|
void parse_selector(Bit16u raw_selector, bx_selector_t *selector)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
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
|
|
|
|
2009-12-27 19:53:35 +03:00
|
|
|
Bit8u get_ar_byte(const bx_descriptor_t *d)
|
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
|
|
|
}
|
|
|
|
|
2009-12-27 19:53:35 +03:00
|
|
|
void set_ar_byte(bx_descriptor_t *d, Bit8u ar_byte)
|
2006-05-27 18:02:34 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2009-04-05 23:09:44 +04:00
|
|
|
Bit32u limit = d->u.segment.limit_scaled;
|
|
|
|
if (d->u.segment.g)
|
|
|
|
limit >>= 12;
|
|
|
|
|
|
|
|
Bit32u val = ((d->u.segment.base & 0xffff) << 16) | (limit & 0xffff);
|
2006-04-23 21:16:27 +04:00
|
|
|
|
2011-12-19 20:06:53 +04:00
|
|
|
if (d->segment || !d->valid) {
|
2006-04-23 21:16:27 +04:00
|
|
|
return(val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (d->type) {
|
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-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-04-05 23:09:44 +04:00
|
|
|
Bit32u limit = d->u.segment.limit_scaled;
|
|
|
|
if (d->u.segment.g)
|
|
|
|
limit >>= 12;
|
|
|
|
|
2011-12-19 20:06:53 +04:00
|
|
|
if (d->segment || !d->valid) {
|
2006-04-23 21:16:27 +04:00
|
|
|
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) |
|
2009-04-05 22:16:29 +04:00
|
|
|
(d->p << 15) | (limit & 0xf0000) |
|
2006-04-23 21:16:27 +04:00
|
|
|
(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 BX_SYS_SEGMENT_AVAIL_286_TSS:
|
|
|
|
case BX_SYS_SEGMENT_BUSY_286_TSS:
|
2006-08-31 22:18:17 +04:00
|
|
|
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:
|
2009-04-05 23:09:44 +04:00
|
|
|
val = ((d->u.segment.base >> 16) & 0xff) |
|
2006-04-23 21:16:27 +04:00
|
|
|
(d->type << 8) |
|
|
|
|
(d->dpl << 13) |
|
2009-04-05 22:16:29 +04:00
|
|
|
(d->p << 15) | (limit & 0xf0000) |
|
2009-04-05 23:09:44 +04:00
|
|
|
(d->u.segment.avl << 20) |
|
|
|
|
(d->u.segment.d_b << 22) |
|
|
|
|
(d->u.segment.g << 23) |
|
|
|
|
(d->u.segment.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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-12-19 20:06:53 +04:00
|
|
|
if (d->segment || !valid) { /* 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
|
|
|
}
|
|
|
|
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:
|
2009-04-05 23:09:44 +04:00
|
|
|
d->u.segment.avl = (ar_data >> 12) & 0x1;
|
|
|
|
d->u.segment.d_b = (ar_data >> 14) & 0x1;
|
|
|
|
d->u.segment.g = (ar_data >> 15) & 0x1;
|
|
|
|
d->u.segment.base = base;
|
|
|
|
d->u.segment.limit_scaled = 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
|
|
|
|
2009-12-28 12:26:22 +03:00
|
|
|
void parse_descriptor(Bit32u dword1, Bit32u dword2, bx_descriptor_t *temp)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit8u AR_byte;
|
2009-04-05 22:16:29 +04:00
|
|
|
Bit32u limit;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
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 */
|
2009-04-05 22:16:29 +04:00
|
|
|
limit = (dword1 & 0xffff) | (dword2 & 0x000F0000);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-04-05 22:16:29 +04:00
|
|
|
temp->u.segment.base = (dword1 >> 16) | ((dword2 & 0xFF) << 16);
|
2006-03-29 22:08:13 +04:00
|
|
|
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)
|
2009-04-05 22:16:29 +04:00
|
|
|
temp->u.segment.limit_scaled = (limit << 12) | 0xfff;
|
2001-04-10 05:04:59 +04:00
|
|
|
else
|
2009-04-05 22:16:29 +04:00
|
|
|
temp->u.segment.limit_scaled = 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) {
|
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:
|
2009-04-05 22:16:29 +04:00
|
|
|
limit = (dword1 & 0xffff) | (dword2 & 0x000F0000);
|
2009-04-05 23:09:44 +04:00
|
|
|
temp->u.segment.base = (dword1 >> 16) |
|
2009-12-28 12:26:22 +03:00
|
|
|
((dword2 & 0xff) << 16) | (dword2 & 0xff000000);
|
2009-04-05 23:09:44 +04:00
|
|
|
temp->u.segment.g = (dword2 & 0x00800000) > 0;
|
|
|
|
temp->u.segment.d_b = (dword2 & 0x00400000) > 0;
|
|
|
|
temp->u.segment.avl = (dword2 & 0x00100000) > 0;
|
|
|
|
if (temp->u.segment.g)
|
|
|
|
temp->u.segment.limit_scaled = (limit << 12) | 0xfff;
|
2001-04-10 05:04:59 +04:00
|
|
|
else
|
2009-04-05 23:09:44 +04:00
|
|
|
temp->u.segment.limit_scaled = limit;
|
2001-04-10 05:04:59 +04:00
|
|
|
temp->valid = 1;
|
|
|
|
break;
|
|
|
|
|
2009-12-28 12:26:22 +03:00
|
|
|
default: // reserved
|
|
|
|
temp->valid = 0;
|
|
|
|
break;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2009-07-27 09:52:28 +04:00
|
|
|
void BX_CPP_AttrRegparmN(2)
|
|
|
|
BX_CPU_C::touch_segment(bx_selector_t *selector, bx_descriptor_t *descriptor)
|
|
|
|
{
|
|
|
|
if (! IS_SEGMENT_ACCESSED(descriptor->type)) {
|
|
|
|
Bit8u AR_byte = get_ar_byte(descriptor);
|
|
|
|
AR_byte |= 1;
|
|
|
|
descriptor->type |= 1;
|
|
|
|
|
|
|
|
if (selector->ti == 0) { /* GDT */
|
2014-07-20 00:01:44 +04:00
|
|
|
system_write_byte(BX_CPU_THIS_PTR gdtr.base + selector->index*8 + 5, AR_byte);
|
2009-07-27 09:52:28 +04:00
|
|
|
}
|
|
|
|
else { /* LDT */
|
2014-07-20 00:01:44 +04:00
|
|
|
system_write_byte(BX_CPU_THIS_PTR ldtr.cache.u.segment.base + selector->index*8 + 5, AR_byte);
|
2009-07-27 09:52:28 +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.
|
2009-09-19 10:42:31 +04:00
|
|
|
selector->value = (BX_SELECTOR_RPL_MASK & selector->value) | cpl;
|
2008-04-25 00:52:27 +04:00
|
|
|
|
2009-09-19 10:42:31 +04:00
|
|
|
if ((selector->value & BX_SELECTOR_RPL_MASK) != 0)
|
|
|
|
touch_segment(selector, descriptor);
|
2009-07-28 18:55:27 +04:00
|
|
|
|
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;
|
2015-01-25 23:55:10 +03:00
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].cache.valid = SegValidCache;
|
2012-03-25 15:54:32 +04:00
|
|
|
|
|
|
|
invalidate_stack_cache();
|
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) {
|
2009-10-02 20:09:08 +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));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(exception_no, selector->value & 0xfffc);
|
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"));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(exception_no, selector->value & 0xfffc);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2009-04-05 23:09:44 +04:00
|
|
|
if ((index*8 + 7) > BX_CPU_THIS_PTR ldtr.cache.u.segment.limit_scaled) {
|
2009-10-02 20:09:08 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor: LDT: index (%x) %x > limit (%x)",
|
2009-04-05 23:09:44 +04:00
|
|
|
index*8 + 7, index, BX_CPU_THIS_PTR ldtr.cache.u.segment.limit_scaled));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(exception_no, selector->value & 0xfffc);
|
2005-02-02 00:17:57 +03:00
|
|
|
}
|
2009-04-05 23:09:44 +04:00
|
|
|
offset = BX_CPU_THIS_PTR ldtr.cache.u.segment.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
|
|
|
}
|
2009-04-05 23:09:44 +04:00
|
|
|
if ((index*8 + 7) > BX_CPU_THIS_PTR ldtr.cache.u.segment.limit_scaled)
|
2008-01-20 23:11:17 +03:00
|
|
|
return 0;
|
2009-04-05 23:09:44 +04:00
|
|
|
offset = BX_CPU_THIS_PTR ldtr.cache.u.segment.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) {
|
2009-10-02 20:09:08 +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));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(exception_no, selector->value & 0xfffc);
|
2005-08-02 22:44:20 +04:00
|
|
|
}
|
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"));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(exception_no, selector->value & 0xfffc);
|
2005-08-02 22:44:20 +04:00
|
|
|
}
|
2009-04-05 23:09:44 +04:00
|
|
|
if ((index*8 + 15) > BX_CPU_THIS_PTR ldtr.cache.u.segment.limit_scaled) {
|
2009-10-02 20:09:08 +04:00
|
|
|
BX_ERROR(("fetch_raw_descriptor64: LDT: index (%x) %x > limit (%x)",
|
2009-04-05 23:09:44 +04:00
|
|
|
index*8 + 15, index, BX_CPU_THIS_PTR ldtr.cache.u.segment.limit_scaled));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(exception_no, selector->value & 0xfffc);
|
2005-08-02 22:44:20 +04:00
|
|
|
}
|
2009-04-05 23:09:44 +04:00
|
|
|
offset = BX_CPU_THIS_PTR ldtr.cache.u.segment.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"));
|
2010-03-14 18:51:27 +03:00
|
|
|
exception(BX_GP_EXCEPTION, selector->value & 0xfffc);
|
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
|
|
|
}
|
2009-10-02 20:09:08 +04:00
|
|
|
|
|
|
|
bx_bool BX_CPU_C::fetch_raw_descriptor2_64(const bx_selector_t *selector,
|
|
|
|
Bit32u *dword1, Bit32u *dword2, Bit32u *dword3)
|
|
|
|
{
|
|
|
|
Bit32u index = selector->index;
|
|
|
|
bx_address offset;
|
|
|
|
Bit64u raw_descriptor1, raw_descriptor2;
|
|
|
|
|
|
|
|
if (selector->ti == 0) { /* GDT */
|
|
|
|
if ((index*8 + 15) > BX_CPU_THIS_PTR gdtr.limit) {
|
|
|
|
BX_ERROR(("fetch_raw_descriptor2_64: GDT: index (%x) %x > limit (%x)",
|
|
|
|
index*8 + 15, index, BX_CPU_THIS_PTR gdtr.limit));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
offset = BX_CPU_THIS_PTR gdtr.base + index*8;
|
|
|
|
}
|
|
|
|
else { /* LDT */
|
|
|
|
if (BX_CPU_THIS_PTR ldtr.cache.valid==0) {
|
|
|
|
BX_ERROR(("fetch_raw_descriptor2_64: LDTR.valid=0"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ((index*8 + 15) > BX_CPU_THIS_PTR ldtr.cache.u.segment.limit_scaled) {
|
|
|
|
BX_ERROR(("fetch_raw_descriptor2_64: LDT: index (%x) %x > limit (%x)",
|
|
|
|
index*8 + 15, index, BX_CPU_THIS_PTR ldtr.cache.u.segment.limit_scaled));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
offset = BX_CPU_THIS_PTR ldtr.cache.u.segment.base + index*8;
|
|
|
|
}
|
|
|
|
|
|
|
|
raw_descriptor1 = system_read_qword(offset);
|
|
|
|
raw_descriptor2 = system_read_qword(offset + 8);
|
|
|
|
|
|
|
|
if (raw_descriptor2 & BX_CONST64(0x00001F0000000000)) {
|
|
|
|
BX_ERROR(("fetch_raw_descriptor2_64: extended attributes DWORD4 TYPE != 0"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dword1 = GET32L(raw_descriptor1);
|
|
|
|
*dword2 = GET32H(raw_descriptor1);
|
|
|
|
*dword3 = GET32L(raw_descriptor2);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2005-08-02 22:44:20 +04:00
|
|
|
#endif
|