diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..0bc7dc4 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,9 @@ +[unstable] +build-std-features = ["compiler-builtins-mem"] +build-std = ["core", "compiler_builtins"] + +[build] +target = "x86_64-blog_os.json" + +[target.'cfg(target_os = "none")'] +runner = "bootimage runner" diff --git a/blog_os/Cargo.toml b/blog_os/Cargo.toml index 98d2a61..d032a1d 100644 --- a/blog_os/Cargo.toml +++ b/blog_os/Cargo.toml @@ -6,9 +6,4 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] - -[profile.dev] -panic = "abort" - -[profile.release] -panic = "abort" \ No newline at end of file +bootloader = "0.9" \ No newline at end of file diff --git a/blog_os/src/main.rs b/blog_os/src/main.rs index eab5a28..0f0eac1 100644 --- a/blog_os/src/main.rs +++ b/blog_os/src/main.rs @@ -1,12 +1,21 @@ -#![no_std] // don't link the Rust standard library -#![no_main] // disable all Rust-level entry points +#![no_std] +#![no_main] use core::panic::PanicInfo; -#[no_mangle] // don't mangle the name of this function +static HELLO: &[u8] = b"Hello World!"; + +#[no_mangle] pub extern "C" fn _start() -> ! { - // this function is the entry point, since the linker looks for a function - // named `_start` by default + let vga_buffer = 0xb8000 as *mut u8; + + for (i, &byte) in HELLO.iter().enumerate() { + unsafe { + *vga_buffer.offset(i as isize * 2) = byte; + *vga_buffer.offset(i as isize * 2 + 1) = 0xb; + } + } + loop {} } @@ -14,4 +23,4 @@ pub extern "C" fn _start() -> ! { #[panic_handler] fn panic(_info: &PanicInfo) -> ! { loop {} -} \ No newline at end of file +} diff --git a/x86_64-blog_os.json b/x86_64-blog_os.json new file mode 100644 index 0000000..0956b04 --- /dev/null +++ b/x86_64-blog_os.json @@ -0,0 +1,15 @@ +{ + "llvm-target": "x86_64-unknown-none", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", + "arch": "x86_64", + "target-endian": "little", + "target-pointer-width": "64", + "target-c-int-width": "32", + "os": "none", + "executables": true, + "linker-flavor": "ld.lld", + "linker": "rust-lld", + "panic-strategy": "abort", + "disable-redzone": true, + "features": "-mmx,-sse,+soft-float" +} \ No newline at end of file