diff options
author | Palmer Dabbelt <palmer@dabbelt.com> | 2018-08-03 13:37:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-03 13:37:00 -0700 |
commit | d64dfb3d17c82ba1a95cdc7e31fd14ae4d27587c (patch) | |
tree | 03d0bc05e023d2c07eb5e1355095e193b515eb1a | |
parent | 537ae11ae506b6fa6c4dd9dc37c9cc818af84027 (diff) | |
parent | 165c85caeec4f2558c3981c4221573426acd58dc (diff) | |
download | riscv-pk-d64dfb3d17c82ba1a95cdc7e31fd14ae4d27587c.zip riscv-pk-d64dfb3d17c82ba1a95cdc7e31fd14ae4d27587c.tar.gz riscv-pk-d64dfb3d17c82ba1a95cdc7e31fd14ae4d27587c.tar.bz2 |
Merge pull request #104 from heshamelmatary/disable_vm
bbl: boot payload in machine mode on --enable-boot-machine
-rw-r--r-- | bbl/bbl.ac | 5 | ||||
-rw-r--r-- | bbl/bbl.c | 4 | ||||
-rw-r--r-- | config.h.in | 3 | ||||
-rwxr-xr-x | configure | 15 | ||||
-rw-r--r-- | machine/mentry.S | 5 | ||||
-rw-r--r-- | machine/minit.c | 24 | ||||
-rw-r--r-- | machine/mtrap.h | 2 |
7 files changed, 57 insertions, 1 deletions
@@ -18,3 +18,8 @@ AC_ARG_WITH([payload], AS_HELP_STRING([--with-payload], [Set ELF payload for bbl AC_ARG_WITH([logo], AS_HELP_STRING([--with-logo], [Specify a better logo]), [AC_SUBST([BBL_LOGO_FILE], $with_logo, [Logo for bbl])], [AC_SUBST([BBL_LOGO_FILE], [riscv_logo.txt], [Logo for bbl])]) + +AC_ARG_ENABLE([boot-machine], AS_HELP_STRING([--enable-boot-machine], [Run payload in machine mode])) +AS_IF([test "x$enable_boot_machine" == "xyes"], [ + AC_DEFINE([BBL_BOOT_MACHINE],,[Define to run payload in machine mode]) +]) @@ -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) diff --git a/config.h.in b/config.h.in index a350c78..dbacd78 100644 --- a/config.h.in +++ b/config.h.in @@ -1,5 +1,8 @@ /* config.h.in. Generated from configure.ac by autoheader. */ +/* Define to run payload in machine mode */ +#undef BBL_BOOT_MACHINE + /* Define if subproject MCPPBS_SPROJ_NORM is enabled */ #undef BBL_ENABLED @@ -677,6 +677,7 @@ enable_vm enable_logo with_payload with_logo +enable_boot_machine enable_fp_emulation ' ac_precious_vars='build_alias @@ -1325,6 +1326,7 @@ Optional Features: Enable all optional subprojects --disable-vm Disable virtual memory --enable-logo Enable boot logo + --enable-boot-machine Run payload in machine mode --disable-fp-emulation Disable floating-point emulation Optional Packages: @@ -4272,6 +4274,19 @@ else fi +# Check whether --enable-boot-machine was given. +if test "${enable_boot_machine+set}" = set; then : + enableval=$enable_boot_machine; +fi + +if test "x$enable_boot_machine" == "xyes"; then : + + +$as_echo "#define BBL_BOOT_MACHINE /**/" >>confdefs.h + + +fi + diff --git a/machine/mentry.S b/machine/mentry.S index ede40bb..99e1b72 100644 --- a/machine/mentry.S +++ b/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 diff --git a/machine/minit.c b/machine/minit.c index a411978..953e1ba 100644 --- a/machine/minit.c +++ b/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() @@ -184,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. @@ -196,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); @@ -213,3 +220,18 @@ 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) +{ + setup_pmp(); + + 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(); +} diff --git a/machine/mtrap.h b/machine/mtrap.h index 4b9e569..a5bcea2 100644 --- a/machine/mtrap.h +++ b/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); |