chore: adjust boot_stack

This commit is contained in:
Paul Pan 2023-12-17 15:25:54 +08:00
parent 5a11fbd169
commit c7c36e5665
2 changed files with 10 additions and 12 deletions

View File

@ -6,7 +6,7 @@ unsafe extern "C" fn _start(hart_id: usize, device_tree_addr: usize) -> ! {
// no stack here // no stack here
const STACK_SIZE: usize = 4096 * 16; const STACK_SIZE: usize = 4096 * 16;
#[link_section = ".boot_stack"] #[link_section = ".bss.boot_stack"]
static mut STACK: [u8; STACK_SIZE] = [0u8; STACK_SIZE]; static mut STACK: [u8; STACK_SIZE] = [0u8; STACK_SIZE];
core::arch::asm!( 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) -> ! { extern "C" fn pre_main(hart_id: usize, device_tree_addr: usize) -> ! {
// TODO: multiboot
unsafe { zero_bss() } unsafe { zero_bss() }
// TODO: initialize page table // TODO: initialize page table
@ -28,16 +30,14 @@ extern "C" fn pre_main(hart_id: usize, device_tree_addr: usize) -> ! {
} }
extern "C" { extern "C" {
static mut __bss_start: u8; static mut __boot_stack_end: u8;
static mut __bss_end: u8; static mut __bss_end: u8;
} }
#[inline(always)]
unsafe fn zero_bss() { 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; let end = &mut __bss_end as *mut u8;
while cur < end { core::slice::from_raw_parts_mut(cur, end.offset_from(cur) as usize).fill(0);
cur.write_volatile(0);
cur = cur.add(1);
}
} }

View File

@ -42,14 +42,12 @@ SECTIONS {
__data_end = .; __data_end = .;
} > DRAM } > DRAM
.stack : {
. = ALIGN(8);
*(.boot_stack)
} > DRAM
.bss : { .bss : {
. = ALIGN(8); . = ALIGN(8);
__bss_start = .; __bss_start = .;
*(.bss.boot_stack)
__boot_stack_end = .;
*(.bss .bss.*) *(.bss .bss.*)
*(.sbss .sbss.*) *(.sbss .sbss.*)
__bss_end = .; __bss_end = .;