From 76103215711d268b4b02f62e900f2be3032cf295 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 02:18:30 +0200 Subject: Initial commit: raisernics toy kernel - Bare-metal x86_64 UEFI kernel (PE32+, no libc) - GOP framebuffer + 8x16 bitmap font - PS/2 keyboard (polling, scancode set 1) - UART 16550 serial driver (COM1, 115200 8N1) - Bump allocator as #[global_allocator] (alloc::String, Vec, format!) - UEFI memory map capture (static buffer, ADR 0001) - Shell with 7 commands (help, echo, clear, hello, info, mem, halt) - Dual output: GOP framebuffer + serial console - Makefile: run, run-gui, debug, release, image targets - tools/: qemu.sh, boot-image.sh, debug-kernel.py --- build.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 build.rs (limited to 'build.rs') diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..44e6344 --- /dev/null +++ b/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