	Derivation of 9k
	Geoff Collyer
	Jun  8 14:39:06 PDT 2021
	edited Jul-Aug 2026

AMD64

Jim McKie created 9k for the amd64 k10 (initially k8) architecture, as
a cpu server kernel, primarily to explore high-performance computing
(HPC, or supercomputing) on larger (64-bit) systems.  It's more
careful about using varargs for system call arguments and about sizes
of integers generally; it uses uintptr a lot where 9 used ulong.  Jim
made some other changes (e.g., created the Sys struct, rewrote sysexec
and removed swapping).  He didn't bother with a lot of drivers for old
crufty hardware (e.g., 10Mb/s ethernet) and put no effort into
creating a terminal kernel, so omitted USB and VGA.  USB and VESA VGA
are easy to restore, but I haven't needed nor wanted them.

VGA is of course a can of worms: aside from the churn in video cards,
the 9/pc implementation requires using real mode and providing access
to hardware registers via #v, and once a cpu is in 64-bit long mode,
it's going to be quite painful to revert to real mode and back.  It
was bad enough reverting to 32-bit protected mode in order to
implement graceful reboot.  [Added in 2026: The real mode switch
wasn't as bad as I had feared, though someone else did the work.  How
this could work in an EFI-only world with no BIOS CSM isn't obvious.]

I picked up the Bell Labs /2014/0306/sys/src/9k in 2019, when I
upgraded my Xeon servers.  It could only support 600MB of ram, got
stray traps, had outdated drivers, and some (mainly pci-e) drivers for
modern devices had never been brought forward to 9k.  I fixed all of
that.  I didn't expect anyone else to run my copy of the system, so I
have done some refactoring (notably main and sysexec) and made other
changes to suit my taste.  I find long functions (over a page, say)
harder to follow, so have broken some up.  I moved a few
almost-portable files like syscall.c to port with only minor changes
to factor out the unportabilities.  With a bit of work to smooth over
9 vs.  9k differences, the important drivers (igbe, xgbe, ahci, nvme)
are identical in my 9/pc and 9k/k10, or very close to identical.  I
still run 9/pc on a couple of systems: a console server, and a cpu
server for ghostscript, mpm and bridge(3) for tinyemu.

RISC-V

The riscv64 rv port is derived from the amd64 port.  It's initially
for the RV64GC Polarfire Icicle.  There was an assumption that memory
started at physical address 0; I have removed that assumption.  I
generally link the system to load and start at 0x80200000, which seems
to also be the usual physical address of the start of usable ram for
RISC-V; it's strongly encouraged by machine mode having no paging.
The console is expected to be on the second uart (uart 1).

It expects to usually be started in supervisor mode in rv64 mode.  It
runs in tinyemu, starting in machine mode.  The rv port implements
39-bit, 48-bit and 57-bit virtual addresses, as available.  64-bit
addressing is implemented but not yet working right, at least in tinyemu.

I have enough documentation for the Synopsys PCI-E controller, so
PCI-E cards in the Hifive P550 work, notably Samsung 990 NVME SSD and
Intel 226 Gb Ethernet with modified drivers.  Graceful reboot works.
Commands seem to work correctly in general; ghostscript still
misbehaves sometimes.  I have built APE, though I can build awk (and
thus build a kernel) without it.
