From 74c0c0c9447822672ab47fa484ee35381a3a1bbb Mon Sep 17 00:00:00 2001 From: zhangxinyu <840317537@qq.com> Date: Mon, 15 May 2023 13:39:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AC=A6=E5=8F=B7=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E9=94=99=E8=AF=AF=E5=9C=B0=E5=9D=80,=20=E6=94=B9?= =?UTF-8?q?=E5=8F=98=E5=AF=BC=E5=85=A5=E6=96=B9=E5=BC=8F,=20static?= =?UTF-8?q?=E5=8F=98=E4=B8=BAfn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch1/src/lang_items/panic.rs | 3 --- ch1/src/main.rs | 19 +++++++++---------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ch1/src/lang_items/panic.rs b/ch1/src/lang_items/panic.rs index 58dde79..2e893c2 100644 --- a/ch1/src/lang_items/panic.rs +++ b/ch1/src/lang_items/panic.rs @@ -15,7 +15,4 @@ fn panic(info: &PanicInfo) -> ! { println!("Panicked: {}", info.message().unwrap()); } shutdown(); - loop { - - } } \ No newline at end of file diff --git a/ch1/src/main.rs b/ch1/src/main.rs index c5087fc..ed9307f 100644 --- a/ch1/src/main.rs +++ b/ch1/src/main.rs @@ -12,16 +12,19 @@ mod sbi; // 汇编脚本引入, 调整内核的内存布局之后, 会跳入到 rust_main中执行 global_asm!(include_str!("entry.asm")); +extern "C" { + fn stext(); + fn etext(); + fn sbss(); + fn ebss(); +} #[no_mangle] pub fn rust_main(){ init_bss(); - println!("hello world"); - let mut a = 123; - a = 234; - a = 345; - println!("hello world {:?}", a); + + println!("stext: {:#x}, etext: {:#x}", stext as usize, etext as usize); panic!("my panic"); } @@ -29,11 +32,7 @@ pub fn rust_main(){ /// ## 初始化bss段 /// fn init_bss() { - extern "C" { - static mut sbss: u64; - static mut ebss: u64; - } 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)) } }