Change Bit32u -> bx_phy_address in memory

This commit is contained in:
Stanislav Shwartsman 2006-03-28 16:53:02 +00:00
parent 42aac37624
commit 4fd9bd53c3
6 changed files with 74 additions and 75 deletions

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: cpu.h,v 1.273 2006-03-27 18:02:07 sshwarts Exp $
// $Id: cpu.h,v 1.274 2006-03-28 16:53:02 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -2718,10 +2718,10 @@ public: // for now...
BX_SMF void access_linear(bx_address address, unsigned length, unsigned pl,
unsigned rw, void *data) BX_CPP_AttrRegparmN(3);
BX_SMF Bit32u translate_linear(bx_address laddr,
BX_SMF bx_phy_address translate_linear(bx_address laddr,
unsigned pl, unsigned rw, unsigned access_type) BX_CPP_AttrRegparmN(3);
BX_SMF Bit32u itranslate_linear(bx_address laddr, unsigned pl) BX_CPP_AttrRegparmN(2);
BX_SMF Bit32u dtranslate_linear(bx_address laddr, unsigned pl, unsigned rw) BX_CPP_AttrRegparmN(3);
BX_SMF bx_phy_address itranslate_linear(bx_address laddr, unsigned pl) BX_CPP_AttrRegparmN(2);
BX_SMF bx_phy_address dtranslate_linear(bx_address laddr, unsigned pl, unsigned rw) BX_CPP_AttrRegparmN(3);
BX_SMF void TLB_flush(bx_bool invalidateGlobal);
BX_SMF void TLB_invlpg(bx_address laddr);
BX_SMF void TLB_init(void);
@ -2741,7 +2741,6 @@ public: // for now...
BX_SMF void exception(unsigned vector, Bit16u error_code, bx_bool is_INT)
BX_CPP_AttrNoReturn();
#endif
BX_SMF bx_bool smram_write(bx_phy_address a20addr);
BX_SMF void smram_save_state(void);
BX_SMF bx_bool smram_restore_state(void);
BX_SMF int int_number(bx_segment_reg_t *seg);

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: paging.cc,v 1.69 2006-03-26 19:39:37 sshwarts Exp $
// $Id: paging.cc,v 1.70 2006-03-28 16:53:02 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -606,7 +606,7 @@ void BX_CPU_C::INVLPG(bxInstruction_c* i)
// Translate a linear address to a physical address, for
// a data access (D)
Bit32u BX_CPP_AttrRegparmN(3)
bx_phy_address BX_CPP_AttrRegparmN(3)
BX_CPU_C::translate_linear(bx_address laddr, unsigned pl, unsigned rw, unsigned access_type)
{
bx_address lpf;
@ -1057,13 +1057,13 @@ page_fault_not_present:
return(0); // keep compiler happy
}
Bit32u BX_CPP_AttrRegparmN(3)
bx_phy_address BX_CPP_AttrRegparmN(3)
BX_CPU_C::dtranslate_linear(bx_address laddr, unsigned pl, unsigned rw)
{
return translate_linear(laddr, pl, rw, DATA_ACCESS);
}
Bit32u BX_CPP_AttrRegparmN(2)
bx_phy_address BX_CPP_AttrRegparmN(2)
BX_CPU_C::itranslate_linear(bx_address laddr, unsigned pl)
{
return translate_linear(laddr, pl, BX_READ, CODE_ACCESS);

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: smm.cc,v 1.9 2006-03-27 20:09:37 sshwarts Exp $
// $Id: smm.cc,v 1.10 2006-03-28 16:53:02 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006 Stanislav Shwartsman
@ -47,13 +47,18 @@ void BX_CPU_C::RSM(bxInstruction_c *i)
BX_CPU_THIS_PTR in_smm = 0;
UndefinedOpcode(i);
// restore the CPU state from SMRAM
if (! smram_restore_state()) {
BX_PANIC(("RSM: Incorrect state when restoring CPU state - shutdown !"));
}
}
void BX_CPU_C::enter_system_management_mode(void)
{
invalidate_prefetch_q();
// save processor state to the SMRAM
// save CPU state to the SMRAM
BX_CPU_THIS_PTR smram_save_state();
// all status flags at known values, use BX_CPU_THIS_PTR eflags structure
@ -64,6 +69,30 @@ void BX_CPU_C::enter_system_management_mode(void)
BX_CPU_THIS_PTR prev_eip = RIP = 0x000080000;
// DR7
BX_CPU_THIS_PTR dr7 = 0x00000400;
// CR0 - PE, EM, TS, and PG flags set to 0; others unmodified
BX_CPU_THIS_PTR cr0.pe = 0; // real mode (bit 0)
BX_CPU_THIS_PTR cr0.em = 0; // emulate math coprocessor (bit 2)
BX_CPU_THIS_PTR cr0.ts = 0; // no task switch (bit 3)
BX_CPU_THIS_PTR cr0.pg = 0; // paging disabled (bit 31)
BX_CPU_THIS_PTR cr0.val32 &= 0x7ffffff2;
// paging mode was changed - flush TLB
TLB_flush(1); // 1 = Flush Global entries also
#if BX_CPU_LEVEL >= 4
BX_CPU_THIS_PTR cr4.setRegister(0);
#endif
// EFER.LME = 0, EFER.LME = 1
#if BX_SUPPORT_X86_64
BX_CPU_THIS_PTR msr.lme = 0;
BX_CPU_THIS_PTR msr.lma = 0;
#endif
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value = BX_CPU_THIS_PTR smbase << 4;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.index = 0;
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.ti = 0;
@ -122,35 +151,6 @@ void BX_CPU_C::enter_system_management_mode(void)
BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES] = BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS];
BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS] = BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS];
BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS] = BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS];
// DR7
BX_CPU_THIS_PTR dr7 = 0x00000400;
// CR0 - PE, EM, TS, and PG flags set to 0; others unmodified
BX_CPU_THIS_PTR cr0.pe = 0; // real mode (bit 0)
BX_CPU_THIS_PTR cr0.em = 0; // emulate math coprocessor (bit 2)
BX_CPU_THIS_PTR cr0.ts = 0; // no task switch (bit 3)
BX_CPU_THIS_PTR cr0.pg = 0; // paging disabled (bit 31)
BX_CPU_THIS_PTR cr0.val32 &= 0x7ffffff2;
// paging mode was changed - flush TLB
TLB_flush(1); // 1 = Flush Global entries also
#if BX_CPU_LEVEL >= 4
BX_CPU_THIS_PTR cr4.setRegister(0);
#endif
// EFER.LME = 0, EFER.LME = 1
#if BX_SUPPORT_X86_64
BX_CPU_THIS_PTR msr.lme = 0;
BX_CPU_THIS_PTR msr.lma = 0;
#endif
}
bx_bool BX_CPU_C::smram_write(bx_phy_address a20addr)
{
return 1; // for now
}
#define SMRAM_TRANSLATE(addr) (((0x8000 - (addr)) >> 2) - 1)
@ -318,7 +318,7 @@ void BX_CPU_C::smram_save_state(void)
/* base+0x7f9c to base+0x7f04 is reserved */
/* base+0x7f02 is Auto HALT restart field (2 byte) */
/* base+0x7f00 is I/O restart field (2 byte) */
/* base+0x7efc is SMM Revision Identifier field */
/* base+0x7efc is SMM Revision Identifier field */
saved_state[SMRAM_TRANSLATE(0x7ef8)] = BX_CPU_THIS_PTR smbase;
/* base+0x7ef4 to base+0x7e00 is reserved */

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: memory.cc,v 1.52 2006-03-26 22:15:07 sshwarts Exp $
// $Id: memory.cc,v 1.53 2006-03-28 16:53:02 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -44,10 +44,10 @@
//
void BX_CPP_AttrRegparmN(3)
BX_MEM_C::writePhysicalPage(BX_CPU_C *cpu, Bit32u addr, unsigned len, void *data)
BX_MEM_C::writePhysicalPage(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, void *data)
{
Bit8u *data_ptr;
Bit32u a20addr = A20ADDR(addr);
bx_phy_address a20addr = A20ADDR(addr);
// Note: accesses should always be contained within a single page now
@ -161,7 +161,7 @@ inc_one:
// SMMRAM
if (a20addr <= 0x000bffff) {
// devices are not allowed to access SMMRAM under VGA memory
if (cpu && cpu->smram_write(a20addr)) {
if (cpu) {
vector[a20addr] = *data_ptr;
BX_DBG_DIRTY_PAGE(a20addr >> 12);
}
@ -202,10 +202,10 @@ inc_one:
}
void BX_CPP_AttrRegparmN(3)
BX_MEM_C::readPhysicalPage(BX_CPU_C *cpu, Bit32u addr, unsigned len, void *data)
BX_MEM_C::readPhysicalPage(BX_CPU_C *cpu, bx_phy_address addr, unsigned len, void *data)
{
Bit8u *data_ptr;
Bit32u a20addr = A20ADDR(addr);
bx_phy_address a20addr = A20ADDR(addr);
// Note: accesses should always be contained within a single page now
@ -361,7 +361,7 @@ inc_one:
#endif
for (unsigned i = 0; i < len; i++) {
if (a20addr >= (Bit32u)~BIOS_MASK)
if (a20addr >= (bx_phy_address)~BIOS_MASK)
*data_ptr = rom[a20addr & BIOS_MASK];
else
*data_ptr = 0xff;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: memory.h,v 1.36 2006-03-27 18:02:07 sshwarts Exp $
// $Id: memory.h,v 1.37 2006-03-28 16:53:02 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2001 MandrakeSoft S.A.
@ -54,8 +54,8 @@ typedef bx_bool (*memory_handler_t)(unsigned long addr, unsigned long len, void
struct memory_handler_struct {
struct memory_handler_struct *next;
void *param;
unsigned long begin;
unsigned long end;
bx_phy_address begin;
bx_phy_address end;
memory_handler_t read_handler;
memory_handler_t write_handler;
};
@ -93,21 +93,21 @@ public:
BX_MEM_SMF void enable_smram(bx_bool enable, bx_bool restricted);
BX_MEM_SMF void disable_smram(void);
BX_MEM_SMF bx_bool is_smram_accessible(void);
BX_MEM_SMF void readPhysicalPage(BX_CPU_C *cpu, Bit32u addr,
BX_MEM_SMF void readPhysicalPage(BX_CPU_C *cpu, bx_phy_address addr,
unsigned len, void *data) BX_CPP_AttrRegparmN(3);
BX_MEM_SMF void writePhysicalPage(BX_CPU_C *cpu, Bit32u addr,
BX_MEM_SMF void writePhysicalPage(BX_CPU_C *cpu, bx_phy_address addr,
unsigned len, void *data) BX_CPP_AttrRegparmN(3);
BX_MEM_SMF void load_ROM(const char *path, Bit32u romaddress, Bit8u type);
BX_MEM_SMF void load_RAM(const char *path, Bit32u romaddress, Bit8u type);
BX_MEM_SMF void load_ROM(const char *path, bx_phy_address romaddress, Bit8u type);
BX_MEM_SMF void load_RAM(const char *path, bx_phy_address romaddress, Bit8u type);
BX_MEM_SMF Bit32u get_memory_in_k(void);
BX_MEM_SMF bx_bool dbg_fetch_mem(Bit32u addr, unsigned len, Bit8u *buf);
BX_MEM_SMF bx_bool dbg_set_mem(Bit32u addr, unsigned len, Bit8u *buf);
BX_MEM_SMF bx_bool dbg_crc32(Bit32u addr1, Bit32u addr2, Bit32u *crc);
BX_MEM_SMF Bit8u* getHostMemAddr(BX_CPU_C *cpu, Bit32u a20Addr, unsigned op, unsigned access_type);
BX_MEM_SMF bx_bool dbg_fetch_mem(bx_phy_address addr, unsigned len, Bit8u *buf);
BX_MEM_SMF bx_bool dbg_set_mem(bx_phy_address addr, unsigned len, Bit8u *buf);
BX_MEM_SMF bx_bool dbg_crc32(bx_phy_address addr1, bx_phy_address addr2, Bit32u *crc);
BX_MEM_SMF Bit8u* getHostMemAddr(BX_CPU_C *cpu, bx_phy_address a20Addr, unsigned op, unsigned access_type);
BX_MEM_SMF bx_bool registerMemoryHandlers(void *param, memory_handler_t read_handler,
memory_handler_t write_handler, Bit32u begin_addr, Bit32u end_addr);
BX_MEM_SMF bx_bool unregisterMemoryHandlers(memory_handler_t read_handler, memory_handler_t write_handler,
Bit32u begin_addr, Bit32u end_addr);
memory_handler_t write_handler, bx_phy_address begin_addr, bx_phy_address end_addr);
BX_MEM_SMF bx_bool unregisterMemoryHandlers(memory_handler_t read_handler, memory_handler_t write_handler,
bx_phy_address begin_addr, bx_phy_address end_addr);
};
#if BX_PROVIDE_CPU_MEMORY==1

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////
// $Id: misc_mem.cc,v 1.86 2006-03-27 18:02:07 sshwarts Exp $
// $Id: misc_mem.cc,v 1.87 2006-03-28 16:53:02 sshwarts Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
@ -94,7 +94,7 @@ void BX_MEM_C::init_memory(int memsize)
{
int idx;
BX_DEBUG(("Init $Id: misc_mem.cc,v 1.86 2006-03-27 18:02:07 sshwarts Exp $"));
BX_DEBUG(("Init $Id: misc_mem.cc,v 1.87 2006-03-28 16:53:02 sshwarts Exp $"));
// you can pass 0 if memory has been allocated already through
// the constructor, or the desired size of memory if it hasn't
@ -179,7 +179,7 @@ Bit8u mp_checksum(const Bit8u *p, int len)
// 1 : VGA Bios
// 2 : Optional ROM Bios
//
void BX_MEM_C::load_ROM(const char *path, Bit32u romaddress, Bit8u type)
void BX_MEM_C::load_ROM(const char *path, bx_phy_address romaddress, Bit8u type)
{
struct stat stat_buf;
int fd, ret, i, start_idx, end_idx;
@ -244,7 +244,7 @@ void BX_MEM_C::load_ROM(const char *path, Bit32u romaddress, Bit8u type)
return;
}
} else {
romaddress = (Bit32u)-size;
romaddress = (bx_phy_address)-size;
}
offset = romaddress & BIOS_MASK;
if ((romaddress & 0xf0000) < 0xf0000) {
@ -385,7 +385,7 @@ void BX_MEM_C::load_ROM(const char *path, Bit32u romaddress, Bit8u type)
path));
}
void BX_MEM_C::load_RAM(const char *path, Bit32u ramaddress, Bit8u type)
void BX_MEM_C::load_RAM(const char *path, bx_phy_address ramaddress, Bit8u type)
{
struct stat stat_buf;
int fd, ret;
@ -432,7 +432,7 @@ void BX_MEM_C::load_RAM(const char *path, Bit32u ramaddress, Bit8u type)
#if ( BX_DEBUGGER || BX_DISASM || BX_GDBSTUB)
bx_bool BX_MEM_C::dbg_fetch_mem(Bit32u addr, unsigned len, Bit8u *buf)
bx_bool BX_MEM_C::dbg_fetch_mem(bx_phy_address addr, unsigned len, Bit8u *buf)
{
bx_bool ret = 1;
@ -497,7 +497,7 @@ bx_bool BX_MEM_C::dbg_fetch_mem(Bit32u addr, unsigned len, Bit8u *buf)
#endif
#if BX_DEBUGGER || BX_GDBSTUB
bx_bool BX_MEM_C::dbg_set_mem(Bit32u addr, unsigned len, Bit8u *buf)
bx_bool BX_MEM_C::dbg_set_mem(bx_phy_address addr, unsigned len, Bit8u *buf)
{
if ((addr + len) > BX_MEM_THIS len) {
return(0); // error, beyond limits of memory
@ -535,7 +535,7 @@ bx_bool BX_MEM_C::dbg_set_mem(Bit32u addr, unsigned len, Bit8u *buf)
}
#endif
bx_bool BX_MEM_C::dbg_crc32(Bit32u addr1, Bit32u addr2, Bit32u *crc)
bx_bool BX_MEM_C::dbg_crc32(bx_phy_address addr1, bx_phy_address addr2, Bit32u *crc)
{
*crc = 0;
if (addr1 > addr2)
@ -573,7 +573,7 @@ bx_bool BX_MEM_C::dbg_crc32(Bit32u addr1, Bit32u addr2, Bit32u *crc)
// 0xf0000 - 0xfffff Upper BIOS Area (64K)
//
Bit8u *BX_MEM_C::getHostMemAddr(BX_CPU_C *cpu, Bit32u a20Addr, unsigned op, unsigned access_type)
Bit8u *BX_MEM_C::getHostMemAddr(BX_CPU_C *cpu, bx_phy_address a20Addr, unsigned op, unsigned access_type)
{
BX_ASSERT(cpu != 0); // getHostMemAddr could be used only inside the CPU
@ -641,7 +641,7 @@ Bit8u *BX_MEM_C::getHostMemAddr(BX_CPU_C *cpu, Bit32u a20Addr, unsigned op, unsi
return( (Bit8u *) & rom[(a20Addr & EXROM_MASK) + BIOSROMSZ]);
}
}
else if (a20Addr >= (Bit32u)~BIOS_MASK)
else if (a20Addr >= (bx_phy_address)~BIOS_MASK)
{
return (Bit8u *) & rom[a20Addr & BIOS_MASK];
}
@ -658,7 +658,7 @@ Bit8u *BX_MEM_C::getHostMemAddr(BX_CPU_C *cpu, Bit32u a20Addr, unsigned op, unsi
return(NULL); // Error, requested addr is out of bounds.
else if ((a20Addr & 0xfffe0000) == 0x000a0000)
return(NULL); // Vetoed! Mem mapped IO (VGA)
else if (a20Addr >= (Bit32u)~BIOS_MASK)
else if (a20Addr >= (bx_phy_address)~BIOS_MASK)
return(NULL); // Vetoed! ROMs
#if BX_SUPPORT_PCI
else if (pci_enabled && ((a20Addr & 0xfffc0000) == 0x000c0000))
@ -700,7 +700,7 @@ Bit8u *BX_MEM_C::getHostMemAddr(BX_CPU_C *cpu, Bit32u a20Addr, unsigned op, unsi
*/
bx_bool
BX_MEM_C::registerMemoryHandlers(void *param, memory_handler_t read_handler,
memory_handler_t write_handler, Bit32u begin_addr, Bit32u end_addr)
memory_handler_t write_handler, bx_phy_address begin_addr, bx_phy_address end_addr)
{
if (end_addr < begin_addr)
return false;
@ -722,7 +722,7 @@ BX_MEM_C::registerMemoryHandlers(void *param, memory_handler_t read_handler,
bx_bool
BX_MEM_C::unregisterMemoryHandlers(memory_handler_t read_handler, memory_handler_t write_handler,
Bit32u begin_addr, Bit32u end_addr)
bx_phy_address begin_addr, bx_phy_address end_addr)
{
bx_bool ret = true;
BX_INFO(("Memory access handlers unregistered: %08x-%08x", begin_addr, end_addr));