From 060c0de0f3c57c5bc1cd52dd2b58f16bbce70d43 Mon Sep 17 00:00:00 2001 From: inixyz Date: Fri, 13 Oct 2023 23:53:41 +0300 Subject: [PATCH] stack pointer and memsize --- src/main.c | 2 +- src/tinyriscv.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index e5b412a..d38bf83 100644 --- a/src/main.c +++ b/src/main.c @@ -51,7 +51,7 @@ int main(int argc, char** argv){ } trv_cpu cpu; - cpu.mem = malloc(mem_size); + cpu.mem = malloc(cpu.mem_size = mem_size); //file handling FILE* file = fopen(file_path, "rb"); diff --git a/src/tinyriscv.h b/src/tinyriscv.h index ac12897..4f722e7 100644 --- a/src/tinyriscv.h +++ b/src/tinyriscv.h @@ -12,7 +12,7 @@ typedef int16_t i16; typedef int32_t i32; typedef struct{ - u32 regs[32], pc; + u32 regs[32], pc, mem_size; u8* mem; }trv_cpu; @@ -174,6 +174,7 @@ void trv_step(trv_cpu* cpu){ } void trv_init(trv_cpu* cpu){ + cpu->regs[2] = trv_MEM_OFFSET + cpu->mem_size; cpu->pc = trv_MEM_OFFSET; }