2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2009-12-04 19:53:12 +03:00
|
|
|
// Copyright (C) 2001-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-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2008-04-17 18:39:33 +04:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "bochs.h"
|
|
|
|
#include "cpu/cpu.h"
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev/iodev.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_MEM_THIS
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-26 22:58:01 +04:00
|
|
|
//
|
|
|
|
// Memory map inside the 1st megabyte:
|
|
|
|
//
|
|
|
|
// 0x00000 - 0x7ffff DOS area (512K)
|
|
|
|
// 0x80000 - 0x9ffff Optional fixed memory hole (128K)
|
|
|
|
// 0xa0000 - 0xbffff Standard PCI/ISA Video Mem / SMMRAM (128K)
|
|
|
|
// 0xc0000 - 0xdffff Expansion Card BIOS and Buffer Area (128K)
|
|
|
|
// 0xe0000 - 0xeffff Lower BIOS Area (64K)
|
|
|
|
// 0xf0000 - 0xfffff Upper BIOS Area (64K)
|
|
|
|
//
|
|
|
|
|
2008-04-07 22:39:17 +04:00
|
|
|
void BX_MEM_C::writePhysicalPage(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, void *data)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit8u *data_ptr;
|
2006-03-28 20:53:02 +04:00
|
|
|
bx_phy_address a20addr = A20ADDR(addr);
|
2006-03-29 01:09:04 +04:00
|
|
|
struct memory_handler_struct *memory_handler = NULL;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
// Note: accesses should always be contained within a single page now
|
2008-04-17 18:39:33 +04:00
|
|
|
if ((addr>>12) != ((addr+len-1)>>12)) {
|
2008-05-10 02:33:37 +04:00
|
|
|
BX_PANIC(("writePhysicalPage: cross page access at address 0x" FMT_PHY_ADDRX ", len=%d", addr, len));
|
2008-04-17 18:39:33 +04:00
|
|
|
}
|
2006-03-06 22:23:13 +03:00
|
|
|
|
2008-05-02 00:46:00 +04:00
|
|
|
#if BX_SUPPORT_MONITOR_MWAIT
|
|
|
|
BX_MEM_THIS check_monitor(a20addr, len);
|
|
|
|
#endif
|
|
|
|
|
2009-10-17 22:42:15 +04:00
|
|
|
bx_bool is_bios = (a20addr >= (bx_phy_address)~BIOS_MASK);
|
|
|
|
#if BX_PHY_ADDRESS_LONG
|
|
|
|
if (a20addr > BX_CONST64(0xffffffff)) is_bios = 0;
|
|
|
|
#endif
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
if (cpu != NULL) {
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_IODEBUG
|
2008-12-30 21:11:13 +03:00
|
|
|
bx_devices.pluginIODebug->mem_write(cpu, a20addr, len, data);
|
2001-09-15 03:02:56 +04:00
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
BX_INSTR_PHY_WRITE(cpu->which_cpu(), a20addr, len);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-08-03 19:01:07 +04:00
|
|
|
if ((a20addr >= 0x000a0000 && a20addr < 0x000c0000) && BX_MEM_THIS smram_available)
|
2006-03-27 02:15:07 +04:00
|
|
|
{
|
|
|
|
// SMRAM memory space
|
|
|
|
if (BX_MEM_THIS smram_enable || (cpu->smm_mode() && !BX_MEM_THIS smram_restricted))
|
2006-03-26 22:58:01 +04:00
|
|
|
goto mem_write;
|
|
|
|
}
|
2006-03-06 22:23:13 +03:00
|
|
|
}
|
2006-03-03 02:16:13 +03:00
|
|
|
|
2006-09-02 16:08:28 +04:00
|
|
|
memory_handler = BX_MEM_THIS memory_handlers[a20addr >> 20];
|
2005-10-01 13:52:35 +04:00
|
|
|
while (memory_handler) {
|
2005-10-13 20:22:21 +04:00
|
|
|
if (memory_handler->begin <= a20addr &&
|
|
|
|
memory_handler->end >= a20addr &&
|
2006-02-27 22:04:01 +03:00
|
|
|
memory_handler->write_handler(a20addr, len, data, memory_handler->param))
|
2005-10-13 20:22:21 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memory_handler = memory_handler->next;
|
2005-10-01 13:52:35 +04:00
|
|
|
}
|
|
|
|
|
2006-03-26 22:58:01 +04:00
|
|
|
mem_write:
|
|
|
|
|
2009-08-03 19:01:07 +04:00
|
|
|
// all memory access fits in single 4K page
|
2009-10-17 22:42:15 +04:00
|
|
|
if (a20addr < BX_MEM_THIS len && ! is_bios) {
|
2001-04-10 05:04:59 +04:00
|
|
|
// all of data is within limits of physical memory
|
2009-08-03 19:01:07 +04:00
|
|
|
if (a20addr < 0x000a0000 || a20addr >= 0x00100000)
|
2006-03-26 22:58:01 +04:00
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
if (len == 8) {
|
2011-01-05 00:03:44 +03:00
|
|
|
pageWriteStampTable.decWriteStamp(a20addr, 8);
|
2008-04-17 18:39:33 +04:00
|
|
|
WriteHostQWordToLittleEndian(BX_MEM_THIS get_vector(a20addr), *(Bit64u*)data);
|
2006-03-03 15:55:37 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 4) {
|
2011-01-05 00:03:44 +03:00
|
|
|
pageWriteStampTable.decWriteStamp(a20addr, 4);
|
2008-04-17 18:39:33 +04:00
|
|
|
WriteHostDWordToLittleEndian(BX_MEM_THIS get_vector(a20addr), *(Bit32u*)data);
|
2002-09-22 22:22:24 +04:00
|
|
|
return;
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 2) {
|
2011-01-05 00:03:44 +03:00
|
|
|
pageWriteStampTable.decWriteStamp(a20addr, 2);
|
2008-04-17 18:39:33 +04:00
|
|
|
WriteHostWordToLittleEndian(BX_MEM_THIS get_vector(a20addr), *(Bit16u*)data);
|
2002-09-22 22:22:24 +04:00
|
|
|
return;
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 1) {
|
2011-01-05 00:03:44 +03:00
|
|
|
pageWriteStampTable.decWriteStamp(a20addr, 1);
|
2008-04-17 18:39:33 +04:00
|
|
|
* (BX_MEM_THIS get_vector(a20addr)) = * (Bit8u *) data;
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2002-09-22 22:22:24 +04:00
|
|
|
// len == other, just fall thru to special cases handling
|
2005-10-13 20:22:21 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2011-01-05 00:03:44 +03:00
|
|
|
pageWriteStampTable.decWriteStamp(a20addr);
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
2006-02-27 22:04:01 +03:00
|
|
|
data_ptr = (Bit8u *) data;
|
2001-04-10 05:04:59 +04:00
|
|
|
#else // BX_BIG_ENDIAN
|
2006-02-27 22:04:01 +03:00
|
|
|
data_ptr = (Bit8u *) data + (len - 1);
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
|
2009-08-03 19:01:07 +04:00
|
|
|
if (a20addr < 0x000a0000 || a20addr >= 0x00100000)
|
2006-03-26 22:58:01 +04:00
|
|
|
{
|
2009-08-03 19:01:07 +04:00
|
|
|
// addr *not* in range 000A0000 .. 000FFFFF
|
2008-05-03 03:18:51 +04:00
|
|
|
while(1) {
|
|
|
|
*(BX_MEM_THIS get_vector(a20addr)) = *data_ptr;
|
|
|
|
if (len == 1) return;
|
|
|
|
len--;
|
|
|
|
a20addr++;
|
2001-04-10 05:04:59 +04:00
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
2008-05-03 03:18:51 +04:00
|
|
|
data_ptr++;
|
2001-04-10 05:04:59 +04:00
|
|
|
#else // BX_BIG_ENDIAN
|
2008-05-03 03:18:51 +04:00
|
|
|
data_ptr--;
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2008-05-03 03:18:51 +04:00
|
|
|
}
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-26 22:58:01 +04:00
|
|
|
// addr must be in range 000A0000 .. 000FFFFF
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-05-03 03:18:51 +04:00
|
|
|
for(unsigned i=0; i<len; i++) {
|
|
|
|
|
|
|
|
// SMMRAM
|
2009-08-03 19:01:07 +04:00
|
|
|
if (a20addr < 0x000c0000) {
|
2008-05-03 03:18:51 +04:00
|
|
|
// devices are not allowed to access SMMRAM under VGA memory
|
|
|
|
if (cpu) {
|
|
|
|
*(BX_MEM_THIS get_vector(a20addr)) = *data_ptr;
|
|
|
|
}
|
|
|
|
goto inc_one;
|
2006-03-26 22:58:01 +04:00
|
|
|
}
|
|
|
|
|
2008-05-03 03:18:51 +04:00
|
|
|
// adapter ROM C0000 .. DFFFF
|
|
|
|
// ROM BIOS memory E0000 .. FFFFF
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_PCI == 0
|
2008-05-03 03:18:51 +04:00
|
|
|
// ignore write to ROM
|
2001-04-10 05:04:59 +04:00
|
|
|
#else
|
2008-05-03 03:18:51 +04:00
|
|
|
// Write Based on 440fx Programming
|
|
|
|
if (BX_MEM_THIS pci_enabled && ((a20addr & 0xfffc0000) == 0x000c0000))
|
|
|
|
{
|
2010-11-23 17:59:36 +03:00
|
|
|
switch (DEV_pci_wr_memtype((Bit32u) a20addr)) {
|
2008-05-03 03:18:51 +04:00
|
|
|
case 0x1: // Writes to ShadowRAM
|
2008-05-10 02:33:37 +04:00
|
|
|
BX_DEBUG(("Writing to ShadowRAM: address 0x" FMT_PHY_ADDRX ", data %02x", a20addr, *data_ptr));
|
2008-05-03 03:18:51 +04:00
|
|
|
*(BX_MEM_THIS get_vector(a20addr)) = *data_ptr;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0: // Writes to ROM, Inhibit
|
2008-05-10 02:33:37 +04:00
|
|
|
BX_DEBUG(("Write to ROM ignored: address 0x" FMT_PHY_ADDRX ", data %02x", a20addr, *data_ptr));
|
2008-05-03 03:18:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
BX_PANIC(("writePhysicalPage: default case"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-05-03 03:18:51 +04:00
|
|
|
inc_one:
|
|
|
|
a20addr++;
|
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
|
|
|
data_ptr++;
|
|
|
|
#else // BX_BIG_ENDIAN
|
|
|
|
data_ptr--;
|
|
|
|
#endif
|
2005-01-15 16:10:15 +03:00
|
|
|
|
2006-03-26 22:58:01 +04:00
|
|
|
}
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
else {
|
2006-03-26 22:58:01 +04:00
|
|
|
// access outside limits of physical memory, ignore
|
2008-05-10 02:33:37 +04:00
|
|
|
BX_DEBUG(("Write outside the limits of physical memory (0x"FMT_PHY_ADDRX") (ignore)", a20addr));
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2008-04-07 22:39:17 +04:00
|
|
|
void BX_MEM_C::readPhysicalPage(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, void *data)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit8u *data_ptr;
|
2006-03-28 20:53:02 +04:00
|
|
|
bx_phy_address a20addr = A20ADDR(addr);
|
2006-03-29 01:09:04 +04:00
|
|
|
struct memory_handler_struct *memory_handler = NULL;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
// Note: accesses should always be contained within a single page now
|
2008-04-17 18:39:33 +04:00
|
|
|
if ((addr>>12) != ((addr+len-1)>>12)) {
|
2008-05-10 02:33:37 +04:00
|
|
|
BX_PANIC(("readPhysicalPage: cross page access at address 0x" FMT_PHY_ADDRX ", len=%d", addr, len));
|
2008-04-17 18:39:33 +04:00
|
|
|
}
|
2006-03-06 22:23:13 +03:00
|
|
|
|
2009-10-17 22:42:15 +04:00
|
|
|
bx_bool is_bios = (a20addr >= (bx_phy_address)~BIOS_MASK);
|
|
|
|
#if BX_PHY_ADDRESS_LONG
|
|
|
|
if (a20addr > BX_CONST64(0xffffffff)) is_bios = 0;
|
|
|
|
#endif
|
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
if (cpu != NULL) {
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_IODEBUG
|
2008-12-30 21:11:13 +03:00
|
|
|
bx_devices.pluginIODebug->mem_read(cpu, a20addr, len, data);
|
2001-09-15 03:02:56 +04:00
|
|
|
#endif
|
2008-02-03 23:27:06 +03:00
|
|
|
|
2006-03-06 22:23:13 +03:00
|
|
|
BX_INSTR_PHY_READ(cpu->which_cpu(), a20addr, len);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-08-03 19:01:07 +04:00
|
|
|
if ((a20addr >= 0x000a0000 && a20addr < 0x000c0000) && BX_MEM_THIS smram_available)
|
2006-03-27 02:15:07 +04:00
|
|
|
{
|
|
|
|
// SMRAM memory space
|
|
|
|
if (BX_MEM_THIS smram_enable || (cpu->smm_mode() && !BX_MEM_THIS smram_restricted))
|
2006-03-26 22:58:01 +04:00
|
|
|
goto mem_read;
|
|
|
|
}
|
2006-03-06 22:23:13 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-09-02 16:08:28 +04:00
|
|
|
memory_handler = BX_MEM_THIS memory_handlers[a20addr >> 20];
|
2005-10-01 13:52:35 +04:00
|
|
|
while (memory_handler) {
|
2005-10-13 20:22:21 +04:00
|
|
|
if (memory_handler->begin <= a20addr &&
|
|
|
|
memory_handler->end >= a20addr &&
|
2006-02-27 22:04:01 +03:00
|
|
|
memory_handler->read_handler(a20addr, len, data, memory_handler->param))
|
2005-10-13 20:22:21 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memory_handler = memory_handler->next;
|
2005-10-01 13:52:35 +04:00
|
|
|
}
|
|
|
|
|
2006-03-26 22:58:01 +04:00
|
|
|
mem_read:
|
|
|
|
|
2009-11-29 20:24:29 +03:00
|
|
|
if (a20addr < BX_MEM_THIS len && ! is_bios) {
|
2001-04-10 05:04:59 +04:00
|
|
|
// all of data is within limits of physical memory
|
2009-08-03 19:01:07 +04:00
|
|
|
if (a20addr < 0x000a0000 || a20addr >= 0x00100000)
|
2006-03-26 22:58:01 +04:00
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
if (len == 8) {
|
2008-04-17 18:39:33 +04:00
|
|
|
ReadHostQWordFromLittleEndian(BX_MEM_THIS get_vector(a20addr), * (Bit64u*) data);
|
2006-03-03 15:55:37 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 4) {
|
2008-04-17 18:39:33 +04:00
|
|
|
ReadHostDWordFromLittleEndian(BX_MEM_THIS get_vector(a20addr), * (Bit32u*) data);
|
2002-09-22 22:22:24 +04:00
|
|
|
return;
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 2) {
|
2008-04-17 18:39:33 +04:00
|
|
|
ReadHostWordFromLittleEndian(BX_MEM_THIS get_vector(a20addr), * (Bit16u*) data);
|
2002-09-22 22:22:24 +04:00
|
|
|
return;
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 1) {
|
2008-04-17 18:39:33 +04:00
|
|
|
* (Bit8u *) data = * (BX_MEM_THIS get_vector(a20addr));
|
2001-04-10 05:04:59 +04:00
|
|
|
return;
|
|
|
|
}
|
2006-03-26 22:58:01 +04:00
|
|
|
// len == other case can just fall thru to special cases handling
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
|
|
|
data_ptr = (Bit8u *) data;
|
|
|
|
#else // BX_BIG_ENDIAN
|
|
|
|
data_ptr = (Bit8u *) data + (len - 1);
|
|
|
|
#endif
|
|
|
|
|
2009-08-03 19:01:07 +04:00
|
|
|
if (a20addr < 0x000a0000 || a20addr >= 0x00100000)
|
2006-03-26 22:58:01 +04:00
|
|
|
{
|
2009-08-03 19:01:07 +04:00
|
|
|
// addr *not* in range 000A0000 .. 000FFFFF
|
2008-05-03 03:18:51 +04:00
|
|
|
while(1) {
|
|
|
|
*data_ptr = *(BX_MEM_THIS get_vector(a20addr));
|
|
|
|
if (len == 1) return;
|
|
|
|
len--;
|
|
|
|
a20addr++;
|
2001-04-10 05:04:59 +04:00
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
2008-05-03 03:18:51 +04:00
|
|
|
data_ptr++;
|
2001-04-10 05:04:59 +04:00
|
|
|
#else // BX_BIG_ENDIAN
|
2008-05-03 03:18:51 +04:00
|
|
|
data_ptr--;
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2008-05-03 03:18:51 +04:00
|
|
|
}
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2006-03-26 22:58:01 +04:00
|
|
|
// addr must be in range 000A0000 .. 000FFFFF
|
|
|
|
|
2008-05-03 03:18:51 +04:00
|
|
|
for (unsigned i=0; i<len; i++) {
|
|
|
|
|
|
|
|
// SMMRAM
|
2009-08-03 19:01:07 +04:00
|
|
|
if (a20addr < 0x000c0000) {
|
2008-05-03 03:18:51 +04:00
|
|
|
// devices are not allowed to access SMMRAM under VGA memory
|
|
|
|
if (cpu) *data_ptr = *(BX_MEM_THIS get_vector(a20addr));
|
|
|
|
goto inc_one;
|
|
|
|
}
|
2006-03-26 22:58:01 +04:00
|
|
|
|
2004-11-11 23:55:29 +03:00
|
|
|
#if BX_SUPPORT_PCI
|
2008-05-03 03:18:51 +04:00
|
|
|
if (BX_MEM_THIS pci_enabled && ((a20addr & 0xfffc0000) == 0x000c0000))
|
|
|
|
{
|
2010-11-23 17:59:36 +03:00
|
|
|
switch (DEV_pci_rd_memtype((Bit32u) a20addr)) {
|
2008-05-03 03:18:51 +04:00
|
|
|
case 0x0: // Read from ROM
|
|
|
|
if ((a20addr & 0xfffe0000) == 0x000e0000) {
|
2010-05-18 11:44:37 +04:00
|
|
|
// last 128K of BIOS ROM mapped to 0xE0000-0xFFFFF
|
2010-05-18 12:54:01 +04:00
|
|
|
*data_ptr = BX_MEM_THIS rom[BIOS_MAP_LAST128K(a20addr)];
|
2008-05-03 03:18:51 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*data_ptr = BX_MEM_THIS rom[(a20addr & EXROM_MASK) + BIOSROMSZ];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x1: // Read from ShadowRAM
|
|
|
|
*data_ptr = *(BX_MEM_THIS get_vector(a20addr));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BX_PANIC(("readPhysicalPage: default case"));
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2008-05-03 03:18:51 +04:00
|
|
|
else
|
2004-11-11 23:55:29 +03:00
|
|
|
#endif // #if BX_SUPPORT_PCI
|
2008-05-03 03:18:51 +04:00
|
|
|
{
|
|
|
|
if ((a20addr & 0xfffc0000) != 0x000c0000) {
|
|
|
|
*data_ptr = *(BX_MEM_THIS get_vector(a20addr));
|
|
|
|
}
|
|
|
|
else if ((a20addr & 0xfffe0000) == 0x000e0000) {
|
2010-05-18 11:44:37 +04:00
|
|
|
// last 128K of BIOS ROM mapped to 0xE0000-0xFFFFF
|
2010-05-18 12:54:01 +04:00
|
|
|
*data_ptr = BX_MEM_THIS rom[BIOS_MAP_LAST128K(a20addr)];
|
2008-05-03 03:18:51 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*data_ptr = BX_MEM_THIS rom[(a20addr & EXROM_MASK) + BIOSROMSZ];
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2008-05-03 03:18:51 +04:00
|
|
|
|
|
|
|
inc_one:
|
|
|
|
a20addr++;
|
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
|
|
|
data_ptr++;
|
|
|
|
#else // BX_BIG_ENDIAN
|
|
|
|
data_ptr--;
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
2009-08-03 19:01:07 +04:00
|
|
|
else // access outside limits of physical memory
|
|
|
|
{
|
|
|
|
#if BX_PHY_ADDRESS_LONG
|
2009-08-11 19:56:09 +04:00
|
|
|
if (a20addr > BX_CONST64(0xffffffff)) {
|
2009-08-03 19:01:07 +04:00
|
|
|
memset(data, 0xFF, len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
|
|
|
data_ptr = (Bit8u *) data;
|
|
|
|
#else // BX_BIG_ENDIAN
|
|
|
|
data_ptr = (Bit8u *) data + (len - 1);
|
|
|
|
#endif
|
|
|
|
|
2009-08-03 19:01:07 +04:00
|
|
|
if (a20addr >= (bx_phy_address)~BIOS_MASK) {
|
|
|
|
for (unsigned i = 0; i < len; i++) {
|
2006-09-02 16:08:28 +04:00
|
|
|
*data_ptr = BX_MEM_THIS rom[a20addr & BIOS_MASK];
|
2009-08-03 19:01:07 +04:00
|
|
|
a20addr++;
|
2001-04-10 05:04:59 +04:00
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
2009-08-03 19:01:07 +04:00
|
|
|
data_ptr++;
|
2001-04-10 05:04:59 +04:00
|
|
|
#else // BX_BIG_ENDIAN
|
2009-08-03 19:01:07 +04:00
|
|
|
data_ptr--;
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2009-08-03 19:01:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
memset(data, 0xFF, len);
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|