From 8b4421bacba28f97da2ddeb6a6fba9e184e91bee Mon Sep 17 00:00:00 2001 From: "Wesley W. Terpstra" Date: Wed, 5 Apr 2017 16:27:19 -0700 Subject: bbl: prevent named cores from booting --- bbl/bbl.c | 2 +- machine/mentry.S | 14 +++++++++++++- machine/minit.c | 2 +- machine/mtrap.c | 1 + machine/mtrap.h | 3 +++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/bbl/bbl.c b/bbl/bbl.c index 44802c1..f64b2e7 100644 --- a/bbl/bbl.c +++ b/bbl/bbl.c @@ -23,7 +23,7 @@ static void filter_dtb(uintptr_t source) memcpy((void*)dest, (void*)source, size); // Remove information from the chained FDT - // filter_harts(dest, 0x2); + filter_harts(dest, HART_MASK); filter_plic(dest); filter_compat(dest, "riscv,clint0"); filter_compat(dest, "riscv,debug-013"); diff --git a/machine/mentry.S b/machine/mentry.S index 9575dc9..62a850d 100644 --- a/machine/mentry.S +++ b/machine/mentry.S @@ -257,7 +257,11 @@ do_reset: slli a2, a3, RISCV_PGSHIFT add sp, sp, a2 - beqz a3, init_first_hart + # Boot on the first unmasked hart + li a4, (~HART_MASK & (HART_MASK+1)) + srl a4, a4, a3 + andi a4, a4, 1 + bnez a4, init_first_hart # set MSIE bit to receive IPI li a2, MIP_MSIP @@ -267,6 +271,14 @@ do_reset: #if MAX_HARTS > 1 # wait for an IPI to signal that it's safe to boot wfi + + # masked harts never start + li a4, HART_MASK + srl a4, a4, a3 + andi a4, a4, 1 + bnez a4, .LmultiHart + + # only start if mip is set csrr a2, mip andi a2, a2, MIP_MSIP beqz a2, .LmultiHart diff --git a/machine/minit.c b/machine/minit.c index baf45a5..94a1491 100644 --- a/machine/minit.c +++ b/machine/minit.c @@ -124,7 +124,7 @@ static void hart_plic_init() static void wake_harts() { for (int hart = 0; hart < MAX_HARTS; ++hart) - if (((hart_mask >> hart) & 1)) + if ((((~HART_MASK & hart_mask) >> hart) & 1)) *OTHER_HLS(hart)->ipi = 1; // wakeup the hart } diff --git a/machine/mtrap.c b/machine/mtrap.c index d7def4c..be264f3 100644 --- a/machine/mtrap.c +++ b/machine/mtrap.c @@ -50,6 +50,7 @@ void printm(const char* s, ...) static void send_ipi(uintptr_t recipient, int event) { + if (((HART_MASK >> recipient) & 1)) return; atomic_or(&OTHER_HLS(recipient)->mipi_pending, event); mb(); *OTHER_HLS(recipient)->ipi = 1; diff --git a/machine/mtrap.h b/machine/mtrap.h index e8dfc49..1437b11 100644 --- a/machine/mtrap.h +++ b/machine/mtrap.h @@ -9,6 +9,9 @@ # define MAX_HARTS 1 #endif +// These harts will be prevented from booting beyond bbl +#define HART_MASK 0x0UL + #ifndef __ASSEMBLER__ #include -- cgit v1.1