From 6a5c32fa6ae8ec34e3e5b44d7e5a78ded8fe729b Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 02:58:31 +0200 Subject: restructure: rsnix kernel + shell crate + rsdos entry point MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Architecture: rs-dos/ (workspace root, was raisernics/) ├── rsnix/ — kernel lib crate (uefi, serial, gop, ps2, interrupts, memory) ├── shell/ — shell lib crate (prompt, commands, line input) ├── rsdos/ — binary crate (efi_main, init, panic handler) └── rsboot/ — future git submodule No functional changes — boots to shell prompt identically. Version auto-pulled from Cargo.toml via env!("CARGO_PKG_VERSION"). --- rsnix/build.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 rsnix/build.rs (limited to 'rsnix/build.rs') diff --git a/rsnix/build.rs b/rsnix/build.rs new file mode 100644 index 0000000..35447e9 --- /dev/null +++ b/rsnix/build.rs @@ -0,0 +1,70 @@ +/// Build script — extracts glyph data from a PSF2 font file. +/// Uses zcat (system gzip) to decompress — zero dependencies. +use std::env; +use std::fs; +use std::path::Path; +use std::process::{Command, Output}; + +fn main() -> Result<(), Box> { + let font_path = "/usr/share/kbd/consolefonts/lat1-16.psfu.gz"; + println!("cargo::rerun-if-changed={}", font_path); + + // Decompress via zcat (available on any Linux system) + let Output { stdout, status, .. } = Command::new("zcat").arg(font_path).output()?; + if !status.success() { + return Err(format!("zcat exited with {status:?}").into()); + } + let raw = stdout; + + if raw.len() < 32 { + return Err("PSF font too small".into()); + } + + // PSF2 magic: 0x864ab572 (little-endian) + let magic = u32::from_le_bytes(raw[..4].try_into()?); + if magic != 0x864ab572 { + return Err("not a PSF2 font".into()); + } + + let hdr_size = u32::from_le_bytes(raw[8..12].try_into()?) as usize; + let num_glyphs = u32::from_le_bytes(raw[16..20].try_into()?) as usize; + let bytes_per_glyph = u32::from_le_bytes(raw[20..24].try_into()?) as usize; + + if num_glyphs != 256 { + return Err(format!("expected 256 glyphs, got {num_glyphs}").into()); + } + if bytes_per_glyph != 16 { + return Err(format!("expected 16 bytes/glyph, got {bytes_per_glyph}").into()); + } + + let glyph_data = &raw[hdr_size..hdr_size + num_glyphs * bytes_per_glyph]; + + // Write generated Rust source into OUT_DIR + let out_dir = env::var("OUT_DIR")?; + let dest = Path::new(&out_dir).join("font_data.rs"); + + let mut code = String::from( + "/// 8×16 bitmap font glyph data (256 glyphs, 16 bytes each). +#[rustfmt::skip] +#[allow(clippy::unreadable_literal)] +pub const GLYPH_8X16: [[u8; 16]; 256] = [", + ); + + for g in 0..256 { + let offset = g * 16; + code.push_str("\n ["); + for row in 0..16 { + if row % 4 == 0 { + code.push('\n'); + } + let byte = glyph_data[offset + row]; + code.push_str(&format!(" 0x{byte:02X},")); + } + code.push_str("\n ],"); + } + + code.push_str("\n];\n"); + + fs::write(&dest, code)?; + Ok(()) +} -- cgit v1.2.3