diff --git a/kernel/src/arch/riscv32/boot/entry.asm b/kernel/src/arch/riscv32/boot/entry.asm index 0485f0e..3cee2fd 100644 --- a/kernel/src/arch/riscv32/boot/entry.asm +++ b/kernel/src/arch/riscv32/boot/entry.asm @@ -10,7 +10,7 @@ _start: call rust_main - .section .bss + .section .bss.stack .align 12 #PGSHIFT .global bootstack bootstack: diff --git a/kernel/src/arch/riscv32/boot/linker.ld b/kernel/src/arch/riscv32/boot/linker.ld index cd5de10..d51cbe8 100644 --- a/kernel/src/arch/riscv32/boot/linker.ld +++ b/kernel/src/arch/riscv32/boot/linker.ld @@ -22,14 +22,14 @@ SECTIONS .text : { stext = .; *(.text.entry) - *(.text .stub .text.* .gnu.linkonce.t.*) + *(.text .text.*) . = ALIGN(4K); etext = .; } .rodata : { srodata = .; - *(.rodata .rodata.* .gnu.linkonce.r.*) + *(.rodata .rodata.*) . = ALIGN(4K); erodata = .; } @@ -37,21 +37,18 @@ SECTIONS .data : { sdata = .; *(.data .data.*) - . = ALIGN(4K); edata = .; } + .stack : { + *(.bss.stack) + } + .bss : { sbss = .; - *(.bss .bss.* .sbss*) - . = ALIGN(4K); + *(.bss .bss.*) ebss = .; } - .got : { - *(.got .got.*) - . = ALIGN(4K); - } - PROVIDE(end = .); } diff --git a/kernel/src/arch/riscv32/boot/linker64.ld b/kernel/src/arch/riscv32/boot/linker64.ld index 8d4165e..4c38522 100644 --- a/kernel/src/arch/riscv32/boot/linker64.ld +++ b/kernel/src/arch/riscv32/boot/linker64.ld @@ -32,14 +32,16 @@ SECTIONS .data : { sdata = .; *(.data .data.*) - . = ALIGN(4K); edata = .; } + .stack : { + *(.bss.stack) + } + .bss : { sbss = .; *(.bss .bss.*) - . = ALIGN(4K); ebss = .; } diff --git a/kernel/src/arch/riscv32/memory.rs b/kernel/src/arch/riscv32/memory.rs index 7ba0b9f..ca355f6 100644 --- a/kernel/src/arch/riscv32/memory.rs +++ b/kernel/src/arch/riscv32/memory.rs @@ -82,6 +82,7 @@ fn remap_the_kernel() { ms.push(MemoryArea::new_identity(stext as usize, etext as usize, MemoryAttr::default().execute().readonly(), "text")); ms.push(MemoryArea::new_identity(sdata as usize, edata as usize, MemoryAttr::default(), "data")); ms.push(MemoryArea::new_identity(srodata as usize, erodata as usize, MemoryAttr::default().readonly(), "rodata")); + ms.push(MemoryArea::new_identity(bootstack as usize, bootstacktop as usize, MemoryAttr::default(), "stack")); ms.push(MemoryArea::new_identity(sbss as usize, ebss as usize, MemoryAttr::default(), "bss")); unsafe { ms.activate(); } unsafe { SATP = ms.token(); } @@ -93,6 +94,14 @@ fn remap_the_kernel() { // Other cores load it later. static mut SATP: usize = 0; +pub unsafe fn clear_bss() { + let bss_start = sbss as usize; + let bss_end = ebss as usize; + for i in bss_start..bss_end { + (i as *mut u8).write(0); + } +} + // Symbols provided by linker script extern { fn stext(); diff --git a/kernel/src/arch/riscv32/mod.rs b/kernel/src/arch/riscv32/mod.rs index 1cf3cfb..f874e5f 100644 --- a/kernel/src/arch/riscv32/mod.rs +++ b/kernel/src/arch/riscv32/mod.rs @@ -10,15 +10,19 @@ pub mod cpu; #[no_mangle] pub extern fn rust_main(hartid: usize, dtb: usize, hart_mask: usize, functions: usize) -> ! { unsafe { cpu::set_cpu_id(hartid); } - unsafe { BBL_FUNCTIONS_PTR = functions as *const _; } - println!("Hello RISCV! in hart {}, dtb @ {:#x}, functions @ {:#x}", hartid, dtb, functions); if hartid != 0 { while unsafe { !cpu::has_started(hartid) } { } + println!("Hello RISCV! in hart {}, dtb @ {:#x}, functions @ {:#x}", hartid, dtb, functions); others_main(); unreachable!(); } + unsafe { memory::clear_bss(); } + unsafe { BBL_FUNCTIONS_PTR = functions as *const _; } + + println!("Hello RISCV! in hart {}, dtb @ {:#x}, functions @ {:#x}", hartid, dtb, functions); + crate::logging::init(); interrupt::init(); memory::init();