2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// $Id: misc_mem.cc,v 1.15 2001-10-03 13:10:38 bdenney Exp $
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "bochs.h"
|
2001-05-23 12:02:15 +04:00
|
|
|
#define LOG_THIS BX_MEM(0)->
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if BX_PROVIDE_CPU_MEMORY
|
|
|
|
Bit32u
|
|
|
|
BX_MEM_C::get_memory_in_k(void)
|
|
|
|
{
|
|
|
|
return(BX_MEM_THIS megabytes * 1024);
|
|
|
|
}
|
|
|
|
#endif // #if BX_PROVIDE_CPU_MEMORY
|
|
|
|
|
|
|
|
|
|
|
|
#if BX_PROVIDE_CPU_MEMORY
|
|
|
|
// BX_MEM_C constructor
|
|
|
|
BX_MEM_C::BX_MEM_C(void)
|
|
|
|
{
|
2001-06-20 01:36:09 +04:00
|
|
|
char mem[6];
|
|
|
|
snprintf(mem, 6, "MEM%d", BX_SIM_ID);
|
2001-06-27 23:16:01 +04:00
|
|
|
put(mem);
|
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
|
|
|
settype(MEMLOG);
|
|
|
|
|
2001-05-23 12:02:15 +04:00
|
|
|
vector = NULL;
|
|
|
|
len = 0;
|
|
|
|
megabytes = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
#endif // #if BX_PROVIDE_CPU_MEMORY
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if BX_PROVIDE_CPU_MEMORY
|
|
|
|
// BX_MEM_C constructor
|
|
|
|
BX_MEM_C::BX_MEM_C(size_t memsize)
|
|
|
|
{
|
|
|
|
vector = new Bit8u[memsize];
|
|
|
|
len = memsize;
|
|
|
|
megabytes = len / (1024*1024);
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("Init(%uB == %.2f)",memsize, megabytes));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
#endif // #if BX_PROVIDE_CPU_MEMORY
|
|
|
|
|
|
|
|
|
|
|
|
#if BX_PROVIDE_CPU_MEMORY
|
|
|
|
// BX_MEM_C destructor
|
|
|
|
BX_MEM_C::~BX_MEM_C(void)
|
|
|
|
{
|
|
|
|
if (this-> vector != NULL) {
|
|
|
|
delete this->vector;
|
|
|
|
}
|
|
|
|
else {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_DEBUG(("(%u) memory not freed as it wasn't allocated!", BX_SIM_ID));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // #if BX_PROVIDE_CPU_MEMORY
|
|
|
|
|
|
|
|
|
|
|
|
#if BX_PROVIDE_CPU_MEMORY
|
|
|
|
void
|
|
|
|
BX_MEM_C::init_memory(int memsize)
|
|
|
|
{
|
2001-10-03 17:10:38 +04:00
|
|
|
BX_DEBUG(("Init $Id: misc_mem.cc,v 1.15 2001-10-03 13:10:38 bdenney Exp $"));
|
2001-04-10 05:04:59 +04:00
|
|
|
// you can pass 0 if memory has been allocated already through
|
|
|
|
// the constructor, or the desired size of memory if it hasn't
|
|
|
|
|
|
|
|
if (BX_MEM_THIS vector == NULL) {
|
|
|
|
// memory not already allocated, do now...
|
|
|
|
BX_MEM_THIS vector = new Bit8u[memsize];
|
|
|
|
BX_MEM_THIS len = memsize;
|
|
|
|
BX_MEM_THIS megabytes = memsize / (1024*1024);
|
2001-06-28 00:27:49 +04:00
|
|
|
BX_INFO(("%.2fMB", memsize, (float)(BX_MEM_THIS megabytes) ));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
// initialize all memory to 0x00
|
|
|
|
memset(BX_MEM_THIS vector, 0x00, BX_MEM_THIS len);
|
|
|
|
|
|
|
|
// initialize ROM area (0xc0000 .. 0xfffff) to 0xff
|
|
|
|
memset(BX_MEM_THIS vector + 0xc0000, 0xff, 0x40000);
|
|
|
|
|
|
|
|
#if BX_DEBUGGER
|
|
|
|
// initialize dirty pages table
|
2001-05-23 12:02:15 +04:00
|
|
|
memset(dbg_dirty_pages, 0, sizeof(dbg_dirty_pages));
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2001-05-23 12:02:15 +04:00
|
|
|
if (megabytes > BX_MAX_DIRTY_PAGE_TABLE_MEGS) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("Error: memory larger than dirty page table can handle"));
|
|
|
|
BX_PANIC(("Error: increase BX_MAX_DIRTY_PAGE_TABLE_MEGS"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif // #if BX_PROVIDE_CPU_MEMORY
|
|
|
|
|
|
|
|
|
|
|
|
#if BX_PROVIDE_CPU_MEMORY
|
|
|
|
void
|
|
|
|
BX_MEM_C::load_ROM(const char *path, Bit32u romaddress)
|
|
|
|
{
|
|
|
|
struct stat stat_buf;
|
|
|
|
int fd, ret;
|
|
|
|
unsigned long size, offset;
|
|
|
|
|
|
|
|
// read in ROM BIOS image file
|
|
|
|
fd = open(path, O_RDONLY
|
|
|
|
#ifdef O_BINARY
|
|
|
|
| O_BINARY
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
if (fd < 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(( "ROM: couldn't open ROM image file '%s'.", path));
|
2001-04-10 05:04:59 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
ret = fstat(fd, &stat_buf);
|
|
|
|
if (ret) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(( "ROM: couldn't stat ROM image file '%s'.", path));
|
2001-04-10 05:04:59 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
size = stat_buf.st_size;
|
|
|
|
|
|
|
|
if ( (romaddress + size) > BX_MEM_THIS len ) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(( "ROM: ROM address range > physical memsize!"));
|
2001-04-10 05:04:59 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
while (size > 0) {
|
|
|
|
#if BX_PCI_SUPPORT
|
2001-06-21 18:56:43 +04:00
|
|
|
if (bx_options.Oi440FXSupport->get ())
|
2001-05-23 12:02:15 +04:00
|
|
|
ret = read(fd, (bx_ptr_t) &bx_devices.pci->s.i440fx.shadow[romaddress - 0xC0000 + offset],
|
2001-04-10 05:04:59 +04:00
|
|
|
size);
|
|
|
|
else
|
|
|
|
ret = read(fd, (bx_ptr_t) &BX_MEM_THIS vector[romaddress + offset], size);
|
|
|
|
#else
|
|
|
|
ret = read(fd, (bx_ptr_t) &BX_MEM_THIS vector[romaddress + offset], size);
|
|
|
|
#endif
|
|
|
|
if (ret <= 0) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(( "ROM: read failed on BIOS image: '%s'",path));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
size -= ret;
|
|
|
|
offset += ret;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
#if BX_PCI_SUPPORT
|
2001-06-21 18:56:43 +04:00
|
|
|
if (bx_options.Oi440FXSupport->get ())
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("rom in i440FX RAM 0x%06x/%u ('%s')",
|
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
|
|
|
(unsigned) romaddress,
|
|
|
|
(unsigned) stat_buf.st_size,
|
|
|
|
path
|
|
|
|
));
|
2001-04-10 05:04:59 +04:00
|
|
|
else
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_INFO(("rom at 0x%05x/%u ('%s')",
|
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
|
|
|
(unsigned) romaddress,
|
|
|
|
(unsigned) stat_buf.st_size,
|
|
|
|
path
|
|
|
|
));
|
2001-04-10 05:04:59 +04:00
|
|
|
#else // #if BX_PCI_SUPPORT
|
2001-08-31 20:06:32 +04:00
|
|
|
BX_INFO(("rom at 0x%05x/%u ('%s')",
|
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
|
|
|
(unsigned) romaddress,
|
|
|
|
(unsigned) stat_buf.st_size,
|
|
|
|
path
|
|
|
|
));
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif // #if BX_PCI_SUPPORT
|
|
|
|
}
|
|
|
|
#endif // #if BX_PROVIDE_CPU_MEMORY
|
|
|
|
|
|
|
|
|
|
|
|
#if ( BX_DEBUGGER || BX_DISASM )
|
|
|
|
Boolean
|
|
|
|
BX_MEM_C::dbg_fetch_mem(Bit32u addr, unsigned len, Bit8u *buf)
|
|
|
|
{
|
2001-05-23 12:02:15 +04:00
|
|
|
if ( (addr + len) > this->len ) {
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_INFO(("dbg_fetch_mem out of range. %p > %p",
|
2001-05-23 12:02:15 +04:00
|
|
|
addr+len, this->len));
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0); // error, beyond limits of memory
|
|
|
|
}
|
|
|
|
for (; len>0; len--) {
|
|
|
|
#if BX_SUPPORT_VGA
|
|
|
|
if ( (addr & 0xfffe0000) == 0x000a0000 ) {
|
|
|
|
*buf = BX_VGA_MEM_READ(addr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#endif
|
|
|
|
#if BX_PCI_SUPPORT == 0
|
2001-05-23 12:02:15 +04:00
|
|
|
*buf = vector[addr];
|
2001-04-10 05:04:59 +04:00
|
|
|
#else
|
2001-06-21 18:56:43 +04:00
|
|
|
if ( bx_options.Oi440FXSupport->get () &&
|
2001-04-10 05:04:59 +04:00
|
|
|
((addr >= 0x000C0000) && (addr <= 0x000FFFFF)) ) {
|
2001-05-23 12:02:15 +04:00
|
|
|
switch (bx_devices.pci->rd_memType (addr)) {
|
2001-04-10 05:04:59 +04:00
|
|
|
case 0x0: // Fetch from ShadowRAM
|
2001-05-23 12:02:15 +04:00
|
|
|
*buf = vector[addr];
|
2001-05-30 22:56:02 +04:00
|
|
|
// BX_INFO(("Fetching from ShadowRAM %06x, len %u !", (unsigned)addr, (unsigned)len));
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1: // Fetch from ROM
|
|
|
|
*buf = bx_pci.s.i440fx.shadow[(addr - 0xC0000)];
|
2001-05-30 22:56:02 +04:00
|
|
|
// BX_INFO(("Fetching from ROM %06x, Data %02x ", (unsigned)addr, *buf));
|
2001-04-10 05:04:59 +04:00
|
|
|
break;
|
|
|
|
default:
|
2001-05-30 22:56:02 +04:00
|
|
|
BX_PANIC(("dbg_fetch_mem: default case"));
|
2001-04-10 05:04:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2001-05-23 12:02:15 +04:00
|
|
|
*buf = vector[addr];
|
2001-04-10 05:04:59 +04:00
|
|
|
#endif // #if BX_PCI_SUPPORT == 0
|
|
|
|
}
|
|
|
|
buf++;
|
|
|
|
addr++;
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BX_DEBUGGER
|
|
|
|
Boolean
|
|
|
|
BX_MEM_C::dbg_set_mem(Bit32u addr, unsigned len, Bit8u *buf)
|
|
|
|
{
|
2001-05-23 12:02:15 +04:00
|
|
|
if ( (addr + len) > this->len ) {
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0); // error, beyond limits of memory
|
|
|
|
}
|
|
|
|
for (; len>0; len--) {
|
|
|
|
#if BX_SUPPORT_VGA
|
|
|
|
if ( (addr & 0xfffe0000) == 0x000a0000 ) {
|
|
|
|
BX_VGA_MEM_WRITE(addr, *buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2001-05-23 12:02:15 +04:00
|
|
|
vector[addr] = *buf;
|
2001-04-10 05:04:59 +04:00
|
|
|
buf++;
|
|
|
|
addr++;
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Boolean
|
|
|
|
BX_MEM_C::dbg_crc32(unsigned long (*f)(unsigned char *buf, int len),
|
|
|
|
Bit32u addr1, Bit32u addr2, Bit32u *crc)
|
|
|
|
{
|
|
|
|
unsigned len;
|
|
|
|
|
|
|
|
*crc = 0;
|
|
|
|
if (addr1 > addr2)
|
|
|
|
return(0);
|
|
|
|
|
2001-05-23 12:02:15 +04:00
|
|
|
if (addr2 >= this->len) {
|
2001-04-10 05:04:59 +04:00
|
|
|
return(0); // error, specified address past last phy mem addr
|
|
|
|
}
|
|
|
|
|
|
|
|
len = 1 + addr2 - addr1;
|
2001-05-23 12:02:15 +04:00
|
|
|
*crc = f(vector + addr1, len);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
return(1);
|
|
|
|
}
|