Finish basic structure
This commit is contained in:
parent
960d5191f3
commit
e33464e47d
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@ -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"
|
@ -1,8 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "anos"
|
name = "anos"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
authors = ["Sainnhe Park <sainnhe@gmail.com>"]
|
||||||
edition = "2021"
|
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 时的栈展开
|
||||||
|
20
src/main.rs
20
src/main.rs
@ -1,3 +1,19 @@
|
|||||||
fn main() {
|
#![no_std] // 不链接 Rust 标准库
|
||||||
println!("Hello, world!");
|
#![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 {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user