2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2010-07-23 00:12:25 +04:00
|
|
|
// $Id: access.cc,v 1.127 2010-07-22 20:12:24 sshwarts Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2009-12-04 19:53:12 +03:00
|
|
|
// Copyright (C) 2005-2009 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-10-11 01:48:46 +04: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
|
|
|
|
2008-06-25 06:28:31 +04:00
|
|
|
bx_bool BX_CPP_AttrRegparmN(3)
|
2008-06-12 23:14:40 +04:00
|
|
|
BX_CPU_C::write_virtual_checks(bx_segment_reg_t *seg, Bit32u offset, unsigned length)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit32u upper_limit;
|
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
if (seg->cache.valid==0) {
|
|
|
|
BX_DEBUG(("write_virtual_checks(): segment descriptor not valid"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-27 01:46:39 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
if (seg->cache.p == 0) { /* not present */
|
|
|
|
BX_ERROR(("write_virtual_checks(): segment not present"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2005-01-25 23:41:43 +03:00
|
|
|
}
|
2008-05-27 01:46:39 +04:00
|
|
|
|
|
|
|
switch (seg->cache.type) {
|
|
|
|
case 0: case 1: // read only
|
|
|
|
case 4: case 5: // read only, expand down
|
|
|
|
case 8: case 9: // execute only
|
|
|
|
case 10: case 11: // execute/read
|
|
|
|
case 12: case 13: // execute only, conforming
|
|
|
|
case 14: case 15: // execute/read-only, conforming
|
|
|
|
BX_ERROR(("write_virtual_checks(): no write access to seg"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-01 09:11:19 +04:00
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
case 2: case 3: /* read/write */
|
|
|
|
if (offset > (seg->cache.u.segment.limit_scaled - length + 1)
|
2005-01-25 23:41:43 +03:00
|
|
|
|| (length-1 > seg->cache.u.segment.limit_scaled))
|
2008-05-27 01:46:39 +04:00
|
|
|
{
|
|
|
|
BX_ERROR(("write_virtual_checks(): write beyond limit, r/w"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-27 01:46:39 +04:00
|
|
|
}
|
2008-07-26 18:19:06 +04:00
|
|
|
if (seg->cache.u.segment.limit_scaled >= 15) {
|
2008-05-27 01:46:39 +04:00
|
|
|
// Mark cache as being OK type for succeeding read/writes. The limit
|
|
|
|
// checks still needs to be done though, but is more simple. We
|
|
|
|
// could probably also optimize that out with a flag for the case
|
|
|
|
// when limit is the maximum 32bit value. Limit should accomodate
|
|
|
|
// at least a dword, since we subtract from it in the simple
|
|
|
|
// limit check in other functions, and we don't want the value to roll.
|
|
|
|
// Only normal segments (not expand down) are handled this way.
|
|
|
|
seg->cache.valid |= SegAccessROK | SegAccessWOK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6: case 7: /* read/write, expand down */
|
|
|
|
if (seg->cache.u.segment.d_b)
|
|
|
|
upper_limit = 0xffffffff;
|
|
|
|
else
|
|
|
|
upper_limit = 0x0000ffff;
|
|
|
|
if ((offset <= seg->cache.u.segment.limit_scaled) ||
|
|
|
|
(offset > upper_limit) || ((upper_limit - offset) < (length - 1)))
|
|
|
|
{
|
|
|
|
BX_ERROR(("write_virtual_checks(): write beyond limit, r/w ED"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-27 01:46:39 +04:00
|
|
|
}
|
|
|
|
break;
|
2007-12-10 22:08:13 +03:00
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
default:
|
|
|
|
BX_PANIC(("write_virtual_checks(): unknown descriptor type=%d", seg->cache.type));
|
2005-01-25 23:41:43 +03:00
|
|
|
}
|
2008-06-25 06:28:31 +04:00
|
|
|
|
|
|
|
return 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-06-25 06:28:31 +04:00
|
|
|
bx_bool BX_CPP_AttrRegparmN(3)
|
2008-06-12 23:14:40 +04:00
|
|
|
BX_CPU_C::read_virtual_checks(bx_segment_reg_t *seg, Bit32u offset, unsigned length)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit32u upper_limit;
|
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
if (seg->cache.valid==0) {
|
|
|
|
BX_DEBUG(("read_virtual_checks(): segment descriptor not valid"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-27 01:46:39 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
if (seg->cache.p == 0) { /* not present */
|
|
|
|
BX_ERROR(("read_virtual_checks(): segment not present"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-27 01:46:39 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
switch (seg->cache.type) {
|
|
|
|
case 0: case 1: /* read only */
|
|
|
|
case 2: case 3: /* read/write */
|
|
|
|
case 10: case 11: /* execute/read */
|
|
|
|
case 14: case 15: /* execute/read-only, conforming */
|
|
|
|
if (offset > (seg->cache.u.segment.limit_scaled - length + 1)
|
|
|
|
|| (length-1 > seg->cache.u.segment.limit_scaled))
|
|
|
|
{
|
|
|
|
BX_ERROR(("read_virtual_checks(): read beyond limit"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-27 01:46:39 +04:00
|
|
|
}
|
2008-07-26 18:19:06 +04:00
|
|
|
if (seg->cache.u.segment.limit_scaled >= 15) {
|
2008-05-27 01:46:39 +04:00
|
|
|
// Mark cache as being OK type for succeeding reads. See notes for
|
|
|
|
// write checks; similar code.
|
|
|
|
seg->cache.valid |= SegAccessROK;
|
|
|
|
}
|
|
|
|
break;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
case 4: case 5: /* read only, expand down */
|
|
|
|
case 6: case 7: /* read/write, expand down */
|
|
|
|
if (seg->cache.u.segment.d_b)
|
|
|
|
upper_limit = 0xffffffff;
|
|
|
|
else
|
|
|
|
upper_limit = 0x0000ffff;
|
|
|
|
if ((offset <= seg->cache.u.segment.limit_scaled) ||
|
|
|
|
(offset > upper_limit) || ((upper_limit - offset) < (length - 1)))
|
|
|
|
{
|
|
|
|
BX_ERROR(("read_virtual_checks(): read beyond limit ED"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-27 01:46:39 +04:00
|
|
|
}
|
|
|
|
break;
|
2008-05-01 09:11:19 +04:00
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
case 8: case 9: /* execute only */
|
|
|
|
case 12: case 13: /* execute only, conforming */
|
|
|
|
/* can't read or write an execute-only segment */
|
|
|
|
BX_ERROR(("read_virtual_checks(): execute only"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2007-12-10 22:08:13 +03:00
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
default:
|
|
|
|
BX_PANIC(("read_virtual_checks(): unknown descriptor type=%d", seg->cache.type));
|
2007-10-11 01:48:46 +04:00
|
|
|
}
|
2008-06-25 06:28:31 +04:00
|
|
|
|
|
|
|
return 1;
|
2007-10-11 01:48:46 +04:00
|
|
|
}
|
|
|
|
|
2008-06-25 06:28:31 +04:00
|
|
|
bx_bool BX_CPP_AttrRegparmN(3)
|
2008-06-12 23:14:40 +04:00
|
|
|
BX_CPU_C::execute_virtual_checks(bx_segment_reg_t *seg, Bit32u offset, unsigned length)
|
2007-10-11 01:48:46 +04:00
|
|
|
{
|
|
|
|
Bit32u upper_limit;
|
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
if (seg->cache.valid==0) {
|
|
|
|
BX_DEBUG(("execute_virtual_checks(): segment descriptor not valid"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-27 01:46:39 +04:00
|
|
|
}
|
2007-10-11 01:48:46 +04:00
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
if (seg->cache.p == 0) { /* not present */
|
|
|
|
BX_ERROR(("execute_virtual_checks(): segment not present"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2007-10-11 01:48:46 +04:00
|
|
|
}
|
2008-05-01 09:11:19 +04:00
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
switch (seg->cache.type) {
|
|
|
|
case 0: case 1: /* read only */
|
|
|
|
case 2: case 3: /* read/write */
|
|
|
|
case 10: case 11: /* execute/read */
|
|
|
|
case 14: case 15: /* execute/read-only, conforming */
|
|
|
|
if (offset > (seg->cache.u.segment.limit_scaled - length + 1)
|
|
|
|
|| (length-1 > seg->cache.u.segment.limit_scaled))
|
|
|
|
{
|
|
|
|
BX_ERROR(("execute_virtual_checks(): read beyond limit"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-27 01:46:39 +04:00
|
|
|
}
|
2008-07-26 18:19:06 +04:00
|
|
|
if (seg->cache.u.segment.limit_scaled >= 15) {
|
2008-05-27 01:46:39 +04:00
|
|
|
// Mark cache as being OK type for succeeding reads. See notes for
|
|
|
|
// write checks; similar code.
|
|
|
|
seg->cache.valid |= SegAccessROK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8: case 9: /* execute only */
|
|
|
|
case 12: case 13: /* execute only, conforming */
|
|
|
|
if (offset > (seg->cache.u.segment.limit_scaled - length + 1)
|
|
|
|
|| (length-1 > seg->cache.u.segment.limit_scaled))
|
|
|
|
{
|
|
|
|
BX_ERROR(("execute_virtual_checks(): read beyond limit execute only"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-27 01:46:39 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: case 5: /* read only, expand down */
|
|
|
|
case 6: case 7: /* read/write, expand down */
|
|
|
|
if (seg->cache.u.segment.d_b)
|
|
|
|
upper_limit = 0xffffffff;
|
|
|
|
else
|
|
|
|
upper_limit = 0x0000ffff;
|
|
|
|
if ((offset <= seg->cache.u.segment.limit_scaled) ||
|
|
|
|
(offset > upper_limit) || ((upper_limit - offset) < (length - 1)))
|
|
|
|
{
|
|
|
|
BX_ERROR(("execute_virtual_checks(): read beyond limit ED"));
|
2008-06-25 06:28:31 +04:00
|
|
|
return 0;
|
2008-05-27 01:46:39 +04:00
|
|
|
}
|
|
|
|
break;
|
2007-12-10 22:08:13 +03:00
|
|
|
|
2008-05-27 01:46:39 +04:00
|
|
|
default:
|
2008-05-31 01:14:49 +04:00
|
|
|
BX_PANIC(("execute_virtual_checks(): unknown descriptor type=%d", seg->cache.type));
|
2005-01-25 23:41:43 +03:00
|
|
|
}
|
2008-06-25 06:28:31 +04:00
|
|
|
|
|
|
|
return 1;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-03-23 00:29:41 +03:00
|
|
|
const char *BX_CPU_C::strseg(bx_segment_reg_t *seg)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2008-04-05 21:51:55 +04:00
|
|
|
if (seg == &BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES]) return("ES");
|
|
|
|
else if (seg == &BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS]) return("CS");
|
|
|
|
else if (seg == &BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS]) return("SS");
|
|
|
|
else if (seg == &BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS]) return("DS");
|
|
|
|
else if (seg == &BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS]) return("FS");
|
|
|
|
else if (seg == &BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS]) return("GS");
|
2001-04-10 05:04:59 +04:00
|
|
|
else {
|
2006-02-27 00:44:03 +03:00
|
|
|
BX_PANIC(("undefined segment passed to strseg()!"));
|
2001-04-10 05:04:59 +04:00
|
|
|
return("??");
|
2005-01-25 23:41:43 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-04-05 21:51:55 +04:00
|
|
|
int BX_CPU_C::int_number(unsigned s)
|
|
|
|
{
|
|
|
|
if (s == BX_SEG_REG_SS)
|
|
|
|
return BX_SS_EXCEPTION;
|
|
|
|
else
|
|
|
|
return BX_GP_EXCEPTION;
|
|
|
|
}
|
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
Bit8u BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::system_read_byte(bx_address laddr)
|
|
|
|
{
|
|
|
|
Bit8u data;
|
|
|
|
|
|
|
|
unsigned tlbIndex = BX_TLB_INDEX_OF(laddr, 0);
|
|
|
|
bx_address lpf = LPFOf(laddr);
|
|
|
|
bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlbIndex];
|
|
|
|
if (tlbEntry->lpf == lpf) {
|
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
|
|
|
BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr, tlbEntry->ppf | pageOffset, 1, BX_READ);
|
|
|
|
Bit8u *hostAddr = (Bit8u*) (hostPageAddr | pageOffset);
|
|
|
|
data = *hostAddr;
|
|
|
|
BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
|
|
|
|
tlbEntry->ppf | pageOffset, 1, 0, BX_READ, (Bit8u*) &data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2010-07-23 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (! IsCanonical(laddr)) {
|
|
|
|
BX_ERROR(("system_read_byte(): canonical failure"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
access_read_linear(laddr, 1, 0, BX_READ, (void *) &data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit16u BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::system_read_word(bx_address laddr)
|
|
|
|
{
|
|
|
|
Bit16u data;
|
|
|
|
|
|
|
|
unsigned tlbIndex = BX_TLB_INDEX_OF(laddr, 1);
|
|
|
|
bx_address lpf = LPFOf(laddr);
|
|
|
|
bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlbIndex];
|
|
|
|
if (tlbEntry->lpf == lpf) {
|
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
|
|
|
BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr, tlbEntry->ppf | pageOffset, 2, BX_READ);
|
|
|
|
Bit16u *hostAddr = (Bit16u*) (hostPageAddr | pageOffset);
|
|
|
|
ReadHostWordFromLittleEndian(hostAddr, data);
|
|
|
|
BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
|
|
|
|
tlbEntry->ppf | pageOffset, 2, 0, BX_READ, (Bit8u*) &data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2010-07-23 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (! IsCanonical(laddr) || ! IsCanonical(laddr+1)) {
|
|
|
|
BX_ERROR(("system_read_word(): canonical failure"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
access_read_linear(laddr, 2, 0, BX_READ, (void *) &data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit32u BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::system_read_dword(bx_address laddr)
|
|
|
|
{
|
|
|
|
Bit32u data;
|
|
|
|
|
|
|
|
unsigned tlbIndex = BX_TLB_INDEX_OF(laddr, 3);
|
|
|
|
bx_address lpf = LPFOf(laddr);
|
|
|
|
bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlbIndex];
|
|
|
|
if (tlbEntry->lpf == lpf) {
|
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
|
|
|
BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr, tlbEntry->ppf | pageOffset, 4, BX_READ);
|
|
|
|
Bit32u *hostAddr = (Bit32u*) (hostPageAddr | pageOffset);
|
|
|
|
ReadHostDWordFromLittleEndian(hostAddr, data);
|
|
|
|
BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
|
|
|
|
tlbEntry->ppf | pageOffset, 4, 0, BX_READ, (Bit8u*) &data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2010-07-23 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (! IsCanonical(laddr) || ! IsCanonical(laddr+3)) {
|
|
|
|
BX_ERROR(("system_read_dword(): canonical failure"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
access_read_linear(laddr, 4, 0, BX_READ, (void *) &data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit64u BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::system_read_qword(bx_address laddr)
|
|
|
|
{
|
|
|
|
Bit64u data;
|
|
|
|
|
|
|
|
unsigned tlbIndex = BX_TLB_INDEX_OF(laddr, 7);
|
|
|
|
bx_address lpf = LPFOf(laddr);
|
|
|
|
bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlbIndex];
|
|
|
|
if (tlbEntry->lpf == lpf) {
|
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
|
|
|
BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr, tlbEntry->ppf | pageOffset, 8, BX_READ);
|
|
|
|
Bit64u *hostAddr = (Bit64u*) (hostPageAddr | pageOffset);
|
|
|
|
ReadHostQWordFromLittleEndian(hostAddr, data);
|
|
|
|
BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
|
|
|
|
tlbEntry->ppf | pageOffset, 8, 0, BX_READ, (Bit8u*) &data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2010-07-23 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (! IsCanonical(laddr) || ! IsCanonical(laddr+7)) {
|
|
|
|
BX_ERROR(("system_read_qword(): canonical failure"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
access_read_linear(laddr, 8, 0, BX_READ, (void *) &data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2009-10-08 22:07:50 +04:00
|
|
|
void BX_CPP_AttrRegparmN(2)
|
|
|
|
BX_CPU_C::system_write_byte(bx_address laddr, Bit8u data)
|
|
|
|
{
|
|
|
|
unsigned tlbIndex = BX_TLB_INDEX_OF(laddr, 0);
|
|
|
|
Bit32u lpf = LPFOf(laddr);
|
|
|
|
bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlbIndex];
|
|
|
|
if (tlbEntry->lpf == lpf) {
|
|
|
|
// See if the TLB entry privilege level allows us write access
|
|
|
|
// from this CPL.
|
|
|
|
if (! (tlbEntry->accessBits & 0x2)) {
|
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
|
|
|
BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr, tlbEntry->ppf | pageOffset, 1, BX_WRITE);
|
|
|
|
BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
|
|
|
|
tlbEntry->ppf | pageOffset, 1, 0, BX_WRITE, (Bit8u*) &data);
|
|
|
|
Bit8u *hostAddr = (Bit8u*) (hostPageAddr | pageOffset);
|
|
|
|
pageWriteStampTable.decWriteStamp(tlbEntry->ppf);
|
|
|
|
*hostAddr = data;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-23 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (! IsCanonical(laddr)) {
|
|
|
|
BX_ERROR(("system_write_byte(): canonical failure"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-10-08 22:07:50 +04:00
|
|
|
access_write_linear(laddr, 1, 0, (void *) &data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BX_CPP_AttrRegparmN(2)
|
|
|
|
BX_CPU_C::system_write_word(bx_address laddr, Bit16u data)
|
|
|
|
{
|
|
|
|
unsigned tlbIndex = BX_TLB_INDEX_OF(laddr, 1);
|
|
|
|
Bit32u lpf = LPFOf(laddr);
|
|
|
|
bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlbIndex];
|
|
|
|
if (tlbEntry->lpf == lpf) {
|
|
|
|
// See if the TLB entry privilege level allows us write access
|
|
|
|
// from this CPL.
|
|
|
|
if (! (tlbEntry->accessBits & 0x2)) {
|
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
|
|
|
BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr, tlbEntry->ppf | pageOffset, 2, BX_WRITE);
|
|
|
|
BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
|
|
|
|
tlbEntry->ppf | pageOffset, 2, 0, BX_WRITE, (Bit8u*) &data);
|
|
|
|
Bit16u *hostAddr = (Bit16u*) (hostPageAddr | pageOffset);
|
|
|
|
pageWriteStampTable.decWriteStamp(tlbEntry->ppf);
|
|
|
|
WriteHostWordToLittleEndian(hostAddr, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-23 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (! IsCanonical(laddr) || ! IsCanonical(laddr+1)) {
|
|
|
|
BX_ERROR(("system_write_word(): canonical failure"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-10-08 22:07:50 +04:00
|
|
|
access_write_linear(laddr, 2, 0, (void *) &data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BX_CPP_AttrRegparmN(2)
|
|
|
|
BX_CPU_C::system_write_dword(bx_address laddr, Bit32u data)
|
|
|
|
{
|
|
|
|
unsigned tlbIndex = BX_TLB_INDEX_OF(laddr, 3);
|
|
|
|
Bit32u lpf = LPFOf(laddr);
|
|
|
|
bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlbIndex];
|
|
|
|
if (tlbEntry->lpf == lpf) {
|
|
|
|
// See if the TLB entry privilege level allows us write access
|
|
|
|
// from this CPL.
|
|
|
|
if (! (tlbEntry->accessBits & 0x2)) {
|
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
|
|
|
BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr, tlbEntry->ppf | pageOffset, 4, BX_WRITE);
|
|
|
|
BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
|
|
|
|
tlbEntry->ppf | pageOffset, 4, 0, BX_WRITE, (Bit8u*) &data);
|
|
|
|
Bit32u *hostAddr = (Bit32u*) (hostPageAddr | pageOffset);
|
|
|
|
pageWriteStampTable.decWriteStamp(tlbEntry->ppf);
|
|
|
|
WriteHostDWordToLittleEndian(hostAddr, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-23 00:12:25 +04:00
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
if (! IsCanonical(laddr) || ! IsCanonical(laddr+3)) {
|
|
|
|
BX_ERROR(("system_write_dword(): canonical failure"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-10-08 22:07:50 +04:00
|
|
|
access_write_linear(laddr, 4, 0, (void *) &data);
|
|
|
|
}
|
|
|
|
|
2008-02-03 00:46:54 +03:00
|
|
|
Bit8u* BX_CPP_AttrRegparmN(2)
|
2008-08-03 23:53:09 +04:00
|
|
|
BX_CPU_C::v2h_read_byte(bx_address laddr, bx_bool user)
|
2005-08-24 00:01:54 +04:00
|
|
|
{
|
2007-12-27 02:07:44 +03:00
|
|
|
unsigned tlbIndex = BX_TLB_INDEX_OF(laddr, 0);
|
2005-08-24 00:01:54 +04:00
|
|
|
bx_address lpf = LPFOf(laddr);
|
|
|
|
bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlbIndex];
|
2007-11-11 23:44:07 +03:00
|
|
|
if (tlbEntry->lpf == lpf) {
|
2005-08-24 00:01:54 +04:00
|
|
|
// See if the TLB entry privilege level allows us read access
|
|
|
|
// from this CPL.
|
2008-08-15 02:26:15 +04:00
|
|
|
if (! (tlbEntry->accessBits & user)) { // Read this pl OK.
|
2005-08-24 00:01:54 +04:00
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
2007-12-27 02:07:44 +03:00
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
2005-08-24 00:01:54 +04:00
|
|
|
Bit8u *hostAddr = (Bit8u*) (hostPageAddr | pageOffset);
|
|
|
|
return hostAddr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-03 00:46:54 +03:00
|
|
|
Bit8u* BX_CPP_AttrRegparmN(2)
|
2008-08-03 23:53:09 +04:00
|
|
|
BX_CPU_C::v2h_write_byte(bx_address laddr, bx_bool user)
|
2005-08-24 00:01:54 +04:00
|
|
|
{
|
2007-12-27 02:07:44 +03:00
|
|
|
unsigned tlbIndex = BX_TLB_INDEX_OF(laddr, 0);
|
2005-08-24 00:01:54 +04:00
|
|
|
bx_address lpf = LPFOf(laddr);
|
|
|
|
bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlbIndex];
|
2007-11-11 23:44:07 +03:00
|
|
|
if (tlbEntry->lpf == lpf)
|
2005-08-24 00:01:54 +04:00
|
|
|
{
|
|
|
|
// See if the TLB entry privilege level allows us write access
|
|
|
|
// from this CPL.
|
2008-08-15 02:26:15 +04:00
|
|
|
if (! (tlbEntry->accessBits & (0x2 | user))) {
|
2005-08-24 00:01:54 +04:00
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
2007-12-27 02:07:44 +03:00
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
2005-08-24 00:01:54 +04:00
|
|
|
Bit8u *hostAddr = (Bit8u*) (hostPageAddr | pageOffset);
|
|
|
|
pageWriteStampTable.decWriteStamp(tlbEntry->ppf);
|
|
|
|
return hostAddr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|