mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-22 09:26:26 +04:00
Chapter1: Update panic_handler.
This commit is contained in:
parent
49050aca3f
commit
c701cd00ce
@ -1,6 +1,12 @@
|
||||
use core::panic::PanicInfo;
|
||||
use crate::sbi::shutdown;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
if let Some(location) = info.location() {
|
||||
println!("Panicked at {}:{} {}", location.file(), location.line(), info.message().unwrap());
|
||||
} else {
|
||||
println!("Panicked: {}", info.message().unwrap());
|
||||
}
|
||||
shutdown()
|
||||
}
|
||||
|
@ -2,17 +2,28 @@
|
||||
#![no_main]
|
||||
#![feature(global_asm)]
|
||||
#![feature(llvm_asm)]
|
||||
#![feature(panic_info_message)]
|
||||
|
||||
mod lang_items;
|
||||
mod sbi;
|
||||
#[macro_use]
|
||||
mod console;
|
||||
mod lang_items;
|
||||
mod sbi;
|
||||
|
||||
|
||||
global_asm!(include_str!("entry.asm"));
|
||||
|
||||
fn clear_bss() {
|
||||
extern "C" {
|
||||
fn sbss();
|
||||
fn ebss();
|
||||
}
|
||||
(sbss as usize..ebss as usize).for_each(|a| {
|
||||
unsafe { (a as *mut u8).write_volatile(0) }
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn rust_main() -> ! {
|
||||
println!("Hello, world!");
|
||||
extern "C" {
|
||||
fn stext();
|
||||
fn etext();
|
||||
@ -25,10 +36,12 @@ pub fn rust_main() -> ! {
|
||||
fn boot_stack();
|
||||
fn boot_stack_top();
|
||||
};
|
||||
clear_bss();
|
||||
println!("Hello, world!");
|
||||
println!(".text [{:#x}, {:#x})", stext as usize, etext as usize);
|
||||
println!(".rodata [{:#x}, {:#x})", srodata as usize, erodata as usize);
|
||||
println!(".data [{:#x}, {:#x})", sdata as usize, edata as usize);
|
||||
println!("boot_stack [{:#x}, {:#x})", boot_stack as usize, boot_stack_top as usize);
|
||||
println!(".bss [{:#x}, {:#x})", sbss as usize, ebss as usize);
|
||||
loop {}
|
||||
panic!("Shutdown machine!");
|
||||
}
|
Loading…
Reference in New Issue
Block a user