add .stack section. clear bss

toolchain_update
WangRunji 6 years ago
parent 7240198a54
commit 0af9776dbd

@ -10,7 +10,7 @@ _start:
call rust_main call rust_main
.section .bss .section .bss.stack
.align 12 #PGSHIFT .align 12 #PGSHIFT
.global bootstack .global bootstack
bootstack: bootstack:

@ -22,14 +22,14 @@ SECTIONS
.text : { .text : {
stext = .; stext = .;
*(.text.entry) *(.text.entry)
*(.text .stub .text.* .gnu.linkonce.t.*) *(.text .text.*)
. = ALIGN(4K); . = ALIGN(4K);
etext = .; etext = .;
} }
.rodata : { .rodata : {
srodata = .; srodata = .;
*(.rodata .rodata.* .gnu.linkonce.r.*) *(.rodata .rodata.*)
. = ALIGN(4K); . = ALIGN(4K);
erodata = .; erodata = .;
} }
@ -37,21 +37,18 @@ SECTIONS
.data : { .data : {
sdata = .; sdata = .;
*(.data .data.*) *(.data .data.*)
. = ALIGN(4K);
edata = .; edata = .;
} }
.stack : {
*(.bss.stack)
}
.bss : { .bss : {
sbss = .; sbss = .;
*(.bss .bss.* .sbss*) *(.bss .bss.*)
. = ALIGN(4K);
ebss = .; ebss = .;
} }
.got : {
*(.got .got.*)
. = ALIGN(4K);
}
PROVIDE(end = .); PROVIDE(end = .);
} }

@ -32,14 +32,16 @@ SECTIONS
.data : { .data : {
sdata = .; sdata = .;
*(.data .data.*) *(.data .data.*)
. = ALIGN(4K);
edata = .; edata = .;
} }
.stack : {
*(.bss.stack)
}
.bss : { .bss : {
sbss = .; sbss = .;
*(.bss .bss.*) *(.bss .bss.*)
. = ALIGN(4K);
ebss = .; ebss = .;
} }

@ -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(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(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(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")); ms.push(MemoryArea::new_identity(sbss as usize, ebss as usize, MemoryAttr::default(), "bss"));
unsafe { ms.activate(); } unsafe { ms.activate(); }
unsafe { SATP = ms.token(); } unsafe { SATP = ms.token(); }
@ -93,6 +94,14 @@ fn remap_the_kernel() {
// Other cores load it later. // Other cores load it later.
static mut SATP: usize = 0; 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 // Symbols provided by linker script
extern { extern {
fn stext(); fn stext();

@ -10,15 +10,19 @@ pub mod cpu;
#[no_mangle] #[no_mangle]
pub extern fn rust_main(hartid: usize, dtb: usize, hart_mask: usize, functions: usize) -> ! { pub extern fn rust_main(hartid: usize, dtb: usize, hart_mask: usize, functions: usize) -> ! {
unsafe { cpu::set_cpu_id(hartid); } 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 { if hartid != 0 {
while unsafe { !cpu::has_started(hartid) } { } while unsafe { !cpu::has_started(hartid) } { }
println!("Hello RISCV! in hart {}, dtb @ {:#x}, functions @ {:#x}", hartid, dtb, functions);
others_main(); others_main();
unreachable!(); 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(); crate::logging::init();
interrupt::init(); interrupt::init();
memory::init(); memory::init();

Loading…
Cancel
Save