Browse Source

Merge pull request #104 from heshamelmatary/disable_vm

bbl: boot payload in machine mode on --enable-boot-machine
pull/115/head
Palmer Dabbelt 8 years ago
committed by GitHub
parent
commit
d64dfb3d17
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      bbl/bbl.ac
  2. 4
      bbl/bbl.c
  3. 3
      config.h.in
  4. 15
      configure
  5. 5
      machine/mentry.S
  6. 24
      machine/minit.c
  7. 2
      machine/mtrap.h

5
bbl/bbl.ac

@ -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])
])

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)

3
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

15
configure

@ -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

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

24
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();
}

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