From 66e9877056923419f445d7d88910ad8ff8221813 Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Fri, 21 Jun 2024 09:52:54 +0200 Subject: [PATCH] First bootable kernel --- .cargo/config.toml | 9 +++++++++ Cargo.toml | 9 ++++----- rust-toolchain | 1 + src/main.rs | 20 ++++++++++++++++---- toolchain.toml | 2 ++ x86_64-fabios.json | 15 +++++++++++++++ 6 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 .cargo/config.toml create mode 100644 rust-toolchain create mode 100644 toolchain.toml create mode 100644 x86_64-fabios.json diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..c157e09 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,9 @@ +[unstable] +build-std = ["core", "compiler_builtins"] +build-std-features = ["compiler-builtins-mem"] + +[build] +target = "x86_64-fabios.json" + +[target.'cfg(target_os = "none")'] +runner = "bootimage runner" diff --git a/Cargo.toml b/Cargo.toml index d134f34..435b80e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,10 +3,9 @@ name = "fabios" version = "0.1.0" edition = "2018" -[profile.dev] -panic = "abort" - -[profile.release] -panic = "abort" +[package.metadata.bootimage] +build-command = ["build"] +run-command = ["qemu-system-x86_64", "-drive", "format=raw,file={}"] [dependencies] +bootloader = "0.9" diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..bf867e0 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly diff --git a/src/main.rs b/src/main.rs index 18c979e..ac13a73 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,12 +3,24 @@ use core::panic::PanicInfo; +static HELLO: &[u8] = b"Welcome to FabiOS"; + +#[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 {} +} + #[panic_handler] fn panic(_info: &PanicInfo) -> ! { loop {} } -#[no_mangle] -pub extern "C" fn _start() -> ! { - loop{} -} diff --git a/toolchain.toml b/toolchain.toml new file mode 100644 index 0000000..5d56faf --- /dev/null +++ b/toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly" diff --git a/x86_64-fabios.json b/x86_64-fabios.json new file mode 100644 index 0000000..ceedc5d --- /dev/null +++ b/x86_64-fabios.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" +}