From b2f0b35307c069e0004054c4091fab250813fa2c Mon Sep 17 00:00:00 2001 From: thatscringebro Date: Mon, 9 Sep 2024 20:00:34 -0400 Subject: [PATCH] Booting from the code --- .cargo/config.toml | 9 +++++++++ Cargo.toml | 7 +------ src/main.rs | 11 +++++++++++ x86_64-simpleos.json | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 .cargo/config.toml create mode 100644 x86_64-simpleos.json diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..f184121 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,9 @@ +[build] +target = "x86_64-simpleos.json" + +[unstable] +build-std-features = ["compiler-builtins-mem"] +build-std = ["core", "compiler_builtins"] + +[target.'cfg(target_os = "none")'] +runner = "bootimage runner" diff --git a/Cargo.toml b/Cargo.toml index 9a0f736..f786cae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,10 +3,5 @@ name = "simpleos" version = "0.1.0" edition = "2021" -[profile.dev] -panic = "abort" - -[profile.release] -panic = "abort" - [dependencies] +bootloader = "0.9" diff --git a/src/main.rs b/src/main.rs index 716751a..1542447 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,19 @@ use core::panic::PanicInfo; +static HELLO: &[u8] = b"Hello World!"; + #[no_mangle] pub extern "C" fn _start() -> ! { + 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 {} } diff --git a/x86_64-simpleos.json b/x86_64-simpleos.json new file mode 100644 index 0000000..ceedc5d --- /dev/null +++ b/x86_64-simpleos.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" +}