Browse Source

bbl: boot payload in machine mode when --enable-boot-machine is passed

pull/104/head
Hesham Almatary 8 years ago
parent
commit
72672f9a39
  1. 4
      bbl/bbl.c
  2. 5
      machine/mentry.S
  3. 26
      machine/minit.c
  4. 2
      machine/mtrap.h

4
bbl/bbl.c

@ -58,7 +58,11 @@ void boot_other_hart(uintptr_t unused __attribute__((unused)))
}
}
#ifdef BBL_BOOT_MACHINE
enter_machine_mode(entry, hartid, dtb_output());
#else /* Run bbl in supervisor mode */
enter_supervisor_mode(entry, hartid, dtb_output());
#endif
}
void boot_loader(uintptr_t dtb)

5
machine/mentry.S

@ -2,6 +2,7 @@
#include "mtrap.h"
#include "bits.h"
#include "config.h"
.data
.align 6
@ -18,7 +19,11 @@ trap_table:
.word bad_trap
.word mcall_trap
.word bad_trap
#ifdef BBL_BOOT_MACHINE
.word mcall_trap
#else
.word bad_trap
#endif /* BBL_BOOT_MACHINE */
.word bad_trap
#define TRAP_FROM_MACHINE_MODE_VECTOR 13
.word __trap_from_machine_mode

26
machine/minit.c

@ -95,7 +95,9 @@ static void hart_init()
{
mstatus_init();
fp_init();
#ifndef BBL_BOOT_MACHINE
delegate_traps();
#endif /* BBL_BOOT_MACHINE */
}
static void plic_init()
@ -213,3 +215,27 @@ void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1
asm volatile ("mret" : : "r" (a0), "r" (a1));
__builtin_unreachable();
}
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");
uintptr_t mstatus = read_csr(mstatus);
mstatus = INSERT_FIELD(mstatus, MSTATUS_MPIE, 0);
write_csr(mstatus, mstatus);
write_csr(mscratch, MACHINE_STACK_TOP() - MENTRY_FRAME_SIZE);
/* Jump to the payload's entry point */
fn(arg0, arg1);
__builtin_unreachable();
}

2
machine/mtrap.h

@ -67,6 +67,8 @@ void putstring(const char* s);
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)
__attribute__((noreturn));
void boot_loader(uintptr_t dtb);
void boot_other_hart(uintptr_t dtb);

Loading…
Cancel
Save