Skip to content

Prep: Ship Your Commands — 53k

Session: Fri Dec 4, 1h30 · Exercises: 53k_ship_your_commands · Prep time: ~40 min · Lecture: Week 15 · fork, wait, and the User Shell

Same reading as Thursday. Read the 53k part of Week 15 · Essentials before class. The session opens with a 15-minute talk. 53k is not on the final; the long question it rehearses below is.

What you will build

The finish line. oslings ship compiles the commands you wrote in September for RISC-V, flattens each ELF, and embeds them as myecho, mycat, and so on. At the $ prompt from 52k, mycat notes.txt then runs the cat you wrote in September on your own kernel.

Reference images (64 KiB budget; yours will differ a little):

Command Flat image
echo 332 B
cat 1,202 B
wc 1,749 B
head 2,839 B
grep 2,990 B

Concepts you need

Read before class

What Time
Watch the videos Shipped Without an Edit (6:54), then From Keypress to Exit (6:48), and, for the extra credit, Headers Say Where (6:26) and The Timer Takes It Back (6:39). Each video's page links the explainer page it walks through 27 min
Week 15 · Friday · 53k Ship your commands through What oslings ship does 3 min
Week 15 · The long question, one layer per line, with the 54k extra-credit box 3 min
ulib and Commands: The rv6 backend, oslings ship and The budget 7 min

Mental model

One September command, wc, built twice. Not a line of it changes; the target does:

              on your laptop          on rv6, through oslings ship
built for     your laptop's target    riscv64gc-unknown-none-elf
what runs     wc, under cargo test    mywc: a flat image, run from address 0

Where the switch between the two lives is the first question below. And since rv6 cannot read ELF, oslings ship does the loading ahead of time.

Check yourself

  1. Your echo source has no #[cfg], yet it runs on your laptop and on rv6. Where is the switch, and why is println! still forbidden?
    AnswerInside ulib: the backend is chosen by target_os, so on the kernel every call is one ecall with the number in a7. println! comes from std, so it does not exist on the no_std kernel target; even a core::fmt stand-in would roughly quintuple the largest image.

What "done" looks like

oslings run is green, then oslings submit before you leave. Not green? Submit anyway — the tests that pass earn their share — then finish it at a make-up session (office hours, on the class network) for three quarters, or anywhere else for half, and submit again.

Extra credit today

54k_elf_loader (+1.0). Every program so far is a flat image: byte 0 is the entry point, every page read-execute, no .bss. This exercise teaches the kernel to read the ELF the compiler already emits, taking entry point, segment permissions, and a zeroed .bss from its PT_LOAD headers.

60k_preemption (+0.5). A user process that never makes a system call never gives the CPU back; this exercise lets the timer take it away, so processes that spin share the CPU in turns. See Extra Credit.

If you finish early

Work Week 15 · Problem 4: Size a shipped command on paper. Tuesday Dec 8 is the final exam, in class, the last day of the term — there is no exam during finals week. Practice Set 3 goes out today and its solutions go up Monday Dec 7, so attempt it on paper first.