diff options
| author | salmonik <salmonik@tuta.io> | 2026-08-27 17:16:04 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-08-27 17:16:04 +0200 |
| commit | 8767dbecb45bbe5f748952fb9171b1a96c173f67 (patch) | |
| tree | c10a66c91a53522feb980d8b59aa8c87293537f8 /bins/mem/src/main.rs | |
| parent | streams: per-invocation channel, pumping mode, filter pipeline wiring (diff) | |
| download | rs-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 'bins/mem/src/main.rs')
| -rw-r--r-- | bins/mem/src/main.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/bins/mem/src/main.rs b/bins/mem/src/main.rs new file mode 100644 index 0000000..fd99f47 --- /dev/null +++ b/bins/mem/src/main.rs | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | //! mem — show memory statistics via the exports table. | ||
| 2 | |||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | |||
| 6 | #[panic_handler] | ||
| 7 | fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| 8 | loop { core::hint::spin_loop(); } | ||
| 9 | } | ||
| 10 | |||
| 11 | fn put(exports: &rsapi::Exports, buf: &[u8]) { | ||
| 12 | (exports.put_line)(rsapi::Line { ptr: buf.as_ptr(), len: buf.len() }); | ||
| 13 | } | ||
| 14 | |||
| 15 | fn fmt_kib(exports: &rsapi::Exports, v: u64) { | ||
| 16 | let mut buf = [0u8; 32]; | ||
| 17 | let kb = v / 1024; | ||
| 18 | let mut i = buf.len(); | ||
| 19 | if kb == 0 { i -= 1; buf[i] = b'0'; } | ||
| 20 | else { let mut n = kb; while n > 0 { i -= 1; buf[i] = b'0' + (n % 10) as u8; n /= 10; } } | ||
| 21 | let s = b" KiB"; | ||
| 22 | buf[i..i+s.len()].copy_from_slice(s); | ||
| 23 | put(exports, &buf[i..i+s.len()]); | ||
| 24 | } | ||
| 25 | |||
| 26 | #[unsafe(no_mangle)] | ||
| 27 | pub extern "C" fn efi_main(exports: &'static rsapi::Exports, _argc: usize, _argv: *const rsapi::Arg) -> i32 { | ||
| 28 | let mut s = rsapi::MemStats { heap_total: 0, heap_free: 0, pages_total: 0, pages_free: 0 }; | ||
| 29 | (exports.mem_stats)(&mut s); | ||
| 30 | let msg = b"heap:"; | ||
| 31 | put(exports, msg); | ||
| 32 | put(exports, b" free"); fmt_kib(exports, s.heap_free); | ||
| 33 | put(exports, b" / total"); fmt_kib(exports, s.heap_total); | ||
| 34 | let msg2 = b"pages:"; | ||
| 35 | put(exports, msg2); | ||
| 36 | put(exports, b" free"); | ||
| 37 | let mut fb = [0u8; 16]; | ||
| 38 | let mut i = fb.len(); | ||
| 39 | let n = s.pages_free; if n==0 { i-=1; fb[i]=b'0'; } else { let mut m=n; while m>0 { i-=1; fb[i]=b'0'+(m%10) as u8; m/=10; } } | ||
| 40 | put(exports, &fb[i..]); | ||
| 41 | put(exports, b" / "); | ||
| 42 | let mut tb = [0u8; 16]; | ||
| 43 | let mut j = tb.len(); | ||
| 44 | let t = s.pages_total; if t==0 { j-=1; tb[j]=b'0'; } else { let mut m=t; while m>0 { j-=1; tb[j]=b'0'+(m%10) as u8; m/=10; } } | ||
| 45 | put(exports, &tb[j..]); | ||
| 46 | 0 | ||
| 47 | } | ||
