diff --git a/src/arch/riscv/entry.rs b/src/arch/riscv/entry.rs index 854bb68..16d75c4 100644 --- a/src/arch/riscv/entry.rs +++ b/src/arch/riscv/entry.rs @@ -6,7 +6,7 @@ unsafe extern "C" fn _start(hart_id: usize, device_tree_addr: usize) -> ! { // no stack here const STACK_SIZE: usize = 4096 * 16; - #[link_section = ".boot_stack"] + #[link_section = ".bss.boot_stack"] static mut STACK: [u8; STACK_SIZE] = [0u8; STACK_SIZE]; core::arch::asm!( @@ -20,6 +20,8 @@ unsafe extern "C" fn _start(hart_id: usize, device_tree_addr: usize) -> ! { } extern "C" fn pre_main(hart_id: usize, device_tree_addr: usize) -> ! { + // TODO: multiboot + unsafe { zero_bss() } // TODO: initialize page table @@ -28,16 +30,14 @@ extern "C" fn pre_main(hart_id: usize, device_tree_addr: usize) -> ! { } extern "C" { - static mut __bss_start: u8; + static mut __boot_stack_end: u8; static mut __bss_end: u8; } +#[inline(always)] unsafe fn zero_bss() { - let mut cur = &mut __bss_start as *mut u8; + let cur = &mut __boot_stack_end as *mut u8; let end = &mut __bss_end as *mut u8; - while cur < end { - cur.write_volatile(0); - cur = cur.add(1); - } + core::slice::from_raw_parts_mut(cur, end.offset_from(cur) as usize).fill(0); } diff --git a/src/arch/riscv/linker.ld b/src/arch/riscv/linker.ld index fee37f6..38fe63c 100644 --- a/src/arch/riscv/linker.ld +++ b/src/arch/riscv/linker.ld @@ -42,14 +42,12 @@ SECTIONS { __data_end = .; } > DRAM - .stack : { - . = ALIGN(8); - *(.boot_stack) - } > DRAM - .bss : { . = ALIGN(8); __bss_start = .; + *(.bss.boot_stack) + __boot_stack_end = .; + *(.bss .bss.*) *(.sbss .sbss.*) __bss_end = .;