Two bugs reported from actual use, plus a test harness that had stopped testing. init could be killed by Ctrl-C, taking the machine with it. SIGINT goes to the foreground process group, init is pgid 1, and any window where tty_fg_pgrp is 1 -- before a shell claims the terminal, after one exits, or between the two while the key is held -- lands it on init. init has no handler, so killed was set, exit() ran, and exit() panics outright on initproc. Spamming Ctrl-C at a frozen program is exactly the input that finds that window. POSIX and Linux both discard a default-action signal for pid 1; init_ignores() now does the same, SIGKILL included, because init is not killable from userspace on any Unix. Everything was slow because BSIZE was 1024 while a SchFS block is 4096, so every block cost four IDE requests, each with its own interrupt and sleep/wakeup. exec() of the 800 KB toybox binary meant ~800 round trips. The giveaway: `seq 1 200`, which touches no file and prints nothing, cost the same 2.0s as `cat /bin/toybox`, and `ls | wc -l` cost exactly double -- both dominated by loading the same binary twice. BSIZE is 4096 now, one request per SchFS block, and NBUF is 256 blocks (1 MB) rather than 90 KB -- smaller than the binary every command execs, so nothing was ever still resident. ideinit() issues SET MULTIPLE MODE, which is what makes a 4096-byte transfer legal: READ/WRITE MULTIPLE move the drive's multiple count per interrupt and nothing had ever set it, which is the real reason idestart() carried a sector_per_block > 7 panic. seq 1 200 2.02s -> 0.06s ls /bin 2.76s -> 0.68s ls /bin | wc -l 4.68s -> 0.73s And the harness. bootcheck called Find-Qemu from a param() default, which is bound before any function in the body exists -- so it died on its first line and printed an error containing neither "FAIL" nor "Exception", the two things being grepped for. It had not run since it was made host-portable. Worse, an earlier index-based edit had deleted the Expect blocks for -Tty, -Usb, -Sock, -Ps and -Evdev, so five of the seven modes asserted nothing at all. Restored, and the USB run gets its own 16 MB build/usbstick.img: it had been pointed at build/fs.img, which nothing builds since SchFS became root, so QEMU refused to start. 242 checks across seven modes, all passing, and make schfs-check green.
164 lines
6.9 KiB
PowerShell
164 lines
6.9 KiB
PowerShell
# Photograph the boot splash.
|
|
#
|
|
# The splash is on screen from the moment stage2 draws it until
|
|
# console_takeover() clears it at the first exec(), which is a window of a
|
|
# couple of seconds -- so a single screendump at a guessed delay is a coin
|
|
# flip. This takes a burst instead and keeps every frame, which makes the
|
|
# question "what does boot actually look like, second by second" answerable
|
|
# rather than a matter of catching it at the right instant.
|
|
#
|
|
# Same shape as tools/crashshot.ps1: monitor on TCP because QEMU on Windows has
|
|
# no unix sockets, serial to a logfile so the transcript survives.
|
|
#
|
|
# tools/splashshot.ps1 frames every 400ms for 8s
|
|
# tools/splashshot.ps1 -Every 200 -For 4
|
|
|
|
param(
|
|
[int]$Every = 400, # milliseconds between frames
|
|
[int]$For = 8, # seconds to keep capturing
|
|
[string]$OutDir = "build/shots",
|
|
[string]$Qemu
|
|
)
|
|
|
|
# QEMU, on whichever host this is.
|
|
#
|
|
# PowerShell 7 runs on Linux, macOS and the BSDs as well as Windows, so these
|
|
# scripts are usable from all of them -- but the old default was a hardcoded
|
|
# scoop path under $env:USERPROFILE, which exists on exactly one of those. PATH
|
|
# first, because a package-managed qemu is on it everywhere; the scoop location
|
|
# is only a fallback for the Windows install that does not add itself to PATH.
|
|
function Find-Qemu {
|
|
$exe = if ($IsWindows -or $env:OS -eq 'Windows_NT') { 'qemu-system-x86_64.exe' }
|
|
else { 'qemu-system-x86_64' }
|
|
$onPath = Get-Command $exe -ErrorAction SilentlyContinue
|
|
if ($onPath) { return $onPath.Source }
|
|
if ($env:USERPROFILE) {
|
|
$scoop = Join-Path (Join-Path $env:USERPROFILE 'scoop/apps/qemu/current') $exe
|
|
if (Test-Path $scoop) { return $scoop }
|
|
}
|
|
foreach ($p in @('/usr/bin', '/usr/local/bin', '/opt/homebrew/bin')) {
|
|
$c = Join-Path $p $exe
|
|
if (Test-Path $c) { return $c }
|
|
}
|
|
throw "qemu-system-x86_64 not found on PATH. Install QEMU, or pass -Qemu <path>."
|
|
}
|
|
|
|
if (-not $Qemu) { $Qemu = Find-Qemu }
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
# Repo root is two levels up: this script lives in tools/windows/.
|
|
$root = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
|
|
$log = Join-Path $root 'build/splashshot.log'
|
|
$dir = Join-Path $root $OutDir
|
|
|
|
Remove-Item -Recurse -Force $dir -ErrorAction SilentlyContinue
|
|
New-Item -ItemType Directory -Force $dir | Out-Null
|
|
Remove-Item -Force $log -ErrorAction SilentlyContinue
|
|
|
|
$hda = Join-Path $root 'schos.img'
|
|
# The root filesystem. SchFS is the only root there is: the kernel mounts
|
|
# device 1 in forkret() and panics if it is not a SchFS volume, so this is
|
|
# not a choice and there is no -SchFS switch any more. It used to default to
|
|
# build/fs.img, which stopped being bootable the moment SchFS became root.
|
|
$hdb = Join-Path $root 'build/schfs.img'
|
|
|
|
$monPort = 55556 # not crashshot's port, so the two can run back to back
|
|
|
|
$psi = New-Object System.Diagnostics.ProcessStartInfo
|
|
$psi.FileName = $Qemu
|
|
$psi.Arguments = @(
|
|
# -snapshot with file.locking=off, rather than booting from copies. QEMU
|
|
# takes an exclusive lock on its drive images, so an interactive session the
|
|
# developer already has open would otherwise make this fail with "Failed to
|
|
# get write lock" -- and a capture script is exactly the thing you want to
|
|
# run without first shutting down what you were looking at. Copying was the
|
|
# first fix and it meant duplicating build/fs.img, all 153 MB of it, on
|
|
# every run. -snapshot keeps writes in a temporary overlay, so the originals
|
|
# are untouched either way.
|
|
"-drive file=`"$hda`",format=raw,index=0,media=disk,file.locking=off"
|
|
"-drive file=`"$hdb`",format=raw,index=1,media=disk,file.locking=off"
|
|
'-snapshot'
|
|
'-m 1G -smp 1 -cpu qemu64,+rdtscp -machine pc-i440fx-9.2'
|
|
'-display none'
|
|
"-chardev stdio,id=c0,logfile=`"$log`""
|
|
'-serial chardev:c0'
|
|
"-monitor tcp:127.0.0.1:$monPort,server,nowait"
|
|
) -join ' '
|
|
$psi.RedirectStandardInput = $true
|
|
$psi.UseShellExecute = $false
|
|
|
|
Write-Host "==> booting" -ForegroundColor Cyan
|
|
$p = [System.Diagnostics.Process]::Start($psi)
|
|
|
|
$frames = @()
|
|
try {
|
|
# Connect immediately -- the interesting frames are the early ones, so any
|
|
# fixed warm-up sleep here is time spent missing them.
|
|
$client = $null
|
|
for ($i = 0; $i -lt 40 -and -not $client; $i++) {
|
|
try { $client = New-Object System.Net.Sockets.TcpClient('127.0.0.1', $monPort) }
|
|
catch { Start-Sleep -Milliseconds 100 }
|
|
}
|
|
if (-not $client) { throw "could not reach the QEMU monitor on port $monPort" }
|
|
|
|
$writer = New-Object System.IO.StreamWriter($client.GetStream())
|
|
$writer.AutoFlush = $true
|
|
|
|
$n = [int](($For * 1000) / $Every)
|
|
$sw = [System.Diagnostics.Stopwatch]::StartNew()
|
|
for ($i = 0; $i -lt $n; $i++) {
|
|
$ms = [int]$sw.ElapsedMilliseconds
|
|
$f = Join-Path $dir ("{0:d5}ms.ppm" -f $ms)
|
|
$writer.WriteLine("screendump $f")
|
|
$frames += $f
|
|
Start-Sleep -Milliseconds $Every
|
|
}
|
|
$writer.WriteLine('quit')
|
|
Start-Sleep -Milliseconds 500
|
|
$client.Close()
|
|
} finally {
|
|
if (-not $p.HasExited) { $p.Kill() }
|
|
Start-Sleep -Milliseconds 800
|
|
}
|
|
|
|
# Report each frame by its distinct-colour count. Two colours means a text
|
|
# console (or a blank screen); an anti-aliased logo pushes it into the dozens.
|
|
# The same reason the full-stack harness counted pixels rather than log lines: a capture
|
|
# that exists is not a capture that drew anything.
|
|
Write-Host "==> frames" -ForegroundColor Cyan
|
|
$kept = 0
|
|
foreach ($f in $frames) {
|
|
if (-not (Test-Path $f)) { continue }
|
|
$kept++
|
|
$b = [System.IO.File]::ReadAllBytes($f)
|
|
# PPM P6: "P6\n<w> <h>\n255\n" then raw RGB. Skip three whitespace-run
|
|
# separated header fields rather than assuming a fixed header length --
|
|
# QEMU's is compact but that is not guaranteed.
|
|
$pos = 2; $fields = 0
|
|
while ($fields -lt 3 -and $pos -lt $b.Length) {
|
|
while ($pos -lt $b.Length -and [char]$b[$pos] -match '\s') { $pos++ }
|
|
while ($pos -lt $b.Length -and [char]$b[$pos] -notmatch '\s') { $pos++ }
|
|
$fields++
|
|
}
|
|
$pos++
|
|
$seen = @{}
|
|
for ($i = $pos; $i + 2 -lt $b.Length; $i += 3 * 7) { # sample every 7th pixel
|
|
$seen[($b[$i] -shl 16) -bor ($b[$i+1] -shl 8) -bor $b[$i+2]] = 1
|
|
}
|
|
$name = Split-Path $f -Leaf
|
|
$c = $seen.Count
|
|
$tag = if ($c -ge 16) { 'graphical' } elseif ($c -le 3) { 'flat/text' } else { 'sparse' }
|
|
$col = if ($c -ge 16) { 'Green' } else { 'DarkGray' }
|
|
Write-Host (" {0,-12} {1,4} colours {2}" -f $name, $c, $tag) -ForegroundColor $col
|
|
}
|
|
|
|
if ($kept -eq 0) { Write-Host "FAIL: no frames captured" -ForegroundColor Red; exit 1 }
|
|
Write-Host "==> $kept frames in $dir" -ForegroundColor Green
|
|
|
|
# Convert to PNG if ImageMagick is around, so they can just be looked at.
|
|
if (Get-Command magick -ErrorAction SilentlyContinue) {
|
|
foreach ($f in $frames) {
|
|
if (Test-Path $f) { & magick $f ([System.IO.Path]::ChangeExtension($f, '.png')) }
|
|
}
|
|
Write-Host "==> PNGs alongside" -ForegroundColor Green
|
|
}
|