summaryrefslogtreecommitdiffstats
path: root/bins/pci/src/main.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-08-27 17:16:04 +0200
committersalmonik <salmonik@tuta.io>2026-08-27 17:16:04 +0200
commit8767dbecb45bbe5f748952fb9171b1a96c173f67 (patch)
treec10a66c91a53522feb980d8b59aa8c87293537f8 /bins/pci/src/main.rs
parentstreams: per-invocation channel, pumping mode, filter pipeline wiring (diff)
downloadrs-dos-8767dbecb45bbe5f748952fb9171b1a96c173f67.tar.gz
rs-dos-8767dbecb45bbe5f748952fb9171b1a96c173f67.zip
tool migration: v2 exports + 10 external CLI binaries
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.
Diffstat (limited to '')
-rw-r--r--bins/pci/src/main.rs53
1 files changed, 53 insertions, 0 deletions
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 @@
1//! pci — list PCI devices via the exports table.
2
3#![no_std]
4#![no_main]
5
6#[panic_handler]
7fn panic(_info: &core::panic::PanicInfo) -> ! {
8 loop { core::hint::spin_loop(); }
9}
10
11fn put(exports: &rsapi::Exports, buf: &[u8]) {
12 (exports.put_line)(rsapi::Line { ptr: buf.as_ptr(), len: buf.len() });
13}
14
15fn hex2(b: u8, out: &mut [u8]) {
16 let hi = b >> 4; let lo = b & 0xf;
17 out[0] = if hi < 10 { b'0' + hi } else { b'a' + hi - 10 };
18 out[1] = if lo < 10 { b'0' + lo } else { b'a' + lo - 10 };
19}
20
21#[unsafe(no_mangle)]
22pub extern "C" fn efi_main(exports: &'static rsapi::Exports, _argc: usize, _argv: *const rsapi::Arg) -> i32 {
23 let count = (exports.pci_probe)();
24 let mut i = 0u32;
25 while i < count {
26 let mut d = rsapi::PciDevice { bus: 0, device: 0, function: 0, class: 0, subclass: 0, vendor: 0, device_id: 0 };
27 if (exports.pci_device)(i, &mut d) {
28 // "XX:XX.F class=XX:XX ven=XXXX dev=XXXX" = 42 bytes max
29 let mut buf = [0u8; 42];
30 hex2(d.bus, &mut buf[0..2]); buf[2] = b':';
31 hex2(d.device, &mut buf[3..5]); buf[5] = b'.';
32 buf[6] = b'0' + d.function;
33 let class_lbl = b" class=";
34 buf[7..7+class_lbl.len()].copy_from_slice(class_lbl);
35 let o = 7 + class_lbl.len();
36 hex2(d.class, &mut buf[o..o+2]); buf[o+2] = b':';
37 hex2(d.subclass, &mut buf[o+3..o+5]);
38 let ven_lbl = b" ven=";
39 buf[o+5..o+5+ven_lbl.len()].copy_from_slice(ven_lbl);
40 let v = o + 5 + ven_lbl.len();
41 hex2((d.vendor >> 8) as u8, &mut buf[v..v+2]);
42 hex2((d.vendor & 0xff) as u8, &mut buf[v+2..v+4]);
43 let dev_lbl = b" dev=";
44 buf[v+4..v+4+dev_lbl.len()].copy_from_slice(dev_lbl);
45 let dd = v + 4 + dev_lbl.len();
46 hex2((d.device_id >> 8) as u8, &mut buf[dd..dd+2]);
47 hex2((d.device_id & 0xff) as u8, &mut buf[dd+2..dd+4]);
48 put(exports, &buf[..dd+4]);
49 }
50 i += 1;
51 }
52 0
53}