From 386d64ddd5a9537798f30110ccfd7449a625076c Mon Sep 17 00:00:00 2001 From: javalsai Date: Sat, 21 Feb 2026 23:06:50 +0100 Subject: [PATCH] sad: death of panicless *+ smth Give in in favor of str and utf8 with perfect valid state and panic bailout everywhere in std. Define some more Boot Info Format tags. --- Cargo.lock | 7 +++++ Cargo.toml | 1 - members/oxide/Cargo.toml | 1 + members/oxide/src/main.rs | 17 ++++++----- members/oxide/src/multiboot2.rs | 51 ++++++++++++++++++++++++++++++--- members/oxide/src/vga/vt.rs | 12 -------- 6 files changed, 65 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f6e596c..e423811 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "ascii" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" + [[package]] name = "bios" version = "0.1.0" @@ -10,5 +16,6 @@ version = "0.1.0" name = "oxide" version = "0.1.0" dependencies = [ + "ascii", "bios", ] diff --git a/Cargo.toml b/Cargo.toml index 18b0899..e31e436 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,6 @@ members = ["deps/bios", "members/oxide"] bios = { path = "deps/bios" } [profile.release] -opt-level = "z" codegen-units = 1 lto = "fat" panic = "abort" diff --git a/members/oxide/Cargo.toml b/members/oxide/Cargo.toml index bff1181..b9ca8da 100644 --- a/members/oxide/Cargo.toml +++ b/members/oxide/Cargo.toml @@ -10,4 +10,5 @@ test = false bench = false [dependencies] +ascii = { version = "1.1.0", default-features = false } bios = { workspace = true } diff --git a/members/oxide/src/main.rs b/members/oxide/src/main.rs index adbc83e..6ed46ec 100644 --- a/members/oxide/src/main.rs +++ b/members/oxide/src/main.rs @@ -16,11 +16,16 @@ /// Triggers a linker failure if this reaches that phase #[panic_handler] fn panic(_info: &PanicInfo) -> ! { - unsafe extern "C" { - static __PANIC_HANDLER_WAS_LINKED__DO_NOT_DEFINE: extern "C" fn() -> !; - } + // 2026-02-21: Officially the end of panicless OxideOS, did you know `Debug for str` has panic + // code paths :pensive:. At least compile ones, maybe runtime impossible but still not compiled + // away. + unsafe { asm!("ud2", "hlt", options(noreturn)) }; - unsafe { __PANIC_HANDLER_WAS_LINKED__DO_NOT_DEFINE() }; + // unsafe extern "C" { + // static __PANIC_HANDLER_WAS_LINKED__DO_NOT_DEFINE: extern "C" fn() -> !; + // } + + // unsafe { __PANIC_HANDLER_WAS_LINKED__DO_NOT_DEFINE() }; } use core::{arch::asm, fmt::Write as _, hint::black_box, panic::PanicInfo}; @@ -49,15 +54,13 @@ extern "C" fn start(boot_info: &bif::FixedPart) -> ! { vt.set_color(VgaColor::new(ColorNibble::BLUE, ColorNibble::GREEN)); vt.put_at(10, 5); vt.slide(); - vt.print_n(boot_info as *const _ as usize as u32); vt.write(b"testinggg\ntags:\n"); let tags = bif::TagsIter::new(boot_info); for tag in tags { sleep_short(); - vt.print_n(tag.typ()); - vt.write(b": "); + let _ = write!(&mut vt, "{}: ", tag.typ()); let Some(tag) = tag.tag() else { vt.write(b"unknown tag\n"); continue; diff --git a/members/oxide/src/multiboot2.rs b/members/oxide/src/multiboot2.rs index e9ff536..03c02d4 100644 --- a/members/oxide/src/multiboot2.rs +++ b/members/oxide/src/multiboot2.rs @@ -54,6 +54,8 @@ pub mod bif { } pub mod types { + use ascii::AsciiStr; + macro tagset($taggedvis:vis $taggedname:ident { $( $typname:ident ($typn:expr) { $($typprop:ident : $typpropty:ty),* $(,)? } ),* $(,)? }) { $( #[repr(C)] @@ -71,14 +73,14 @@ pub mod bif { } } + // All these AsciiStr are actually CStr's tagset! { pub TagTagged { - Terminate(0) {}, BootCommandLine(1) { - string: [u8], + string: AsciiStr, }, BootLoaderName(2) { - string: [u8], + string: AsciiStr, }, BasicMemoryInformation(4) { mem_lower: u32, @@ -89,6 +91,42 @@ pub mod bif { partition: u32, sub_partition: u32, }, + MemoryMap(6) { + entry_size: u32, + entry_version: u32, + entries: [u8], // "varies"? + }, + FramebufferInfo(8) { + addr: u64, + pitch: u32, + width: u32, + height: u32, + bpp: u8, + typ: u8, + _reserved: u8, + color_info: [u8], + }, + ELFSymbols(9) { + num: u16, + entsize: u16, + shndx: u16, + _reserved: u16, + section_headers: [u8], // "varies"? + }, + APMTable(10) { + version: u16, + cseg: u16, + offset: u32, + cseg_16: u16, + dseg: u16, + flags: u16, + cseg_len: u16, + cseg_16_len: u16, + dseg_len: u16, + }, + ACPIoldRSDP(14) { + rsdpv1_old: [u8], + }, ImageLoadBasePhyAddr(21) { load_base_addr: u32, }, @@ -155,13 +193,18 @@ pub mod bif { } typ_match!(match typ { + Terminate BasicMemoryInformation BIOSBootDevice - Terminate + APMTable ImageLoadBasePhyAddr } fat { BootCommandLine BootLoaderName + MemoryMap + FramebufferInfo + ELFSymbols + ACPIoldRSDP }) } } diff --git a/members/oxide/src/vga/vt.rs b/members/oxide/src/vga/vt.rs index e73c143..1c64f5b 100644 --- a/members/oxide/src/vga/vt.rs +++ b/members/oxide/src/vga/vt.rs @@ -54,18 +54,6 @@ where } } - pub fn print_n(&mut self, n: u32) { - const BASE: u32 = 10; - - if n == 0 { - // TODO: print a 0 if no recursion in the future - } else { - let digit = (n % BASE) as u8; - self.print_n(n / 10); - self.write(&[b'0' + digit]); - } - } - pub fn write(&mut self, data: &[u8]) { const BAD_CHAR_COL: VgaColor = VgaColor::new(ColorNibble::WHITE, ColorNibble::RED);