os-workshop

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

commit 78f833375450b7fb59459e1488bae7304c01a8e5
parent 076c950cbce75bd1a65f78262f7bfd9832a5724e
Author: Brian Swetland <swetland@frotz.net>
Date:   Mon,  9 May 2022 11:44:03 -0700

misc/traps: make this demo run again

- use memory info from hw/platform.h
- don't return from fatal exceptions

Diffstat:
Mmisc/traps.c | 30++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/misc/traps.c b/misc/traps.c @@ -3,20 +3,20 @@ #include <hw/riscv.h> #include <hw/debug.h> +#include <hw/platform.h> -#define MEMORY_BASE (0x80000000) -#define MEMORY_SIZE (128*1024*1024) -#define MEMORY_TOP (MEMORY_BASE + MEMORY_SIZE) +#define MEMORY_TOP (DRAM_BASE + DRAM_SIZE) -#define SVC_SP (MEMORY_TOP) -#define USER_SP (MEMORY_TOP - (1024*1024)) +#define SVC_SP (MEMORY_TOP - 8*1024) +#define USER_SP (MEMORY_TOP - 16*1024) extern void svc_exception_entry(void); +void enter_mode_u(uint32_t a0, uint32_t a1, uint32_t user_pc, uint32_t user_sp); void svc_exception_handler(uint32_t regs[32]) { uint32_t cause = csr_read(CSR_SCAUSE); uint32_t val = csr_read(CSR_STVAL); - xprintf("SUPERVISOR EXCEPTION %08x %08x %08x\n", + xprintf("\nSUPERVISOR EXCEPTION %08x %08x %08x\n", cause, val, (unsigned) regs); xprintf("pc %08x ra %08x sp %08x gp %08x\n", @@ -25,28 +25,30 @@ void svc_exception_handler(uint32_t regs[32]) { regs[4], regs[5], regs[6], regs[7]); xprintf("fp %08x s1 %08x a0 %08x a1 %08x\n", regs[8], regs[9], regs[10], regs[11]); - xprintf("a2 %08x a3 %08x a4 %08x a5 %08x\n", + xprintf("a2 %08x a3 %08x a4 %08x a5 %08x\n\n", regs[12], regs[13], regs[14], regs[15]); if (cause == EXCn_ECALL_UMODE) { // advance return address to next instr regs[0] += 4; + xprintf("RETURNING FROM ECALL\n"); + return; } - csr_clr(CSR_SIP, INTb_SVC_SW); + xprintf("HALTED\n"); + for (;;) ; } -void enter_mode_u(uint32_t a0, uint32_t a1, uint32_t user_pc, uint32_t user_sp); - void user_start(uint32_t hartid, uint32_t fdt) { xprintf("Hello, User Mode hartid=%08x fdt=%08x\n", hartid, fdt); - // illegal write from user mode - // csr_write(CSR_MEPC, 0x42); - // syscall asm volatile ("ecall"); + // illegal write from user mode + csr_write(CSR_MEPC, 0x42); + + xprintf("\nSTOP\n"); for (;;) ; } @@ -57,7 +59,7 @@ void start(uint32_t hartid, uint32_t fdt) { csr_write(CSR_STVEC, (uintptr_t) svc_exception_entry); csr_write(CSR_SSCRATCH, SVC_SP); - csr_set(CSR_SIE, INTb_SVC_SW); + //csr_set(CSR_SIE, INTb_SVC_SW); enter_mode_u(hartid, fdt, (uintptr_t)user_start, USER_SP);