修改符号导入错误地址, 改变导入方式, static变为fn

ch1
zhangxinyu 2 years ago
parent ed66d2b399
commit 74c0c0c944

@ -15,7 +15,4 @@ fn panic(info: &PanicInfo) -> ! {
println!("Panicked: {}", info.message().unwrap()); println!("Panicked: {}", info.message().unwrap());
} }
shutdown(); shutdown();
loop {
}
} }

@ -12,16 +12,19 @@ mod sbi;
// 汇编脚本引入, 调整内核的内存布局之后, 会跳入到 rust_main中执行 // 汇编脚本引入, 调整内核的内存布局之后, 会跳入到 rust_main中执行
global_asm!(include_str!("entry.asm")); global_asm!(include_str!("entry.asm"));
extern "C" {
fn stext();
fn etext();
fn sbss();
fn ebss();
}
#[no_mangle] #[no_mangle]
pub fn rust_main(){ pub fn rust_main(){
init_bss(); init_bss();
println!("hello world");
let mut a = 123;
a = 234; println!("stext: {:#x}, etext: {:#x}", stext as usize, etext as usize);
a = 345;
println!("hello world {:?}", a);
panic!("my panic"); panic!("my panic");
} }
@ -29,11 +32,7 @@ pub fn rust_main(){
/// ## 初始化bss段 /// ## 初始化bss段
/// ///
fn init_bss() { fn init_bss() {
extern "C" {
static mut sbss: u64;
static mut ebss: u64;
}
unsafe { unsafe {
(sbss..ebss).for_each(|p| (p as *mut u8).write_unaligned(0)) (sbss as usize..ebss as usize).for_each(|p| (p as *mut u8).write_unaligned(0))
} }
} }

Loading…
Cancel
Save