Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Tezro-specific settings apply when `machine.profile = "tezro_ip53"`.
| Key | Default | Values and behavior |
|---|---|---|
| `flash` | unset | Persistent 16 MiB boot-flash file. Unset, the flash is volatile. |
| `console` | `l1` | `l1`, `ioc4_a`, `ioc4_b`, `ioc4_c` or `ioc4_d`. Selects the guest console connection. |
| `console` | `l1` | `l1`, `ioc4_a`, `ioc4_b`, `ioc4_c` or `ioc4_d`. Selects the host connection only. The PROM uses the L1 until `console ioc4` is run in its Command Monitor and the machine is reset; it then uses UART A (`ioc4_a`) only, and keeps the choice in the `flash` file. |
| `l1_port` | `8882` | Host TCP port for the L1 console. |
| `l1_log` | unset | Optional serial log path for L1 output when an IOC4 port is selected as console. |
| `serial_port_c`, `serial_port_d` | `8883`, `8884` | Host TCP ports of IOC4 ports 2 and 3; ports 0 and 1 use `serial_port_a` and `serial_port_b`. |
Expand Down
2 changes: 1 addition & 1 deletion STORAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ debugging the wrapper itself.

# In another terminal: drive it
./target/release/iris-ci status --wait-ready 60 # guest state + monitor readiness
./target/release/iris-ci boot # PROM menu → IRIS console login (one cmd)
./target/release/iris-ci boot # PROM menu (if shown) → login prompt (one cmd)
./target/release/iris-ci login # send root + dismiss vt100 prompt + wait #
./target/release/iris-ci run 'ls /' # send shell command, get stdout + exit code
./target/release/iris-ci save base/multiuser
Expand Down
6 changes: 5 additions & 1 deletion docs/tezro-ip53.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ matches a captured Tezro. One processor needs at least 512 MiB, two or four at l
the L1 port and log. The console options are `l1` (the default) and `ioc4_a`
to `ioc4_d`, the IOC4's ports 0 to 3. IOC4 ports 0 and 1 listen on
`serial_port_a` and `serial_port_b`, ports 2 and 3 on `tezro.serial_port_c`
and `tezro.serial_port_d`. `nvram` names the 32 KiB DS1744 store; its clock
and `tezro.serial_port_d`. The setting only picks the host connection: the
PROM writes to the L1 until `console ioc4` is run in its Command Monitor and
the machine is reset, after which the menu appears on UART A (`ioc4_a`) only.
The PROM keeps that choice in the flash, so set `flash` or it is lost on the
next start. `nvram` names the 32 KiB DS1744 store; its clock
reference is kept beside it with a `.clock` suffix.

## Firmware inputs
Expand Down
20 changes: 20 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4072,6 +4072,15 @@ impl MachineConfig {
}
}
self.validate_serial_sockets()?;
// The test device decodes GIO expansion slot 0, as do the Ultra64 board and the second Newport head.
if self.test_device && matches!(self.machine.profile, MachineProfile::IndyIp24 | MachineProfile::Indigo2Ip22 | MachineProfile::Indigo2Ip28) {
if self.ultra64.enabled {
return Err("test_device and [ultra64] both claim GIO expansion slot 0; enable one".into());
}
if self.graphics.heads == 2 && !self.headless {
return Err("test_device and the second graphics head (graphics.heads = 2) both claim GIO expansion slot 0".into());
}
}
if self.test_device_run_config.is_some() {
if !self.test_device {
return Err("test_device_run_config needs test_device".into());
Expand Down Expand Up @@ -5375,6 +5384,17 @@ mod export_tests {
assert!(alone.contains("needs test_device"), "{alone}");
}

#[test]
fn the_test_device_refuses_another_card_in_gio_slot_0() {
let cli = |a: &[&str]| Cli::parse_from(["iris"].iter().chain(a)).apply(MachineConfig::default());
let mut cfg = cli(&["--test-device"]);
cfg.ultra64.enabled = true;
assert!(cfg.validate().unwrap_err().contains("[ultra64]"));
let mut cfg = cli(&["--test-device"]);
cfg.graphics.heads = 2;
assert!(cfg.validate().unwrap_err().contains("second graphics head"));
}

#[test]
fn parse_mac_accepts_both_separators_and_rejects_junk() {
assert_eq!(parse_mac("00:80:19:12:34:56").unwrap(), [0, 0x80, 0x19, 0x12, 0x34, 0x56]);
Expand Down
77 changes: 47 additions & 30 deletions src/dev/ds1685.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
use std::sync::mpsc::SyncSender;
use std::sync::{Arc, Weak};
use std::sync::Arc;
use std::time::{Duration, Instant};

use parking_lot::{Condvar, Mutex};
Expand Down Expand Up @@ -201,6 +201,16 @@ fn save_nvram((path, image, clock): &NvramJob) -> std::io::Result<()> {
/// A rewrite of the NVRAM file waiting for the writer thread.
type NvramJob = (std::path::PathBuf, Vec<u8>, Option<Vec<u8>>);

/// What the writer thread shares with the part. It holds only this, so
/// dropping the part's last reference runs its `Drop`, which joins the writer.
#[derive(Default)]
struct WriterSlot {
/// The NVRAM image the writer thread has yet to put in the file.
job: Mutex<Option<NvramJob>>,
ready: Condvar,
running: AtomicBool,
}

/// The clock part: its registers and RAM, the file they persist in, and the
/// thread that writes it.
pub struct Ds1685 {
Expand All @@ -210,25 +220,18 @@ pub struct Ds1685 {
/// Where the guest's power-off goes: one `PowerOff` event when it writes
/// the bit.
events: Option<SyncSender<MachineEvent>>,
/// The NVRAM image the writer thread has yet to put in the file.
job: Mutex<Option<NvramJob>>,
ready: Condvar,
running: AtomicBool,
slot: Arc<WriterSlot>,
thread: Mutex<Option<std::thread::JoinHandle<()>>>,
me: Weak<Ds1685>,
}

impl Ds1685 {
pub fn new(events: Option<SyncSender<MachineEvent>>) -> Arc<Ds1685> {
Arc::new_cyclic(|me| Ds1685 {
Arc::new(Ds1685 {
st: Mutex::new(Rtc::new()),
dirty: AtomicU64::new(0),
events,
job: Mutex::new(None),
ready: Condvar::new(),
running: AtomicBool::new(false),
slot: Arc::default(),
thread: Mutex::new(None),
me: me.clone(),
})
}

Expand Down Expand Up @@ -312,8 +315,8 @@ impl Ds1685 {
/// The debounce ran out: hand the image to the writer thread.
pub fn hand_over(&self) {
if let Some(job) = self.take_dirty(NVRAM_QUIET) {
*self.job.lock() = Some(job);
self.ready.notify_all();
*self.slot.job.lock() = Some(job);
self.slot.ready.notify_all();
}
}

Expand All @@ -340,13 +343,12 @@ impl Ds1685 {
}

/// Write the NVRAM file when the timer hands over an image.
fn writer(me: Weak<Ds1685>) {
fn writer(s: Arc<WriterSlot>) {
loop {
let job = {
let Some(d) = me.upgrade() else { return };
let mut slot = d.job.lock();
while slot.is_none() && d.running.load(Ordering::SeqCst) {
d.ready.wait(&mut slot);
let mut slot = s.job.lock();
while slot.is_none() && s.running.load(Ordering::SeqCst) {
s.ready.wait(&mut slot);
}
match slot.take() {
Some(j) => j,
Expand Down Expand Up @@ -405,39 +407,35 @@ impl Device for Ds1685 {

/// Start the writer thread.
fn start(&self) {
if self.running.swap(true, Ordering::SeqCst) {
if self.slot.running.swap(true, Ordering::SeqCst) {
return;
}
let me = self.me.clone();
let slot = self.slot.clone();
*self.thread.lock() = Some(
std::thread::Builder::new()
.name("IOC3-NVRAM".into())
.spawn(move || Ds1685::writer(me))
.spawn(move || Ds1685::writer(slot))
.expect("spawn ds1685 nvram thread"),
);
}

/// Join the writer and flush the file.
fn stop(&self) {
if !self.running.swap(false, Ordering::SeqCst) {
if !self.slot.running.swap(false, Ordering::SeqCst) {
return;
}
// The writer waits on the job slot's lock: take it so the wake-up
// cannot fall between its check of `running` and its wait.
drop(self.job.lock());
self.ready.notify_all();
// The writer can hold the last reference for a moment, and then this
// runs on it; it cannot join itself.
drop(self.slot.job.lock());
self.slot.ready.notify_all();
if let Some(t) = self.thread.lock().take() {
if t.thread().id() != std::thread::current().id() {
let _ = t.join();
}
let _ = t.join();
}
self.flush();
}

fn is_running(&self) -> bool {
self.running.load(Ordering::SeqCst)
self.slot.running.load(Ordering::SeqCst)
}

fn get_clock(&self) -> u64 {
Expand All @@ -451,3 +449,22 @@ impl Drop for Ds1685 {
self.flush();
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn dropping_a_started_part_without_stop_ends_its_writer() {
let d = Ds1685::new(None);
d.start();
// Wait for the writer to park holding its reference.
let t = Instant::now();
while Arc::strong_count(&d) < 2 && t.elapsed() < Duration::from_millis(500) {
std::thread::yield_now();
}
let part = Arc::downgrade(&d);
drop(d);
assert!(part.upgrade().is_none(), "the writer kept the part alive");
}
}
2 changes: 1 addition & 1 deletion src/ip27.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ pub(crate) fn pci_devices(
let ps2 = ioc3.ps2();
let reset_scsi = scsi.clone();
let disk_scsi = scsi.clone();
let disc_changer = scsi.first().map(|c| c.clone() as Arc<dyn DiscChanger>);
let disc_changer = Some(Arc::new(crate::workstation::DiscChangers(scsi.iter().map(|c| c.clone() as _).collect())) as Arc<dyn DiscChanger>);
let reset_clock = timekeeper.clone();
let flush = timekeeper.clone();
let reset: Box<dyn Fn() + Send + Sync> = Box::new(move || {
Expand Down
3 changes: 1 addition & 2 deletions src/ip30_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1515,9 +1515,8 @@ impl Workstation for OctaneMachine {
fn scratch_path(&self) -> Option<&std::path::Path> {
self.scratch_path.as_deref()
}
/// Disc changes on the internal bus.
fn disc_changer(&self) -> Option<Arc<dyn crate::workstation::DiscChanger>> {
Some(self.scsi[0].clone() as Arc<dyn crate::workstation::DiscChanger>)
Some(Arc::new(crate::workstation::DiscChangers(self.scsi.iter().map(|c| c.clone() as _).collect())))
}
fn pending_chd_sync_count(&self) -> usize {
self.disk_buses().iter().map(|b| b.pending_chd_sync_count()).sum()
Expand Down
5 changes: 2 additions & 3 deletions src/ip32_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,10 +906,9 @@ impl Workstation for O2Machine {
fn ci_rollback(&mut self) -> Result<(), String> { O2Machine::ci_rollback(self) }

fn scratch_path(&self) -> Option<&std::path::Path> { self.scratch_path.as_deref() }
/// Disc changes on the internal bus (controller 0), as the Indigo2 offers
/// its first controller.
fn disc_changer(&self) -> Option<Arc<dyn crate::workstation::DiscChanger>> {
self.bus.scsi.lock().unwrap().first().map(|c| c.clone() as Arc<dyn crate::workstation::DiscChanger>)
let ctls = self.bus.scsi.lock().unwrap().iter().map(|c| c.clone() as _).collect();
Some(Arc::new(crate::workstation::DiscChangers(ctls)))
}
/// The same `/CDROM` remount the Indy types: controller 0 is `dks0` to
/// IRIX on the O2 as well.
Expand Down
88 changes: 79 additions & 9 deletions src/iris_ci_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,14 @@ enum Cmd {
timeout: u64,
},

/// Boot from PROM menu through to the IRIS console login prompt.
/// Boot through the PROM menu, if it appears, to the login prompt.
Boot {
/// Total timeout in seconds for boot to reach the login prompt.
#[arg(long, default_value_t = 240)]
timeout: u64,
/// Console text that means the login prompt is up.
#[arg(long, default_value = "login:")]
prompt: String,
},
/// Send root login + dismiss the vt100 prompt + wait for the shell.
Login {
Expand Down Expand Up @@ -378,7 +381,7 @@ fn dispatch(opts: &Opts, cmd: Cmd) -> Result<()> {
Cmd::SerialRead => cmd_serial_read(opts),
Cmd::SerialWait { pattern, timeout } => cmd_serial_wait(opts, &pattern, timeout * 1000),

Cmd::Boot { timeout } => cmd_boot(opts, timeout),
Cmd::Boot { timeout, prompt } => cmd_boot(opts, timeout, &prompt),
Cmd::Login { user, password } => cmd_login(opts, &user, password.as_deref()),
Cmd::Run { command, shell, timeout } => cmd_run(opts, &command, &shell, timeout * 1000),
Cmd::WaitPrompt { timeout } => cmd_wait_prompt(opts, timeout * 1000),
Expand Down Expand Up @@ -944,16 +947,26 @@ fn screen_wait(

// ---- boot/login/run macros --------------------------------------------------

fn cmd_boot(opts: &Opts, timeout_s: u64) -> Result<()> {
fn cmd_boot(opts: &Opts, timeout_s: u64, prompt: &str) -> Result<()> {
let deadline = Instant::now() + Duration::from_secs(timeout_s);
if !opts.quiet { eprintln!("boot: starting CPU"); }
send(opts, "start", json!({}))?;
if !opts.quiet { eprintln!("boot: waiting for PROM menu"); }
wait_with_deadline(opts, "Option?", deadline)?;
if !opts.quiet { eprintln!("boot: PROM reached, selecting 1) Start System"); }
send(opts, "serial-send", json!({"data": "1\r"}))?;
if !opts.quiet { eprintln!("boot: waiting for kernel boot to login prompt"); }
wait_with_deadline(opts, "IRIS console login", deadline)?;
// An autoloading PROM never shows the menu, so watch for both together.
let (mut seen, mut menu) = (String::new(), false);
loop {
let read = send(opts, "serial-read", json!({}))?;
seen.push_str(read.as_str().unwrap_or(""));
if seen.contains(prompt) { break; }
if !menu && seen.contains("Option?") {
menu = true;
if !opts.quiet { eprintln!("boot: PROM reached, selecting 1) Start System"); }
send(opts, "serial-send", json!({"data": "1\r"}))?;
}
if Instant::now() >= deadline {
return Err(Error::Timeout(format!("boot: no {prompt:?} within {timeout_s}s")));
}
std::thread::sleep(Duration::from_millis(250));
}
if !opts.quiet { eprintln!("boot: ready at login"); }
Ok(())
}
Expand Down Expand Up @@ -1642,4 +1655,61 @@ mod tests {
assert_eq!(count_differing(&golden, &no_root, 32), Some(156));
assert!(100 <= SCREEN_MAX_PIXELS && SCREEN_MAX_PIXELS < 156);
}
/// Serves `start`, `serial-send` and `serial-read` for `cmd_boot`; the
/// console shows `before` until `1\r` arrives (or always, when `after`
/// is None) and `after` from then on. Returns the address and a handle
/// that yields the data sent.
fn fake_console(before: &'static str, after: Option<&'static str>)
-> (String, std::sync::Arc<std::sync::Mutex<Vec<String>>>)
{
let l = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
let addr = l.local_addr().unwrap().to_string();
let sent = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));
let log = sent.clone();
std::thread::spawn(move || {
for s in l.incoming() {
let s = s.unwrap();
let mut line = String::new();
BufReader::new(s.try_clone().unwrap()).read_line(&mut line).unwrap();
let req: Value = serde_json::from_str(&line).unwrap();
let data = match req["cmd"].as_str().unwrap() {
"serial-send" => {
log.lock().unwrap().push(req["args"]["data"].as_str().unwrap().into());
Value::Null
}
"serial-read" => {
let sent = !log.lock().unwrap().is_empty();
json!(if sent { after.unwrap_or(before) } else { before })
}
// The fixed waits the old script used never match a real console.
"wait-serial" => {
writeln!(&s, "{}", json!({"ok": false, "error": "timeout", "timeout": true})).unwrap();
continue;
}
_ => Value::Null,
};
writeln!(&s, "{}", json!({"ok": true, "data": data})).unwrap();
}
});
(addr, sent)
}

fn boot_opts(addr: &str) -> Opts {
Opts { socket: addr.into(), json: false, quiet: true }
}

#[test]
fn boot_presses_the_menu_and_stops_at_any_hostnames_login() {
let (addr, sent) = fake_console("Option? ", Some("ip30-6530 console login: "));
cmd_boot(&boot_opts(&addr), 5, "login:").unwrap();
assert_eq!(*sent.lock().unwrap(), ["1\r"]);
}

#[test]
fn boot_of_an_autoloading_prom_needs_no_menu() {
let (addr, sent) = fake_console("Starting up the system...\r\nindy-6522 console login: ", None);
cmd_boot(&boot_opts(&addr), 5, "login:").unwrap();
assert!(sent.lock().unwrap().is_empty());
}

}
Loading