Browse Source

SBI: a0+a1 hold hartid+dtb pointer between boot loader stages

fdt
Wesley W. Terpstra 9 years ago
parent
commit
23ab37ad78
  1. 8
      bbl/bbl.c
  2. 27
      machine/mentry.S
  3. 16
      machine/minit.c
  4. 4
      machine/mtrap.h
  5. 6
      pk/pk.c

8
bbl/bbl.c

@ -8,17 +8,17 @@
static const void* entry_point;
void boot_other_hart()
void boot_other_hart(uintptr_t dtb)
{
const void* entry;
do {
entry = entry_point;
mb();
} while (!entry);
enter_supervisor_mode(entry, read_csr(mhartid), 0);
enter_supervisor_mode(entry, read_csr(mhartid), dtb);
}
void boot_loader()
void boot_loader(uintptr_t dtb)
{
extern char _payload_start;
#ifdef PK_ENABLE_LOGO
@ -26,5 +26,5 @@ void boot_loader()
#endif
mb();
entry_point = &_payload_start;
boot_other_hart();
boot_other_hart(dtb);
}

27
machine/mentry.S

@ -217,8 +217,9 @@ do_reset:
li x7, 0
li x8, 0
li x9, 0
li x10, 0
li x11, 0
// save a0 and a1; arguments from previous boot loader stage:
// li x10, 0
// li x11, 0
li x12, 0
li x13, 0
li x14, 0
@ -249,28 +250,28 @@ do_reset:
la sp, stacks + RISCV_PGSIZE - MENTRY_FRAME_SIZE
csrr a0, mhartid
slli a1, a0, RISCV_PGSHIFT
add sp, sp, a1
csrr a3, mhartid
slli a2, a3, RISCV_PGSHIFT
add sp, sp, a2
beqz a0, init_first_hart
beqz a3, init_first_hart
# set MSIE bit to receive IPI
li a1, MIP_MSIP
csrw mie, a1
li a2, MIP_MSIP
csrw mie, a2
.LmultiHart:
#if MAX_HARTS > 1
# wait for an IPI to signal that it's safe to boot
wfi
csrr a1, mip
andi a1, a1, MIP_MSIP
beqz a1, .LmultiHart
csrr a2, mip
andi a2, a2, MIP_MSIP
beqz a2, .LmultiHart
# make sure our hart id is within a valid range
fence
li a1, MAX_HARTS
bltu a0, a1, init_other_hart
li a2, MAX_HARTS
bltu a3, a2, init_other_hart
#endif
wfi
j .LmultiHart

16
machine/minit.c

@ -72,8 +72,6 @@ hls_t* hls_init(uintptr_t id)
return hls;
}
#define DTB 0x1014
static void memory_init()
{
mem_size = mem_size / MEGAPAGE_SIZE * MEGAPAGE_SIZE;
@ -122,27 +120,27 @@ static void hart_plic_init()
*HLS()->plic_s_thresh = 0;
}
void init_first_hart()
void init_first_hart(uintptr_t hartid, uintptr_t dtb)
{
hart_init();
hls_init(0); // this might get called again from parse_config_string
query_mem(DTB);
query_harts(DTB);
query_clint(DTB);
query_mem(dtb);
query_harts(dtb);
query_clint(dtb);
plic_init();
hart_plic_init();
//prci_test();
memory_init();
boot_loader();
boot_loader(dtb);
}
void init_other_hart()
void init_other_hart(uintptr_t hartid, uintptr_t dtb)
{
hart_init();
hart_plic_init();
boot_other_hart();
boot_other_hart(dtb);
}
void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1)

4
machine/mtrap.h

@ -64,8 +64,8 @@ void putstring(const char* s);
void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1)
__attribute__((noreturn));
void boot_loader();
void boot_other_hart();
void boot_loader(uintptr_t dtb);
void boot_other_hart(uintptr_t dtb);
static inline void wfi()
{

6
pk/pk.c

@ -154,7 +154,7 @@ static void rest_of_boot_loader(uintptr_t kstack_top)
run_loaded_program(argc, args.argv, kstack_top);
}
void boot_loader()
void boot_loader(uintptr_t dtb)
{
extern char trap_entry;
write_csr(stvec, &trap_entry);
@ -163,10 +163,10 @@ void boot_loader()
set_csr(sstatus, SSTATUS_SUM);
file_init();
enter_supervisor_mode(rest_of_boot_loader, pk_vm_init(), 0);
enter_supervisor_mode(rest_of_boot_loader, pk_vm_init(), dtb);
}
void boot_other_hart()
void boot_other_hart(uintptr_t dtb)
{
// stall all harts besides hart 0
while (1)

Loading…
Cancel
Save