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
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2013-02-19 00:52:19 +04:00
|
|
|
// Copyright (C) 2001-2013 The Bochs Project
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
2004-01-15 05:08:37 +03:00
|
|
|
// I/O memory handlers API Copyright (C) 2003 by Frank Cornelis
|
|
|
|
//
|
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"
|
2010-02-26 17:18:19 +03:00
|
|
|
#include "param_names.h"
|
2006-03-07 01:03:16 +03:00
|
|
|
#include "cpu/cpu.h"
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev/iodev.h"
|
2001-05-23 12:02:15 +04:00
|
|
|
#define LOG_THIS BX_MEM(0)->
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2009-08-11 19:56:09 +04:00
|
|
|
// alignment of memory vector, must be a power of 2
|
2008-04-17 18:39:33 +04:00
|
|
|
#define BX_MEM_VECTOR_ALIGN 4096
|
2008-05-11 01:36:55 +04:00
|
|
|
#define BX_MEM_HANDLERS ((BX_CONST64(1) << BX_PHY_ADDRESS_WIDTH) >> 20) /* one per megabyte */
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2011-07-22 21:46:06 +04:00
|
|
|
#if BX_LARGE_RAMFILE
|
|
|
|
Bit8u* const BX_MEM_C::swapped_out = ((Bit8u*)NULL - sizeof(Bit8u));
|
|
|
|
#endif
|
|
|
|
|
2006-03-26 22:58:01 +04:00
|
|
|
BX_MEM_C::BX_MEM_C()
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2012-01-19 22:32:11 +04:00
|
|
|
put("memory", "MEM0");
|
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
|
|
|
|
2001-05-23 12:02:15 +04:00
|
|
|
vector = NULL;
|
2002-09-18 09:28:55 +04:00
|
|
|
actual_vector = NULL;
|
2009-10-16 21:10:36 +04:00
|
|
|
blocks = NULL;
|
2001-05-23 12:02:15 +04:00
|
|
|
len = 0;
|
2009-10-16 21:10:36 +04:00
|
|
|
used_blocks = 0;
|
2004-01-15 05:08:37 +03:00
|
|
|
|
|
|
|
memory_handlers = NULL;
|
2011-07-22 21:46:06 +04:00
|
|
|
|
|
|
|
#if BX_LARGE_RAMFILE
|
|
|
|
next_swapout_idx = 0;
|
|
|
|
overflow_file = NULL;
|
|
|
|
#endif
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2009-10-23 17:23:31 +04:00
|
|
|
Bit8u* BX_MEM_C::alloc_vector_aligned(Bit32u bytes, Bit32u alignment)
|
2002-09-04 06:11:33 +04:00
|
|
|
{
|
|
|
|
Bit64u test_mask = alignment - 1;
|
2009-10-23 17:23:31 +04:00
|
|
|
BX_MEM_THIS actual_vector = new Bit8u [(Bit32u)(bytes + test_mask)];
|
|
|
|
if (BX_MEM_THIS actual_vector == 0) {
|
|
|
|
BX_PANIC(("alloc_vector_aligned: unable to allocate host RAM !"));
|
|
|
|
return 0;
|
|
|
|
}
|
2008-02-03 23:27:06 +03:00
|
|
|
// round address forward to nearest multiple of alignment. Alignment
|
2002-09-04 06:11:33 +04:00
|
|
|
// MUST BE a power of two for this to work.
|
2009-10-23 17:23:31 +04:00
|
|
|
Bit64u masked = ((Bit64u)(BX_MEM_THIS actual_vector + test_mask)) & ~test_mask;
|
2008-04-17 18:39:33 +04:00
|
|
|
Bit8u *vector = (Bit8u *) masked;
|
2002-09-04 06:11:33 +04:00
|
|
|
// sanity check: no lost bits during pointer conversion
|
2009-10-23 17:23:31 +04:00
|
|
|
assert(sizeof(masked) >= sizeof(vector));
|
2002-09-04 06:11:33 +04:00
|
|
|
// sanity check: after realignment, everything fits in allocated space
|
2009-10-23 17:23:31 +04:00
|
|
|
assert(vector+bytes <= BX_MEM_THIS actual_vector+bytes+test_mask);
|
2008-04-17 18:39:33 +04:00
|
|
|
return vector;
|
2002-09-04 06:11:33 +04:00
|
|
|
}
|
|
|
|
|
2006-03-26 22:58:01 +04:00
|
|
|
BX_MEM_C::~BX_MEM_C()
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2011-07-22 21:46:06 +04:00
|
|
|
#if BX_LARGE_RAMFILE
|
|
|
|
if (overflow_file)
|
|
|
|
fclose(BX_MEM_THIS overflow_file);
|
|
|
|
#endif
|
|
|
|
|
2006-09-15 21:02:52 +04:00
|
|
|
cleanup_memory();
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2009-10-16 21:10:36 +04:00
|
|
|
void BX_MEM_C::init_memory(Bit64u guest, Bit64u host)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2013-02-19 00:52:19 +04:00
|
|
|
unsigned i, idx;
|
2004-09-01 22:12:23 +04:00
|
|
|
|
2011-02-25 01:05:47 +03:00
|
|
|
BX_DEBUG(("Init $Id$"));
|
2009-10-16 21:10:36 +04:00
|
|
|
|
|
|
|
// accept only memory size which is multiply of 1M
|
|
|
|
BX_ASSERT((host & 0xfffff) == 0);
|
|
|
|
BX_ASSERT((guest & 0xfffff) == 0);
|
2008-04-17 18:39:33 +04:00
|
|
|
|
|
|
|
if (BX_MEM_THIS actual_vector != NULL) {
|
2009-10-16 21:10:36 +04:00
|
|
|
BX_INFO(("freeing existing memory vector"));
|
2008-04-17 18:39:33 +04:00
|
|
|
delete [] BX_MEM_THIS actual_vector;
|
|
|
|
BX_MEM_THIS actual_vector = NULL;
|
|
|
|
BX_MEM_THIS vector = NULL;
|
2009-10-16 21:10:36 +04:00
|
|
|
BX_MEM_THIS blocks = NULL;
|
2008-04-17 18:39:33 +04:00
|
|
|
}
|
2009-10-23 17:23:31 +04:00
|
|
|
BX_MEM_THIS vector = alloc_vector_aligned(host + BIOSROMSZ + EXROMSIZE + 4096, BX_MEM_VECTOR_ALIGN);
|
2009-10-16 21:10:36 +04:00
|
|
|
BX_INFO(("allocated memory at %p. after alignment, vector=%p",
|
2011-07-22 21:46:06 +04:00
|
|
|
BX_MEM_THIS actual_vector, BX_MEM_THIS vector));
|
2006-09-01 22:14:13 +04:00
|
|
|
|
2009-10-16 21:10:36 +04:00
|
|
|
BX_MEM_THIS len = guest;
|
|
|
|
BX_MEM_THIS allocated = host;
|
|
|
|
BX_MEM_THIS rom = &BX_MEM_THIS vector[host];
|
|
|
|
BX_MEM_THIS bogus = &BX_MEM_THIS vector[host + BIOSROMSZ + EXROMSIZE];
|
2008-04-18 00:20:43 +04:00
|
|
|
memset(BX_MEM_THIS rom, 0xff, BIOSROMSZ + EXROMSIZE + 4096);
|
2009-10-16 21:10:36 +04:00
|
|
|
|
|
|
|
// block must be large enough to fit num_blocks in 32-bit
|
|
|
|
BX_ASSERT((BX_MEM_THIS len / BX_MEM_BLOCK_LEN) <= 0xffffffff);
|
|
|
|
|
2010-08-15 23:57:50 +04:00
|
|
|
Bit32u num_blocks = (Bit32u)(BX_MEM_THIS len / BX_MEM_BLOCK_LEN);
|
2009-10-16 21:10:36 +04:00
|
|
|
BX_INFO(("%.2fMB", (float)(BX_MEM_THIS len / (1024.0*1024.0))));
|
|
|
|
BX_INFO(("mem block size = 0x%08x, blocks=%u", BX_MEM_BLOCK_LEN, num_blocks));
|
|
|
|
BX_MEM_THIS blocks = new Bit8u* [num_blocks];
|
|
|
|
if (0) {
|
|
|
|
// all guest memory is allocated, just map it
|
|
|
|
for (idx = 0; idx < num_blocks; idx++) {
|
|
|
|
BX_MEM_THIS blocks[idx] = BX_MEM_THIS vector + (idx * BX_MEM_BLOCK_LEN);
|
|
|
|
}
|
|
|
|
BX_MEM_THIS used_blocks = num_blocks;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// host cannot allocate all requested guest memory
|
|
|
|
for (idx = 0; idx < num_blocks; idx++) {
|
|
|
|
BX_MEM_THIS blocks[idx] = NULL;
|
|
|
|
}
|
|
|
|
BX_MEM_THIS used_blocks = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_MEM_THIS memory_handlers = new struct memory_handler_struct *[BX_MEM_HANDLERS];
|
|
|
|
for (idx = 0; idx < BX_MEM_HANDLERS; idx++)
|
|
|
|
BX_MEM_THIS memory_handlers[idx] = NULL;
|
|
|
|
|
2012-11-11 12:11:17 +04:00
|
|
|
BX_MEM_THIS pci_enabled = SIM->get_param_bool(BXPN_PCI_ENABLED)->get();
|
2012-12-02 23:59:23 +04:00
|
|
|
BX_MEM_THIS bios_write_enabled = 0;
|
2006-03-27 02:15:07 +04:00
|
|
|
BX_MEM_THIS smram_available = 0;
|
|
|
|
BX_MEM_THIS smram_enable = 0;
|
|
|
|
BX_MEM_THIS smram_restricted = 0;
|
2002-08-31 16:24:41 +04:00
|
|
|
|
2013-02-19 00:52:19 +04:00
|
|
|
for (i = 0; i < 65; i++)
|
|
|
|
BX_MEM_THIS rom_present[i] = 0;
|
|
|
|
for (i = 0; i <= BX_MEM_AREA_F0000; i++) {
|
|
|
|
BX_MEM_THIS memory_type[i][0] = 0;
|
|
|
|
BX_MEM_THIS memory_type[i][1] = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-16 21:10:36 +04:00
|
|
|
BX_MEM_THIS register_state();
|
|
|
|
}
|
|
|
|
|
2011-07-22 21:46:06 +04:00
|
|
|
#if BX_LARGE_RAMFILE
|
|
|
|
void BX_MEM_C::read_block(Bit32u block)
|
|
|
|
{
|
|
|
|
const Bit64u block_address = ((Bit64u)block)*BX_MEM_BLOCK_LEN;
|
|
|
|
|
|
|
|
if (fseeko64(BX_MEM_THIS overflow_file, block_address, SEEK_SET))
|
|
|
|
BX_PANIC(("FATAL ERROR: Could not seek to 0x%lx in memory overflow file!", block_address));
|
|
|
|
|
|
|
|
// We could legitimately get an EOF condition if we are reading the last bit of memory.ram
|
|
|
|
if ((fread(BX_MEM_THIS blocks[block], BX_MEM_BLOCK_LEN, 1, BX_MEM_THIS overflow_file) != 1) &&
|
|
|
|
(!feof(BX_MEM_THIS overflow_file)))
|
|
|
|
BX_PANIC(("FATAL ERROR: Could not read from 0x%lx in memory overflow file!", block_address));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-10-16 21:10:36 +04:00
|
|
|
void BX_MEM_C::allocate_block(Bit32u block)
|
|
|
|
{
|
2011-07-22 21:46:06 +04:00
|
|
|
const Bit32u max_blocks = BX_MEM_THIS allocated / BX_MEM_BLOCK_LEN;
|
|
|
|
|
|
|
|
#if BX_LARGE_RAMFILE
|
|
|
|
/*
|
|
|
|
* Match block to vector address
|
|
|
|
* First, see if there is any spare host memory blocks we can still freely allocate
|
|
|
|
*/
|
|
|
|
if (BX_MEM_THIS used_blocks >= max_blocks) {
|
|
|
|
Bit32u original_replacement_block = BX_MEM_THIS next_swapout_idx;
|
|
|
|
// Find a block to replace
|
|
|
|
bx_bool used_for_tlb;
|
|
|
|
Bit8u *buffer;
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
// Wrap if necessary
|
|
|
|
if (++(BX_MEM_THIS next_swapout_idx)==((BX_MEM_THIS len)/BX_MEM_BLOCK_LEN))
|
|
|
|
BX_MEM_THIS next_swapout_idx = 0;
|
|
|
|
if (BX_MEM_THIS next_swapout_idx == original_replacement_block)
|
|
|
|
BX_PANIC(("FATAL ERROR: Insufficient working RAM, all blocks are currently used for TLB entries!"));
|
|
|
|
buffer = BX_MEM_THIS blocks[BX_MEM_THIS next_swapout_idx];
|
|
|
|
} while ((!buffer) || (buffer == BX_MEM_C::swapped_out));
|
|
|
|
|
|
|
|
used_for_tlb = false;
|
|
|
|
// tlb buffer check loop
|
|
|
|
const Bit8u* buffer_end = buffer+BX_MEM_BLOCK_LEN;
|
|
|
|
// Don't replace it if any CPU is using it as a TLB entry
|
|
|
|
for (int i=0; i<BX_SMP_PROCESSORS && !used_for_tlb;i++)
|
|
|
|
used_for_tlb = BX_CPU(i)->check_addr_in_tlb_buffers(buffer, buffer_end);
|
|
|
|
} while (used_for_tlb);
|
|
|
|
// Flush the block to be replaced
|
|
|
|
bx_phy_address address = ((bx_phy_address)BX_MEM_THIS next_swapout_idx)*BX_MEM_BLOCK_LEN;
|
|
|
|
// Create overflow file if it does not currently exist.
|
|
|
|
if (!BX_MEM_THIS overflow_file) {
|
2011-10-15 23:29:42 +04:00
|
|
|
BX_MEM_THIS overflow_file = tmpfile64();
|
2011-07-22 21:46:06 +04:00
|
|
|
if (!BX_MEM_THIS overflow_file)
|
|
|
|
BX_PANIC(("Unable to allocate memory overflow file"));
|
|
|
|
}
|
|
|
|
// Write swapped out block
|
|
|
|
if (fseeko64(BX_MEM_THIS overflow_file, address, SEEK_SET))
|
2012-09-23 23:09:20 +04:00
|
|
|
BX_PANIC(("FATAL ERROR: Could not seek to 0x" FMT_PHY_ADDRX " in overflow file!", address));
|
2011-07-22 21:46:06 +04:00
|
|
|
if (1 != fwrite (BX_MEM_THIS blocks[BX_MEM_THIS next_swapout_idx], BX_MEM_BLOCK_LEN, 1, BX_MEM_THIS overflow_file))
|
2012-09-23 23:09:20 +04:00
|
|
|
BX_PANIC(("FATAL ERROR: Could not write at 0x" FMT_PHY_ADDRX " in overflow file!", address));
|
2011-07-22 21:46:06 +04:00
|
|
|
// Mark swapped out block
|
|
|
|
BX_MEM_THIS blocks[BX_MEM_THIS next_swapout_idx] = BX_MEM_C::swapped_out;
|
|
|
|
BX_MEM_THIS blocks[block] = buffer;
|
|
|
|
read_block(block);
|
2013-12-24 18:59:00 +04:00
|
|
|
BX_DEBUG(("allocate_block: block=0x%x, replaced 0x%x", block, BX_MEM_THIS next_swapout_idx));
|
2011-07-22 21:46:06 +04:00
|
|
|
}
|
|
|
|
else {
|
2013-12-24 18:59:00 +04:00
|
|
|
BX_MEM_THIS blocks[block] = BX_MEM_THIS vector + (BX_MEM_THIS used_blocks++ * BX_MEM_BLOCK_LEN);
|
|
|
|
BX_DEBUG(("allocate_block: block=0x%x used 0x%x of 0x%x",
|
2011-07-22 21:46:06 +04:00
|
|
|
block, BX_MEM_THIS used_blocks, max_blocks));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
// Legacy default allocator
|
2009-10-23 12:50:07 +04:00
|
|
|
if (BX_MEM_THIS used_blocks >= max_blocks) {
|
2009-10-16 21:10:36 +04:00
|
|
|
BX_PANIC(("FATAL ERROR: all available memory is already allocated !"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BX_MEM_THIS blocks[block] = BX_MEM_THIS vector + (BX_MEM_THIS used_blocks * BX_MEM_BLOCK_LEN);
|
|
|
|
BX_MEM_THIS used_blocks++;
|
|
|
|
}
|
2011-07-29 12:16:28 +04:00
|
|
|
BX_DEBUG(("allocate_block: used_blocks=0x%x of 0x%x", BX_MEM_THIS used_blocks, max_blocks));
|
2011-07-22 21:46:06 +04:00
|
|
|
#endif
|
2009-10-16 21:10:36 +04:00
|
|
|
}
|
|
|
|
|
2011-07-22 21:46:06 +04:00
|
|
|
#if BX_LARGE_RAMFILE
|
|
|
|
// The blocks in RAM must also be flushed to the save file.
|
|
|
|
void ramfile_save_handler(void *devptr, FILE *fp)
|
|
|
|
{
|
|
|
|
for (Bit32u idx = 0; idx < (BX_MEM(0)->len / BX_MEM_BLOCK_LEN); idx++) {
|
|
|
|
if ((BX_MEM(0)->blocks[idx]) && (BX_MEM(0)->blocks[idx] != BX_MEM(0)->swapped_out))
|
|
|
|
{
|
|
|
|
bx_phy_address address = ((bx_phy_address)idx)*BX_MEM_BLOCK_LEN;
|
|
|
|
if (fseeko64(fp, address, SEEK_SET))
|
2012-09-23 23:09:20 +04:00
|
|
|
BX_PANIC(("FATAL ERROR: Could not seek to 0x" FMT_PHY_ADDRX " in overflow file!", address));
|
2011-07-22 21:46:06 +04:00
|
|
|
if (1 != fwrite (BX_MEM(0)->blocks[idx], BX_MEM_BLOCK_LEN, 1, fp))
|
2012-09-23 23:09:20 +04:00
|
|
|
BX_PANIC(("FATAL ERROR: Could not write at 0x" FMT_PHY_ADDRX " in overflow file!", address));
|
2011-07-22 21:46:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Note: This must be called before the memory file save handler is called.
|
2009-10-16 22:29:45 +04:00
|
|
|
Bit64s memory_param_save_handler(void *devptr, bx_param_c *param)
|
2009-10-16 21:10:36 +04:00
|
|
|
{
|
|
|
|
const char *pname = param->get_name();
|
|
|
|
if (! strncmp(pname, "blk", 3)) {
|
2011-07-22 21:46:06 +04:00
|
|
|
Bit32u blk_index = atoi(pname + 3);
|
|
|
|
if (! BX_MEM(0)->blocks[blk_index])
|
|
|
|
return -1;
|
|
|
|
#if BX_LARGE_RAMFILE
|
|
|
|
// If swapped out, will be saved by common handler.
|
|
|
|
if (BX_MEM(0)->blocks[blk_index] == BX_MEM(0)->swapped_out)
|
|
|
|
return -2;
|
|
|
|
#endif
|
|
|
|
// Return the block offset into the array
|
|
|
|
Bit32u val = (Bit32u) (BX_MEM(0)->blocks[blk_index] - BX_MEM(0)->vector);
|
|
|
|
if ((val & (BX_MEM_BLOCK_LEN-1)) == 0)
|
|
|
|
return val / BX_MEM_BLOCK_LEN;
|
2009-10-16 21:10:36 +04:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-10-16 22:29:45 +04:00
|
|
|
void memory_param_restore_handler(void *devptr, bx_param_c *param, Bit64s val)
|
2009-10-16 21:10:36 +04:00
|
|
|
{
|
|
|
|
const char *pname = param->get_name();
|
|
|
|
if (! strncmp(pname, "blk", 3)) {
|
2011-07-22 21:46:06 +04:00
|
|
|
Bit32u blk_index = atoi(pname + 3);
|
|
|
|
#if BX_LARGE_RAMFILE
|
|
|
|
if ((Bit32s) val == -2) {
|
|
|
|
BX_MEM(0)->blocks[blk_index] = BX_MEM(0)->swapped_out;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if((Bit32s) val < 0) {
|
2009-10-16 21:10:36 +04:00
|
|
|
BX_MEM(0)->blocks[blk_index] = NULL;
|
2011-07-22 21:46:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
BX_MEM(0)->blocks[blk_index] = BX_MEM(0)->vector + val * BX_MEM_BLOCK_LEN;
|
|
|
|
#if BX_LARGE_RAMFILE
|
|
|
|
BX_MEM(0)->read_block(blk_index);
|
|
|
|
#endif
|
2009-10-16 21:10:36 +04:00
|
|
|
}
|
2007-09-28 23:52:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BX_MEM_C::register_state()
|
|
|
|
{
|
2012-01-19 22:32:11 +04:00
|
|
|
char param_name[15];
|
|
|
|
|
2012-02-12 22:43:20 +04:00
|
|
|
bx_list_c *list = new bx_list_c(SIM->get_bochs_root(), "memory", "Memory State");
|
2011-07-22 21:46:06 +04:00
|
|
|
Bit32u num_blocks = BX_MEM_THIS len / BX_MEM_BLOCK_LEN;
|
|
|
|
#if BX_LARGE_RAMFILE
|
|
|
|
bx_shadow_filedata_c *ramfile = new bx_shadow_filedata_c(list, "ram", &(BX_MEM_THIS overflow_file));
|
|
|
|
ramfile->set_sr_handlers(this, ramfile_save_handler, (filedata_restore_handler)NULL);
|
|
|
|
#else
|
2009-10-16 21:10:36 +04:00
|
|
|
new bx_shadow_data_c(list, "ram", BX_MEM_THIS vector, BX_MEM_THIS allocated);
|
2011-07-22 21:46:06 +04:00
|
|
|
#endif
|
2007-11-01 21:03:48 +03:00
|
|
|
BXRS_DEC_PARAM_FIELD(list, len, BX_MEM_THIS len);
|
2009-10-16 21:10:36 +04:00
|
|
|
BXRS_DEC_PARAM_FIELD(list, allocated, BX_MEM_THIS allocated);
|
|
|
|
BXRS_DEC_PARAM_FIELD(list, used_blocks, BX_MEM_THIS used_blocks);
|
|
|
|
|
2012-02-12 22:43:20 +04:00
|
|
|
bx_list_c *mapping = new bx_list_c(list, "mapping");
|
2009-10-16 21:10:36 +04:00
|
|
|
for (Bit32u blk=0; blk < num_blocks; blk++) {
|
|
|
|
sprintf(param_name, "blk%d", blk);
|
|
|
|
bx_param_num_c *param = new bx_param_num_c(mapping, param_name, "", "", 0, BX_MAX_BIT32U, 0);
|
|
|
|
param->set_base(BASE_DEC);
|
|
|
|
param->set_sr_handlers(this, memory_param_save_handler, memory_param_restore_handler);
|
|
|
|
}
|
2012-02-12 22:43:20 +04:00
|
|
|
bx_list_c *memtype = new bx_list_c(list, "memtype");
|
2012-01-19 22:32:11 +04:00
|
|
|
for (int i = 0; i <= BX_MEM_AREA_F0000; i++) {
|
|
|
|
sprintf(param_name, "%d_r", i);
|
|
|
|
new bx_shadow_bool_c(memtype, param_name, &BX_MEM_THIS memory_type[i][0]);
|
|
|
|
sprintf(param_name, "%d_w", i);
|
|
|
|
new bx_shadow_bool_c(memtype, param_name, &BX_MEM_THIS memory_type[i][1]);
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
|
2006-09-15 21:02:52 +04:00
|
|
|
void BX_MEM_C::cleanup_memory()
|
|
|
|
{
|
|
|
|
unsigned idx;
|
|
|
|
|
|
|
|
if (BX_MEM_THIS vector != NULL) {
|
|
|
|
delete [] BX_MEM_THIS actual_vector;
|
|
|
|
BX_MEM_THIS actual_vector = NULL;
|
|
|
|
BX_MEM_THIS vector = NULL;
|
2009-08-03 19:01:07 +04:00
|
|
|
BX_MEM_THIS rom = NULL;
|
|
|
|
BX_MEM_THIS bogus = NULL;
|
2009-10-16 21:21:49 +04:00
|
|
|
delete [] BX_MEM_THIS blocks;
|
|
|
|
BX_MEM_THIS blocks = 0;
|
|
|
|
BX_MEM_THIS used_blocks = 0;
|
2006-09-15 21:02:52 +04:00
|
|
|
if (BX_MEM_THIS memory_handlers != NULL) {
|
2008-05-02 00:28:36 +04:00
|
|
|
for (idx = 0; idx < BX_MEM_HANDLERS; idx++) {
|
2006-09-15 21:02:52 +04:00
|
|
|
struct memory_handler_struct *memory_handler = BX_MEM_THIS memory_handlers[idx];
|
|
|
|
struct memory_handler_struct *prev = NULL;
|
|
|
|
while (memory_handler) {
|
|
|
|
prev = memory_handler;
|
|
|
|
memory_handler = memory_handler->next;
|
|
|
|
delete prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete [] BX_MEM_THIS memory_handlers;
|
|
|
|
BX_MEM_THIS memory_handlers = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-21 22:20:40 +04:00
|
|
|
//
|
|
|
|
// Values for type:
|
|
|
|
// 0 : System Bios
|
|
|
|
// 1 : VGA Bios
|
|
|
|
// 2 : Optional ROM Bios
|
|
|
|
//
|
2006-03-28 20:53:02 +04:00
|
|
|
void BX_MEM_C::load_ROM(const char *path, bx_phy_address romaddress, Bit8u type)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
struct stat stat_buf;
|
2004-09-01 22:12:23 +04:00
|
|
|
int fd, ret, i, start_idx, end_idx;
|
2004-08-26 11:58:33 +04:00
|
|
|
unsigned long size, max_size, offset;
|
2005-12-19 23:48:51 +03:00
|
|
|
bx_bool is_bochs_bios = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2003-04-02 21:03:34 +04:00
|
|
|
if (*path == '\0') {
|
2003-08-05 17:19:35 +04:00
|
|
|
if (type == 2) {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PANIC(("ROM: Optional ROM image undefined"));
|
2005-11-27 22:40:56 +03:00
|
|
|
}
|
2003-08-05 17:19:35 +04:00
|
|
|
else if (type == 1) {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PANIC(("ROM: VGA BIOS image undefined"));
|
2005-11-27 22:40:56 +03:00
|
|
|
}
|
2003-08-05 17:19:35 +04:00
|
|
|
else {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PANIC(("ROM: System BIOS image undefined"));
|
2003-04-02 21:03:34 +04:00
|
|
|
}
|
2005-11-27 22:40:56 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
// read in ROM BIOS image file
|
|
|
|
fd = open(path, O_RDONLY
|
|
|
|
#ifdef O_BINARY
|
2011-07-22 21:46:06 +04:00
|
|
|
| O_BINARY
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif
|
|
|
|
);
|
|
|
|
if (fd < 0) {
|
2003-08-06 12:24:14 +04:00
|
|
|
if (type < 2) {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PANIC(("ROM: couldn't open ROM image file '%s'.", path));
|
2005-11-27 22:40:56 +03:00
|
|
|
}
|
2003-04-02 21:03:34 +04:00
|
|
|
else {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_ERROR(("ROM: couldn't open ROM image file '%s'.", path));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-11-27 22:40:56 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
ret = fstat(fd, &stat_buf);
|
|
|
|
if (ret) {
|
2003-08-06 12:24:14 +04:00
|
|
|
if (type < 2) {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PANIC(("ROM: couldn't stat ROM image file '%s'.", path));
|
2005-11-27 22:40:56 +03:00
|
|
|
}
|
2003-04-02 21:03:34 +04:00
|
|
|
else {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_ERROR(("ROM: couldn't stat ROM image file '%s'.", path));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-11-27 22:40:56 +03:00
|
|
|
return;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2005-06-07 23:26:21 +04:00
|
|
|
size = (unsigned long)stat_buf.st_size;
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2004-08-26 11:58:33 +04:00
|
|
|
if (type > 0) {
|
2009-03-30 00:08:27 +04:00
|
|
|
max_size = 0x20000;
|
2004-08-26 11:58:33 +04:00
|
|
|
} else {
|
2005-10-12 21:11:44 +04:00
|
|
|
max_size = BIOSROMSZ;
|
2004-08-26 11:58:33 +04:00
|
|
|
}
|
|
|
|
if (size > max_size) {
|
2004-09-01 22:12:23 +04:00
|
|
|
close(fd);
|
2004-08-26 11:58:33 +04:00
|
|
|
BX_PANIC(("ROM: ROM image too large"));
|
2002-09-03 20:44:33 +04:00
|
|
|
return;
|
2004-08-26 11:58:33 +04:00
|
|
|
}
|
|
|
|
if (type == 0) {
|
2005-12-27 19:59:27 +03:00
|
|
|
if (romaddress > 0) {
|
|
|
|
if ((romaddress + size) != 0x100000 && (romaddress + size)) {
|
|
|
|
close(fd);
|
|
|
|
BX_PANIC(("ROM: System BIOS must end at 0xfffff"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2007-12-30 21:02:22 +03:00
|
|
|
romaddress = -size;
|
2004-08-26 11:58:33 +04:00
|
|
|
}
|
2005-10-12 21:11:44 +04:00
|
|
|
offset = romaddress & BIOS_MASK;
|
2005-12-27 19:59:27 +03:00
|
|
|
if ((romaddress & 0xf0000) < 0xf0000) {
|
2011-02-11 18:33:08 +03:00
|
|
|
BX_MEM_THIS rom_present[64] = 1;
|
2004-09-01 22:12:23 +04:00
|
|
|
}
|
2005-12-19 23:48:51 +03:00
|
|
|
is_bochs_bios = (strstr(path, "BIOS-bochs-latest") != NULL);
|
2004-08-26 11:58:33 +04:00
|
|
|
} else {
|
2004-09-01 22:12:23 +04:00
|
|
|
if ((size % 512) != 0) {
|
2004-09-02 22:24:50 +04:00
|
|
|
close(fd);
|
|
|
|
BX_PANIC(("ROM: ROM image size must be multiple of 512 (size = %ld)", size));
|
|
|
|
return;
|
2004-09-01 22:12:23 +04:00
|
|
|
}
|
2004-08-26 11:58:33 +04:00
|
|
|
if ((romaddress % 2048) != 0) {
|
2004-09-01 22:12:23 +04:00
|
|
|
close(fd);
|
2004-08-26 11:58:33 +04:00
|
|
|
BX_PANIC(("ROM: ROM image must start at a 2k boundary"));
|
|
|
|
return;
|
|
|
|
}
|
2005-10-25 23:12:54 +04:00
|
|
|
if ((romaddress < 0xc0000) ||
|
2006-04-05 20:58:22 +04:00
|
|
|
(((romaddress + size - 1) > 0xdffff) && (romaddress < 0xe0000))) {
|
2004-09-01 22:12:23 +04:00
|
|
|
close(fd);
|
2004-08-26 11:58:33 +04:00
|
|
|
BX_PANIC(("ROM: ROM address space out of range"));
|
|
|
|
return;
|
|
|
|
}
|
2005-10-25 12:33:55 +04:00
|
|
|
if (romaddress < 0xe0000) {
|
|
|
|
offset = (romaddress & EXROM_MASK) + BIOSROMSZ;
|
2010-08-15 23:57:50 +04:00
|
|
|
start_idx = (((Bit32u)romaddress - 0xc0000) >> 11);
|
2006-04-05 20:58:22 +04:00
|
|
|
end_idx = start_idx + (size >> 11) + (((size % 2048) > 0) ? 1 : 0);
|
2005-10-25 12:33:55 +04:00
|
|
|
} else {
|
|
|
|
offset = romaddress & BIOS_MASK;
|
2006-04-05 20:58:22 +04:00
|
|
|
start_idx = 64;
|
|
|
|
end_idx = 64;
|
2005-10-25 12:33:55 +04:00
|
|
|
}
|
2004-09-01 22:12:23 +04:00
|
|
|
for (i = start_idx; i < end_idx; i++) {
|
2011-02-11 18:33:08 +03:00
|
|
|
if (BX_MEM_THIS rom_present[i]) {
|
2004-09-01 22:12:23 +04:00
|
|
|
close(fd);
|
2005-10-12 21:11:44 +04:00
|
|
|
BX_PANIC(("ROM: address space 0x%x already in use", (i * 2048) + 0xc0000));
|
2004-09-01 22:12:23 +04:00
|
|
|
return;
|
|
|
|
} else {
|
2011-02-11 18:33:08 +03:00
|
|
|
BX_MEM_THIS rom_present[i] = 1;
|
2004-09-01 22:12:23 +04:00
|
|
|
}
|
|
|
|
}
|
2004-08-26 11:58:33 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
while (size > 0) {
|
2005-10-12 21:11:44 +04:00
|
|
|
ret = read(fd, (bx_ptr_t) &BX_MEM_THIS rom[offset], size);
|
2001-04-10 05:04:59 +04:00
|
|
|
if (ret <= 0) {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PANIC(("ROM: read failed on BIOS image: '%s'",path));
|
2005-10-25 23:12:54 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
size -= ret;
|
|
|
|
offset += ret;
|
2005-10-25 23:12:54 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
close(fd);
|
2005-12-19 23:48:51 +03:00
|
|
|
offset -= (unsigned long)stat_buf.st_size;
|
2006-09-28 23:01:04 +04:00
|
|
|
if (((romaddress & 0xfffff) != 0xe0000) ||
|
2007-05-15 16:48:59 +04:00
|
|
|
((BX_MEM_THIS rom[offset] == 0x55) && (BX_MEM_THIS rom[offset+1] == 0xaa))) {
|
2005-10-25 23:12:54 +04:00
|
|
|
Bit8u checksum = 0;
|
|
|
|
for (i = 0; i < stat_buf.st_size; i++) {
|
|
|
|
checksum += BX_MEM_THIS rom[offset + i];
|
|
|
|
}
|
|
|
|
if (checksum != 0) {
|
|
|
|
if (type == 1) {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PANIC(("ROM: checksum error in VGABIOS image: '%s'", path));
|
2005-12-19 23:48:51 +03:00
|
|
|
} else if (is_bochs_bios) {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_ERROR(("ROM: checksum error in BIOS image: '%s'", path));
|
2005-10-25 23:12:54 +04:00
|
|
|
}
|
2004-09-02 22:24:50 +04:00
|
|
|
}
|
|
|
|
}
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_INFO(("rom at 0x%05x/%u ('%s')",
|
2011-07-22 21:46:06 +04:00
|
|
|
(unsigned) romaddress,
|
|
|
|
(unsigned) stat_buf.st_size,
|
|
|
|
path));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2005-10-28 04:12:27 +04:00
|
|
|
|
2006-03-28 20:53:02 +04:00
|
|
|
void BX_MEM_C::load_RAM(const char *path, bx_phy_address ramaddress, Bit8u type)
|
2005-10-28 04:12:27 +04:00
|
|
|
{
|
|
|
|
struct stat stat_buf;
|
2005-10-28 10:33:53 +04:00
|
|
|
int fd, ret;
|
2010-08-15 23:57:50 +04:00
|
|
|
Bit32u size, offset;
|
2005-10-28 04:12:27 +04:00
|
|
|
|
|
|
|
if (*path == '\0') {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PANIC(("RAM: Optional RAM image undefined"));
|
2005-10-28 04:12:27 +04:00
|
|
|
return;
|
2006-05-31 21:20:52 +04:00
|
|
|
}
|
2005-10-28 04:12:27 +04:00
|
|
|
// read in RAM BIOS image file
|
|
|
|
fd = open(path, O_RDONLY
|
|
|
|
#ifdef O_BINARY
|
|
|
|
| O_BINARY
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
if (fd < 0) {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PANIC(("RAM: couldn't open RAM image file '%s'.", path));
|
2005-10-28 04:12:27 +04:00
|
|
|
return;
|
2005-11-27 22:40:56 +03:00
|
|
|
}
|
2005-10-28 04:12:27 +04:00
|
|
|
ret = fstat(fd, &stat_buf);
|
|
|
|
if (ret) {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PANIC(("RAM: couldn't stat RAM image file '%s'.", path));
|
2005-10-28 04:12:27 +04:00
|
|
|
return;
|
2005-11-27 22:40:56 +03:00
|
|
|
}
|
2005-10-28 04:12:27 +04:00
|
|
|
|
|
|
|
size = (unsigned long)stat_buf.st_size;
|
|
|
|
|
|
|
|
offset = ramaddress;
|
|
|
|
while (size > 0) {
|
2008-04-17 18:39:33 +04:00
|
|
|
ret = read(fd, (bx_ptr_t) BX_MEM_THIS get_vector(offset), size);
|
2005-10-28 04:12:27 +04:00
|
|
|
if (ret <= 0) {
|
2008-02-16 01:05:43 +03:00
|
|
|
BX_PANIC(("RAM: read failed on RAM image: '%s'",path));
|
2005-10-28 04:12:27 +04:00
|
|
|
}
|
|
|
|
size -= ret;
|
|
|
|
offset += ret;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
BX_INFO(("ram at 0x%05x/%u ('%s')",
|
2011-07-22 21:46:06 +04:00
|
|
|
(unsigned) ramaddress,
|
|
|
|
(unsigned) stat_buf.st_size,
|
|
|
|
path));
|
2005-10-28 04:12:27 +04:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2008-02-16 01:05:43 +03:00
|
|
|
#if (BX_DEBUGGER || BX_DISASM || BX_GDBSTUB)
|
2006-10-02 21:40:20 +04:00
|
|
|
bx_bool BX_MEM_C::dbg_fetch_mem(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, Bit8u *buf)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2004-11-16 21:50:21 +03:00
|
|
|
bx_bool ret = 1;
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
for (; len>0; len--) {
|
2006-03-26 22:58:01 +04:00
|
|
|
// Reading standard PCI/ISA Video Mem / SMMRAM
|
2009-08-03 19:01:07 +04:00
|
|
|
if (addr >= 0x000a0000 && addr < 0x000c0000) {
|
2006-10-02 21:40:20 +04:00
|
|
|
if (BX_MEM_THIS smram_enable || cpu->smm_mode())
|
2008-04-17 18:39:33 +04:00
|
|
|
*buf = *(BX_MEM_THIS get_vector(addr));
|
2008-02-03 23:27:06 +03:00
|
|
|
else
|
2006-03-26 22:58:01 +04:00
|
|
|
*buf = DEV_vga_mem_read(addr);
|
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
#if BX_SUPPORT_PCI
|
2012-01-19 22:32:11 +04:00
|
|
|
else if (BX_MEM_THIS pci_enabled && (addr >= 0x000c0000 && addr < 0x00100000)) {
|
|
|
|
unsigned area = (unsigned)(addr >> 14) & 0x0f;
|
|
|
|
if (area > BX_MEM_AREA_F0000) area = BX_MEM_AREA_F0000;
|
|
|
|
if (BX_MEM_THIS memory_type[area][0] == 0) {
|
|
|
|
// Read from ROM
|
|
|
|
if ((addr & 0xfffe0000) == 0x000e0000) {
|
|
|
|
// last 128K of BIOS ROM mapped to 0xE0000-0xFFFFF
|
|
|
|
*buf = BX_MEM_THIS rom[BIOS_MAP_LAST128K(addr)];
|
|
|
|
} else {
|
|
|
|
*buf = BX_MEM_THIS rom[(addr & EXROM_MASK) + BIOSROMSZ];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Read from ShadowRAM
|
|
|
|
*buf = *(BX_MEM_THIS get_vector(addr));
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // #if BX_SUPPORT_PCI
|
2005-10-12 21:11:44 +04:00
|
|
|
else if (addr < BX_MEM_THIS len)
|
2004-11-14 17:06:43 +03:00
|
|
|
{
|
2009-08-10 11:51:41 +04:00
|
|
|
if (addr < 0x000c0000 || addr >= 0x00100000) {
|
2008-04-17 18:39:33 +04:00
|
|
|
*buf = *(BX_MEM_THIS get_vector(addr));
|
2005-10-12 21:11:44 +04:00
|
|
|
}
|
2009-08-10 11:51:41 +04:00
|
|
|
// must be in C0000 - FFFFF range
|
|
|
|
else if ((addr & 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
|
|
|
*buf = BX_MEM_THIS rom[BIOS_MAP_LAST128K(addr)];
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2009-08-10 11:51:41 +04:00
|
|
|
else {
|
2006-09-02 16:08:28 +04:00
|
|
|
*buf = BX_MEM_THIS rom[(addr & EXROM_MASK) + BIOSROMSZ];
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
2008-10-18 22:10:14 +04:00
|
|
|
#if BX_PHY_ADDRESS_LONG
|
2009-08-11 19:56:09 +04:00
|
|
|
else if (addr > BX_CONST64(0xffffffff)) {
|
2008-10-18 22:10:14 +04:00
|
|
|
*buf = 0xff;
|
|
|
|
ret = 0; // error, beyond limits of memory
|
|
|
|
}
|
|
|
|
#endif
|
2006-04-05 20:58:22 +04:00
|
|
|
else if (addr >= (bx_phy_address)~BIOS_MASK)
|
2005-10-12 21:11:44 +04:00
|
|
|
{
|
2006-09-02 16:08:28 +04:00
|
|
|
*buf = BX_MEM_THIS rom[addr & BIOS_MASK];
|
2005-10-12 21:11:44 +04:00
|
|
|
}
|
2004-11-16 21:50:21 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*buf = 0xff;
|
|
|
|
ret = 0; // error, beyond limits of memory
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
buf++;
|
|
|
|
addr++;
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
2004-11-16 21:50:21 +03:00
|
|
|
return ret;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-10-03 09:15:28 +04:00
|
|
|
#if BX_DEBUGGER || BX_GDBSTUB
|
2006-03-28 20:53:02 +04:00
|
|
|
bx_bool BX_MEM_C::dbg_set_mem(bx_phy_address addr, unsigned len, Bit8u *buf)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
2006-05-31 21:20:52 +04:00
|
|
|
if ((addr + len - 1) > BX_MEM_THIS len) {
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0); // error, beyond limits of memory
|
2005-11-27 22:40:56 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
for (; len>0; len--) {
|
2006-03-26 22:58:01 +04:00
|
|
|
// Write to standard PCI/ISA Video Mem / SMMRAM
|
2009-08-03 19:01:07 +04:00
|
|
|
if (addr >= 0x000a0000 && addr < 0x000c0000) {
|
2006-03-27 02:15:07 +04:00
|
|
|
if (BX_MEM_THIS smram_enable)
|
2008-04-17 18:39:33 +04:00
|
|
|
*(BX_MEM_THIS get_vector(addr)) = *buf;
|
2008-02-03 23:27:06 +03:00
|
|
|
else
|
2006-03-26 22:58:01 +04:00
|
|
|
DEV_vga_mem_write(addr, *buf);
|
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
#if BX_SUPPORT_PCI
|
2012-01-19 22:32:11 +04:00
|
|
|
else if (BX_MEM_THIS pci_enabled && (addr >= 0x000c0000 && addr < 0x00100000)) {
|
|
|
|
unsigned area = (unsigned)(addr >> 14) & 0x0f;
|
|
|
|
if (area > BX_MEM_AREA_F0000) area = BX_MEM_AREA_F0000;
|
|
|
|
if (BX_MEM_THIS memory_type[area][1] == 1) {
|
|
|
|
// Write to ShadowRAM
|
|
|
|
*(BX_MEM_THIS get_vector(addr)) = *buf;
|
|
|
|
} else {
|
|
|
|
// Ignore write to ROM
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
|
|
|
#endif // #if BX_SUPPORT_PCI
|
2009-08-10 11:51:41 +04:00
|
|
|
else if ((addr < 0x000c0000 || addr >= 0x00100000) && (addr < (bx_phy_address)(~BIOS_MASK)))
|
2004-11-11 23:55:29 +03:00
|
|
|
{
|
2008-04-17 18:39:33 +04:00
|
|
|
*(BX_MEM_THIS get_vector(addr)) = *buf;
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
buf++;
|
|
|
|
addr++;
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2006-03-28 20:53:02 +04:00
|
|
|
bx_bool BX_MEM_C::dbg_crc32(bx_phy_address addr1, bx_phy_address addr2, Bit32u *crc)
|
2001-04-10 05:04:59 +04:00
|
|
|
{
|
|
|
|
*crc = 0;
|
|
|
|
if (addr1 > addr2)
|
|
|
|
return(0);
|
|
|
|
|
2006-03-26 22:58:01 +04:00
|
|
|
if (addr2 >= BX_MEM_THIS len)
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0); // error, specified address past last phy mem addr
|
2008-02-03 23:27:06 +03:00
|
|
|
|
2005-11-27 22:40:56 +03:00
|
|
|
unsigned len = 1 + addr2 - addr1;
|
2008-04-17 18:39:33 +04:00
|
|
|
|
|
|
|
// do not cross 4K boundary
|
|
|
|
while(1) {
|
|
|
|
unsigned remainsInPage = 0x1000 - (addr1 & 0xfff);
|
|
|
|
unsigned access_length = (len < remainsInPage) ? len : remainsInPage;
|
2008-10-18 22:10:14 +04:00
|
|
|
*crc = crc32(BX_MEM_THIS get_vector(addr1), access_length);
|
2008-04-17 18:39:33 +04:00
|
|
|
addr1 += access_length;
|
|
|
|
len -= access_length;
|
|
|
|
}
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
return(1);
|
|
|
|
}
|
2008-04-17 18:39:33 +04:00
|
|
|
#endif
|
Integrated patches for:
- Paging code rehash. You must now use --enable-4meg-pages to
use 4Meg pages, with the default of disabled, since we don't well
support 4Meg pages yet. Paging table walks model a real CPU
more closely now, and I fixed some bugs in the old logic.
- Segment check redundancy elimination. After a segment is loaded,
reads and writes are marked when a segment type check succeeds, and
they are skipped thereafter, when possible.
- Repeated IO and memory string copy acceleration. Only some variants
of instructions are available on all platforms, word and dword
variants only on x86 for the moment due to alignment and endian issues.
This is compiled in currently with no option - I should add a configure
option.
- Added a guest linear address to host TLB. Actually, I just stick
the host address (mem.vector[addr] address) in the upper 29 bits
of the field 'combined_access' since they are unused. Convenient
for now. I'm only storing page frame addresses. This was the
simplest for of such a TLB. We can likely enhance this. Also,
I only accelerated the normal read/write routines in access.cc.
Could also modify the read-modify-write versions too. You must
use --enable-guest2host-tlb, to try this out. Currently speeds
up Win95 boot time by about 3.5% for me. More ground to cover...
- Minor mods to CPUI/MOV_CdRd for CMOV.
- Integrated enhancements from Volker to getHostMemAddr() for PCI
being enabled.
2002-09-02 00:12:09 +04:00
|
|
|
|
2004-10-30 01:15:48 +04:00
|
|
|
//
|
|
|
|
// Return a host address corresponding to the guest physical memory
|
|
|
|
// address (with A20 already applied), given that the calling
|
|
|
|
// code will perform an 'op' operation. This address will be
|
2009-10-16 01:39:40 +04:00
|
|
|
// used for direct access to guest memory.
|
2008-12-06 01:34:42 +03:00
|
|
|
// Values of 'op' are { BX_READ, BX_WRITE, BX_EXECUTE, BX_RW }.
|
2004-10-30 01:15:48 +04:00
|
|
|
//
|
|
|
|
// The other assumption is that the calling code _only_ accesses memory
|
|
|
|
// directly within the page that encompasses the address requested.
|
|
|
|
//
|
|
|
|
|
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)
|
|
|
|
//
|
|
|
|
|
2009-03-09 00:23:40 +03:00
|
|
|
Bit8u *BX_MEM_C::getHostMemAddr(BX_CPU_C *cpu, bx_phy_address addr, unsigned rw)
|
Integrated patches for:
- Paging code rehash. You must now use --enable-4meg-pages to
use 4Meg pages, with the default of disabled, since we don't well
support 4Meg pages yet. Paging table walks model a real CPU
more closely now, and I fixed some bugs in the old logic.
- Segment check redundancy elimination. After a segment is loaded,
reads and writes are marked when a segment type check succeeds, and
they are skipped thereafter, when possible.
- Repeated IO and memory string copy acceleration. Only some variants
of instructions are available on all platforms, word and dword
variants only on x86 for the moment due to alignment and endian issues.
This is compiled in currently with no option - I should add a configure
option.
- Added a guest linear address to host TLB. Actually, I just stick
the host address (mem.vector[addr] address) in the upper 29 bits
of the field 'combined_access' since they are unused. Convenient
for now. I'm only storing page frame addresses. This was the
simplest for of such a TLB. We can likely enhance this. Also,
I only accelerated the normal read/write routines in access.cc.
Could also modify the read-modify-write versions too. You must
use --enable-guest2host-tlb, to try this out. Currently speeds
up Win95 boot time by about 3.5% for me. More ground to cover...
- Minor mods to CPUI/MOV_CdRd for CMOV.
- Integrated enhancements from Volker to getHostMemAddr() for PCI
being enabled.
2002-09-02 00:12:09 +04:00
|
|
|
{
|
2009-08-03 19:01:07 +04:00
|
|
|
bx_phy_address a20addr = A20ADDR(addr);
|
2009-03-09 00:23:40 +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
|
|
|
|
|
2008-12-06 01:34:42 +03:00
|
|
|
bx_bool write = rw & 1;
|
|
|
|
|
2006-03-27 02:15:07 +04:00
|
|
|
// allow direct access to SMRAM memory space for code and veto data
|
2008-12-13 14:03:36 +03:00
|
|
|
if ((cpu != NULL) && (rw == BX_EXECUTE)) {
|
2006-03-27 02:15:07 +04:00
|
|
|
// reading from SMRAM memory space
|
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
|
|
|
{
|
|
|
|
if (BX_MEM_THIS smram_enable || cpu->smm_mode())
|
2009-08-03 19:01:07 +04:00
|
|
|
return BX_MEM_THIS get_vector(a20addr);
|
2006-03-26 22:58:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-01 21:03:48 +03:00
|
|
|
#if BX_SUPPORT_MONITOR_MWAIT
|
2010-03-16 17:51:20 +03:00
|
|
|
if (write && BX_MEM_THIS is_monitor(a20addr & ~((bx_phy_address)(0xfff)), 0xfff)) {
|
2008-04-18 00:20:43 +04:00
|
|
|
// Vetoed! Write monitored page !
|
2009-08-10 11:51:41 +04:00
|
|
|
return(NULL);
|
2007-11-01 21:03:48 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-08-03 19:01:07 +04:00
|
|
|
struct memory_handler_struct *memory_handler = BX_MEM_THIS memory_handlers[a20addr >> 20];
|
2005-01-30 02:29:08 +03:00
|
|
|
while (memory_handler) {
|
2009-08-03 19:01:07 +04:00
|
|
|
if (memory_handler->begin <= a20addr &&
|
|
|
|
memory_handler->end >= a20addr) {
|
2011-06-30 22:07:14 +04:00
|
|
|
if (memory_handler->da_handler)
|
|
|
|
return memory_handler->da_handler(a20addr, rw, memory_handler->param);
|
2011-06-29 23:48:46 +04:00
|
|
|
else
|
|
|
|
return(NULL); // Vetoed! memory handler for i/o apic, vram, mmio and PCI PnP
|
2005-01-30 02:29:08 +03:00
|
|
|
}
|
|
|
|
memory_handler = memory_handler->next;
|
|
|
|
}
|
|
|
|
|
2008-12-06 01:34:42 +03:00
|
|
|
if (! write) {
|
2009-08-03 19:01:07 +04:00
|
|
|
if ((a20addr >= 0x000a0000 && a20addr < 0x000c0000))
|
2004-10-30 01:15:48 +04:00
|
|
|
return(NULL); // Vetoed! Mem mapped IO (VGA)
|
2004-11-11 23:55:29 +03:00
|
|
|
#if BX_SUPPORT_PCI
|
2012-01-19 22:32:11 +04:00
|
|
|
else if (BX_MEM_THIS pci_enabled && (a20addr >= 0x000c0000 && a20addr < 0x00100000)) {
|
|
|
|
unsigned area = (unsigned)(a20addr >> 14) & 0x0f;
|
|
|
|
if (area > BX_MEM_AREA_F0000) area = BX_MEM_AREA_F0000;
|
|
|
|
if (BX_MEM_THIS memory_type[area][0] == 0) {
|
|
|
|
// Read from ROM
|
|
|
|
if ((a20addr & 0xfffe0000) == 0x000e0000) {
|
|
|
|
// last 128K of BIOS ROM mapped to 0xE0000-0xFFFFF
|
|
|
|
return (Bit8u *) &BX_MEM_THIS rom[BIOS_MAP_LAST128K(a20addr)];
|
|
|
|
} else {
|
|
|
|
return (Bit8u *) &BX_MEM_THIS rom[(a20addr & EXROM_MASK) + BIOSROMSZ];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Read from ShadowRAM
|
|
|
|
return BX_MEM_THIS get_vector(a20addr);
|
Integrated patches for:
- Paging code rehash. You must now use --enable-4meg-pages to
use 4Meg pages, with the default of disabled, since we don't well
support 4Meg pages yet. Paging table walks model a real CPU
more closely now, and I fixed some bugs in the old logic.
- Segment check redundancy elimination. After a segment is loaded,
reads and writes are marked when a segment type check succeeds, and
they are skipped thereafter, when possible.
- Repeated IO and memory string copy acceleration. Only some variants
of instructions are available on all platforms, word and dword
variants only on x86 for the moment due to alignment and endian issues.
This is compiled in currently with no option - I should add a configure
option.
- Added a guest linear address to host TLB. Actually, I just stick
the host address (mem.vector[addr] address) in the upper 29 bits
of the field 'combined_access' since they are unused. Convenient
for now. I'm only storing page frame addresses. This was the
simplest for of such a TLB. We can likely enhance this. Also,
I only accelerated the normal read/write routines in access.cc.
Could also modify the read-modify-write versions too. You must
use --enable-guest2host-tlb, to try this out. Currently speeds
up Win95 boot time by about 3.5% for me. More ground to cover...
- Minor mods to CPUI/MOV_CdRd for CMOV.
- Integrated enhancements from Volker to getHostMemAddr() for PCI
being enabled.
2002-09-02 00:12:09 +04:00
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
Integrated patches for:
- Paging code rehash. You must now use --enable-4meg-pages to
use 4Meg pages, with the default of disabled, since we don't well
support 4Meg pages yet. Paging table walks model a real CPU
more closely now, and I fixed some bugs in the old logic.
- Segment check redundancy elimination. After a segment is loaded,
reads and writes are marked when a segment type check succeeds, and
they are skipped thereafter, when possible.
- Repeated IO and memory string copy acceleration. Only some variants
of instructions are available on all platforms, word and dword
variants only on x86 for the moment due to alignment and endian issues.
This is compiled in currently with no option - I should add a configure
option.
- Added a guest linear address to host TLB. Actually, I just stick
the host address (mem.vector[addr] address) in the upper 29 bits
of the field 'combined_access' since they are unused. Convenient
for now. I'm only storing page frame addresses. This was the
simplest for of such a TLB. We can likely enhance this. Also,
I only accelerated the normal read/write routines in access.cc.
Could also modify the read-modify-write versions too. You must
use --enable-guest2host-tlb, to try this out. Currently speeds
up Win95 boot time by about 3.5% for me. More ground to cover...
- Minor mods to CPUI/MOV_CdRd for CMOV.
- Integrated enhancements from Volker to getHostMemAddr() for PCI
being enabled.
2002-09-02 00:12:09 +04:00
|
|
|
#endif
|
2009-10-17 22:42:15 +04:00
|
|
|
else if(a20addr < BX_MEM_THIS len && ! is_bios)
|
2004-11-11 23:55:29 +03:00
|
|
|
{
|
2009-08-03 19:01:07 +04:00
|
|
|
if (a20addr < 0x000c0000 || a20addr >= 0x00100000) {
|
|
|
|
return BX_MEM_THIS get_vector(a20addr);
|
2005-10-12 21:11:44 +04:00
|
|
|
}
|
2009-08-03 19:01:07 +04:00
|
|
|
// must be in C0000 - FFFFF range
|
|
|
|
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
|
|
|
return (Bit8u *) &BX_MEM_THIS rom[BIOS_MAP_LAST128K(a20addr)];
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
2008-04-18 00:20:43 +04:00
|
|
|
else {
|
2009-08-03 19:01:07 +04:00
|
|
|
return((Bit8u *) &BX_MEM_THIS rom[(a20addr & EXROM_MASK) + BIOSROMSZ]);
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
Integrated patches for:
- Paging code rehash. You must now use --enable-4meg-pages to
use 4Meg pages, with the default of disabled, since we don't well
support 4Meg pages yet. Paging table walks model a real CPU
more closely now, and I fixed some bugs in the old logic.
- Segment check redundancy elimination. After a segment is loaded,
reads and writes are marked when a segment type check succeeds, and
they are skipped thereafter, when possible.
- Repeated IO and memory string copy acceleration. Only some variants
of instructions are available on all platforms, word and dword
variants only on x86 for the moment due to alignment and endian issues.
This is compiled in currently with no option - I should add a configure
option.
- Added a guest linear address to host TLB. Actually, I just stick
the host address (mem.vector[addr] address) in the upper 29 bits
of the field 'combined_access' since they are unused. Convenient
for now. I'm only storing page frame addresses. This was the
simplest for of such a TLB. We can likely enhance this. Also,
I only accelerated the normal read/write routines in access.cc.
Could also modify the read-modify-write versions too. You must
use --enable-guest2host-tlb, to try this out. Currently speeds
up Win95 boot time by about 3.5% for me. More ground to cover...
- Minor mods to CPUI/MOV_CdRd for CMOV.
- Integrated enhancements from Volker to getHostMemAddr() for PCI
being enabled.
2002-09-02 00:12:09 +04:00
|
|
|
}
|
2008-10-18 22:10:14 +04:00
|
|
|
#if BX_PHY_ADDRESS_LONG
|
2009-08-11 19:56:09 +04:00
|
|
|
else if (a20addr > BX_CONST64(0xffffffff)) {
|
2008-10-18 22:10:14 +04:00
|
|
|
// Error, requested addr is out of bounds.
|
2009-08-03 19:01:07 +04:00
|
|
|
return (Bit8u *) &BX_MEM_THIS bogus[a20addr & 0xfff];
|
2008-10-18 22:10:14 +04:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-03 19:01:07 +04:00
|
|
|
else if (a20addr >= (bx_phy_address)~BIOS_MASK)
|
2005-10-12 21:11:44 +04:00
|
|
|
{
|
2009-08-03 19:01:07 +04:00
|
|
|
return (Bit8u *) &BX_MEM_THIS rom[a20addr & BIOS_MASK];
|
2005-10-12 21:11:44 +04:00
|
|
|
}
|
2004-11-16 21:50:21 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Error, requested addr is out of bounds.
|
2009-08-03 19:01:07 +04:00
|
|
|
return (Bit8u *) &BX_MEM_THIS bogus[a20addr & 0xfff];
|
2004-11-16 21:50:21 +03:00
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // op == {BX_WRITE, BX_RW}
|
2009-10-17 22:42:15 +04:00
|
|
|
if (a20addr >= BX_MEM_THIS len || is_bios)
|
2004-11-16 21:50:21 +03:00
|
|
|
return(NULL); // Error, requested addr is out of bounds.
|
2009-08-03 19:01:07 +04:00
|
|
|
else if (a20addr >= 0x000a0000 && a20addr < 0x000c0000)
|
2004-11-11 23:55:29 +03:00
|
|
|
return(NULL); // Vetoed! Mem mapped IO (VGA)
|
|
|
|
#if BX_SUPPORT_PCI
|
2009-08-03 19:01:07 +04:00
|
|
|
else if (BX_MEM_THIS pci_enabled && (a20addr >= 0x000c0000 && a20addr < 0x00100000))
|
2004-11-11 23:55:29 +03:00
|
|
|
{
|
2006-04-29 20:55:22 +04:00
|
|
|
// Veto direct writes to this area. Otherwise, there is a chance
|
|
|
|
// for Guest2HostTLB and memory consistency problems, for example
|
|
|
|
// when some 16K block marked as write-only using PAM registers.
|
|
|
|
return(NULL);
|
2004-10-21 22:20:40 +04:00
|
|
|
}
|
2004-11-11 23:55:29 +03:00
|
|
|
#endif
|
2002-09-19 23:17:20 +04:00
|
|
|
else
|
2004-11-11 23:55:29 +03:00
|
|
|
{
|
2009-08-03 19:01:07 +04:00
|
|
|
if (a20addr < 0x000c0000 || a20addr >= 0x00100000) {
|
2009-10-16 01:39:40 +04:00
|
|
|
return BX_MEM_THIS get_vector(a20addr);
|
2002-09-19 23:17:20 +04:00
|
|
|
}
|
2008-04-18 00:20:43 +04:00
|
|
|
else {
|
2004-11-11 23:55:29 +03:00
|
|
|
return(NULL); // Vetoed! ROMs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Integrated patches for:
- Paging code rehash. You must now use --enable-4meg-pages to
use 4Meg pages, with the default of disabled, since we don't well
support 4Meg pages yet. Paging table walks model a real CPU
more closely now, and I fixed some bugs in the old logic.
- Segment check redundancy elimination. After a segment is loaded,
reads and writes are marked when a segment type check succeeds, and
they are skipped thereafter, when possible.
- Repeated IO and memory string copy acceleration. Only some variants
of instructions are available on all platforms, word and dword
variants only on x86 for the moment due to alignment and endian issues.
This is compiled in currently with no option - I should add a configure
option.
- Added a guest linear address to host TLB. Actually, I just stick
the host address (mem.vector[addr] address) in the upper 29 bits
of the field 'combined_access' since they are unused. Convenient
for now. I'm only storing page frame addresses. This was the
simplest for of such a TLB. We can likely enhance this. Also,
I only accelerated the normal read/write routines in access.cc.
Could also modify the read-modify-write versions too. You must
use --enable-guest2host-tlb, to try this out. Currently speeds
up Win95 boot time by about 3.5% for me. More ground to cover...
- Minor mods to CPUI/MOV_CdRd for CMOV.
- Integrated enhancements from Volker to getHostMemAddr() for PCI
being enabled.
2002-09-02 00:12:09 +04:00
|
|
|
}
|
2004-01-15 05:08:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* One needs to provide both a read_handler and a write_handler.
|
|
|
|
*/
|
2008-02-03 23:27:06 +03:00
|
|
|
bx_bool
|
2006-02-27 22:04:01 +03:00
|
|
|
BX_MEM_C::registerMemoryHandlers(void *param, memory_handler_t read_handler,
|
2011-07-22 21:46:06 +04:00
|
|
|
memory_handler_t write_handler, memory_direct_access_handler_t da_handler,
|
2011-06-29 23:48:46 +04:00
|
|
|
bx_phy_address begin_addr, bx_phy_address end_addr)
|
2004-01-15 05:08:37 +03:00
|
|
|
{
|
2005-11-27 22:40:56 +03:00
|
|
|
if (end_addr < begin_addr)
|
2007-11-01 21:03:48 +03:00
|
|
|
return 0;
|
2011-06-29 23:48:46 +04:00
|
|
|
if (!read_handler || !write_handler) // allow NULL fetch handler
|
2007-11-01 21:03:48 +03:00
|
|
|
return 0;
|
2008-05-10 02:33:37 +04:00
|
|
|
BX_INFO(("Register memory access handlers: 0x" FMT_PHY_ADDRX " - 0x" FMT_PHY_ADDRX, begin_addr, end_addr));
|
2012-09-25 00:11:50 +04:00
|
|
|
for (Bit32u page_idx = (Bit32u)(begin_addr >> 20); page_idx <= (Bit32u)(end_addr >> 20); page_idx++) {
|
2012-09-23 23:09:20 +04:00
|
|
|
Bit16u bitmap = 0xffff;
|
|
|
|
if (begin_addr > (page_idx << 20)) {
|
|
|
|
bitmap &= (0xffff << ((begin_addr >> 16) & 0xf));
|
|
|
|
}
|
|
|
|
if (end_addr < ((page_idx + 1) << 20)) {
|
|
|
|
bitmap &= (0xffff >> (0x0f - ((end_addr >> 16) & 0xf)));
|
|
|
|
}
|
|
|
|
if (BX_MEM_THIS memory_handlers[page_idx] != NULL) {
|
|
|
|
if ((bitmap & BX_MEM_THIS memory_handlers[page_idx]->bitmap) != 0) {
|
|
|
|
BX_ERROR(("Register failed: overlapping memory handlers!"));
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
bitmap |= BX_MEM_THIS memory_handlers[page_idx]->bitmap;
|
|
|
|
}
|
|
|
|
}
|
2005-11-27 22:40:56 +03:00
|
|
|
struct memory_handler_struct *memory_handler = new struct memory_handler_struct;
|
2006-09-02 16:08:28 +04:00
|
|
|
memory_handler->next = BX_MEM_THIS memory_handlers[page_idx];
|
|
|
|
BX_MEM_THIS memory_handlers[page_idx] = memory_handler;
|
2005-11-27 22:40:56 +03:00
|
|
|
memory_handler->read_handler = read_handler;
|
|
|
|
memory_handler->write_handler = write_handler;
|
2011-06-30 22:07:14 +04:00
|
|
|
memory_handler->da_handler = da_handler;
|
2006-02-27 22:04:01 +03:00
|
|
|
memory_handler->param = param;
|
2005-11-27 22:40:56 +03:00
|
|
|
memory_handler->begin = begin_addr;
|
|
|
|
memory_handler->end = end_addr;
|
2012-09-23 23:09:20 +04:00
|
|
|
memory_handler->bitmap = bitmap;
|
2005-11-27 22:40:56 +03:00
|
|
|
}
|
2007-11-01 21:03:48 +03:00
|
|
|
return 1;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
|
|
|
|
2008-02-03 23:27:06 +03:00
|
|
|
bx_bool
|
2011-06-29 23:48:46 +04:00
|
|
|
BX_MEM_C::unregisterMemoryHandlers(void *param, bx_phy_address begin_addr, bx_phy_address end_addr)
|
2004-01-15 05:08:37 +03:00
|
|
|
{
|
2007-11-01 21:03:48 +03:00
|
|
|
bx_bool ret = 1;
|
2008-05-10 02:33:37 +04:00
|
|
|
BX_INFO(("Memory access handlers unregistered: 0x" FMT_PHY_ADDRX " - 0x" FMT_PHY_ADDRX, begin_addr, end_addr));
|
2012-09-25 00:11:50 +04:00
|
|
|
for (Bit32u page_idx = (Bit32u)(begin_addr >> 20); page_idx <= (Bit32u)(end_addr >> 20); page_idx++) {
|
2006-09-02 16:08:28 +04:00
|
|
|
struct memory_handler_struct *memory_handler = BX_MEM_THIS memory_handlers[page_idx];
|
2006-02-27 22:04:01 +03:00
|
|
|
struct memory_handler_struct *prev = NULL;
|
2008-02-03 23:27:06 +03:00
|
|
|
while (memory_handler &&
|
2011-06-29 23:48:46 +04:00
|
|
|
memory_handler->param != param &&
|
2008-02-03 23:27:06 +03:00
|
|
|
memory_handler->begin != begin_addr &&
|
2005-11-27 22:40:56 +03:00
|
|
|
memory_handler->end != end_addr)
|
2006-02-27 22:04:01 +03:00
|
|
|
{
|
|
|
|
prev = memory_handler;
|
|
|
|
memory_handler = memory_handler->next;
|
|
|
|
}
|
|
|
|
if (!memory_handler) {
|
2007-11-01 21:03:48 +03:00
|
|
|
ret = 0; // we should have found it
|
2006-02-27 22:04:01 +03:00
|
|
|
continue; // anyway, try the other pages
|
|
|
|
}
|
|
|
|
if (prev)
|
|
|
|
prev->next = memory_handler->next;
|
|
|
|
else
|
2006-09-02 16:08:28 +04:00
|
|
|
BX_MEM_THIS memory_handlers[page_idx] = memory_handler->next;
|
2006-02-27 22:04:01 +03:00
|
|
|
delete memory_handler;
|
2008-02-03 23:27:06 +03:00
|
|
|
}
|
2006-02-27 22:04:01 +03:00
|
|
|
return ret;
|
2004-01-15 05:08:37 +03:00
|
|
|
}
|
2006-03-26 22:58:01 +04:00
|
|
|
|
2006-03-27 22:02:07 +04:00
|
|
|
void BX_MEM_C::enable_smram(bx_bool enable, bx_bool restricted)
|
2006-03-26 22:58:01 +04:00
|
|
|
{
|
2006-03-27 02:15:07 +04:00
|
|
|
BX_MEM_THIS smram_available = 1;
|
|
|
|
BX_MEM_THIS smram_enable = (enable > 0);
|
|
|
|
BX_MEM_THIS smram_restricted = (restricted > 0);
|
2006-03-26 22:58:01 +04:00
|
|
|
}
|
|
|
|
|
2006-03-27 22:02:07 +04:00
|
|
|
void BX_MEM_C::disable_smram(void)
|
2006-03-26 22:58:01 +04:00
|
|
|
{
|
2006-03-27 02:15:07 +04:00
|
|
|
BX_MEM_THIS smram_available = 0;
|
|
|
|
BX_MEM_THIS smram_enable = 0;
|
|
|
|
BX_MEM_THIS smram_restricted = 0;
|
2006-03-26 22:58:01 +04:00
|
|
|
}
|
2006-03-27 22:02:07 +04:00
|
|
|
|
|
|
|
// check if SMRAM is aavailable for CPU data accesses
|
|
|
|
bx_bool BX_MEM_C::is_smram_accessible(void)
|
|
|
|
{
|
|
|
|
return(BX_MEM_THIS smram_available) &&
|
|
|
|
(BX_MEM_THIS smram_enable || !BX_MEM_THIS smram_restricted);
|
|
|
|
}
|
2007-11-01 21:03:48 +03:00
|
|
|
|
2012-01-19 22:32:11 +04:00
|
|
|
void BX_MEM_C::set_memory_type(memory_area_t area, bx_bool rw, bx_bool dram)
|
|
|
|
{
|
|
|
|
if (area <= BX_MEM_AREA_F0000) {
|
|
|
|
BX_MEM_THIS memory_type[area][rw] = dram;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-02 23:59:23 +04:00
|
|
|
void BX_MEM_C::set_bios_write(bx_bool enabled)
|
|
|
|
{
|
|
|
|
BX_MEM_THIS bios_write_enabled = enabled;
|
|
|
|
}
|
|
|
|
|
2007-11-01 21:03:48 +03:00
|
|
|
#if BX_SUPPORT_MONITOR_MWAIT
|
|
|
|
|
|
|
|
//
|
|
|
|
// MONITOR/MWAIT - x86arch way to optimize idle loops in CPU
|
|
|
|
//
|
|
|
|
|
|
|
|
bx_bool BX_MEM_C::is_monitor(bx_phy_address begin_addr, unsigned len)
|
|
|
|
{
|
|
|
|
for (int i=0; i<BX_SMP_PROCESSORS;i++) {
|
2010-03-07 12:16:24 +03:00
|
|
|
if (BX_CPU(i)->is_monitor(begin_addr, len))
|
|
|
|
return 1;
|
2007-11-01 21:03:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0; // // this is NOT monitored page
|
|
|
|
}
|
|
|
|
|
|
|
|
void BX_MEM_C::check_monitor(bx_phy_address begin_addr, unsigned len)
|
|
|
|
{
|
|
|
|
for (int i=0; i<BX_SMP_PROCESSORS;i++) {
|
2010-03-07 12:16:24 +03:00
|
|
|
BX_CPU(i)->check_monitor(begin_addr, len);
|
2007-11-01 21:03:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|