Post 2 - A minimal kernel

This commit is contained in:
2024-08-25 20:14:25 +02:00
parent e2b1368e94
commit 9a7c2e38e5
4 changed files with 40 additions and 12 deletions

9
.cargo/config.toml Normal file
View File

@@ -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"

View File

@@ -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"
bootloader = "0.9"

View File

@@ -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 {}
}

15
x86_64-blog_os.json Normal file
View File

@@ -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"
}