now fetching from ram correctly as ram is 32 bit word not byte indexed

This commit is contained in:
Yehowshua Immanuel 2025-03-07 21:41:46 -05:00
parent 3f50fe32f8
commit 63a73d3f71
3 changed files with 9 additions and 1 deletions

View file

@ -25,6 +25,11 @@ essence forms the context of our micro-op machinery.
Change instructions to support Nix
## Disassembling
```
riscv64-unknown-elf-objdump -D -b binary -m riscv:rv64 ./rv_tests/hello_world/hello.bin > hello.asm
```
# TODO
- [ ] fetch should invoke mem read function

View file

@ -56,7 +56,7 @@ read :: ReadRequest -> Peripherals -> IO ReadResponse
read (Request addr size) peripherals
| not (alignCheck addr size) = return |> Left UnAligned
| (addr >= ramStart) && (addr <= ramEnd) =
return |> Right |> Peripherals.Ram.read size ramAddr (ram peripherals)
return |> Right |> Peripherals.Ram.read size ramWordAddr (ram peripherals)
| (addr >= uartStart) && (addr <= uartEnd) =
fmap Right (Peripherals.Uart.read size uartAddr)
| otherwise = return |> Left UnMapped
@ -64,6 +64,8 @@ read (Request addr size) peripherals
ramAddrNoOffset = addr - ramStart
ramAddr :: RamAddr
ramAddr = resize ramAddrNoOffset
ramWordAddr :: RamAddr
ramWordAddr = resize |> ramAddrNoOffset `shiftR` 2
uartAddrNoOffset = addr - uartStart
uartAddr :: UartAddr

View file

@ -46,6 +46,7 @@ simulationLoop n machine = do
fetchResult <- fetchInstruction machinePeripherals currPc
let decodeResult = decode fetchResult
putStrLn |> show decodeResult P.++ debugInsn fetchResult
putStrLn $ "PC: " P.++ show currPc
let pc' = currPc + 4
cpu' = (cpu machine) { pc = pc' }
machine' = machine { cpu = cpu' }