2001-10-03 17:10:38 +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) 2005-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-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
|
|
|
|
2010-10-19 02:19:45 +04:00
|
|
|
bx_address bx_asize_mask[] = {
|
|
|
|
0xffff, // as16 (asize = '00)
|
|
|
|
0xffffffff, // as32 (asize = '01)
|
|
|
|
#if BX_SUPPORT_X86_64
|
|
|
|
BX_CONST64(0xffffffffffffffff), // as64 (asize = '10)
|
|
|
|
BX_CONST64(0xffffffffffffffff) // as64 (asize = '11)
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2013-08-04 23:37:04 +04:00
|
|
|
#if BX_SUPPORT_EVEX
|
|
|
|
#define BX_MAX_MEM_ACCESS_LENGTH 64
|
|
|
|
#else
|
|
|
|
#if BX_SUPPORT_AVX
|
|
|
|
#define BX_MAX_MEM_ACCESS_LENGTH 32
|
|
|
|
#else
|
|
|
|
#define BX_MAX_MEM_ACCESS_LENGTH 16
|
|
|
|
#endif
|
|
|
|
#endif
|
2013-07-26 16:50:56 +04:00
|
|
|
|
2015-01-26 22:09:58 +03:00
|
|
|
bx_bool BX_CPP_AttrRegparmN(4)
|
|
|
|
BX_CPU_C::write_virtual_checks(bx_segment_reg_t *seg, Bit32u offset, unsigned length, bx_bool align)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit32u upper_limit;
|
|
|
|
|
2015-01-26 22:09:58 +03:00
|
|
|
length--;
|
|
|
|
|
|
|
|
if (align) {
|
2017-03-18 10:32:17 +03:00
|
|
|
Bit32u laddr = (Bit32u)(seg->cache.u.segment.base + offset);
|
2015-01-28 19:49:46 +03:00
|
|
|
if (laddr & length) {
|
2015-01-26 22:16:51 +03:00
|
|
|
BX_DEBUG(("write_virtual_checks(): #GP misaligned access"));
|
2015-01-26 22:09:58 +03:00
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 */
|
2015-02-08 09:37:59 +03:00
|
|
|
if (seg->cache.u.segment.limit_scaled == 0xffffffff && seg->cache.u.segment.base == 0) {
|
|
|
|
seg->cache.valid |= SegAccessROK | SegAccessWOK | SegAccessROK4G | SegAccessWOK4G;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-13 23:41:10 +04:00
|
|
|
if (offset > (seg->cache.u.segment.limit_scaled - length)
|
|
|
|
|| length > 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
|
|
|
}
|
2013-07-26 16:50:56 +04:00
|
|
|
if (seg->cache.u.segment.limit_scaled >= (BX_MAX_MEM_ACCESS_LENGTH-1)) {
|
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;
|
2012-03-13 23:41:10 +04:00
|
|
|
if (offset <= seg->cache.u.segment.limit_scaled ||
|
|
|
|
offset > upper_limit || (upper_limit - offset) < length)
|
2008-05-27 01:46:39 +04:00
|
|
|
{
|
2015-01-26 23:52:03 +03:00
|
|
|
BX_ERROR(("write_virtual_checks(): write beyond limit, r/w expand down"));
|
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
|
|
|
}
|
|
|
|
|
2015-01-26 22:09:58 +03:00
|
|
|
bx_bool BX_CPP_AttrRegparmN(4)
|
|
|
|
BX_CPU_C::read_virtual_checks(bx_segment_reg_t *seg, Bit32u offset, unsigned length, bx_bool align)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit32u upper_limit;
|
|
|
|
|
2015-01-26 22:09:58 +03:00
|
|
|
length--;
|
|
|
|
|
|
|
|
if (align) {
|
2017-03-18 10:32:17 +03:00
|
|
|
Bit32u laddr = (Bit32u)(seg->cache.u.segment.base + offset);
|
2015-01-28 19:49:46 +03:00
|
|
|
if (laddr & length) {
|
2015-01-26 22:09:58 +03:00
|
|
|
BX_DEBUG(("read_virtual_checks(): #GP misaligned access"));
|
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 */
|
2015-01-26 23:52:03 +03:00
|
|
|
case 10: case 11: /* execute/read */
|
|
|
|
case 14: case 15: /* execute/read-only, conforming */
|
2015-02-08 09:37:59 +03:00
|
|
|
if (seg->cache.u.segment.limit_scaled == 0xffffffff && seg->cache.u.segment.base == 0) {
|
|
|
|
seg->cache.valid |= SegAccessROK | SegAccessROK4G;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-26 23:52:03 +03:00
|
|
|
if (offset > (seg->cache.u.segment.limit_scaled - length)
|
|
|
|
|| length > seg->cache.u.segment.limit_scaled)
|
|
|
|
{
|
|
|
|
BX_ERROR(("read_virtual_checks(): read beyond limit"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (seg->cache.u.segment.limit_scaled >= (BX_MAX_MEM_ACCESS_LENGTH-1)) {
|
|
|
|
// Mark cache as being OK type for succeeding reads. See notes for
|
|
|
|
// write checks; similar code.
|
|
|
|
seg->cache.valid |= SegAccessROK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
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;
|
2012-03-13 23:41:10 +04:00
|
|
|
if (offset <= seg->cache.u.segment.limit_scaled ||
|
|
|
|
offset > upper_limit || (upper_limit - offset) < length)
|
2008-05-27 01:46:39 +04:00
|
|
|
{
|
2015-01-26 23:52:03 +03:00
|
|
|
BX_ERROR(("read_virtual_checks(): read beyond limit expand down"));
|
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
|
|
|
|
2012-03-13 23:41:10 +04:00
|
|
|
length--;
|
|
|
|
|
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 */
|
2015-02-08 09:37:59 +03:00
|
|
|
if (seg->cache.u.segment.limit_scaled == 0xffffffff && seg->cache.u.segment.base == 0) {
|
|
|
|
seg->cache.valid |= SegAccessROK | SegAccessROK4G;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-13 23:41:10 +04:00
|
|
|
if (offset > (seg->cache.u.segment.limit_scaled - length)
|
|
|
|
|| length > seg->cache.u.segment.limit_scaled)
|
2008-05-27 01:46:39 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2013-07-26 16:50:56 +04:00
|
|
|
if (seg->cache.u.segment.limit_scaled >= (BX_MAX_MEM_ACCESS_LENGTH-1)) {
|
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 */
|
2012-03-13 23:41:10 +04:00
|
|
|
if (offset > (seg->cache.u.segment.limit_scaled - length)
|
|
|
|
|| length > seg->cache.u.segment.limit_scaled)
|
2008-05-27 01:46:39 +04:00
|
|
|
{
|
|
|
|
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;
|
2012-03-13 23:41:10 +04:00
|
|
|
if (offset <= seg->cache.u.segment.limit_scaled ||
|
|
|
|
offset > upper_limit || (upper_limit - offset) < length)
|
2008-05-27 01:46:39 +04:00
|
|
|
{
|
2015-01-26 23:52:03 +03:00
|
|
|
BX_ERROR(("execute_virtual_checks(): read beyond limit expand down"));
|
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;
|
|
|
|
|
|
|
|
bx_address lpf = LPFOf(laddr);
|
2015-09-22 23:10:22 +03:00
|
|
|
bx_TLB_entry *tlbEntry = BX_TLB_ENTRY_OF(laddr, 0);
|
2008-09-06 21:44:02 +04:00
|
|
|
if (tlbEntry->lpf == lpf) {
|
2013-01-16 21:28:20 +04:00
|
|
|
// See if the TLB entry privilege level allows us read access
|
|
|
|
// from this CPL.
|
|
|
|
if (tlbEntry->accessBits & 0x01) {
|
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
|
|
|
Bit8u *hostAddr = (Bit8u*) (hostPageAddr | pageOffset);
|
|
|
|
data = *hostAddr;
|
2015-02-19 23:23:08 +03:00
|
|
|
BX_NOTIFY_LIN_MEMORY_ACCESS(laddr, (tlbEntry->ppf | pageOffset), 1, tlbEntry->get_memtype(), BX_READ, (Bit8u*) &data);
|
2013-01-16 21:28:20 +04:00
|
|
|
return data;
|
|
|
|
}
|
2008-09-06 21:44:02 +04:00
|
|
|
}
|
|
|
|
|
2014-07-20 22:19:02 +04:00
|
|
|
if (access_read_linear(laddr, 1, 0, BX_READ, 0x0, (void *) &data) < 0)
|
2010-07-23 00:12:25 +04:00
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit16u BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::system_read_word(bx_address laddr)
|
|
|
|
{
|
|
|
|
Bit16u data;
|
|
|
|
|
|
|
|
bx_address lpf = LPFOf(laddr);
|
2015-09-22 23:10:22 +03:00
|
|
|
bx_TLB_entry *tlbEntry = BX_TLB_ENTRY_OF(laddr, 1);
|
2008-09-06 21:44:02 +04:00
|
|
|
if (tlbEntry->lpf == lpf) {
|
2013-01-16 21:28:20 +04:00
|
|
|
// See if the TLB entry privilege level allows us read access
|
|
|
|
// from this CPL.
|
|
|
|
if (tlbEntry->accessBits & 0x01) {
|
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
|
|
|
Bit16u *hostAddr = (Bit16u*) (hostPageAddr | pageOffset);
|
|
|
|
ReadHostWordFromLittleEndian(hostAddr, data);
|
2015-02-19 23:23:08 +03:00
|
|
|
BX_NOTIFY_LIN_MEMORY_ACCESS(laddr, (tlbEntry->ppf | pageOffset), 2, tlbEntry->get_memtype(), BX_READ, (Bit8u*) &data);
|
2013-01-16 21:28:20 +04:00
|
|
|
return data;
|
|
|
|
}
|
2008-09-06 21:44:02 +04:00
|
|
|
}
|
|
|
|
|
2014-07-03 10:40:42 +04:00
|
|
|
if (access_read_linear(laddr, 2, 0, BX_READ, 0x0, (void *) &data) < 0)
|
2013-12-22 01:56:55 +04:00
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit32u BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::system_read_dword(bx_address laddr)
|
|
|
|
{
|
|
|
|
Bit32u data;
|
|
|
|
|
|
|
|
bx_address lpf = LPFOf(laddr);
|
2015-09-22 23:10:22 +03:00
|
|
|
bx_TLB_entry *tlbEntry = BX_TLB_ENTRY_OF(laddr, 3);
|
2008-09-06 21:44:02 +04:00
|
|
|
if (tlbEntry->lpf == lpf) {
|
2013-01-16 21:28:20 +04:00
|
|
|
// See if the TLB entry privilege level allows us read access
|
|
|
|
// from this CPL.
|
|
|
|
if (tlbEntry->accessBits & 0x01) {
|
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
|
|
|
Bit32u *hostAddr = (Bit32u*) (hostPageAddr | pageOffset);
|
|
|
|
ReadHostDWordFromLittleEndian(hostAddr, data);
|
2015-02-19 23:23:08 +03:00
|
|
|
BX_NOTIFY_LIN_MEMORY_ACCESS(laddr, (tlbEntry->ppf | pageOffset), 4, tlbEntry->get_memtype(), BX_READ, (Bit8u*) &data);
|
2013-01-16 21:28:20 +04:00
|
|
|
return data;
|
|
|
|
}
|
2008-09-06 21:44:02 +04:00
|
|
|
}
|
|
|
|
|
2014-07-03 10:40:42 +04:00
|
|
|
if (access_read_linear(laddr, 4, 0, BX_READ, 0x0, (void *) &data) < 0)
|
2013-12-22 01:56:55 +04:00
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit64u BX_CPP_AttrRegparmN(1)
|
|
|
|
BX_CPU_C::system_read_qword(bx_address laddr)
|
|
|
|
{
|
|
|
|
Bit64u data;
|
|
|
|
|
|
|
|
bx_address lpf = LPFOf(laddr);
|
2015-09-22 23:10:22 +03:00
|
|
|
bx_TLB_entry *tlbEntry = BX_TLB_ENTRY_OF(laddr, 7);
|
2008-09-06 21:44:02 +04:00
|
|
|
if (tlbEntry->lpf == lpf) {
|
2013-01-16 21:28:20 +04:00
|
|
|
// See if the TLB entry privilege level allows us read access
|
|
|
|
// from this CPL.
|
|
|
|
if (tlbEntry->accessBits & 0x01) {
|
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
|
|
|
Bit64u *hostAddr = (Bit64u*) (hostPageAddr | pageOffset);
|
|
|
|
ReadHostQWordFromLittleEndian(hostAddr, data);
|
2015-02-19 23:23:08 +03:00
|
|
|
BX_NOTIFY_LIN_MEMORY_ACCESS(laddr, (tlbEntry->ppf | pageOffset), 8, tlbEntry->get_memtype(), BX_READ, (Bit8u*) &data);
|
2013-01-16 21:28:20 +04:00
|
|
|
return data;
|
|
|
|
}
|
2008-09-06 21:44:02 +04:00
|
|
|
}
|
|
|
|
|
2014-07-03 10:40:42 +04:00
|
|
|
if (access_read_linear(laddr, 8, 0, BX_READ, 0x0, (void *) &data) < 0)
|
2013-12-22 01:56:55 +04:00
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
|
|
|
|
2008-09-06 21:44:02 +04:00
|
|
|
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)
|
|
|
|
{
|
2017-03-18 10:32:17 +03:00
|
|
|
bx_address lpf = LPFOf(laddr);
|
2015-09-22 23:10:22 +03:00
|
|
|
bx_TLB_entry *tlbEntry = BX_TLB_ENTRY_OF(laddr, 0);
|
2009-10-08 22:07:50 +04:00
|
|
|
if (tlbEntry->lpf == lpf) {
|
|
|
|
// See if the TLB entry privilege level allows us write access
|
|
|
|
// from this CPL.
|
2016-03-02 23:44:42 +03:00
|
|
|
if (isWriteOK(tlbEntry, 0)) {
|
2009-10-08 22:07:50 +04:00
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
2011-01-04 19:17:20 +03:00
|
|
|
bx_phy_address pAddr = tlbEntry->ppf | pageOffset;
|
2015-02-19 23:23:08 +03:00
|
|
|
BX_NOTIFY_LIN_MEMORY_ACCESS(laddr, pAddr, 1, tlbEntry->get_memtype(), BX_WRITE, (Bit8u*) &data);
|
2009-10-08 22:07:50 +04:00
|
|
|
Bit8u *hostAddr = (Bit8u*) (hostPageAddr | pageOffset);
|
2011-01-04 19:17:20 +03:00
|
|
|
pageWriteStampTable.decWriteStamp(pAddr, 1);
|
2009-10-08 22:07:50 +04:00
|
|
|
*hostAddr = data;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-20 22:19:02 +04:00
|
|
|
if (access_write_linear(laddr, 1, 0, 0x0, (void *) &data) < 0)
|
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
2009-10-08 22:07:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BX_CPP_AttrRegparmN(2)
|
|
|
|
BX_CPU_C::system_write_word(bx_address laddr, Bit16u data)
|
|
|
|
{
|
2017-03-18 10:32:17 +03:00
|
|
|
bx_address lpf = LPFOf(laddr);
|
2015-09-22 23:10:22 +03:00
|
|
|
bx_TLB_entry *tlbEntry = BX_TLB_ENTRY_OF(laddr, 1);
|
2009-10-08 22:07:50 +04:00
|
|
|
if (tlbEntry->lpf == lpf) {
|
|
|
|
// See if the TLB entry privilege level allows us write access
|
|
|
|
// from this CPL.
|
2016-03-02 23:44:42 +03:00
|
|
|
if (isWriteOK(tlbEntry, 0)) {
|
2009-10-08 22:07:50 +04:00
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
2011-01-04 19:17:20 +03:00
|
|
|
bx_phy_address pAddr = tlbEntry->ppf | pageOffset;
|
2015-02-19 23:23:08 +03:00
|
|
|
BX_NOTIFY_LIN_MEMORY_ACCESS(laddr, pAddr, 2, tlbEntry->get_memtype(), BX_WRITE, (Bit8u*) &data);
|
2009-10-08 22:07:50 +04:00
|
|
|
Bit16u *hostAddr = (Bit16u*) (hostPageAddr | pageOffset);
|
2011-01-04 19:17:20 +03:00
|
|
|
pageWriteStampTable.decWriteStamp(pAddr, 2);
|
2009-10-08 22:07:50 +04:00
|
|
|
WriteHostWordToLittleEndian(hostAddr, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 10:40:42 +04:00
|
|
|
if (access_write_linear(laddr, 2, 0, 0x0, (void *) &data) < 0)
|
2013-12-22 01:56:55 +04:00
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
2009-10-08 22:07:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BX_CPP_AttrRegparmN(2)
|
|
|
|
BX_CPU_C::system_write_dword(bx_address laddr, Bit32u data)
|
|
|
|
{
|
2017-03-18 10:32:17 +03:00
|
|
|
bx_address lpf = LPFOf(laddr);
|
2015-09-22 23:10:22 +03:00
|
|
|
bx_TLB_entry *tlbEntry = BX_TLB_ENTRY_OF(laddr, 3);
|
2009-10-08 22:07:50 +04:00
|
|
|
if (tlbEntry->lpf == lpf) {
|
|
|
|
// See if the TLB entry privilege level allows us write access
|
|
|
|
// from this CPL.
|
2016-03-02 23:44:42 +03:00
|
|
|
if (isWriteOK(tlbEntry, 0)) {
|
2009-10-08 22:07:50 +04:00
|
|
|
bx_hostpageaddr_t hostPageAddr = tlbEntry->hostPageAddr;
|
|
|
|
Bit32u pageOffset = PAGE_OFFSET(laddr);
|
2011-01-04 19:17:20 +03:00
|
|
|
bx_phy_address pAddr = tlbEntry->ppf | pageOffset;
|
2015-02-19 23:23:08 +03:00
|
|
|
BX_NOTIFY_LIN_MEMORY_ACCESS(laddr, pAddr, 4, tlbEntry->get_memtype(), BX_WRITE, (Bit8u*) &data);
|
2009-10-08 22:07:50 +04:00
|
|
|
Bit32u *hostAddr = (Bit32u*) (hostPageAddr | pageOffset);
|
2011-01-04 19:17:20 +03:00
|
|
|
pageWriteStampTable.decWriteStamp(pAddr, 4);
|
2009-10-08 22:07:50 +04:00
|
|
|
WriteHostDWordToLittleEndian(hostAddr, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-03 10:40:42 +04:00
|
|
|
if (access_write_linear(laddr, 4, 0, 0x0, (void *) &data) < 0)
|
2013-12-22 01:56:55 +04:00
|
|
|
exception(BX_GP_EXCEPTION, 0);
|
2009-10-08 22:07:50 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
bx_address lpf = LPFOf(laddr);
|
2015-09-22 23:10:22 +03:00
|
|
|
bx_TLB_entry *tlbEntry = BX_TLB_ENTRY_OF(laddr, 0);
|
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.
|
2016-03-02 23:44:42 +03:00
|
|
|
if (isReadOK(tlbEntry, 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);
|
|
|
|
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
|
|
|
{
|
|
|
|
bx_address lpf = LPFOf(laddr);
|
2015-09-22 23:10:22 +03:00
|
|
|
bx_TLB_entry *tlbEntry = BX_TLB_ENTRY_OF(laddr, 0);
|
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.
|
2016-03-02 23:44:42 +03:00
|
|
|
if (isWriteOK(tlbEntry, 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;
|
|
|
|
}
|