diff --git a/Cargo.toml b/Cargo.toml index dcd35135..68212ff2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,3 +4,11 @@ name = "blog_os" version = "0.2.0" [dependencies] + +# the profile used for `cargo build` +[profile.dev] +panic = "abort" # disable stack unwinding on panic + +# the profile used for `cargo build --release` +[profile.release] +panic = "abort" # disable stack unwinding on panic diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 00000000..6c2d5299 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,27 @@ +#![feature(lang_items)] // required for defining the panic handler +#![no_std] // don't link the Rust standard library +#![no_main] // disable all Rust-level entry points + +#[no_mangle] // don't mangle the name of this function +pub fn _start() -> ! { + // this function is the entry point, since the linker looks for a function + // named `_start_` by default + let vga_buffer = 0xb8000 as *const u8 as *mut u8; + unsafe { + *vga_buffer.offset(0) = b'O'; + *vga_buffer.offset(1) = 0xa; // foreground color green + *vga_buffer.offset(0) = b'K'; + *vga_buffer.offset(3) = 0xa; // foreground color green + } + + loop {} +} + +#[lang = "panic_fmt"] // define a function that should be called on panic +#[no_mangle] // TODO required? +pub extern fn rust_begin_panic(_msg: core::fmt::Arguments, + _file: &'static str, + _line: u32, + _column: u32) -> ! { + loop {} +}