|
|
@ -40,7 +40,7 @@ void mem_register_mmio(uint32_t address, uint32_t reg_size, uint32_t reg_count, |
|
|
|
|
|
|
|
|
|
|
|
void mem_write8(uint32_t address, uint8_t value) |
|
|
|
void mem_write8(uint32_t address, uint8_t value) |
|
|
|
{ |
|
|
|
{ |
|
|
|
address = mmu_resolve(cpu0, address); |
|
|
|
address = mmu_resolve(cpu0, WRITE, address); |
|
|
|
|
|
|
|
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
@ -71,7 +71,7 @@ void mem_write8(uint32_t address, uint8_t value) |
|
|
|
|
|
|
|
|
|
|
|
void mem_write16(uint32_t address, uint16_t value) |
|
|
|
void mem_write16(uint32_t address, uint16_t value) |
|
|
|
{ |
|
|
|
{ |
|
|
|
address = mmu_resolve(cpu0, address); |
|
|
|
address = mmu_resolve(cpu0, WRITE, address); |
|
|
|
|
|
|
|
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
@ -102,7 +102,7 @@ void mem_write16(uint32_t address, uint16_t value) |
|
|
|
|
|
|
|
|
|
|
|
void mem_write32(uint32_t address, uint32_t value) |
|
|
|
void mem_write32(uint32_t address, uint32_t value) |
|
|
|
{ |
|
|
|
{ |
|
|
|
address = mmu_resolve(cpu0, address); |
|
|
|
address = mmu_resolve(cpu0, WRITE, address); |
|
|
|
|
|
|
|
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
@ -133,7 +133,7 @@ void mem_write32(uint32_t address, uint32_t value) |
|
|
|
|
|
|
|
|
|
|
|
uint8_t mem_read8(uint32_t address) |
|
|
|
uint8_t mem_read8(uint32_t address) |
|
|
|
{ |
|
|
|
{ |
|
|
|
address = mmu_resolve(cpu0, address); |
|
|
|
address = mmu_resolve(cpu0, READ, address); |
|
|
|
|
|
|
|
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
@ -164,7 +164,7 @@ uint8_t mem_read8(uint32_t address) |
|
|
|
|
|
|
|
|
|
|
|
uint16_t mem_read16(uint32_t address) |
|
|
|
uint16_t mem_read16(uint32_t address) |
|
|
|
{ |
|
|
|
{ |
|
|
|
address = mmu_resolve(cpu0, address); |
|
|
|
address = mmu_resolve(cpu0, READ, address); |
|
|
|
|
|
|
|
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
@ -195,7 +195,7 @@ uint16_t mem_read16(uint32_t address) |
|
|
|
|
|
|
|
|
|
|
|
uint32_t mem_read32(uint32_t address) |
|
|
|
uint32_t mem_read32(uint32_t address) |
|
|
|
{ |
|
|
|
{ |
|
|
|
address = mmu_resolve(cpu0, address); |
|
|
|
address = mmu_resolve(cpu0, READ, address); |
|
|
|
|
|
|
|
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
@ -223,3 +223,26 @@ uint32_t mem_read32(uint32_t address) |
|
|
|
pthread_mutex_unlock(&memory_mutex); |
|
|
|
pthread_mutex_unlock(&memory_mutex); |
|
|
|
return tr; |
|
|
|
return tr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t mem_fetch(uint32_t address) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
address = mmu_resolve(cpu0, INSTRUCTION_FETCH, address); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Look wether we are on an MMIO region
|
|
|
|
|
|
|
|
struct MMIO_ENTRY* io = mmio; |
|
|
|
|
|
|
|
while(io) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if(MMIO_INSIDE(io, address)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
fprintf(stderr, "MEMORY: Trying to fetch an instruction inside an MMIO region !\n"); |
|
|
|
|
|
|
|
exit(EXIT_FAILURE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
io = io->next; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Proceed with memory read
|
|
|
|
|
|
|
|
pthread_mutex_lock(&memory_mutex); |
|
|
|
|
|
|
|
uint32_t tr = *((uint32_t*) &memory[address]); |
|
|
|
|
|
|
|
pthread_mutex_unlock(&memory_mutex); |
|
|
|
|
|
|
|
return tr; |
|
|
|
|
|
|
|
} |
|
|
|