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; static const void* entry_point;
void boot_other_hart() void boot_other_hart(uintptr_t dtb)
{ {
const void* entry; const void* entry;
do { do {
entry = entry_point; entry = entry_point;
mb(); mb();
} while (!entry); } 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; extern char _payload_start;
#ifdef PK_ENABLE_LOGO #ifdef PK_ENABLE_LOGO
@ -26,5 +26,5 @@ void boot_loader()
#endif #endif
mb(); mb();
entry_point = &_payload_start; 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 x7, 0
li x8, 0 li x8, 0
li x9, 0 li x9, 0
li x10, 0 // save a0 and a1; arguments from previous boot loader stage:
li x11, 0 // li x10, 0
// li x11, 0
li x12, 0 li x12, 0
li x13, 0 li x13, 0
li x14, 0 li x14, 0
@ -249,28 +250,28 @@ do_reset:
la sp, stacks + RISCV_PGSIZE - MENTRY_FRAME_SIZE la sp, stacks + RISCV_PGSIZE - MENTRY_FRAME_SIZE
csrr a0, mhartid csrr a3, mhartid
slli a1, a0, RISCV_PGSHIFT slli a2, a3, RISCV_PGSHIFT
add sp, sp, a1 add sp, sp, a2
beqz a0, init_first_hart beqz a3, init_first_hart
# set MSIE bit to receive IPI # set MSIE bit to receive IPI
li a1, MIP_MSIP li a2, MIP_MSIP
csrw mie, a1 csrw mie, a2
.LmultiHart: .LmultiHart:
#if MAX_HARTS > 1 #if MAX_HARTS > 1
# wait for an IPI to signal that it's safe to boot # wait for an IPI to signal that it's safe to boot
wfi wfi
csrr a1, mip csrr a2, mip
andi a1, a1, MIP_MSIP andi a2, a2, MIP_MSIP
beqz a1, .LmultiHart beqz a2, .LmultiHart
# make sure our hart id is within a valid range # make sure our hart id is within a valid range
fence fence
li a1, MAX_HARTS li a2, MAX_HARTS
bltu a0, a1, init_other_hart bltu a3, a2, init_other_hart
#endif #endif
wfi wfi
j .LmultiHart j .LmultiHart

16
machine/minit.c

@ -72,8 +72,6 @@ hls_t* hls_init(uintptr_t id)
return hls; return hls;
} }
#define DTB 0x1014
static void memory_init() static void memory_init()
{ {
mem_size = mem_size / MEGAPAGE_SIZE * MEGAPAGE_SIZE; mem_size = mem_size / MEGAPAGE_SIZE * MEGAPAGE_SIZE;
@ -122,27 +120,27 @@ static void hart_plic_init()
*HLS()->plic_s_thresh = 0; *HLS()->plic_s_thresh = 0;
} }
void init_first_hart() void init_first_hart(uintptr_t hartid, uintptr_t dtb)
{ {
hart_init(); hart_init();
hls_init(0); // this might get called again from parse_config_string hls_init(0); // this might get called again from parse_config_string
query_mem(DTB); query_mem(dtb);
query_harts(DTB); query_harts(dtb);
query_clint(DTB); query_clint(dtb);
plic_init(); plic_init();
hart_plic_init(); hart_plic_init();
//prci_test(); //prci_test();
memory_init(); memory_init();
boot_loader(); boot_loader(dtb);
} }
void init_other_hart() void init_other_hart(uintptr_t hartid, uintptr_t dtb)
{ {
hart_init(); hart_init();
hart_plic_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) 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) void enter_supervisor_mode(void (*fn)(uintptr_t), uintptr_t arg0, uintptr_t arg1)
__attribute__((noreturn)); __attribute__((noreturn));
void boot_loader(); void boot_loader(uintptr_t dtb);
void boot_other_hart(); void boot_other_hart(uintptr_t dtb);
static inline void wfi() 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); run_loaded_program(argc, args.argv, kstack_top);
} }
void boot_loader() void boot_loader(uintptr_t dtb)
{ {
extern char trap_entry; extern char trap_entry;
write_csr(stvec, &trap_entry); write_csr(stvec, &trap_entry);
@ -163,10 +163,10 @@ void boot_loader()
set_csr(sstatus, SSTATUS_SUM); set_csr(sstatus, SSTATUS_SUM);
file_init(); 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 // stall all harts besides hart 0
while (1) while (1)

Loading…
Cancel
Save