A small 64-bit x86 (x86_64) operating system written from scratch in
freestanding C and NASM. GRUB boots it through Multiboot. It runs ELF programs from a
FAT16 disk in separate, protected address spaces, and it has a preemptive
scheduler, a shell, a text editor, and a mouse-driven desktop. GRUB sets
a 1024x768 framebuffer, and the console is drawn in it with an 8x16 font.
It is on the network too: an Intel e1000 driver, ARP, IPv4, ICMP,
UDP and TCP, an address from DHCP, a DNS resolver, an SNTP client to
set the clock and a TLS 1.3 client, so ping example.com works and fetch gets a page over HTTP or HTTPS,
with the server's certificate checked against Mozilla's list of roots.
It runs Barb, a coding agent: a model at the other end of fetch reads
and edits files and runs commands in Ringtail's own shell.
Current version: v0.28.0 "Time Will Tell". See PROGRESS.md for the history.
A boot in QEMU. The address, the clock and the ping reply come from a small
script that plays DHCP, DNS, NTP and a router for the test suite, so none of
it is the real internet; run hello is a program read off the FAT16 disk.
run gauge is a live system monitor: physical frames, heap and disk use as
bars, and every task with its state and memory, refreshed each second.
run octavo WELCOME.TXT opens the file that ships on the disk in Octavo, a
port of the Win32 editor of the same name, with find, replace, undo and
a status line.
run kenoma is the desktop: pleroma, the window server, with kenoma's
Programs window, an icon for each window program, document and text
program on the disk. Files browses the disk and Settings sets the clock
and the desktop's colours. Ctrl+Alt+Backspace, or Leave in the Ringtail
menu, goes back to the shell.
These pictures are taken from the real ISO by tools/screenshots.py, which
boots it in QEMU, drives it the way the test suite does and saves what the
screen shows. After a make, python3 tools/screenshots.py makes them again.
You need nasm, grub-mkrescue (with xorriso), qemu-system-x86_64,
python3 and a C compiler that targets x86_64. An x86_64-elf-gcc cross
compiler is used when one is installed; otherwise the host gcc of any
64-bit x86 Linux works as it is.
make # kernel, programs, disk image, bootable ISO, all in build/x86_64/
make run # boot it in QEMU; the serial console mirrors to this terminal
make run-serial # serial only, no window
make text-iso # build/x86_64/ringtail-text.iso: the same system in VGA text mode
make test # host unit tests, then the QEMU integration suite
make clean
ARCH picks the machine, and x86_64 is the only one. What differs between
machines lives in src/arch/$(ARCH) and builds into build/$(ARCH)/, so
a second port is a new folder there and a few lines in the Makefile.
(Ringtail was 32-bit i386 up to v0.28; the commit that dropped it says
what to revert to bring it back.)
The disk image (build/x86_64/disk.img) is ordinary FAT16. It holds the
programs in src/programs plus WELCOME.TXT, and files you write in the OS persist on it
across boots. Running make again rebuilds it from scratch, so copy it
somewhere else if you want to keep what you wrote. mdir -i build/x86_64/disk.img
and fsck.fat -n build/x86_64/disk.img both read it.
The display is a linear framebuffer from GRUB, 1024x768 at 32 bits a
pixel, which makes the console 128 columns by 48 rows; the boot banner's
Display: line says what it got. When GRUB cannot set a graphics mode
the kernel falls back to VGA text, 80 by 25, and native graphics to mode 13h,
320 by 200, which is too small for the desktop; kenoma says so and stops.
The text ISO forces that fallback (set gfxpayload=text in its grub.cfg),
and the test suite boots it too, so both paths stay working.
make test runs the host tests, then the QEMU suite.
tests/test_heap_diskfs.c builds the real kernel heap and filesystem
code as a 64-bit Linux program, on top of a RAM disk that can be told to
fail writes. It covers allocation and coalescing, double frees and bad
pointers, name rules and long names (aliases, ~N tails, case,
slots across sectors and clusters, bad checksums), sparse writes, truncation, full disks, root
directory exhaustion, an I/O error during a replace (the old contents
must survive), subdirectories (paths, growth past one cluster, rmdir
rules, remounts, the depth limit), a non-default cluster size and
malformed volumes. At the
end, fsck.fat checks the image the run left behind.
tests/test_netmsg.c builds the DHCP, DNS and SNTP message code, the parts
that read bytes off the wire, under AddressSanitizer and UBSan. It
checks the DHCP client's messages byte by byte and the parser on offers,
NAKs, bad options and bad domains, then the DNS name rules, query
encoding and answer parsing: CNAME chains, compression (pointer loops,
forward pointers, names over 255 bytes), truncation, rcodes, and bytes
that must be escaped before a terminal sees them. For SNTP it checks
the request (nothing in it but a random nonce) and every reason to
ignore or refuse a reply (the wrong mode or nonce, a kiss-o'-death, a
server that is not synchronised, missing timestamps), which era a
timestamp belongs to on either side of the 2036 wrap, and the offset
and round trip from the four timestamps; and the calendar code the
clock is set through, every day from 1970 to 2105 both ways. All three
parsers then eat several hundred thousand mutated messages.
tests/test_crypto.c checks SHA-256, HMAC, HKDF, ChaCha20, Poly1305,
the two together, AES-128, AES-128-GCM and X25519 against the worked examples in the
documents that define them and against Project Wycheproof's vectors,
which are built to catch the mistakes implementations actually make
(a carry dropped in the last limb, a forged tag accepted, a public
value that gives a key of zeros).
tests/test_tls.c runs the TLS client against 218 recorded
conversations. tests/gen_tls_cases.py makes them: it plays a server
written separately from the client, straight from RFC 8446, that can do
everything a server may do (send its flight in one record or a byte per
record, pad, ask for a retry with a cookie, ask for a certificate,
update keys, send tickets) and most of what it must not (wrong version,
suite, group or key share, extensions missing, doubled or uninvited,
messages out of order, damaged records, a wrong Finished, about 150 in
all), each with the outcome and the alert the RFC asks for written down
beforehand. It also records real handshakes with OpenSSL, through
Python's ssl module and through openssl s_server, key updates
included. The test replays each one and checks the result and every
byte the client sent; delivers it again a byte at a time and in odd
pieces; and, for some, cuts it off at every length and flips a bit in
every byte, none of which may be accepted. The generator checks its own
key schedule against the worked example in RFC 8448.
tests/test_sig.c checks the signatures: SHA-384 and SHA-512 against
OpenSSL's answers, then RSA PKCS#1 v1.5, RSA-PSS and ECDSA on P-256 and
P-384 against 3303 cases from Project Wycheproof and OpenSSL, and every
signature that must verify is checked again with a byte of it, or of
the message, changed.
tests/test_x509.c checks certificates and path validation against
C2SP's x509-limbo, which collects the ways other verifiers have been
fooled (every server case but those about revocation, and a sample of
the BetterTLS name-constraint cases), plus 228 cases of our own made by
tests/gen_x509_ours.py from keys it derives itself, each with the
exact error it must give: dates to the second, wildcards, names,
malformed DER at every level, keys too weak, CAs that are not, path
lengths, loops, and name constraints of each kind. Where we answer
otherwise than limbo on purpose (28 cases, mostly the Web PKI's rules
where they differ from RFC 5280), the generator says why. A mutation
sweep (every early return in x509.c disabled in turn) found the
cases that were missing. It also reads every root in disk/roots.pem.
tests/test_keymap.c checks the scancode translation that the keyboard
driver and the window server share (src/lib/keymap.c): Shift, Caps
Lock, Ctrl and Alt, the E0 keys and the keypad, and the fake Shifts
some keyboards send around them. tests/test_wm.c checks pleroma's
window manager (src/programs/lib/wm.c) on a 640x480 frame: where
windows go and how far they can be dragged, what is under each point,
how damage rectangles merge, that drawing one touches nothing outside
it, stacking and shadows, the bar's buttons, the menu and the desktop's
colours. tests/test_tk.c checks the toolkit (src/programs/lib/tk.c)
by feeding it window events and reading its pixels: buttons, check
boxes, focus and Tab, text fields, lists as rows and as icons with
their scroll bars, double clicks and the keys that move through them,
the menu bar by mouse and by keyboard, dialogs, and that it redraws
only what changed. A mutation sweep checked that all three notice when
the code they cover is broken.
tests/qemu_test.py boots the real ISO in QEMU, on a machine with two
CPUs, and drives the shell over a serial socket. It uses build/x86_64/test-disk.img, which adds the test
programs in tests/programs to the normal disk. It checks the boot
banner and runs every program, including the ones that are supposed to
crash. It covers bad pointers handed to syscalls, every register
after a syscall and an int 0x80 (with NMIs arriving meanwhile, from
the QEMU monitor), stack growth and
overflow, malloc, signals (sigtest: handlers, masks, nesting, faults caught
and not, and every register around an asynchronous one), Ctrl+C on foreground jobs, background jobs, raw
terminal mode, ANSI output (read back from the console's character grid through
the QEMU monitor), an editing session in Octavo, file and directory commands,
the timer rate (against the host's clock), the network card's
interrupts,
the switch into graphics mode and back (on the framebuffer and,
from the text ISO, in VGA text mode and mode 13h), the window system
(pleroma with a test client that prints every event it gets: the
pointer, buttons and keys reaching the right window, a drag, the menu,
Clock and Paint, closing, and ending a client that will not close,
all read back from screenshots), the desktop from kenoma (a text program,
found by typing its name, in a terminal window that waits once it is done, a document in
Octavo), Files making, renaming and deleting folders from the
keyboard, and Settings changing the desktop's colours and pleroma
keeping them for its next start, shared memory and channels (shmtest,
chantest), reboot persistence and poweroff,
and the network through QEMU's user network: DHCP at boot, ping,
loopback, UDP and TCP sockets (udptest, tcptest), the random number
generator (rndtest), fetch and nc
against an HTTP server and an echo server on the host (posting too:
fetch -d and -H against a server that echoes what it got), barb
against a scripted API on the host (the tools on the real disk and shell,
a background task that wakes it, a command past its time limit and a
task it stops, both killed with everything they started, and a session
at the terminal with a one-key answer, Ctrl-C and Ctrl-D), fetch over TLS
against OpenSSL on the host with certificates the test makes (a
certificate from no trusted root refused by default, accepted with
--ca; an RSA-PSS server; a wrong name and an expired certificate
refused; -k; pages, redirects between http and https, chunked bodies,
a server that only speaks TLS 1.2, one that is not TLS at all, one that
hangs up; skipped when openssl or Python's cryptography is not
installed),
net static and
net dhcp, and host against tests/dns_server.py, a DNS server on the host whose
names each misbehave in their own way (aliases, loops, SERVFAIL, silence,
forged answers, truncation, a compression loop, escape codes in names),
and sntp against tests/ntp_server.py, a time server that answers
in whatever manner the test asks (an hour off, forged, kisses of death
with escape codes in them, unsynchronised, silent, late, slow, from
2001 or 2101): the clock is set an hour on and back, to within a tenth
of a second, and is left alone when it should be; sntp -b answers in
its one line, once, quickly; the kernel refuses
dates that do not exist and times before the build, and runs a leap
day into March. The boot's own sync asks pool.ntp.org, since QEMU's
DHCP names no time server, and passes however that ends. Afterwards it runs fsck.fat and mtools against the disk. Then it boots
again on a socket network whose only other host is tests/net_peer.py,
which puts raw Ethernet frames on the wire and plays the network's DHCP,
DNS and time server: the guest must set its clock at boot from the time
server DHCP names, without looking anything up. It checks the DHCP messages field by field and a lease's
whole life (renewing, rebinding, running out, NAKs, lying servers, an
address set by hand), ARP and pings of every size and shape, packets
that must be ignored (bad checksums, fragments, other addresses,
broadcasts, short headers), UDP echoed by a guest program and port
unreachable for closed ports, the search domain and a second DNS server,
the guest's own pings answered, timed out, refused by a router or
damaged, and 4000 frames of garbage. Short boots check the other two
e1000 models and a machine with no card, a slow disk and a failing one
(QEMU's I/O throttling and its blkdebug driver), machines with 2 GB
and 6 GB of RAM, and machines whose interrupts come another way: no ACPI
tables, no local APIC, four CPUs (three programs that never yield run
at once, next to the shell, and are killed where they run), and the
q35 chipset with two. Pass --keep to keep the serial log and the disk.
Memory: the CPU runs in long mode with 4-level page tables. The kernel
lives in the top half of every address space, supervisor only: its image
at -2 GB, where it is linked, with its code and read-only data
write-protected and nothing but its code executable, and all of RAM
mapped at 0xFFFF800000000000, never executable, which is how it reaches
page tables, frames and its heap. SMEP stops it from running a program's
pages. The lower half is the program's. It gets the range from 1 GB to
3 GB, and nothing it can write is executable; below 1 GB nothing is
mapped, so a null pointer faults in the kernel too. A program's image is mapped from the ELF segments
with their real permissions. The stack sits at the top and grows on
demand up to 1 MB, with an unmapped guard gap below it. The kernel heap
and the physical frame pool are sized from the Multiboot memory map, and
all of RAM is used, above 4 GB too (up to 512 GB). Frames are handed out
from the top of RAM down, and a frame is first written when it is handed
out, so a 6 GB machine boots as fast as a 64 MB one. A program's heap is the break above its image, moved with
sbrk; the C runtime has malloc, calloc, realloc and free on top.
Interrupts: ACPI's MADT, found through the RSDP in the BIOS area, says
where the local and I/O APICs are and how the ISA interrupts are wired
to them. The kernel then masks the two 8259s for good, routes each
interrupt a driver asks for to the I/O APIC input the MADT names (with
its polarity and trigger mode, or, for a PCI card on an ISA IRQ, level
and active low when the chipset's ELCR says so), and takes its tick from
the local APIC's timer, measured against the PIT at boot (QEMU's comes
out at 1000 MHz). Without an MADT or a local APIC it stays on the 8259s
and the PIT. The banner says which. There is no AML interpreter, so PCI interrupt
routing (_PRT) is not read: a PCI card's interrupt is taken from its
line register, which is right on QEMU but not on every real board.
CPUs: the boot CPU starts the others the MADT lists, one at a time,
with an INIT and two startup IPIs. Each begins in real mode in a
trampoline copied below 1 MB, which takes it to 64-bit mode on page
tables made for it; it then loads its own GDT, TSS and interrupt
stacks, the shared IDT, the kernel's page tables, and sets up its FPU
and local APIC, and becomes the idle task of its own. Tasks then run on
every CPU, but the kernel on one at a time: a CPU takes one big lock
on its way into the kernel and lets it go on its way back to ring 3 or
into its idle halt, so the kernel's critical sections, written for one
CPU, still exclude everything. Each CPU takes its own local APIC
timer tick, which needs the lock only to switch tasks, and a CPU that
leaves a task ready while another sits idle wakes that one with an
IPI. Device interrupts all go to the boot CPU. With the APICs, time is
counted on the TSC, measured against the PIT at boot, so that no one
CPU's ticks have to be the clock; SMP needs it. The banner says how
many CPUs started, and cpus in the shell shows each one's tick and
switch counts and what it is running.
Tasks: a round-robin, preemptive scheduler runs on the 100 Hz tick. The
kernel's own tasks (idle, init) and user programs are scheduled the same
way. init gives DHCP its chance, runs sntp -b once if the network is
up, then starts SAKLAS from the disk, hands it the terminal, and starts a
fresh one whenever it ends. A program that faults gets a signal for it
(SIGSEGV, SIGFPE, SIGILL, SIGBUS or SIGTRAP); unless it catches that, it
ends and the fault is logged (faults in the shell). The tty belongs to one
foreground job, which receives keyboard input, Ctrl+C and Ctrl+. A job
can lend the terminal to a job it started and take it back once that job
is gone, getting its own terminal mode back with it; that is how the
shell runs a program in the foreground. It lends it as part of the spawn
(SPAWN_FOREGROUND), so the program has the terminal before its first
instruction rather than racing its parent for it.
Terminal: programs read the keyboard (or the serial port) through
standard input, a line at a time by default. Raw mode hands over every
key as it comes, with arrows, Home/End, PgUp/PgDn, Delete and F1-F12 as
xterm escape sequences and Alt as an ESC prefix; with TTY_NOSIG, Ctrl+C
is an ordinary byte. Ctrl+\ sends SIGQUIT in any mode, and a third press
within two seconds sends SIGKILL, so it works even on a program that
catches SIGQUIT. poll
waits up to a given number of ticks for input, so a program can redraw on a
timer and still answer a key at once. The console understands the common ANSI escapes for cursor
motion, erasing, colours and hiding the cursor, on screen and on serial
alike. On a framebuffer the screen is redrawn by a kernel task,
console, from a grid of characters and colours, so a burst of output
costs one redraw of the cells that changed rather than one per byte.
tty_size tells a program how many columns and rows it has, and
Octavo, more and gauge use the whole screen. Opening /dev/tty (DEV_TTY) gives the terminal itself, read-only for
keys or write-only for output, whatever standard input and output are
redirected to; that is how more can wait for a key at the end of a pipe.
Signals: 15 of them, numbered as on Linux (SIGINT 2, SIGKILL 9, SIGTERM 15
and so on), sent with kill, by the terminal, by a pipe with no reader
or by a fault. The system call takes a negative id for a whole job, as
kill(-pgid) does on Unix, which stops a command together with whatever
it started (the shell's kill still takes one task). Each one's default ends the program, whose exit status then
says which signal it was. sigaction sets a handler or ignores one
(SIGKILL can be neither), with a mask of signals to hold off while the
handler runs and the flags SA_RESETHAND and SA_NODEFER; sigmask blocks
and unblocks. A signal is acted on as the task goes back to user mode, so
never in the middle of a kernel operation. A handler runs on the
program's own stack, below the red zone, with every register and the
FPU and SSE state saved in a frame there; returning from it makes the
sigreturn call, which puts them back, taking from the frame only what a
program could have set for itself. A wait (sleep, a read from the
keyboard or a pipe, a socket) ends with EINTR when a signal arrives that
is not blocked. Programs start with every signal at its default, whatever
their parent did. At the prompt the shell ignores SIGQUIT and SIGPIPE and
catches SIGINT, which stops a loop it is running itself.
System calls: the syscall instruction, with the number in rax,
arguments in rdi, rsi and rdx (where a C call puts them), and the result
in rax. The CPU uses rcx and r11 for the return address and the flags;
every other register comes back as it was. int 0x80 takes the same
calls and keeps rcx and r11 too; it is about three times slower under
QEMU's emulation (sysregs time measures both). Both build the same frame in the kernel, and a return takes
sysret only when the address is a canonical user one (on Intel a
sysret to any other faults in ring 0, on the user's stack). NMIs,
double faults and machine checks have stacks of their own, since they
can arrive in the few instructions where the entry still runs on the
user's stack; an NMI is counted and logged, not fatal. A failed call returns a negative errno.
Every user pointer is checked against the caller's page tables before the
kernel touches it. The numbers and structures are in
src/include/ringtail/abi.h, and the user-side wrappers are in
src/programs/lib/ulib.h. A spawned program inherits copies of its
parent's standard input, output and error (descriptors 0-2), and spawn
can remap them, hand over one more as descriptor 3, or put the program in
a new or existing job. The shell is
an ordinary program: everything it shows comes through syscalls such as
readdir, kinfo (version, memory, heap, tasks, faults, memory map,
disk) and kill. Pipes are 4 KB kernel buffers: a reader waits for data
and sees end of file once every writer has closed, and a writer waits
for room. A write with no reader left fails with EPIPE and sends the
writer SIGPIPE. dup2 copies a descriptor onto another number. A copy, by
dup2 or handed to a spawned program, is the same open file as the
original, as in POSIX: they share one offset, so a program and its
parent writing to the same redirected file each write after the other,
and the file stays open until the last copy is closed.
Shared memory and channels: shm_new makes zeroed memory (up to 16 MB)
and maps it, and any task that knows its id can map the same frames
with shm_map; the memory lasts until the last task lets go or exits.
Channels are two-way message pipes found by name: a server
chan_listens on a name and accepts, a client chan_connects, and
each write of up to 256 bytes arrives as one message. Both ends work
with pollfd, read, write and close like any descriptor, and a
display owner can wait on its keys and mouse in the same pollfd
(POLLFD_INPUT).
Windows: pleroma is the window server, an ordinary program that owns
the display. A client makes shared memory for its pixels, connects to
the channel pleroma, asks for a window and then draws whenever it
likes, telling the server which rectangle changed; the server copies
from the client's memory when it draws that part of the screen, and
sends the client its pointer, button, key, focus and close events. A
client can also set the desktop's two colours, which pleroma reads from
DESKTOP.CFG when it starts (Settings writes both). The
protocol is src/programs/lib/wsys.h, and win.c wraps it (open,
draw, say what changed, read events). The server never waits on a
client: when a client's queue is full, its events are dropped. Only the
parts of the screen that changed are drawn and copied out. A client
asked to close that has not gone two seconds later is ended with
SIGKILL when the close button is pressed again, if pleroma started it.
The display's owner may start programs (that is how pleroma starts
its clients), and their output goes to the serial port and to the
console behind the desktop. While pleroma runs, Ctrl+C and Ctrl+\ are
keys for the focused window rather than signals for the desktop; three
Ctrl+\ in two seconds still end it.
The toolkit (src/programs/lib/tk.h) draws into a window's pixels and
turns window events into its own: labels, buttons, check boxes, one-line
text fields, lists shown as rows or as icons (with a scroll bar, double
clicks, and keys to move; letters typed in quick succession go to the
name they begin, and one letter again and again steps through the names
that start with it), a menu bar the mouse or
F10 opens, and dialogs that ask a question, with a field if wanted. It
makes no system calls, so the host tests drive it directly. kenoma,
Files and Settings are built on it; desk.c holds what they share,
like which programs make their own windows and how to start the rest.
Terminals: each terminal is a tty object with its own line editing,
foreground job and mode, and each task has a controlling terminal, the
one its standard input was when it started (the console otherwise).
pty_open makes a pseudo-terminal: a master descriptor, which reads
what programs write and whose writes are typed keys, and a slave that
programs use as their terminal. A program started on the slave with
SPAWN_FOREGROUND takes it if no live job has it. When every slave is
closed the master reads end of file; when the master closes, the
programs on it get SIGHUP, their reads return end of file and their
writes EIO. sys_print, colours and /dev/tty follow the controlling
terminal. wterm, the Terminal in pleroma's menu, runs saklas on a pty
and draws it in a window with the console's own emulator (src/lib/vt.c)
and font.
Filesystem: FAT16 with subdirectories and Windows-style long names
(VFAT). A name is up to 255 printable ASCII characters, none of
\ / : * ? " < > |, not starting with a space or ending in a space or
dot. Case is kept as typed and ignored when matching, so cat readme.TXT
finds ReadMe.txt. A name that fits 8.3 in one case per part is stored
as a plain short entry (lowercase via the NT case bits, like Windows);
any other gets long-name slots and a short alias such as MYDOCU~1,
which also works as its name. Disks written by Windows, Linux or mtools
read the same way. Paths use /, start at the task's current directory
unless they begin with /, and know . and ..; a directory's full
path is at most 255 characters. Each task has
its own current directory, inherited by the programs it starts. The FAT
and the root directory are kept in memory, subdirectory sectors go
through a small cache, and all of it is written back after each
operation, FAT first. Files and directories are stamped with the CMOS clock when they are made and
when their contents change (ls shows it, date prints the clock; a rename
keeps it). A new directory's cluster is zeroed on disk before
anything points at it.
File data is always written before the metadata that points at it.
Replacing a file builds the new contents in fresh clusters before
switching the directory entry, so a failure leaves the old file intact;
programs get that through the save syscall.
The disk itself is driven by polled PIO. Every wait has a 30-second
limit in real time, and a command that fails or times out is followed
by a reset of the channel and tried again, up to three times. A drive
that stays busy through all three is taken as gone: the disk returns
errors at once instead of making each operation wait again, and every
10 seconds the next command resets the drive and gives it a second to
show it is back. A drive that answers with an error, such as a bad
sector, stays in use.
Rename moves the entry (and a directory's ..), so an open file stays
open through it, and a directory cannot be moved inside itself. An open
file cannot be deleted, and a directory that is some task's
current directory cannot be removed.
Network: PCI devices are found by scanning configuration space at boot
(pci lists them). The e1000 driver maps the card's registers into a
4 MB device window at 0xC0000000, above user space and in every address
space but supervisor only, and runs a 32-buffer receive ring and an
8-buffer transmit ring. Its interrupt only wakes the net kernel task,
which takes frames off the ring and handles them under one lock, so the
stack never runs in interrupt context. ARP learns neighbours from requests aimed at us and asks three times, a
second apart, before giving up; IPv4 checks lengths and checksums and
drops fragments; ICMP answers echo requests (not broadcast ones) and
matches replies and routers' unreachable messages to the ping syscall
waiting for them. Round trips are timed in microseconds from the tick's
counter (the local APIC timer's, or the PIT's). Anything sent to 127/8 or the machine's own address goes round
through the net task without touching the card.
UDP sockets are file descriptors (socket, bind, sendto,
recvfrom; read and write refuse them). Binding port 0 picks a
random free port from 49152 up, port 68 is the DHCP client's, each
socket queues 16 datagrams and drops the rest, and a datagram for a
closed port gets ICMP port unreachable unless it was a broadcast. The
DHCP client (RFC 2131) runs in the net task: DISCOVER at boot, renewing
at T1 straight to the server, rebinding at T2 by broadcast, starting over
when the lease runs out or on a NAK, which it answers more slowly each
time. It asks for, and keeps, the time servers (option 42) as well as
the DNS ones. init gives it five seconds before starting the shell. net static
turns it off and sets the address by hand; net dhcp starts it again,
asking for the address DHCP gave last. The DNS resolver is user code
(src/programs/lib/dns.c over dnsmsg.c), linked into the programs
that look names up: it asks each server DHCP named in turn, twice, 2 s
each, from a random port with a random ID, believes an answer only from
that server's address and port with that ID and the same question,
follows up to 8 aliases, and tries a name with no dot under the search
domain first. Names that come back are escaped before they are printed.
TCP is split in two. src/net/tcp.c is the protocol engine and knows
nothing of the kernel: RFC 9293 with the MSS option (no window scaling,
timestamps or SACK), RFC 6298 retransmission timing, slow start and
congestion avoidance with NewReno fast recovery, zero-window probes,
delayed ACKs, out-of-order segments held until the gap fills, and the
RFC 5961 checks against blind resets and SYNs. Each connection buffers
16 KB each way; there are 64 at most, counting those still closing.
tests/test_tcp.c runs the engine on the host against a simulated
network that loses, reorders and duplicates segments.
src/net/tcpsock.c puts it in the kernel: the calls behind connect,
listen, accept, shutdown and the rest, all under the net lock,
with tasks sleeping on the connection and the wakeups sent once the
engine is done. TCP sockets read and write like files, and pollfd
waits on any mix of sockets, pipes and the terminal.
Random numbers come from the kernel (src/kernel/random.c, the random
syscall). Every interrupt stirs the CPU's cycle counter into a pool,
and RDRAND goes in where the CPU has it; each request hashes the pool
into a fresh ChaCha20 key, and the key is replaced before the answer is
handed out, so one answer says nothing of the next or the last. TCP
sequence numbers, ports, and DNS and DHCP ids come from it, and so do
TLS keys. Its weak moment is straight after boot on a CPU without
RDRAND, when there has been little to collect.
The clock is the CMOS chip's (src/drivers/rtc.c), read on every
time call. settime sets it to the second, holding the chip's
divider in reset while it writes, so that its next second starts half
a second after the call; a caller that wants it exact calls at the
half second. The kernel refuses a time before the last commit it was
built from (RINGTAIL_TIME_FLOOR, which the Makefile writes to
build/$(ARCH)/gen/timefloor.h), since a clock set before the code existed is
wrong, and since an expired certificate looks good again to a clock
wound back to when it was. sntp (src/programs/net/sntp.c over
lib/ntpmsg.c) is the client, RFC 4330 SNTP: it sends a version 4
request whose only content is a random transmit timestamp, believes
a reply only from the address and port it asked, in server mode,
echoing that timestamp, and refuses one from a server that is not
synchronised or sends a kiss-o'-death. Each try gets a fresh nonce,
two tries of 2 s per address and four addresses at most. Its own
clock for the exchange is the CMOS second it waits to turn over plus
timer ticks since, so the offset is good to about 10 ms. A wire
timestamp is placed in the 136-year era nearest the machine's own
clock, so the 2036 wrap is handled and a clock reset to 2000 still
finds 2026. Without a server named, sntp asks the time servers DHCP
gave (net lists them as Time), or pool.ntp.org if there are none.
init runs sntp -b at boot, once the network has an address: one try
of a second at no more than two addresses, then one line, "Clock:",
saying what it set, or that it left the CMOS time and why, before the
shell starts.
TLS is user code (src/programs/lib/tls.c), a TLS 1.3 client
(RFC 8446) over any stream of bytes: it makes no system calls and
reaches the socket and the random numbers through three functions the
caller gives, which is how the host tests run the same code. It offers
two cipher suites, ChaCha20-Poly1305 first and AES-128-GCM (the one
every server must take), both with SHA-256, and one key exchange,
X25519. None of them looks anything up by a secret or branches on one,
so the time they take gives nothing away; for AES, whose usual form is
a table lookup, that means a bitsliced S-box, a circuit of 113 ANDs and
XORs run on two blocks at once (src/programs/lib/aesgcm.c). It is
about ten times slower than ChaCha20 here, which is why ChaCha20 is
asked for first. It sends the server name, answers a HelloRetryRequest
that brings a cookie, turns down a request for a client certificate,
follows key updates, ignores session tickets, and keeps to the record
limits; a server that breaks a rule gets the alert the RFC names and
the connection is over.
The certificate is checked by a verifier the caller hands to the TLS
code, so tls.c itself knows nothing of X.509. The one fetch uses is in
src/programs/lib/x509.c: it reads the certificates (strict DER, version
3 only, an unknown critical extension refused), searches for a path from
the server's certificate through any it sent to a trusted root, and
checks every signature on it, the dates of each certificate against the
clock, that each CA is one (basicConstraints), its path length, key
usage and extended key usage, and name constraints on DNS names, IP
addresses and directory names. The name is matched against the
subjectAltName only, never the common name, with a wildcard standing
for exactly one leftmost label. Then the server's own signature over
the handshake is checked with the key in its certificate. The
signatures are src/programs/lib/sig.c: RSA (PKCS#1 v1.5 and PSS, 2048
to 4096 bits) and ECDSA on P-256 and P-384, over a small Montgomery
big-number library; SHA-1 and RSA keys under 2048 bits are refused. The
roots are Mozilla's, as the ca-certificates package ships them, in
/roots.pem on the disk (tools/mkroots.py makes disk/roots.pem).
src/arch what differs between machines, one folder each (x86_64): the multiboot
entry, linker script, GDT and TSS, IDT gates and interrupt entry, task switch,
page tables, starting the other CPUs (smp.c, trampoline.asm), the saved
register frame and FPU state (include/arch/)
src/kernel kernel_main, interrupts, tasks, syscalls, ELF loader, faults, power, random numbers
src/mm heap, physical frames, shared memory and checked user copies
src/drivers console (framebuffer, VGA text, serial), the 8x16 font, tty, keyboard, mouse, timer, ATA,
graphics (gfx.c), PCI, e1000,
ACPI tables and the APICs
src/net ARP, IPv4, ICMP and loopback (net.c), UDP sockets (udp.c), TCP (tcp.c, tcpsock.c), the DHCP client (dhcp.c, dhcpmsg.c)
src/fs FAT16 (diskfs.c), file descriptors (file.c) and channels (chan.c)
src/lib string and printf subset, SHA-256, ChaCha20, calendar dates and the terminal emulator (vt.c), shared by the kernel and programs
src/include kernel headers; ringtail/abi.h is the user/kernel contract
src/programs user programs in folders, their C library (lib/: runtime, malloc, DNS, SNTP, TLS, windows) and linker script
apps the big interactive programs: saklas (the shell), octavo, gauge,
pleroma (the window server) and its clients kenoma, wfiles, wprefs,
wclock, wpaint and wterm
files files and directories as things: ls, cp, mv, rm, mkdir, rmdir, touch, find, du, df, basename, dirname
text what is inside files and pipes: cat, grep, sed, sort, diff, od and the rest of the filters
net talks to the network: ping, host, nc, fetch, httpd, sntp
util small tools for building command lines: echo, seq, factor, sleep, xargs, cal, hello and the like
vendor/barb Barb, the coding agent: its portable core and its Ringtail platform, copied from the barb repository
tools mkdisk.py, the FAT16 image builder; screenshots.py, which takes the pictures above;
mkfont.py, which makes the console font from unscii-16
docs ARCHITECTURE.md, a map of the parts and how they fit together; the screenshots
tests host unit tests, the QEMU integration suite, test programs
Type help at the ringtail:/> prompt (it shows the current directory) for the command list. The editor
keeps the last 10 lines (Up and Down). Left, Right, Home, End, Delete and
Backspace work anywhere in the line, Ctrl+Left/Right (or Alt+B/F) jump a
word, and Ctrl+A/E/B/F do what Home/End/Left/Right do. Ctrl+W deletes the word before the cursor, Ctrl+K the rest of
the line and Ctrl+U the whole line. Ctrl+C cancels a line or kills the
foreground program, and Ctrl+L clears the screen. Tab (which works on the end of the line) completes commands,
programs and paths, ignoring case and quoting names with spaces; a second
Tab with several matches lists them.
A program's name, or run <program> [args...] (which skips a built-in or
function of the same name), starts a program from the disk, and a
trailing & runs it in the background. The shell reads POSIX shell:
a | b pipes, a; b, a && b and a || b chain, and < FILE,
> FILE, >> FILE, 2> FILE, 2>&1, <> FILE and here-documents
(<<EOF, <<-EOF, <<'EOF') redirect, built-ins included. It has
variables and parameters ($1, $#, $@, $?, $$, $!,
${x:-default} and the other ${...} forms, ${#x}, ${x%.txt}),
$(command) and backquotes, arithmetic ($((n * 2 + 1))), field
splitting on IFS, quoting with '...', "..." and \, and if,
while, until, for, case, functions (f() { ...; }, with local
and return), ( subshells ) and { groups; }. Its own commands are the
usual ones: cd (cd - goes back), pwd, echo, printf, test and
[, read, set (-e, -u, -x, -f), shift, export,
unset, eval, ., exec, exit, wait, break, continue,
true, false and :. A command can go on over several lines: the
prompt turns into > until it is whole, and Ctrl+C there drops it. A
command line that fails shows [exit status N].
sh FILE [args...] (or saklas FILE) runs a script, as does ./FILE for
a file that is not a program; sh -c 'TEXT' [name args...] runs TEXT,
and sh reads commands from standard input when that is not the
terminal (cat x.sh | sh). There is no fork, so whatever must run apart
from the shell (a subshell, $(...) that is not a plain program, a loop
in a pipeline, something in the background) runs in a new copy of the
shell that gets the variables, functions and parameters over descriptor
3; a program in a pipeline or in the background runs as itself, so
tasks and kill see it. The language lives in
src/programs/lib/shcore.c, apart from the console, so the host test
(tests/test_sh.c) can check it against bash --posix on some 500 scripts.
Ctrl+C stops every program in a pipeline. tasks lists what is running and
kill <id> sends it SIGTERM (kill -9 <id>, kill -KILL <id>, or any
signal by name or number; kill -l lists them); cpus shows which CPU runs what. The file commands (ls, cat, echo, touch, rm,
mkdir, rmdir, mv, cp) are programs on the disk like any other, so they
pipe, take <, and run under find -exec (echo, printf, true and
false are on the disk too, and the shell has its own of each; run echo
picks the program); cat a b > c joins files, rm -r, cp -r, mkdir -p and ls -R work on
trees, and quote text for echo to keep its spacing. An unquoted word with *, ? or [a-z] / [!x] in it is a wildcard: it is replaced by the matching names, sorted and ignoring case, one directory level per / (ls *.txt, cat d/*.c, */readme); names starting with a dot match only a pattern that starts with a dot, a pattern that matches nothing stays as typed, and quoting a word turns the wildcards off. write <file> <text> writes its words as one line into a file. Every file argument can be a path (docs/a.txt, "My Docs/notes.txt",
../B.TXT, /WELCOME.TXT). A bare program name is always looked up in
/, wherever you are; give a path to run one from somewhere else. mem, heap and mmap show memory, date the clock, uptime the
time since boot and timer ticks, and faults the fault log. pci lists the PCI devices, and net shows
the network card, the address and where it came from, the DNS servers,
traffic counts, UDP sockets and the ARP table. net static 10.0.2.20/24 10.0.2.2 10.0.2.3 sets the address, gateway (or none) and
DNS server by hand, and net dhcp goes back to DHCP. color <name> sets
the text colour, and reboot and poweroff do what they say. exit [N]
ends the shell, and init starts a new one. help NAME says what one
command does.
Programs on the disk:
| Program | What it does |
|---|---|
| octavo | Text editor. run octavo [file]. |
| pleroma | The window system: a desktop with a bar (a menu, a button for each window, a clock) and windows that can be dragged by their title bars and closed. run pleroma [PROGRAM...] starts it with those programs in windows, or with kenoma. Its menu (the Ringtail button, or a right click on the desktop) starts Programs, Files, Terminal, Clock, Paint and Settings, or leaves; so does Ctrl+Alt+Backspace. |
| wclock | An analog clock in a window, for pleroma. |
| wpaint | Painting in a window, for pleroma: drag with the left button to draw, the right to erase; pick a colour from the strip or with 1 to 8, and c or Clear clears. |
| wterm | A terminal in a window, for pleroma: 80 by 24, running saklas, or the program it is given (wterm gauge, typed in another terminal). It closes when the program ends, or with -h waits for a key first; closing it hangs the program up. |
| kenoma | The desktop's launcher: run kenoma starts pleroma if it is not running, with a Programs window holding an icon for each window program, each .txt, .lemur and .lem file in the root (opened in Octavo) and each text program (run in a terminal window). Double-click or Enter opens; typing the start of a name goes to it; View shows icons or rows. Needs a 640x480 screen. |
| wfiles | Files, a file browser for pleroma: one directory, folders first, with sizes and dates. Opens folders, programs and documents; makes, renames and deletes through dialogs (F2 renames, Delete deletes, Backspace goes up). wfiles [DIR]. |
| wprefs | Settings, for pleroma: sets the date and time or asks a time server, picks the desktop's colours (kept for next time), and shows the network's address, gateway, DNS and lease. |
| saklas | The command line (the shell). init starts it at boot and again whenever it ends. It is on the disk a second time as sh, the name scripts use. |
| gauge | System monitor: memory, disk and every task, redrawn each second. q quits, p pauses, + and - change the rate. gauge -1 prints one plain snapshot, so it pipes. |
| ping | ping [-c COUNT] [-s SIZE] [-W MS] HOST: ICMP echo, a second apart, with round trips and a summary. HOST is an address or a name. |
| host | host [-p PORT] NAME [SERVER]: asks DNS about a name, or about an address for its name, and prints the answer the way BIND's host does. |
| sntp | sntp [-q] [-b] [-p PORT] [SERVER]: asks a time server (default: the ones DHCP named, else pool.ntp.org) how far off the clock is and sets it, unless it is right to within half a second; -q only asks, -b is quick and says it all in one line, as at boot. Refuses a time before the system was built. |
| fetch | fetch [-i] [-e] [-k] [--ca FILE] [-o FILE] [-d FILE] [-H FILE] [-t SECS] URL: gets a page over HTTP/1.1, or over HTTPS when the URL starts with https://, following up to five redirects. -i shows the headers, -o saves the body, -e shows the body of an error response too. -d FILE posts FILE's contents (a 307 or 308 posts them again to the new place; 301 to 303 become a GET), -H FILE adds its "Name: value" lines as headers (-H - reads them from standard input, which keeps a secret out of the task table; a redirect to another host, another port or from https to http is refused rather than followed with them, and so is one that would post the body again), and -t gives up on a server quiet for SECS seconds instead of 30. HTTPS checks the server's certificate against the roots in /roots.pem, or against the certificates in FILE with --ca; -k skips the check and says so each time. |
| barb | barb [-p TASK] [-y] [-m MODEL] [-C DIR]: Barb, a coding agent. Type a task and a model (through the Anthropic Messages API, or anything that speaks it) reads and edits files and runs commands with sh, asking first (one key: y, n, or a for always). A slow command goes to the background and barb sleeps until it ends, making no model calls meanwhile. The key and the address go in /barb.cfg (key = ..., url = ..., model = ...), since programs have no environment. -p TASK does one task and exits; -p - reads a task longer than the shell's line from standard input. It reads AGENTS.md from the directory it works in. See vendor/barb. |
| httpd | httpd [-p PORT] [-q] [DIR]: serves DIR (default: the current directory) over HTTP on port 8080, one connection at a time. A directory gives its index.html or a listing; .. is refused. Logs each request unless -q. Ctrl+C stops it. |
| nc | nc [-C] [-v] [-w SECS] HOST PORT or nc -l PORT: a TCP connection between the terminal (or stdin) and the other end. -C sends CR LF line ends. |
| sleep | sleep <seconds>, up to an hour. |
| ls | ls [-R] [PATH...]: lists files and directories with sizes and dates; a file is listed as itself, -R goes down. A free-space line on the terminal. |
| cat | cat [-n] [FILE...]: copies files, or its input (also -), to the output; -n numbers the lines. Bytes pass through exactly. |
| echo | echo [-n] [-e | -E] [TEXT...]: prints its arguments, one space apart; -e reads \n \t \xHH and friends. |
| touch | touch [-c] FILE...: creates empty files; one that exists is left alone (it keeps its old date; there is no call to set one). |
| rm | rm [-f] [-r] FILE...: deletes files; -r takes whole directories, -f ignores missing ones. ., .. and / are never removed. |
| mkdir | mkdir [-p] DIR...: makes directories; -p makes the parents too and accepts one that exists. |
| rmdir | rmdir DIR...: removes empty directories. |
| mv | mv [-f | -n] SRC DST or mv ... SRC... DIR: renames or moves a file or a whole directory, replacing a file already there (-n keeps it). |
| cp | cp [-r] [-f | -n] SRC DST or cp ... SRC... DIR: copies files, and with -r whole directories; replaces an existing file unless -n. |
| wc | wc [-lwcmL] [files]: lines, words, bytes (or just the ones asked for), and -L the longest line; a total for several files. |
| grep | grep [options] PATTERN [files]: the lines matching a basic regular expression (-E extended, -F plain text), with -i -v -w -x -c -l -L -n -o -m -q -s -H -h -e -f -r -A -B -C. Lines of any length, "Binary file X matches" for binary files. No back-references. |
| head | head [-n N | -c N] [-q] [FILE...]: the first 10 lines of each file, or of its input; -N is -n N. Stops reading once it has enough. |
| tail | tail [-n [+]N | -c [+]N] [-q] [FILE...]: the last 10 lines, or everything from line N on with +N. Reads to the end, keeping only what it needs. No -f. |
| sort | sort [-bcfnrsu] [-k F1[,F2]] [-t SEP] [-o FILE] [FILE...]: sorts lines bytewise, or as numbers with -n, backwards with -r, ignoring case with -f. -u drops repeats, -c only checks, -o may name an input. One -k key, with the usual field rules. Ties go by the whole line unless -s or -u. Holds all its input in memory. |
| uniq | uniq [-c | -d | -u] [-i] [-f N] [-s N] [-w N] [INPUT [OUTPUT]]: collapses runs of equal lines, with -c counts, -d only the repeated, -u only the single. Streams, so it works on any size; run sort first. |
| cut | cut -b|-c|-f LIST [-d DELIM] [-s] [--complement] [--output-delimiter=STR] [FILE...]: bytes or tab-separated (or -d) fields of each line, picked by a list like 1,3-5,8-. A line with no delimiter passes through unless -s. |
| tr | tr [-cCdst] SET1 [SET2]: translates, deletes (-d) or squeezes (-s) bytes of standard input. Sets take ranges, [:alpha:]-style classes, [c*N] repeats and \n \t \NNN escapes; -c is the complement of SET1. |
| tac | tac [-b] [-s SEP] [FILE...]: each file with its records last first. -b puts the separator before its record, -s changes it from a newline (an empty string means a NUL byte). A last line with no newline is written first, joined to the one after it, as GNU does. Reads the whole file into memory; no -r. |
| rev | rev [FILE...]: each line back to front. Works on bytes, not characters, so a multi-byte UTF-8 letter comes out in pieces. A last line with no newline stays without one. |
| nl | nl [-b|-h|-f STYLE] [-n ln|rn|rz] [-w N] [-s SEP] [-v N] [-i N] [-l N] [-d CC] [-p] [FILE...]: numbers lines, counting on from file to file. Styles are a (all), t (non-empty, the default for the body), n (none) and pREGEX (basic syntax). Lines made of \:\:\:, \:\: and \: start a header, body and footer and restart the numbers unless -p. Numbers are 64 bits; running out is an error. |
| paste | paste [-s] [-d LIST] [FILE...]: the files side by side, line 1 of each joined by a tab, then line 2, and so on; a file that runs out gives empty fields. -s makes one line for each file instead. -d takes a list of delimiters used round and round (\n \t \\ and \0 for none are understood). Every - is the same standard input, so paste - - joins pairs of lines. Opens every file before it writes, so a missing one prints nothing. Bytes, not characters; no -z. |
| comm | comm [-123] [--check-order | --nocheck-order] [--output-delimiter=STR] [--total] FILE1 FILE2: compares two sorted files into three columns: only in the first, only in the second, in both (-1 -2 -3 leave one out). Without a check option it warns about a line out of order once the files have disagreed, as GNU does, and exits 1 at the end. --total adds the counts. Compares bytes, not locale order; no -z. |
| join | join [-i] [-t C] [-1 N] [-2 N] [-j N] [-a 1|2] [-v 1|2] [-e STR] [-o LIST|auto] [-z] [--check-order | --nocheck-order] [--header] FILE1 FILE2: puts together the lines of two sorted files that share a key, like looking things up in a table. Each pair of lines with the same join field (the first, unless -1 -2 -j say otherwise) becomes one line: the key, the rest of the line of FILE1, the rest of the line of FILE2. -a N also writes the lines of file N that found no partner, -v N writes only those, -e STR fills a missing or empty field, and -o picks the fields to write (0 is the key, 1.2 is field 2 of file 1; auto takes as many as the first line has). Fields are split at runs of blanks, or at each C with -t (an empty C makes the whole line one field, \0 is a NUL); -z makes the lines end in NUL; --header joins the first lines as headings. The files must be sorted bytewise on the key; as in GNU, a line out of order is reported once for each file (join: FILE:LINE: is not sorted: ...) when it matters, --check-order stops at it, and the end status is 1. Checked against GNU case by case, including the cross product of equal keys, the messages and how -j1 is told from -j 1. A usage error is status 2, where GNU's is 1, --version stops with a message, and -i folds ASCII letters only. Names in messages are quoted as GNU does, except a name that mixes an apostrophe with control bytes. |
| expand | expand [-i] [-t LIST] [FILE...]: the files with each tab turned into spaces up to the next tab stop, which is every 8 columns unless -t says otherwise. -t N puts a stop every N columns; -t 4,8,12 lists the stops, after which a tab is a single space; the last may start with / (then every multiple of it) or + (then every so many past the last). Another -t goes on from the one before. -i converts only the tabs before any other character on a line. A backspace goes back a column. The files are one stream, so a last line with no newline carries on into the next file. Columns count bytes, not characters: a UTF-8 letter is as many columns as it has bytes, and nothing is double-width. No -4 for -t 4. |
| unexpand | unexpand [-a | --first-only] [-t LIST] [FILE...]: the opposite: runs of spaces that end at a tab stop become a tab. Only the blanks at the start of a line unless -a (or -t, which implies it; --first-only wins over both). A single space is turned into a tab only when it follows another blank or starts the line, as in GNU. -t takes the same lists as expand; past the last stop of a list with no end, nothing is changed. One stream and byte columns, as for expand. |
| fold | fold [-b] [-s] [-w WIDTH] [FILE...]: every line cut so it is no more than WIDTH columns (80 by default; -N is -w N). A tab goes to the next multiple of 8, a backspace back a column and a carriage return to column 0; -b counts every byte as one column instead. -s cuts after the last blank that fits rather than in the middle of a word. Each file is folded on its own, so a last line with no newline stays without one. Columns count bytes, not characters, so a UTF-8 letter counts as several. |
| tee | tee [-a] FILE...: copies standard input to standard output and to the files (-a appends). Passes data on as it arrives. |
| basename | basename NAME [SUFFIX] or basename [-a] [-s SUFFIX] NAME...: the last part of a path, with an optional suffix taken off. |
| dirname | dirname NAME...: a path without its last part. |
| seq | seq [-w] [-s SEP] [FIRST [INCR]] LAST: the numbers from FIRST to LAST, with up to 9 decimals; -w pads with zeros, -s changes the separator. |
| factor | `factor [-h |
| diff | diff [-u | -U N | -c | -C N] [-q] [-s] [-i] [-b] [-w] [-a] [-r] [-N] [-d] [--label L] FILE1 FILE2: which lines changed, in the normal, unified (-u) or context (-c) format, picking the same changes as GNU diff, byte for byte. -i -b -w ignore case and blanks, -q only says whether they differ, -r goes through two directory trees, -N treats a missing file as empty. A file and a directory compare the file with its namesake inside. Binary files (a NUL in the first 4 KB) are only reported unless -a. Exit 0 same, 1 different, 2 trouble. |
| cmp | cmp [-l] [-s] [-n LIMIT] FILE1 [FILE2]: the first byte where two files differ (or every one with -l); exit 0 same, 1 different, 2 trouble. |
| yes | yes [STRING...]: prints STRING (or y) forever, until the reader quits. |
| true, false | Do nothing, with exit status 0 and 1. |
| sed | sed [-nsEr] [-i[SUFFIX]] [-l N] [-e SCRIPT | -f FILE | SCRIPT] [FILE...]: the stream editor. Addresses N, $, /re/I, \%re%, first~step, 0,/re/, a,+N, a,~N, !; commands {} s y d D p P n N g G h H x z = l a i c r w b t T : q Q; s takes & \1..\9 \n \U \L \u \l \E and the flags g p N I M w FILE. Patterns are basic (or -E extended) regular expressions as in grep, but with no back-references inside the pattern. -i edits files in place (writes a temporary, then swaps it in). |
| find | find [PATH...] [EXPRESSION]: walks directory trees. Tests -name -iname -path -type f|d -size -empty, options -maxdepth -mindepth -depth, operators ! -a -o ( ), actions -print -print0 -exec CMD {} ; -delete. Names ignore case, like the disk. |
| hexdump | hexdump [-C | -x] [-v] [-n LENGTH] [-s OFFSET] [FILE...]: the bytes of the files as one stream, as 16-bit words (default, -x) or canonical hex and text (-C). A repeated line becomes * unless -v. -n and -s take hex. |
| od | od [-A d|o|x|n] [-j SKIP] [-N LENGTH] [-t TYPE]... [-v] [-w[N]] [-abcdhilosx] [FILE...]: the bytes of the files as one stream, as octal 16-bit words unless told otherwise. -t takes any number of types, each a letter a c d o u x (named characters, escaped characters, signed decimal, octal, unsigned decimal, hex) with a size of 1, 2, 4 or 8 bytes (or C S I L; 4 if none), and a z after it adds the printable characters between > and <; the old letters -a -b -c -d -h -i -l -o -s -x are shorthands. -A picks the base of the address on the left (octal, decimal, hex, or none), -j skips and -N stops after that many bytes (hex, octal and the suffixes b k m G ... and KB MB ... as in GNU), and -w sets the bytes to a line (16 by default, up to 65536). A repeated line becomes * unless -v. No -t f (there are no floating-point types), no od FILE +OFFSET, and -j and -N stop at 4 GiB, which is more than a file here can hold. |
| strings | strings [-a] [-f] [-n N] [-t o|d|x] [-e s|S] [FILE...]: the runs of printable bytes in the files, one to a line. A run is at least 4 bytes (-n N, -N or --bytes=N change that) of a space up to ~, or a tab. -t puts the offset of each run before it in octal, decimal or hex (-o is -t o), -f the file name, and -e S counts the bytes 128 to 255 as printable too. A run ends at a newline. -a is accepted and does nothing, because the whole file is always scanned. Only the 7-bit and 8-bit encodings; no -s, -w or -d. |
| base64 | base64 [-d] [-i] [-w COLS] [FILE]: any file, binary or not, as plain letters and digits that pass through anything that handles text, and back again. Encoding breaks the line every 76 characters (-w COLS for another length, -w 0 for no breaks). -d decodes: newlines are skipped wherever they fall, and with -i so is anything else that is not part of the alphabet. It stops at the first bad group of four with base64: invalid input and status 1, after writing what came before it, as GNU does. --decode, --ignore-garbage and --wrap=COLS work too, and any unambiguous shortening of them (--dec). A usage error is status 2, where GNU's is 1. No --help or --version. |
| sha256 | sha256 [-b | -t] [--tag] [-z] [FILE...]: a fingerprint of each file (or of standard input, or of -): 64 hex digits that change if even one bit of the file does, so a download or a copy can be checked for coming through whole. It writes what GNU sha256sum does, HASH NAME, with --tag as SHA256 (NAME) = HASH and -z ending lines with a NUL, and a name with a newline or a backslash in it in GNU's backslash form. sha256 -c [-w] [--quiet] [--status] [--strict] [--ignore-missing] [FILE...] reads lists of that kind (the lines GNU reads, down to the odd ones: BSD style, a tab for the blank, upper-case digits, a carriage return at the end) and says NAME: OK or NAME: FAILED for each, then GNU's warnings (2 computed checksums did NOT match) and status 1 if anything failed. As in GNU, the first line of the run that shows whether the lines have a mode character after the blank fixes it for every later line, and a line that names - in a list read from standard input is badly formatted. Long options may be shortened (--ig). A usage error is status 2, where GNU's is 1, and names in messages are written as they are, not in shell quotes. No --help or --version. |
| printf | printf FORMAT [ARG...]: writes its arguments the way FORMAT says, which is how a script lines up columns, pads numbers, or leaves out the newline echo adds. Text in the format is written as it is, with the escapes echo -e takes (\n \t \xHH, octal, \c to stop there) and \uHHHH. %s %b %c %d %i %u %o %x %X %% take the next argument; %b is a string whose escapes are read. Between the % and the letter go the flags - + space # 0, a width and a precision (* takes either from an argument), as in C. A number may be written 0x1f, 010, 0b101, or as 'c for the code of the character c, and is 64 bits. When the format has been used and arguments are left, it is used again, and a directive with none left writes nothing or 0. It is GNU printf's wording and numbers, checked against it case by case: an argument that is not a number gets GNU's message and status 1 and the printing goes on, a bad directive stops there with its message and status 1, and GNU's warnings (ignoring excess arguments, character(s) following character constant have been ignored) are written with status 0. The floating point conversions (%a %e %f %g) and %q are not done: they stop with a message saying so, status 1. A usage error is status 2, where GNU's is 1. printf --help alone writes the usage; there is no --version. |
| split | `split [-l N |
| xargs | xargs [-0rt] [-n N] [-I STR] [COMMAND [ARGS...]]: reads items from standard input and runs the command (echo if none) with them added to its arguments, waiting for each run. Items are split at blanks and newlines, and quotes and backslashes group and escape as in GNU; -0 splits at NULs instead and leaves quotes alone. -n puts at most N items on a run. -I runs the command once for each line, with STR replaced in its arguments (-i is -I{}); it takes whole lines and cannot be combined with -n (the later one wins, with a warning). -t prints each command, quoted, to standard error before it runs. -r skips the run when the input is empty. A run is also cut short at 64 words or 3072 bytes, the most spawn will take, so a long input is several runs; one item that cannot fit alone is an error. Exit status as GNU: 123 if any run failed, 124 if one exited 255 (xargs stops there), 125 if one was killed, 126 and 127 if the command cannot be started or is not found. The command's own standard input is empty, not the terminal. No -L -s -P -p -d -E -x -o -a. |
| df | df [-h] [-k] [FILE...]: size, used and free space on the disk, in 1K blocks or with -h in K, M and G. |
| du | du [-achks] [PATH...]: the space files and directories take on the disk, in 1K blocks rounded up, or with -h in K, M and G (a decimal under 10, rounded up, as GNU). A file counts in whole clusters (the kernel says how big one is: 512 bytes on the test disk), so a 700-byte file is 1K and an empty one is 0; this is what df loses, not what ls shows. A directory is printed after everything in it with the total; -a prints the files too, -s only the PATHs, -c adds a total line. No PATH means .. A directory's own clusters are not counted, since the kernel does not report how many it has, so a tree comes out a little under what df lost. No -b -d -x -L --apparent-size; -k is the default and is accepted. |
| cal | cal [-1 | -3 | -y] [[MONTH] YEAR]: a calendar in the layout BSD cal and ncal print (util-linux's is laid out differently). No arguments is this month; one number is a YEAR and shows the whole year; MONTH YEAR shows one month. MONTH is 1 to 12 or a name (three letters or more, the first three matching, in any case: mar, Marc, september); YEAR is 1 to 9999. -3 shows the month with the ones either side (this one, with no arguments), -y the whole year (a month given with it is ignored), -1 the one month; if several are given the last counts, and -1 or -3 with a year alone is refused. Weeks start on Sunday. The calendar is Julian up to 2 September 1752 and Gregorian after it, the days from 3 to 13 September 1752 missing, which is what BSD and Linux cal show; countries that changed at another time (1582 for much of Europe, 1918 for Russia, and so on) are not known to it, so October 1582 shows all its days. On a terminal, today is shown in reverse; piped or redirected, nothing is added. Exit status 2 for a bad argument. No -j -m -w -A -B -d or the other options of ncal. |
| more | more [FILE...]: one screenful at a time, with a percentage for plain files. Space or PgDn for a screen, Enter or Down for a line, q or Ctrl+C to quit. Reads keys from /dev/tty, so it works on a pipe; when output is not the screen it behaves like cat. |
| hello | Hello world, and the starting point for your own |
To write your own, copy src/programs/util/hello.c. Every .c file in a
folder of src/programs (not lib) is built and put on the disk
automatically, under its name in uppercase, so the name must fit DOS 8.3 and
be different from every other program's, whatever its folder. A new program
goes in the folder for its main job: apps for a big interactive program,
files for one about files and directories as things, text for one that
reads and rewrites what is in them, net for the network, util for the
rest. Test programs go in tests/programs and land only on the
test disk.
A port of Octavo, a small Win32 editor, to the Ringtail terminal. Word wrap is on by default; Alt+Z toggles it.
| Action | Keys |
|---|---|
| New / Open / Save | Ctrl+N / Ctrl+O / Ctrl+S |
| Save as hylic | F12 |
| Undo / Redo | Ctrl+Z / Ctrl+Y |
| Find / Replace | Ctrl+F / Ctrl+R (Tab toggles match case) |
| Find next / previous | F3 / Shift+F3 |
| Cut / Copy / Paste / Select all | Ctrl+X / Ctrl+C / Ctrl+V / Ctrl+A |
| Move or delete by word | Ctrl+Left/Right, Ctrl+Backspace/Delete |
| Start / end of document | Ctrl+Home / Ctrl+End |
| Quit | Ctrl+Q |
Differences from the Windows version: Replace is Ctrl+R because Ctrl+H
is Backspace in a terminal, and Save as hylic is F12 because Ctrl+Shift+S
arrives as Ctrl+S. New documents are saved as .lemur. Files keep their line endings (LF or CR LF). Bytes are shown
one column each, so it is an ASCII editor; there is no mouse, and files
are limited to 1 MB. If it ever hangs, Ctrl+\ ends it.
These are deliberate, or simply not done yet. Programs get the x87 FPU
and SSE (their state is saved per task with fxsave), but not AVX. Long names are ASCII only (a name
with other characters shows as its short alias). The clock is the CMOS
one, with no time zone (UTC under QEMU) and no changes for summer time;
it is set by sntp, once at boot and whenever someone runs it, to the
second, and it is not disciplined between sets. A network that comes
up after boot does not get a sync of its own, and a boot with no
answer from DNS waits on the resolver (up to 4 s a DNS server) before
the shell starts. sntp takes one answer from one server, with no NTS,
so nobody can vouch for it: someone in the middle, or a lying DHCP
server, can set the clock to any time after the system was built. There is no
fork/exec (programs start other programs with spawn). Signals
are a small set (no siginfo, no SA_RESTART, so an interrupted call returns
EINTR, no job control or SIGCHLD, and sockets do not send SIGPIPE). Only one CPU at a time runs in the kernel. The display is one
1024x768 framebuffer that GRUB sets (or VGA text and mode 13h when it
cannot); there is no mode setting after boot, and one program owns the
graphics at a time. Windows in pleroma cannot be resized or minimised,
a terminal window is 80 by 24 with no scrollback or copy and paste,
pleroma's menu is a fixed list, and the desktop needs at least 640x480,
so it does not run in VGA text mode. The network has no IPv6, and the resolver does not retry over
TCP, so DNS answers too big for UDP are an error. The resolver keeps no cache, nothing reads ICMP
port unreachable for a socket (a dead DNS server is found out by
timeout), and the DHCP client does not check that nobody else already
has the address it was given (RFC 5227). The e1000 is the only card it
drives. factor stops at 2^64-1, where GNU's goes on to bigger numbers: a bigger one is refused with a message.
The shell is POSIX shell without trap, getopts, command/type,
readonly, aliases, ~ for the home directory, or job control (no
Ctrl+Z, fg or bg). export marks a variable but there is no
environment for programs to read, and since there is no fork a
subshell is a new copy of the shell, so one costs a program start.
Certificates are checked, but not everything about them is: there is
no revocation (no CRLs, no OCSP), so a certificate its CA has taken
back is still believed until it runs out, and no certificate
transparency or certificate policies. The dates are checked against the
machine's clock, which is whatever the CMOS says until sntp sets it;
a clock that is far wrong makes good certificates look expired, and one
wound back makes expired ones look good (the kernel will not wind it
back past the build, which bounds that). A name must be plain ASCII
(an internationalised name in its xn-- form works). The roots are a
copy taken when the disk was built, and nothing updates them. TLS is
1.3 only, with two cipher suites (ChaCha20-Poly1305, AES-128-GCM) and
one key exchange (X25519); nearly every server on the internet takes
X25519, and one that does not is refused with a message saying so. There is no session resumption, no early data, no
client certificate and no ALPN. fetch makes one request per
connection, does not ask for compressed pages, and has no cookies or
logins; it posts at most 16 MB.
Barb keeps its API key in /barb.cfg as plain text, and FAT has no
permissions, so anyone at the machine can read it. Its replies are not
streamed (a line counts the seconds meanwhile), and the commands it runs
get no terminal: their input is empty. The shell's line, and the
terminal's in cooked mode, holds 255 characters, so a longer task goes
through barb -p - < FILE.



