From 2f8efad24a2dd3d68dee5e82c36fb375eb8a70a6 Mon Sep 17 00:00:00 2001 From: clizia Date: Mon, 25 Aug 2025 01:47:42 +0200 Subject: [PATCH] it now boots and prints hello world --- .cargo/config.toml | 9 +++++++++ Cargo.toml | 1 + src/main.rs | 13 ++++++++++++- x86_64-totos.json | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .cargo/config.toml create mode 100644 x86_64-totos.json diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..f95e6aa --- /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-totos.json" + +[target.'cfg(target_os = "none")'] +runner = "bootimage runner" diff --git a/Cargo.toml b/Cargo.toml index 60e9fc5..4f6eaa3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ panic = "abort" # disable stack unwinding on panic panic = "abort" # disable stack unwinding on panic [dependencies] +bootloader = "0.9" diff --git a/src/main.rs b/src/main.rs index 132c4cc..8d80305 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,11 +3,22 @@ use core::panic::PanicInfo; +static HELLO: &[u8] = b"Hello toto :3"; + // this function is the entry point since the linker // looks for a function named `_start` by default #[unsafe(no_mangle)] pub extern "C" fn _start() -> ! { - loop{} + 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 {} } // called on panic diff --git a/x86_64-totos.json b/x86_64-totos.json new file mode 100644 index 0000000..669ca9d --- /dev/null +++ b/x86_64-totos.json @@ -0,0 +1,16 @@ +{ + "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", + "rustc-abi": "x86-softfloat" +}