From 8767dbecb45bbe5f748952fb9171b1a96c173f67 Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 27 Aug 2026 17:16:04 +0200 Subject: tool migration: v2 exports + 10 external CLI binaries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rsapi v2: 14 new ABI function pointers appended after v1 — fs_resolve, fs_dir_next (iterator), fs_create, fs_remove, fs_read, fs_write, fs_size, fs_close, rtc_now, mem_stats, pci_probe, pci_device, klog_dump, kernel_version. New C-repr structs: DirEntry, RtcTime, MemStats, PciDevice, KernelVersion. ABI_VERSION bumped to 2. Shell-side: build_exports() constructs the full table at runtime per invocation (replaces static const). 14 kernel-side wrapper functions bridge rsapi types to rsnix kernel APIs; fs_dir_next maintains a per-handle cache of children() results for iteration. Tool binaries (10 crates, all linked against rsapi only): - date: rtc_now → formatted YYYY-MM-DD HH:MM:SS - mem: heap/pages free/total via mem_stats - pci: pci_probe + pci_device enumerate all devices - cat: fs_read paths or get_line stdin; put_line output - ls: fs_resolve + fs_dir_next iteration; trailing / for dirs - mkdir: fs_create(path, true) - touch: fs_create(path, false) - rm: fs_remove(path) - klog: klog_dump 2048 bytes → put_line - info: rtc_now + kernel_version (minimal; mem/pci deferred) Gate verified: date prints RTC; pci lists all 4 QEMU devices (8086:29c0, 1234:1111, 8086:10d3, 8086:2918); hello/boom/count still work; test-disk PASS; poweroff clean. --- bins/pci/Cargo.toml | 8 ++++++++ bins/pci/src/main.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 bins/pci/Cargo.toml create mode 100644 bins/pci/src/main.rs (limited to 'bins/pci') diff --git a/bins/pci/Cargo.toml b/bins/pci/Cargo.toml new file mode 100644 index 0000000..85590f8 --- /dev/null +++ b/bins/pci/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "pci" +version.workspace = true +edition.workspace = true +[lints] +workspace = true +[dependencies] +rsapi = { path = "../../rsapi" } diff --git a/bins/pci/src/main.rs b/bins/pci/src/main.rs new file mode 100644 index 0000000..1182d83 --- /dev/null +++ b/bins/pci/src/main.rs @@ -0,0 +1,53 @@ +//! pci — list PCI devices via the exports table. + +#![no_std] +#![no_main] + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop { core::hint::spin_loop(); } +} + +fn put(exports: &rsapi::Exports, buf: &[u8]) { + (exports.put_line)(rsapi::Line { ptr: buf.as_ptr(), len: buf.len() }); +} + +fn hex2(b: u8, out: &mut [u8]) { + let hi = b >> 4; let lo = b & 0xf; + out[0] = if hi < 10 { b'0' + hi } else { b'a' + hi - 10 }; + out[1] = if lo < 10 { b'0' + lo } else { b'a' + lo - 10 }; +} + +#[unsafe(no_mangle)] +pub extern "C" fn efi_main(exports: &'static rsapi::Exports, _argc: usize, _argv: *const rsapi::Arg) -> i32 { + let count = (exports.pci_probe)(); + let mut i = 0u32; + while i < count { + let mut d = rsapi::PciDevice { bus: 0, device: 0, function: 0, class: 0, subclass: 0, vendor: 0, device_id: 0 }; + if (exports.pci_device)(i, &mut d) { + // "XX:XX.F class=XX:XX ven=XXXX dev=XXXX" = 42 bytes max + let mut buf = [0u8; 42]; + hex2(d.bus, &mut buf[0..2]); buf[2] = b':'; + hex2(d.device, &mut buf[3..5]); buf[5] = b'.'; + buf[6] = b'0' + d.function; + let class_lbl = b" class="; + buf[7..7+class_lbl.len()].copy_from_slice(class_lbl); + let o = 7 + class_lbl.len(); + hex2(d.class, &mut buf[o..o+2]); buf[o+2] = b':'; + hex2(d.subclass, &mut buf[o+3..o+5]); + let ven_lbl = b" ven="; + buf[o+5..o+5+ven_lbl.len()].copy_from_slice(ven_lbl); + let v = o + 5 + ven_lbl.len(); + hex2((d.vendor >> 8) as u8, &mut buf[v..v+2]); + hex2((d.vendor & 0xff) as u8, &mut buf[v+2..v+4]); + let dev_lbl = b" dev="; + buf[v+4..v+4+dev_lbl.len()].copy_from_slice(dev_lbl); + let dd = v + 4 + dev_lbl.len(); + hex2((d.device_id >> 8) as u8, &mut buf[dd..dd+2]); + hex2((d.device_id & 0xff) as u8, &mut buf[dd+2..dd+4]); + put(exports, &buf[..dd+4]); + } + i += 1; + } + 0 +} -- cgit v1.2.3