riscv

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 78f5bde3560fc41e88ceee3c4e46d9fa8cb3d3e1
parent 85d3efcca64bf41f52b5763af6ae11b88afc8235
Author: Brian Swetland <swetland@frotz.net>
Date:   Fri, 18 Oct 2019 21:39:26 -0700

rvsim: move memory to 0x80000000

- test suite is setup this way
- stub in ior() iow() for accesses below 0x80000000

Diffstat:
Mrvsim.c | 26+++++++++++++++++++++-----
Msimple.ld | 4++--
2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/rvsim.c b/rvsim.c @@ -34,14 +34,29 @@ int load_image(const char* fn, uint8_t* ptr, size_t sz) { return 0; } +uint32_t ior32(uint32_t addr) { + return 0xffffffff; +} + +void iow32(uint32_t addr, uint32_t val) { +} + uint32_t rd32(uint32_t addr) { - addr &= (sizeof(memory) - 1); - return ((uint32_t*) memory)[addr >> 2]; + if (addr < 0x80000000) { + return ior32(addr); + } else { + addr &= (sizeof(memory) - 1); + return ((uint32_t*) memory)[addr >> 2]; + } } void wr32(uint32_t addr, uint32_t val) { - addr &= (sizeof(memory) - 1); - ((uint32_t*) memory)[addr >> 2] = val; + if (addr < 0x80000000) { + iow32(addr, val); + } else { + addr &= (sizeof(memory) - 1); + ((uint32_t*) memory)[addr >> 2] = val; + } } typedef struct { @@ -53,7 +68,7 @@ void rvsim(rvstate* s) { char dis[128]; uint32_t pc, ins; pc = s->pc; - while (pc < 64) { + while (pc < 0x80000100) { ins = rd32(pc); rvdis(pc, ins, dis); printf("%08x: %08x %s\n", pc, ins, dis); @@ -66,6 +81,7 @@ int main(int argc, char** argv) { rvstate s; if (load_image("out/hello.bin", memory, sizeof(memory)) < 0) return -1; memset(&s, 0, sizeof(s)); + s.pc = 0x80000000; rvsim(&s); return 0; } diff --git a/simple.ld b/simple.ld @@ -1,11 +1,11 @@ MEMORY { - mem : ORIGIN = 0x00000000, LENGTH = 0x00020000 + mem : ORIGIN = 0x80000000, LENGTH = 0x00010000 } SECTIONS { .memory : { - . = 0x000000; + . = 0x00000000; start*(.text); *(.text); *(*);