From 02e6fa10eb67f6e3b0d3a1086c2ac17ce8e452d5 Mon Sep 17 00:00:00 2001 From: Mira Kristipati Date: Thu, 26 Jun 2025 23:27:08 -0400 Subject: [PATCH] initial commit --- .cargo/config.toml | 5 +++++ .gitignore | 1 + Cargo.lock | 7 +++++++ Cargo.toml | 6 ++++++ arm-none-eabihf.json | 28 ++++++++++++++++++++++++++++ notes.md | 11 +++++++++++ src/main.rs | 26 ++++++++++++++++++++++++++ 7 files changed, 84 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 arm-none-eabihf.json create mode 100644 notes.md create mode 100644 src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..e5e3a73 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,5 @@ +[build] +target = "arm-none-eabihf.json" +[unstable] +build-std-features = ["compiler-builtins-mem"] +build-std = ["core", "compiler_builtins"] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..ce56bf4 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "jank_os" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..522230f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "jank_os" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/arm-none-eabihf.json b/arm-none-eabihf.json new file mode 100644 index 0000000..24ce983 --- /dev/null +++ b/arm-none-eabihf.json @@ -0,0 +1,28 @@ +{ + "llvm-target": "arm-none-eabihf", + "target-endian": "little", + "target-pointer-width": "32", + "target-c-int-width": "32", + "os": "none", + "env": "eabi", + "vendor": "unknown", + "arch": "arm", + "panic-strategy": "abort", + "llvm-floatabi": "hard", + "disable-redzone": true, + "linker-flavor": "gcc", + "linker": "arm-none-eabi-gcc", + "pre-link-args": { + "gcc": [ + "-Wall", + "-nostdlib", + "-nostartfiles", + "-ffreestanding", + "-march=armv6" + ] + }, + "features": "+strict-align,+v6,+vfp2,-d32", + "data-layout": "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64", + "executables": true, + "relocation-model": "static" +} diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..fc3b998 --- /dev/null +++ b/notes.md @@ -0,0 +1,11 @@ +build: `cargo build --target arm-none-eabihf.json -Z build-std=core,compiler_builtins` + +qemu: `qemu-system-arm -m 256 -M raspi0 -serial stdio -kernel kernel.elf` + +--- + +# References + +- https://os.phil-opp.com/minimal-rust-kernel/ +- https://wiki.osdev.org/Raspberry_Pi_Bare_Bones +- https://wiki.osdev.org/Raspberry_Pi_Bare_Bones_Rust diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..4f5268c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,26 @@ +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +/// This function is called on panic. +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop {} +} + +static HELLO: &[u8] = b"Hello World!"; + +#[unsafe(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 {} +}