From 1ef81063a08b623110a829bed41e347c66789708 Mon Sep 17 00:00:00 2001 From: inixyz Date: Sun, 15 Oct 2023 21:15:42 +0300 Subject: [PATCH] fix aluipc --- src/main.c | 2 +- src/tinyriscv.h | 2 +- tests/test.bin | Bin 28 -> 28 bytes 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 4d3df88..d7624e0 100644 --- a/src/main.c +++ b/src/main.c @@ -94,7 +94,7 @@ int main(int argc, char** argv){ } tinyriscv_hart hart; - hart.mem = malloc(hart.mem_size = mem_size); + hart.mem = calloc(hart.mem_size = mem_size, 1); //file handling FILE* file = fopen(file_path, "rb"); diff --git a/src/tinyriscv.h b/src/tinyriscv.h index ad81d0e..5426ce9 100644 --- a/src/tinyriscv.h +++ b/src/tinyriscv.h @@ -154,7 +154,7 @@ void tinyriscv_step(tinyriscv_hart* hart){ switch(opcode){ case /*LUI*/ 0x37: hart->x[rd] = inst & 0xfffff000; break; - case /*AUIPC*/ 0x17: hart->x[rd] = hart->pc + (inst & 0xfffff000); break; + case /*AUIPC*/ 0x17: hart->x[rd] = hart->pc - 4 + (inst & 0xfffff000); break; case /*JAL*/ 0x6f: hart->x[rd] = hart->pc; hart->pc += imm_j - 4; break; case /*JALR*/ 0x67: const u32 last_pc = hart->pc; diff --git a/tests/test.bin b/tests/test.bin index 73256dcf5396c4a17ec44d981ed2c9d90e8c2f1e..3df3f69658441776d97df5fa7de918b86ee318b2 100644 GIT binary patch delta 13 Ucmb1