From 8b1c1a23382806fcdbd3dbc7336a6ac2da8a995b Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 31 Jul 2026 16:10:40 +0200 Subject: rtc + pci: CMOS clock with date command, PCI bus enumeration - rtc.rs: read the PC RTC via CMOS ports 0x70/0x71 (UIP wait, BCD/12h normalization, century sanity-check with 2000+ fallback); boot prints the wall clock, shell gains 'date' - pci.rs: legacy config-space access (0xCF8/0xCFC) with full enumeration of buses 0-255; boot reports device count, shell gains 'pci' (lspci style listing with class names) - QEMU q35 verified: Q35 host bridge, stdvga, e1000, ICH9 LPC --- shell/src/lib.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'shell/src/lib.rs') diff --git a/shell/src/lib.rs b/shell/src/lib.rs index 5cab122..500eaae 100644 --- a/shell/src/lib.rs +++ b/shell/src/lib.rs @@ -50,6 +50,8 @@ pub fn run() -> ! { "mem" => cmd_mem(), "mmap" => cmd_mmap(), "stress" => cmd_stress(args), + "date" => cmd_date(), + "pci" => cmd_pci(), _ => { gop_println!("unknown command: {}", cmd); serial_println!("unknown command: {}", cmd); @@ -124,11 +126,13 @@ fn cmd_help() { gop_println!(" mem — show memory info"); gop_println!(" mmap — dump the UEFI memory map"); gop_println!(" stress — stress-test heap/page allocators"); + gop_println!(" date — show current date/time (RTC)"); + gop_println!(" pci — list PCI devices"); gop_println!(" halt — halt the system (hlt loop)"); gop_println!(" poweroff — shut down via ACPI (ResetSystem)"); gop_println!(" exit — alias for poweroff"); serial_println!("available commands:"); - serial_println!(" help, echo, clear, hello, info, mem, mmap, stress, halt, poweroff, exit"); + serial_println!(" help, echo, clear, hello, info, mem, mmap, stress, date, pci, halt, poweroff, exit"); } fn cmd_echo(args: &str) { @@ -364,6 +368,38 @@ fn cmd_halt() -> ! { rsnix::power::halt() } +fn cmd_date() { + let t = rsnix::rtc::now(); + let line = alloc::format!( + "{}-{:02}-{:02} {:02}:{:02}:{:02}", + t.year, t.month, t.day, t.hour, t.minute, t.second + ); + gop_println!("{}", line); + serial_println!("{}", line); +} + +fn cmd_pci() { + let devices = rsnix::pci::probe(); + let mut out = alloc::string::String::new(); + use alloc::fmt::Write; + let _ = writeln!(out, "pci: {} device(s)", devices.len()); + let _ = writeln!(out, " bus dev fn class vendor:device"); + for d in &devices { + let _ = writeln!( + out, + " {:02x}:{:02x}.{} {:<16} {:04x}:{:04x}", + d.bus, + d.device, + d.func, + rsnix::pci::class_name(d.class, d.subclass), + d.vendor, + d.device_id + ); + } + gop_print!("{}", out); + serial_print!("{}", out); +} + fn cmd_poweroff() -> ! { gop_println!("shutting down..."); serial_println!("shutting down..."); -- cgit v1.2.3