From e33464e47dd309e64c27af7c53997a4c3b7eef19 Mon Sep 17 00:00:00 2001 From: Sainnhe Park Date: Wed, 1 Dec 2021 11:41:32 +0800 Subject: [PATCH] Finish basic structure --- Cargo.lock | 7 +++++++ Cargo.toml | 7 +++++-- src/main.rs | 20 ++++++++++++++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..9678ac5 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anos" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 6c4a86b..793a53b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,11 @@ [package] name = "anos" version = "0.1.0" +authors = ["Sainnhe Park "] edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[profile.dev] +panic = "abort" # 禁用 panic 时的栈展开 -[dependencies] +[profile.release] +panic = "abort" # 禁用 panic 时的栈展开 diff --git a/src/main.rs b/src/main.rs index e7a11a9..3457e83 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,19 @@ -fn main() { - println!("Hello, world!"); +#![no_std] // 不链接 Rust 标准库 +#![no_main] // 禁用 main 入口点,因为没有运行时 + +use core::panic::PanicInfo; + +#[no_mangle] // 不重整函数名,否则编译器可能会生成名为 _ZN3blog_os4_start7hb173fedf945531caE 的函数 +// extern "C" 告诉编译器这个函数应当使用 C 语言的调用约定 +// 函数名为 _start 是因为大多数系统默认用这个名字作为入口点名称 +// -> ! 代表这是一个发散函数,不允许有任何返回值,因为它不会被任何函数调用,而是将直接被 bootloader 调用 +pub extern "C" fn _start() -> ! { + loop {} +} + +#[panic_handler] +// panic! 时将会进行栈展开,执行各种 drop 函数来回收垃圾 +// 禁用标准库之后,这些东西就都没有了,我们需要把它重写一遍 +fn panic(_info: &PanicInfo) -> ! { + loop {} }