This commit is contained in:
2021-12-09 19:51:38 +08:00
parent aab190baea
commit 3e153fb1a9
8 changed files with 256 additions and 29 deletions

View File

@@ -1,12 +1,11 @@
#![no_std] // 不链接 Rust 标准库
#![no_main] // 禁用 main 入口点,因为没有运行时
#![feature(custom_test_frameworks)]
#![test_runner(anos::test_runner)]
#![reexport_test_harness_main = "test_main"]
use core::panic::PanicInfo;
mod vga_buffer;
// 定义一个 byte string 类型的静态变量
static HELLO: &[u8] = b"Hello World!";
use anos::println;
#[no_mangle] // 不重整函数名,否则编译器可能会生成名为 _ZN3blog_os4_start7hb173fedf945531caE 的函数
// extern "C" 告诉编译器这个函数应当使用 C 语言的调用约定
@@ -15,9 +14,14 @@ static HELLO: &[u8] = b"Hello World!";
pub extern "C" fn _start() -> ! {
println!("Hello World{}", "!");
#[cfg(test)]
test_main();
loop {}
}
// 在非测试模式下,将 panic 信息打印到 VGA 缓冲区
#[cfg(not(test))]
#[panic_handler]
// panic! 时将会进行栈展开,执行各种 drop 函数来回收垃圾
// 禁用标准库之后,这些东西就都没有了,我们需要把它重写一遍
@@ -25,3 +29,9 @@ fn panic(info: &PanicInfo) -> ! {
println!("{}", info);
loop {}
}
#[cfg(test)]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
anos::test_panic_handler(info)
}