From 815050f0b2bff48d336629132f68b8779b3c9267 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Wed, 19 Dec 2018 14:57:20 -0800 Subject: Set up PMP earlier, so it can be overridden later --- machine/minit.c | 7 ++----- machine/mtrap.h | 1 + 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/machine/minit.c b/machine/minit.c index fe106eb..bb1ee6e 100644 --- a/machine/minit.c +++ b/machine/minit.c @@ -98,6 +98,7 @@ static void hart_init() #ifndef BBL_BOOT_MACHINE delegate_traps(); #endif /* BBL_BOOT_MACHINE */ + setup_pmp(); } static void plic_init() @@ -187,7 +188,7 @@ void init_other_hart(uintptr_t hartid, uintptr_t dtb) boot_other_hart(dtb); } -static inline void setup_pmp(void) +void setup_pmp(void) { // Set up a PMP to permit access to all of memory. // Ignore the illegal-instruction trap if PMPs aren't supported. @@ -203,8 +204,6 @@ static inline void setup_pmp(void) void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1) { - setup_pmp(); - uintptr_t mstatus = read_csr(mstatus); mstatus = INSERT_FIELD(mstatus, MSTATUS_MPP, PRV_S); mstatus = INSERT_FIELD(mstatus, MSTATUS_MPIE, 0); @@ -224,8 +223,6 @@ void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1 void enter_machine_mode(void (*fn)(uintptr_t, uintptr_t), uintptr_t arg0, uintptr_t arg1) { - setup_pmp(); - uintptr_t mstatus = read_csr(mstatus); mstatus = INSERT_FIELD(mstatus, MSTATUS_MPIE, 0); write_csr(mstatus, mstatus); diff --git a/machine/mtrap.h b/machine/mtrap.h index a5bcea2..74520c5 100644 --- a/machine/mtrap.h +++ b/machine/mtrap.h @@ -65,6 +65,7 @@ void putstring(const char* s); #define assert(x) ({ if (!(x)) die("assertion failed: %s", #x); }) #define die(str, ...) ({ printm("%s:%d: " str "\n", __FILE__, __LINE__, ##__VA_ARGS__); poweroff(-1); }) +void setup_pmp(); void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1) __attribute__((noreturn)); void enter_machine_mode(void (*fn)(uintptr_t, uintptr_t), uintptr_t arg0, uintptr_t arg1) -- cgit v1.1