2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2006-03-27 02:15:07 +04:00
|
|
|
// $Id: memory.cc,v 1.52 2006-03-26 22:15:07 sshwarts Exp $
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2001-04-10 06:20:02 +04:00
|
|
|
// Copyright (C) 2001 MandrakeSoft S.A.
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// MandrakeSoft S.A.
|
|
|
|
// 43, rue d'Aboukir
|
|
|
|
// 75002 Paris - France
|
|
|
|
// http://www.linux-mandrake.com/
|
|
|
|
// http://www.mandrakesoft.com/
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
#if BX_PROVIDE_CPU_MEMORY
|
|
|
|
|
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)
|
|
|
|
//
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(3)
|
Now, when you compile with --enable-guest2host-tlb, non-paged
mode uses the notion of the guest-to-host TLB. This has the
benefit of allowing more uniform and streamlined acceleration
code in access.cc which does not have to check if CR0.PG
is set, eliminating a few instructions per guest access.
Shaved just a little off execution time, as expected.
Also, access_linear now breaks accesses which span two pages,
into two calls the the physical memory routines, when paging
is off, just like it always has for paging on. Besides
being more uniform, this allows the physical memory access
routines to known the complete data item is contained
within a single physical page, and stop reapplying the
A20ADDR() macro to pointers as it increments them.
Perhaps things can be optimized a little more now there too...
I renamed the routines to {read,write}PhysicalPage() as
a reminder that these routines now operate on data
solely within one page.
I also added a little code so that the paging module is
notified when the A20 line is tweaked, so it can dump
whatever mappings it wants to.
2002-09-05 06:31:24 +04:00
|
|
|
BX_MEM_C::writePhysicalPage(BX_CPU_C *cpu, Bit32u addr, unsigned len, void *data)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit8u *data_ptr;
|
2006-03-03 15:55:37 +03:00
|
|
|
Bit32u a20addr = A20ADDR(addr);
|
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
|
|
|
|
|
|
|
|
if (cpu != NULL) {
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_IODEBUG
|
2006-03-06 22:23:13 +03:00
|
|
|
bx_iodebug_c::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
|
|
|
|
|
|
|
#if BX_DEBUGGER
|
2006-03-06 22:23:13 +03:00
|
|
|
// (mch) Check for physical write break points, TODO
|
|
|
|
// (bbd) Each breakpoint should have an associated CPU#, TODO
|
|
|
|
for (int i = 0; i < num_write_watchpoints; i++) {
|
|
|
|
if (write_watchpoint[i] == a20addr) {
|
|
|
|
BX_CPU(0)->watchpoint = a20addr;
|
|
|
|
BX_CPU(0)->break_point = BREAK_POINT_WRITE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
|
2006-03-03 02:16:13 +03:00
|
|
|
#if BX_SUPPORT_APIC
|
2006-03-06 22:23:13 +03:00
|
|
|
bx_generic_apic_c *local_apic = &cpu->local_apic;
|
2006-03-26 22:58:01 +04:00
|
|
|
if (local_apic->is_selected(a20addr, len)) {
|
2006-03-06 22:23:13 +03:00
|
|
|
local_apic->write(a20addr, (Bit32u *)data, len);
|
|
|
|
return;
|
|
|
|
}
|
2006-03-03 02:16:13 +03:00
|
|
|
#endif
|
2006-03-26 22:58:01 +04:00
|
|
|
|
2006-03-27 02:15:07 +04:00
|
|
|
if ((a20addr & 0xfffe0000) == 0x000a0000 && (BX_MEM_THIS smram_available))
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
2005-10-01 13:52:35 +04:00
|
|
|
struct memory_handler_struct *memory_handler = memory_handlers[a20addr >> 20];
|
|
|
|
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:
|
|
|
|
|
2006-02-27 22:04:01 +03:00
|
|
|
#if BX_SUPPORT_ICACHE
|
|
|
|
if (a20addr < BX_MEM_THIS len)
|
|
|
|
pageWriteStampTable.decWriteStamp(a20addr);
|
2005-01-15 16:10:15 +03:00
|
|
|
#endif
|
|
|
|
|
2006-03-26 22:58:01 +04:00
|
|
|
// all memory access feets in single 4K page
|
|
|
|
if (a20addr <= BX_MEM_THIS len) {
|
2001-04-10 05:04:59 +04:00
|
|
|
// all of data is within limits of physical memory
|
2006-03-26 22:58:01 +04:00
|
|
|
if ((a20addr & 0xfff80000) != 0x00080000 || (a20addr <= 0x0009ffff))
|
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
if (len == 8) {
|
|
|
|
WriteHostQWordToLittleEndian(&vector[a20addr], *(Bit64u*)data);
|
|
|
|
BX_DBG_DIRTY_PAGE(a20addr >> 12);
|
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 4) {
|
2002-09-22 22:22:24 +04:00
|
|
|
WriteHostDWordToLittleEndian(&vector[a20addr], *(Bit32u*)data);
|
|
|
|
BX_DBG_DIRTY_PAGE(a20addr >> 12);
|
|
|
|
return;
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 2) {
|
2002-09-22 22:22:24 +04:00
|
|
|
WriteHostWordToLittleEndian(&vector[a20addr], *(Bit16u*)data);
|
|
|
|
BX_DBG_DIRTY_PAGE(a20addr >> 12);
|
|
|
|
return;
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 1) {
|
2002-09-22 22:22:24 +04:00
|
|
|
* ((Bit8u *) (&vector[a20addr])) = * (Bit8u *) data;
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_DBG_DIRTY_PAGE(a20addr >> 12);
|
|
|
|
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
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
write_one:
|
2006-03-26 22:58:01 +04:00
|
|
|
if ((a20addr & 0xfff80000) != 0x00080000 || (a20addr <= 0x0009ffff))
|
|
|
|
{
|
|
|
|
// addr *not* in range 000A0000 .. 000FFFFF
|
2001-05-23 12:02:15 +04:00
|
|
|
vector[a20addr] = *data_ptr;
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_DBG_DIRTY_PAGE(a20addr >> 12);
|
|
|
|
inc_one:
|
|
|
|
if (len == 1) return;
|
|
|
|
len--;
|
2002-09-22 22:22:24 +04:00
|
|
|
a20addr++;
|
2001-04-10 05:04:59 +04:00
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
|
|
|
data_ptr++;
|
|
|
|
#else // BX_BIG_ENDIAN
|
|
|
|
data_ptr--;
|
|
|
|
#endif
|
|
|
|
goto write_one;
|
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
|
|
|
|
2006-03-26 22:58:01 +04:00
|
|
|
// SMMRAM
|
|
|
|
if (a20addr <= 0x000bffff) {
|
|
|
|
// devices are not allowed to access SMMRAM under VGA memory
|
|
|
|
if (cpu && cpu->smram_write(a20addr)) {
|
|
|
|
vector[a20addr] = *data_ptr;
|
|
|
|
BX_DBG_DIRTY_PAGE(a20addr >> 12);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
goto inc_one;
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2006-03-26 22:58:01 +04:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
// adapter ROM C0000 .. DFFFF
|
|
|
|
// ROM BIOS memory E0000 .. FFFFF
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_PCI == 0
|
2001-04-10 05:04:59 +04:00
|
|
|
// ignore write to ROM
|
|
|
|
#else
|
|
|
|
// Write Based on 440fx Programming
|
2006-02-20 00:35:50 +03:00
|
|
|
if (pci_enabled && ((a20addr & 0xfffc0000) == 0x000c0000))
|
2004-11-11 23:55:29 +03:00
|
|
|
{
|
2002-11-03 20:17:11 +03:00
|
|
|
switch (DEV_pci_wr_memtype(a20addr & 0xFC000)) {
|
2002-08-31 19:35:51 +04:00
|
|
|
case 0x1: // Writes to ShadowRAM
|
2004-08-26 11:58:33 +04:00
|
|
|
BX_DEBUG(("Writing to ShadowRAM: address %08x, data %02x", (unsigned) a20addr, *data_ptr));
|
2004-11-11 23:55:29 +03:00
|
|
|
vector[a20addr] = *data_ptr;
|
2001-04-10 05:04:59 +04:00
|
|
|
BX_DBG_DIRTY_PAGE(a20addr >> 12);
|
|
|
|
goto inc_one;
|
|
|
|
|
2002-08-31 19:35:51 +04:00
|
|
|
case 0x0: // Writes to ROM, Inhibit
|
2002-08-17 13:23:42 +04:00
|
|
|
BX_DEBUG(("Write to ROM ignored: address %08x, data %02x", (unsigned) a20addr, *data_ptr));
|
2001-04-10 05:04:59 +04:00
|
|
|
goto inc_one;
|
2005-01-15 16:10:15 +03:00
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
default:
|
Now, when you compile with --enable-guest2host-tlb, non-paged
mode uses the notion of the guest-to-host TLB. This has the
benefit of allowing more uniform and streamlined acceleration
code in access.cc which does not have to check if CR0.PG
is set, eliminating a few instructions per guest access.
Shaved just a little off execution time, as expected.
Also, access_linear now breaks accesses which span two pages,
into two calls the the physical memory routines, when paging
is off, just like it always has for paging on. Besides
being more uniform, this allows the physical memory access
routines to known the complete data item is contained
within a single physical page, and stop reapplying the
A20ADDR() macro to pointers as it increments them.
Perhaps things can be optimized a little more now there too...
I renamed the routines to {read,write}PhysicalPage() as
a reminder that these routines now operate on data
solely within one page.
I also added a little code so that the paging module is
notified when the A20 line is tweaked, so it can dump
whatever mappings it wants to.
2002-09-05 06:31:24 +04:00
|
|
|
BX_PANIC(("writePhysicalPage: default case"));
|
2001-04-10 05:04:59 +04:00
|
|
|
goto inc_one;
|
|
|
|
}
|
2006-03-26 22:58:01 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
goto inc_one;
|
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
|
|
|
|
BX_DEBUG(("Write outside the limits of physical memory (ignore)"));
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2003-03-03 02:59:12 +03:00
|
|
|
void BX_CPP_AttrRegparmN(3)
|
Now, when you compile with --enable-guest2host-tlb, non-paged
mode uses the notion of the guest-to-host TLB. This has the
benefit of allowing more uniform and streamlined acceleration
code in access.cc which does not have to check if CR0.PG
is set, eliminating a few instructions per guest access.
Shaved just a little off execution time, as expected.
Also, access_linear now breaks accesses which span two pages,
into two calls the the physical memory routines, when paging
is off, just like it always has for paging on. Besides
being more uniform, this allows the physical memory access
routines to known the complete data item is contained
within a single physical page, and stop reapplying the
A20ADDR() macro to pointers as it increments them.
Perhaps things can be optimized a little more now there too...
I renamed the routines to {read,write}PhysicalPage() as
a reminder that these routines now operate on data
solely within one page.
I also added a little code so that the paging module is
notified when the A20 line is tweaked, so it can dump
whatever mappings it wants to.
2002-09-05 06:31:24 +04:00
|
|
|
BX_MEM_C::readPhysicalPage(BX_CPU_C *cpu, Bit32u addr, unsigned len, void *data)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
Bit8u *data_ptr;
|
2006-03-03 15:55:37 +03:00
|
|
|
Bit32u a20addr = A20ADDR(addr);
|
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
|
|
|
|
|
|
|
|
if (cpu != NULL) {
|
2004-08-06 19:49:55 +04:00
|
|
|
#if BX_SUPPORT_IODEBUG
|
2006-03-06 22:23:13 +03:00
|
|
|
bx_iodebug_c::mem_read(cpu, a20addr, len, data);
|
2001-09-15 03:02:56 +04:00
|
|
|
#endif
|
2004-01-15 05:08:37 +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
|
|
|
|
|
|
|
#if BX_DEBUGGER
|
2006-03-06 22:23:13 +03:00
|
|
|
// (mch) Check for physical read break points, TODO
|
|
|
|
// (bbd) Each breakpoint should have an associated CPU#, TODO
|
|
|
|
for (int i = 0; i < num_read_watchpoints; i++) {
|
|
|
|
if (read_watchpoint[i] == a20addr) {
|
|
|
|
BX_CPU(0)->watchpoint = a20addr;
|
|
|
|
BX_CPU(0)->break_point = BREAK_POINT_READ;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
2006-03-03 02:16:13 +03:00
|
|
|
|
|
|
|
#if BX_SUPPORT_APIC
|
2006-03-06 22:23:13 +03:00
|
|
|
bx_generic_apic_c *local_apic = &cpu->local_apic;
|
|
|
|
if (local_apic->is_selected (a20addr, len)) {
|
|
|
|
local_apic->read(a20addr, data, len);
|
|
|
|
return;
|
|
|
|
}
|
2006-03-03 02:16:13 +03:00
|
|
|
#endif
|
2006-03-26 22:58:01 +04:00
|
|
|
|
2006-03-27 02:15:07 +04:00
|
|
|
if ((a20addr & 0xfffe0000) == 0x000a0000 && (BX_MEM_THIS smram_available))
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
2005-10-01 13:52:35 +04:00
|
|
|
struct memory_handler_struct *memory_handler = memory_handlers[a20addr >> 20];
|
|
|
|
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:
|
|
|
|
|
|
|
|
if (a20addr <= BX_MEM_THIS len) {
|
2001-04-10 05:04:59 +04:00
|
|
|
// all of data is within limits of physical memory
|
2006-03-26 22:58:01 +04:00
|
|
|
if ((a20addr & 0xfff80000) != 0x00080000 || (a20addr <= 0x0009ffff))
|
|
|
|
{
|
2006-03-03 15:55:37 +03:00
|
|
|
if (len == 8) {
|
|
|
|
ReadHostQWordFromLittleEndian(&vector[a20addr], * (Bit64u*) data);
|
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 4) {
|
2002-09-22 22:22:24 +04:00
|
|
|
ReadHostDWordFromLittleEndian(&vector[a20addr], * (Bit32u*) data);
|
|
|
|
return;
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 2) {
|
2002-09-22 22:22:24 +04:00
|
|
|
ReadHostWordFromLittleEndian(&vector[a20addr], * (Bit16u*) data);
|
|
|
|
return;
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
if (len == 1) {
|
2005-10-13 20:22:21 +04:00
|
|
|
* (Bit8u *) data = * ((Bit8u *) (&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
|
|
|
|
|
|
|
|
read_one:
|
2006-03-26 22:58:01 +04:00
|
|
|
if ((a20addr & 0xfff80000) != 0x00080000 || (a20addr <= 0x0009ffff))
|
|
|
|
{
|
2001-04-10 05:04:59 +04:00
|
|
|
// addr *not* in range 00080000 .. 000FFFFF
|
2001-05-23 12:02:15 +04:00
|
|
|
*data_ptr = vector[a20addr];
|
2001-04-10 05:04:59 +04:00
|
|
|
inc_one:
|
|
|
|
if (len == 1) return;
|
|
|
|
len--;
|
2002-09-22 22:22:24 +04:00
|
|
|
a20addr++;
|
2001-04-10 05:04:59 +04:00
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
|
|
|
data_ptr++;
|
|
|
|
#else // BX_BIG_ENDIAN
|
|
|
|
data_ptr--;
|
|
|
|
#endif
|
|
|
|
goto read_one;
|
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
|
|
|
|
|
|
|
|
// SMMRAM
|
|
|
|
if (a20addr <= 0x000bffff) {
|
|
|
|
// devices are not allowed to access SMMRAM under VGA memory
|
|
|
|
if (cpu) *data_ptr = vector[a20addr];
|
|
|
|
goto inc_one;
|
|
|
|
}
|
|
|
|
|
2004-11-11 23:55:29 +03:00
|
|
|
#if BX_SUPPORT_PCI
|
2006-02-20 00:35:50 +03:00
|
|
|
if (pci_enabled && ((a20addr & 0xfffc0000) == 0x000c0000))
|
2004-11-11 23:55:29 +03:00
|
|
|
{
|
|
|
|
switch (DEV_pci_rd_memtype (a20addr)) {
|
|
|
|
case 0x0: // Read from ROM
|
2005-10-12 21:11:44 +04:00
|
|
|
if ( (a20addr & 0xfffe0000) == 0x000e0000 )
|
|
|
|
{
|
|
|
|
*data_ptr = rom[a20addr & BIOS_MASK];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*data_ptr = rom[(a20addr & EXROM_MASK) + BIOSROMSZ];
|
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
goto inc_one;
|
|
|
|
case 0x1: // Read from ShadowRAM
|
|
|
|
*data_ptr = vector[a20addr];
|
|
|
|
goto inc_one;
|
|
|
|
default:
|
|
|
|
BX_PANIC(("readPhysicalPage: default case"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
goto inc_one;
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif // #if BX_SUPPORT_PCI
|
|
|
|
{
|
2006-03-26 22:58:01 +04:00
|
|
|
if ((a20addr & 0xfffc0000) != 0x000c0000) {
|
2005-10-12 21:11:44 +04:00
|
|
|
*data_ptr = vector[a20addr];
|
|
|
|
}
|
2006-03-26 22:58:01 +04:00
|
|
|
else if ((a20addr & 0xfffe0000) == 0x000e0000)
|
2005-10-12 21:11:44 +04:00
|
|
|
{
|
|
|
|
*data_ptr = rom[a20addr & BIOS_MASK];
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
else
|
|
|
|
{
|
2005-10-12 21:11:44 +04:00
|
|
|
*data_ptr = rom[(a20addr & EXROM_MASK) + BIOSROMSZ];
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
goto inc_one;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
|
|
|
else
|
2006-03-26 22:58:01 +04:00
|
|
|
{ // access outside limits of physical memory
|
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
|
|
|
|
|
2005-01-15 16:10:15 +03:00
|
|
|
for (unsigned i = 0; i < len; i++) {
|
2006-03-26 22:58:01 +04:00
|
|
|
if (a20addr >= (Bit32u)~BIOS_MASK)
|
2005-10-12 21:11:44 +04:00
|
|
|
*data_ptr = rom[a20addr & BIOS_MASK];
|
2001-04-10 05:04:59 +04:00
|
|
|
else
|
|
|
|
*data_ptr = 0xff;
|
|
|
|
addr++;
|
Now, when you compile with --enable-guest2host-tlb, non-paged
mode uses the notion of the guest-to-host TLB. This has the
benefit of allowing more uniform and streamlined acceleration
code in access.cc which does not have to check if CR0.PG
is set, eliminating a few instructions per guest access.
Shaved just a little off execution time, as expected.
Also, access_linear now breaks accesses which span two pages,
into two calls the the physical memory routines, when paging
is off, just like it always has for paging on. Besides
being more uniform, this allows the physical memory access
routines to known the complete data item is contained
within a single physical page, and stop reapplying the
A20ADDR() macro to pointers as it increments them.
Perhaps things can be optimized a little more now there too...
I renamed the routines to {read,write}PhysicalPage() as
a reminder that these routines now operate on data
solely within one page.
I also added a little code so that the paging module is
notified when the A20 line is tweaked, so it can dump
whatever mappings it wants to.
2002-09-05 06:31:24 +04:00
|
|
|
a20addr = (addr);
|
2001-04-10 05:04:59 +04:00
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
|
|
|
data_ptr++;
|
|
|
|
#else // BX_BIG_ENDIAN
|
|
|
|
data_ptr--;
|
|
|
|
#endif
|
|
|
|
}
|
2005-01-15 16:10:15 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // #if BX_PROVIDE_CPU_MEMORY
|