aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHesham Almatary <Hesham.Almatary@cl.cam.ac.uk>2018-07-12 11:05:57 +0100
committerHesham Almatary <Hesham.Almatary@cl.cam.ac.uk>2018-07-12 11:05:59 +0100
commit165c85caeec4f2558c3981c4221573426acd58dc (patch)
tree03d0bc05e023d2c07eb5e1355095e193b515eb1a
parent72672f9a393e10e5444f733cba287a9744cd4033 (diff)
downloadriscv-pk-165c85caeec4f2558c3981c4221573426acd58dc.zip
riscv-pk-165c85caeec4f2558c3981c4221573426acd58dc.tar.gz
riscv-pk-165c85caeec4f2558c3981c4221573426acd58dc.tar.bz2
minit: Move pmp setup code to a separate function to avoid duplicating code
Currently it's being used by both enter_supervisor_mode and enter_machine_mode
-rw-r--r--machine/minit.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/machine/minit.c b/machine/minit.c
index de75192..953e1ba 100644
--- a/machine/minit.c
+++ b/machine/minit.c
@@ -186,7 +186,7 @@ void init_other_hart(uintptr_t hartid, uintptr_t dtb)
boot_other_hart(dtb);
}
-void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1)
+static inline 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.
@@ -198,6 +198,11 @@ void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1
".align 2\n\t"
"1: csrw mtvec, t0"
: : "r" (pmpc), "r" (-1UL) : "t0");
+}
+
+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);
@@ -218,16 +223,7 @@ 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)
{
- // Set up a PMP to permit access to all of memory.
- // Ignore the illegal-instruction trap if PMPs aren't supported.
- uintptr_t pmpc = PMP_NAPOT | PMP_R | PMP_W | PMP_X;
- asm volatile ("la t0, 1f\n\t"
- "csrrw t0, mtvec, t0\n\t"
- "csrw pmpaddr0, %1\n\t"
- "csrw pmpcfg0, %0\n\t"
- ".align 2\n\t"
- "1: csrw mtvec, t0"
- : : "r" (pmpc), "r" (-1UL) : "t0");
+ setup_pmp();
uintptr_t mstatus = read_csr(mstatus);
mstatus = INSERT_FIELD(mstatus, MSTATUS_MPIE, 0);