⌂ Home

Lesson 9 — Your first feather

Step 1: a program that visits

Every program so far has owned its machine: it starts, it runs, it ends. A guest program is different. It is built to be laid inside another program — a host — which hands it one number, lets it run, and receives a parting number back. The guest does not boot and does not stop the machine; it visits.

A guest is written in the bare subset of Nifla (the next lesson looks downstairs properly; for now, know that on bare metal the language is sterner and smaller), and it uses two small tools of its own: guestvalue() reads the number the host handed in, and guestgive(n) leaves the parting number:

let gift = guestvalue()
say "A feather is visiting."
say "The host sent " + gift
guestgive(gift + 1)

Bare metal: this program runs on a real machine, not in a web page, so there is no Run button here.

That program is not run by this book's proof — it is compiled, with the flags the next step shows, and it runs when a host calls it through its door. Its say lines speak on the host's screen, in the host's house, as a guest should.

Step 2: the card

A guest by itself is just a program. A feather is a guest together with its card, made by the compiler in one step:

./niflac --bare --guest --feather visitor.nifla -o visitor.feather

The card stands at the feather's head, in plain text — the program's name, what it needs, how many bytes the program is, and a checksum of those bytes (a reckoning called FNV-1a-64, which any different byte anywhere changes). Here is a real card, from a real build of the program in Step 1:

CARDNULL FEATHER 1
name: visitor
needs: the guest door (desk version 1)
bytes: 1732
checksum: 2ce37ea9666eea2e

A host's door is the part of the host that receives feathers. The door reads the card, reckons the checksum over the program bytes that follow it, and lets the feather in only when card and program agree — laying it at the doorstep, a fixed address (2 MiB) the guest was linked for, and calling it there. The honesty of it, stated once and plainly: the checksum proves the bytes match the card and nothing more — it is a card, not a signature — and there is no isolation: host and guest share one memory, and a faulting guest stops the whole machine. A feather is a trusted visitor, checked at the door, not a prisoner in a cell.

Step 3: the doorman's test

Anyone can run the door's test before any door is involved. feathercheck reads a feather and answers in plain words whether its card is true — and answers with its exit code too (Lesson 8): 0 for true, 1 for not true. On the feather built above:

./feathercheck visitor.feather
Feather: visitor
Needs: the guest door (desk version 1)
The card says the program is 1732 bytes, with checksum 2ce37ea9666eea2e.
The program as it stands is 1732 bytes, with checksum 2ce37ea9666eea2e.
The card is true: the program is whole, and a door may let this feather in.

Your turn. In your own copy of the feather file, change one byte anywhere in the program part — a hex editor will do it, or flip a letter well past the card — and run feathercheck again. Before you run it, say out loud what you expect: which line will change, and which will not?

The name and needs lines stand unchanged — the card is untouched. The reckoned line changes, because the program no longer matches its card, and the verdict turns:

Feather: visitor
Needs: the guest door (desk version 1)
The card says the program is 1732 bytes, with checksum 2ce37ea9666eea2e.
The program as it stands is 1732 bytes, with checksum 7496d3f0a6fbd8b9.
The card is not true: the program does not match its card, so a door must refuse this feather.

(Your reckoned checksum will differ from this one — it depends on which byte you changed. The shape of the answer will not differ.)

The living example

This is not a toy mechanism. Cardnull OS 2 — an operating system written in Nifla — opens with a welcome feather that visits through exactly this door. Its card, as the Primer records it:

CARDNULL FEATHER 1
name: welcome-feather
needs: the guest door (desk version 1)
bytes: 2656
checksum: 0b2452a707571de8

The feather you just made is the welcome feather's younger sibling: same card, same door, same test.

Sit with that a moment. A few lessons ago you compiled a greeter and thought it a big step. Now you have built, card and all, the same kind of program an operating system opens its door to — in the same language, with the same words you started with.

Your turn

Write a feather of your own: a guest that is handed a number and gives back three times it. (It will be compiled with --bare --guest by the proof, as every guest in this book is.)

let gift = guestvalue()
guestgive(gift * 3)

Bare metal: this program runs on a real machine, not in a web page, so there is no Run button here.

You can now…

handed one number and leaving one number;

--feather` — a guest with its card laid on it;

plain-words verdict, true or not true.

---

← Lesson 8: Standing on its ownLesson 10: A first look downstairs →