#include <ibmpc.h>
Also provides simple per-page memory protection mechanism.
In case of error operation will NOT be performed (memory will be unaffected, and if driver is handling the page it will *not* be called).
READ operations will return 0 in case of error.
Definition at line 62 of file ibmpc.h.
Public Types | |
PERM_READABLE = 0x0001 | |
This memory page is readable. | |
PERM_WRITEABLE = 0x0002 | |
This memory page is writeable. | |
PAGE_ALLOCATED = 0x8000 | |
Block of memory for this page's storage was allocated by the manager. | |
STATE_FAULT = 0x0001 | |
0:last operation succeeded; 1:failed | |
STATE_DIR = 0x0002 | |
0:last operation was READ, 1:WRITE | |
enum | perm_t { PERM_READABLE = 0x0001, PERM_WRITEABLE = 0x0002, PAGE_ALLOCATED = 0x8000 } |
Memory page permissions bitmask. More... | |
enum | state_t { STATE_FAULT = 0x0001, STATE_DIR = 0x0002 } |
Memory bus state bitmask (used to check for error in last operation). More... | |
Public Member Functions | |
Memory () | |
Construct instance of Memory manager. | |
~Memory () | |
Destruct instance of Memory manager. | |
bool | alloc_pagetable (unsigned int pages_count_pow, unsigned int page_size_pow) |
Allocate/Reallocate memory page table. | |
unsigned int | get_page_size () |
void | page_set_perm (unsigned int page_index, uint32 perm) |
Set permissions for memory page (also see enum perm_t). | |
uint32 | page_get_perm (unsigned int page_index) |
Retrieve permissions of given memory page. | |
bool | page_alloc (unsigned int page_index) |
Allocate real memory for the memory page. | |
void | page_attach (unsigned int page_index, Device *driver) |
Attach device driver to handle accesses to the memory page. | |
void | page_free (unsigned int page_index) |
Free real memory block allocated for this memory page or detach page from Device driver. | |
uint8 | mem_read8 (unsigned int addr) |
Load 8 bits from memory at given "flat" address. | |
void | mem_write8 (unsigned int addr, uint8 data) |
Store 8 bits to memory at given "flat" address. | |
uint32 | get_state () |
Query last memory access status. |
IBMPC::Memory::Memory | ( | ) |
IBMPC::Memory::~Memory | ( | ) |
bool IBMPC::Memory::alloc_pagetable | ( | unsigned int | pages_count_pow, | |
unsigned int | page_size_pow | |||
) |
Allocate/Reallocate memory page table.
Definition at line 30 of file ibmpc.cpp.
Referenced by IBMPC::VirtualMachine::VirtualMachine().
void IBMPC::Memory::page_set_perm | ( | unsigned int | page_index, | |
uint32 | perm | |||
) |
Set permissions for memory page (also see enum perm_t).
This function preserves existing value of PAGE_ALLOCATED bit, no matter which value of this bit is in the parameter "perm" passed to this function.
In DEBUG build, the function will OE_ASSERT() if page index is out of bounds.
uint32 IBMPC::Memory::page_get_perm | ( | unsigned int | page_index | ) |
Retrieve permissions of given memory page.
In DEBUG build, the function will OE_ASSERT() if page index is out of bounds.
bool IBMPC::Memory::page_alloc | ( | unsigned int | page_index | ) |
Allocate real memory for the memory page.
Definition at line 90 of file ibmpc.cpp.
Referenced by IBMPC::VirtualMachine::VirtualMachine().
void IBMPC::Memory::page_attach | ( | unsigned int | page_index, | |
Device * | driver | |||
) |
Attach device driver to handle accesses to the memory page.
Definition at line 105 of file ibmpc.cpp.
Referenced by IBMPC::VDD_Video_CGA_6845::init().
void IBMPC::Memory::page_free | ( | unsigned int | page_index | ) |
Free real memory block allocated for this memory page or detach page from Device driver.
After freeing, the page permissions bitmask will be zeroed.
In DEBUG build, the function will OE_ASSERT() if page index is out of bounds.
Definition at line 116 of file ibmpc.cpp.
Referenced by alloc_pagetable(), IBMPC::VDD_Video_CGA_6845::done(), page_alloc(), page_attach(), and ~Memory().
uint8 IBMPC::Memory::mem_read8 | ( | unsigned int | addr | ) |
Load 8 bits from memory at given "flat" address.
In case page permissions are violated (or attached Device driver performing the operation decided to fail the call) value of 0 will be returned, and state flags (state_t) set to indicate fault.
It is caller's responsibility to check for faults using call to get_state() immediately after performing the access.
Definition at line 128 of file ibmpc.cpp.
Referenced by IBMPC::VDD_DMA::read_next_word().
void IBMPC::Memory::mem_write8 | ( | unsigned int | addr, | |
uint8 | data | |||
) |
Store 8 bits to memory at given "flat" address.
It is caller's responsibility to check for faults using call to get_state() immediately after performing the access.
Definition at line 146 of file ibmpc.cpp.
Referenced by IBMPC::copy_to_mem(), IBMPC::load_ibmpc_rom(), and IBMPC::VDD_DMA::write_next_word().
uint32 IBMPC::Memory::get_state | ( | ) |
Query last memory access status.