7. The first process that is not the kernel

Two worlds, one page table Left: the kernel's view, S-mode, pages U=0. Right: the process's view, U-mode, its pages U=1, kernel pages invisible. Between them the trapframe as the only cargo across sret and ecall; the mode bit is the axle. S · the kernel satp · one table identity map U=0 MMIO U=0 kernel reaches user pages by walking to the PA U · the process code U=1 · stack U=1 kernel pages: absent MMIO: absent reaches the kernel only by ecall trapframe 280 bytes mode bit sret → ← ecall the U bit in the PTE and the mode bit sret sets — the whole isolation the same two objects hearth will point at a guest, with a G-stage table (Part IV)

Why this layer exists

Until this chapter, “kernel” was a lie of vocabulary: everything on the hart was the kernel. From here on some code runs under the kernel, and the CPU — not good intentions — keeps it there. Isolation is exactly two objects: a page table whose kernel entries lack the U bit, and the privilege mode sret sets on the way down. No third thing exists in this chapter, and none is needed: a program that cannot fetch, load, or store outside two pages is contained, whatever else it believes.

This is the whole trick hearth will repeat on guests with a G-stage table in Part IV — a different table, a different mode bit, the same two objects. If this chapter is solid, the hypervisor’s isolation story is already written; only the names change.

Mechanism

Entering U is a return

Chapter 5 built the trap into the kernel; this chapter needs its mirror. sret is the instruction that leaves a trap: it sets the program counter from sepc, the privilege from sstatus.SPP, and interrupts from sstatus.SPIE (SIE←SPIE, SPIE←1). Nothing about sret knows a trap happened — it reads registers and jumps. So a kernel that wants to start a program fabricates the state a return would consume: a struct trapframe with sepc = the program’s entry, sp = the user stack top, and sstatus with SPP=0 — return to U — and SPIE=1, so the sret lands in U with interrupts enabled. A clear SPIE would run U masked, and chapter 8’s tick preemption would never fire; the bit is set now, once, on purpose.

The frame’s register file is zeroed except sp; the program’s _start builds its world from there. The whole load of this program is one memcpy and one page of address space — QEMU’s ELF load in chapter 2 was more work than this, and that asymmetry is the point: entering U is cheaper than loading a file, because the hardware does the privilege part for free.

struct proc *proc_create(const void *blob, unsigned long size,
                         unsigned long va)
{
    struct proc *p = 0;
    unsigned long code_pa = proc_page();
    unsigned long stack_pa = proc_page();
    unsigned long kstack_pa = proc_page();
    unsigned long a;
    int i, slot;

    for (slot = 0; slot < NPROC; slot++)
        if (proc_tab[slot].state == UNUSED || proc_tab[slot].state == DEAD) {
            p = &proc_tab[slot];
            break;
        }
    if (!p)
        halt(1);

    p->pid = (int)(p - proc_tab) + 1;
    p->state = RUNNABLE;
    p->kstack_top = kstack_pa + PAGE_SIZE;

    /* Code pages at va, U=1. The kernel's identity map entry for the
     * same PA stays U=0: one PA, two VAs, two permissions — the
     * kernel reaches its copy, U reaches only this one. */
    for (a = 0; a < size; a += PAGE_SIZE) {
        unsigned long off = a & (PAGE_SIZE - 1);
        unsigned long n = PAGE_SIZE - off;
        unsigned long *dst = (unsigned long *)(code_pa + a);
        const unsigned char *src = (const unsigned char *)blob + a;
        if (n > size - a)
            n = size - a;
        for (i = 0; i < (int)n; i++)
            ((unsigned char *)dst)[i] = src[i];
        map_page(va + a, code_pa + a,
                 PTE_R | PTE_W | PTE_X | PTE_U);
    }

    /* One U page for the stack, growing down. */
    map_page(va + 0x1000UL, stack_pa, PTE_R | PTE_W | PTE_U);

    /* The table changed under a live satp. The hart may hold the old
     * translation for these VAs (chapter 8 maps them twice); the
     * fence orders the PTE writes before any use of the new ones. */
    __asm__ volatile("sfence.vma" ::: "memory");

    /* Fabricate the frame: entering U is the mirror of returning
     * from a trap. SPP=0 so sret drops privilege; SPIE=1 so sret
     * copies it into SIE — U must run with interrupts enabled or
     * chapter 8's preemption never fires. */
    for (i = 0; i < 35; i++)
        ((unsigned long *)&p->tf)[i] = 0;
    p->tf.sepc = va;
    p->tf.sp = va + 0x2000UL;
    p->tf.sstatus = MSTATUS_SPIE; /* SPP=0 | SPIE=1 */

    /* The heap break starts just above the stack page; chapter 9's
     * sbrk maps pages there on demand. */
    p->brk = va + 0x2000UL;

    return p;
}

The user pages go in at USER_BASE, 0x10000, below every MMIO window the kernel maps — the value ember/user/link.ld fixes. Physical pages come from a fixed carve above the page-table pool for now; chapter 9 replaces the carve with the allocator, and the shape — blob to U pages, a kernel stack U=0, a fabricated frame — is the object that survives, not the bump pointer. Three things in the listing belong to chapter 8, where they are explained: the va argument (one table can hold several processes only if each is mapped at its own base — here it is USER_BASE), the slot loop over proc_tab (here it finds slot 0), and the sfence.vma after the maps (the table changed under a live satp; chapter 8 maps the same VAs a second time). Two belong to chapter 9: proc_page, which is the carve in this chapter’s image and the page allocator from chapter 9’s, and p->brk, the heap break sbrk will move.

Why the Part I trap entry cannot be entered from U

The frozen trap_entry starts with addi sp, sp, -280 and then stores through sp. From S that is fine: sp is a kernel page, U=0. From U it is a fault machine: the incoming sp is a user stack address, its page is U=1, and the very first sd is an S-mode store to a U page without sstatus.SUM — cause 15, stval on that same user sp. The fault is a trap; stvec still points at trap_entry; the handler runs addi sp, sp, -280 on the same user sp and faults again, cause 15, forever — each “handler” faulting before it can save anything. The fault never reaches a handler you can see; the hart is lost in a loop that no counter watches. Exercise (c′) has you predict exactly this.

The fix is one instruction at the front of a new entry. sscratch is a scratch CSR the spec defines as read/write with no hardware meaning — the conventional parking place for the kernel stack pointer while U runs. user_vec opens with csrrw sp, sscratch, sp, the atomic swap: sp becomes the proc’s kernel stack (parked there by proc_run), sscratch holds the user sp, and the 280-byte save lands on kernel memory. One instruction, and the recursive fault is gone.

The entries

user_vec saves the same 31 registers and 4 CSRs into the same 280-byte layout as the frozen entry — the frame layout is the frozen object, and duplicating the entry code around it is deliberate: editing trap.S would move every Part I capture, and the frozen entry is correct for traps from S. What changes is the prologue (the swap), the epilogue (re-park, then through user_ret, so a syscall’s writes to tf->sepc and tf->a0 are honored), and one stvec write in each direction.

    .globl user_vec
user_vec:
    csrrw   sp, sscratch, sp
    addi    sp, sp, -280
    sd      ra, 0(sp)
    sd      gp, 16(sp)
    sd      tp, 24(sp)
    sd      t0, 32(sp)
    sd      t1, 40(sp)
    sd      t2, 48(sp)
    sd      s0, 56(sp)
    sd      s1, 64(sp)
    sd      a0, 72(sp)
    sd      a1, 80(sp)
    sd      a2, 88(sp)
    sd      a3, 96(sp)
    sd      a4, 104(sp)
    sd      a5, 112(sp)
    sd      a6, 120(sp)
    sd      a7, 128(sp)
    sd      s2, 136(sp)
    sd      s3, 144(sp)
    sd      s4, 152(sp)
    sd      s5, 160(sp)
    sd      s6, 168(sp)
    sd      s7, 176(sp)
    sd      s8, 184(sp)
    sd      s9, 192(sp)
    sd      s10, 200(sp)
    sd      s11, 208(sp)
    sd      t3, 216(sp)
    sd      t4, 224(sp)
    sd      t5, 232(sp)
    sd      t6, 240(sp)
    csrr    t0, sscratch        /* the user sp */
    sd      t0, 8(sp)
    csrr    t0, sepc
    sd      t0, 248(sp)
    csrr    t0, scause
    sd      t0, 256(sp)
    csrr    t0, stval
    sd      t0, 264(sp)
    csrr    t0, sstatus
    sd      t0, 272(sp)
    la      t0, trap_entry
    csrw    stvec, t0           /* back to the kernel's entry */
    mv      a0, sp
    call    trapper
    /* trapper returns only to keep running the same proc: the frame
     * at sp is authoritative (syscalls wrote tf->sepc, tf->a0).
     * Re-park the kernel sp and re-enter through user_ret — the
     * mirror of the entry swap. Stopping the proc never comes back. */
    addi    t0, sp, 280
    csrw    sscratch, t0
    mv      a0, sp
    tail    user_ret

stvec alternates because it must: stvec is writable by S at any time, so pointing it at user_vec while U runs and back at trap_entry when the kernel runs is legal — and necessary, since each entry is correct for exactly one origin. The write happens on both sides of the crossing, in the entries themselves, so the invariant “stvec matches the world that is about to run” is maintained by the same code that changes the world.

    .globl user_ret
user_ret:
    mv      t6, a0
    ld      t0, 272(t6)         /* sstatus */
    csrw    sstatus, t0
    ld      t0, 264(t6)
    csrw    stval, t0
    ld      t0, 256(t6)
    csrw    scause, t0
    ld      t0, 248(t6)
    csrw    sepc, t0
    la      t0, user_vec
    csrw    stvec, t0
    ld      ra, 0(t6)
    ld      gp, 16(t6)
    ld      tp, 24(t6)
    ld      t0, 32(t6)
    ld      t1, 40(t6)
    ld      t2, 48(t6)
    ld      s0, 56(t6)
    ld      s1, 64(t6)
    ld      a0, 72(t6)
    ld      a1, 80(t6)
    ld      a2, 88(t6)
    ld      a3, 96(t6)
    ld      a4, 104(t6)
    ld      a5, 112(t6)
    ld      a6, 120(t6)
    ld      a7, 128(t6)
    ld      s2, 136(t6)
    ld      s3, 144(t6)
    ld      s4, 152(t6)
    ld      s5, 160(t6)
    ld      s6, 168(t6)
    ld      s7, 176(t6)
    ld      s8, 184(t6)
    ld      s9, 192(t6)
    ld      s10, 200(t6)
    ld      s11, 208(t6)
    ld      t3, 216(t6)
    ld      t4, 224(t6)
    ld      t5, 232(t6)
    ld      sp, 8(t6)           /* the user sp, from the frame */
    ld      t6, 240(t6)         /* t6's saved value, last */
    sret

t6 holds the frame base and is restored from the frame last — every register that touches the copy is loaded from the copy before the base is dropped.

void proc_run(struct proc *p)
{
    curproc = p;
    p->state = RUNNING;
    csr_write(sscratch, p->kstack_top);
    csr_write(stvec, (unsigned long)user_vec);
    user_ret(&p->tf);
}

proc_run parks the kernel stack top in sscratch before the crossing — that value is the first instruction of user_vec’s world — and never returns in this chapter: the program’s exit is a halt, and proc_run’s caller treats a return as an error (halt(1)). Chapter 8, which has somewhere to switch to, will change who calls this and why; the parking order does not change.

The U bit, the fault you cannot see around, and SUM

Between kernel and user PTEs exactly one flag changed: U. The U check, sstatus.SUM and the rule that S never fetches from a U=1 page are chapter 4’s (“Who may touch the page: U, SUM and MXR”); what is new here is that the kernel now has both kinds of page. A U-mode access to a U=0 page faults — loads cause 13, stores 15, fetches 12 — and an S-mode access to a U=1 page faults on the same causes, a load or store unless SUM is set, a fetch whatever SUM says.

This kernel does not set SUM. It does not need to, because it holds something better than a permission: the page table. walk() — the frozen building walk, which shares only its index arithmetic with the hardware’s (chapter 4) — turns a user VA into a PTE; the PTE’s PPN is a physical address; and the kernel’s identity map holds that PA at a U=0 VA. The kernel copies through its own mapping and never executes a user instruction. SUM would be simpler to write (dereference the user pointer directly) and costs exactly the safety the walk buys: with SUM, any kernel bug that leaks a user pointer into a dereference silently reads user memory; without it, that same bug is a page fault, cause 13, in the kernel’s own handler, loud. The trade is real — SUM is one instruction and faster — and this kernel still refuses it. Holding the table is what makes the kernel king.

int copy_in_user(struct proc *p, unsigned long uva, void *kbuf,
                 unsigned long n)
{
    unsigned char *dst = kbuf;
    unsigned long done = 0;

    (void)p; /* one table; the walk is the authority */
    while (done < n) {
        unsigned long va = uva + done;
        unsigned long pa = user_pa(va);
        unsigned long off = va & (PAGE_SIZE - 1);
        unsigned long chunk = PAGE_SIZE - off;
        const unsigned char *src;
        unsigned long i;

        if (!pa || chunk > n - done)
            chunk = n - done;
        if (!pa)
            return -1; /* unmapped or not a U page: the boundary */
        src = (const unsigned char *)(pa | off);
        for (i = 0; i < chunk; i++)
            dst[done + i] = src[i];
        done += chunk;
    }
    return 0;
}

Every byte the kernel ever accepts from a process crosses this function or its mirror copy_out_user (chapter 10’s pipes are its first caller). A VA that is not a mapped U leaf is refused, not followed: the user cannot make the kernel read kernel memory by passing a clever pointer, because the walk only answers for U pages. This one function is the isolation boundary made concrete — the rest of the chapter is plumbing around it.

The ecall path end to end

An ecall is the instruction a U program executes to request service: it raises an exception to the privilege that owns the machine — cause 8 from U — with no arguments, no memory, nothing but the register file as it stands. Chapter 5’s medeleg bit 8 already routes it to S. The path:

  1. U executes ecall with the syscall number in a7, arguments in a0–a2.
  2. Hardware raises cause 8; delegation (medeleg bit 8) sends it to S; stvec is user_vec; hardware sets SPP←U, SPIE←SIE, SIE←0, sepc←the ecall’s PC.
  3. user_vec: the sscratch swap, the 280-byte save on the proc’s kernel stack, stvec←trap_entry.
  4. trapper sees cause 8 and calls syscall(tf).
  5. The syscall runs with kernel privileges, reads its arguments from the saved frame, and writes results back into the frame — tf->a0 for the return value, tf->sepc += 4 to skip the ecall itself.
  6. user_vec’s tail re-parks the kernel sp and enters user_ret, which restores the frame, re-arms stvec←user_vec, and srets: PC←sepc, privilege←SPP=U, interrupts←SPIE.
static long sys_exit(long code)
{
    (void)code;
#if HP_CH < 8
    uart_puts("S: proc 1 exited\r\n");
    uart_puts("PASS\r\n");
    halt(0);
#else
    /* Ch 8: death is a state, not a halt. The kernel says so and
     * returns to the scheduler through the same door as yield. */
    uart_puts("S: proc ");
    uart_putc((char)('0' + curproc->pid));
    uart_puts(" exited\r\n");
#if HP_CH >= 10
    fd_close_all(curproc); /* a pipe's other end learns of this */
#endif
    curproc->state = DEAD;
#if HP_CH >= 13
    wakeup(curproc); /* a parent in wait sleeps on this address */
#endif
    sched(); /* never returns: the loop picks a live world */
#endif
    return 0; /* unreachable; the return silences -Wall */
}

static long sys_write(long fd, long buf, long n)
{
#if HP_CH >= 10
    /* Ch 10: through the descriptor table. fd 1 is still the console;
     * it is just no longer the only thing a process can write. */
    struct file *f = fd_get(curproc, fd);

    if (!f || n < 0)
        return -1;
    return file_write(f, (unsigned long)buf, n);
#else
    char kbuf[128];
    long i;

    if (fd != 1 || n < 0 || (unsigned long)n > sizeof(kbuf))
        return -1;
    if (copy_in_user(curproc, (unsigned long)buf, kbuf,
                     (unsigned long)n) < 0)
        return -1;
    for (i = 0; i < n; i++)
        uart_putc(kbuf[i]);
    return n;
#endif
}

#if HP_CH >= 9
/* Grow the calling process's heap by npages, U|R|W and never X, and
 * return the old break — the start of the new pages. sbrk(0) reads
 * the break. On an empty freelist the pages already mapped stay the
 * process's and brk already covers them; -1 says the request was not
 * met in full. Shrinking is named, not built. */
static long sys_sbrk(long npages)
{
    unsigned long old = curproc->brk;
    long i;

    if (npages < 0)
        return -1;
    for (i = 0; i < npages; i++) {
        unsigned long *slot = walk(curproc->brk);
        unsigned long pa;

        /* One table for everyone: the break can run into the kernel's
         * own low maps (the finisher at 0x100000 is 238 pages up from
         * the first program's heap) or another process's pages. A
         * slot that is already valid is refused, never overwritten. */
        if (!slot || (*slot & PTE_V)) {
            uart_puts("S: sbrk: break hit a mapping\r\n");
            return -1;
        }
        pa = kalloc_page();
        if (!pa) {
            uart_puts("S: sbrk: out of pages\r\n");
            return -1;
        }
        map_page(curproc->brk, pa, PTE_R | PTE_W | PTE_U);
        curproc->brk += PAGE_SIZE;
    }
    __asm__ volatile("sfence.vma" ::: "memory");
    return (long)old;
}
#endif

void syscall(struct trapframe *tf)
{
    long n = (long)tf->a7;
    long a0 = (long)tf->a0, a1 = (long)tf->a1, a2 = (long)tf->a2;

    switch (n) {
    case SYS_exit:
        a0 = sys_exit(a0);
        break;
    case SYS_write:
        a0 = sys_write(a0, a1, a2);
        break;
#if HP_CH >= 8
    case SYS_yield:
        /* Still runnable — the loop decides for how long. */
        curproc->state = RUNNABLE;
        sched();
        a0 = 0;
        break;
#endif
#if HP_CH >= 9
    case SYS_sbrk:
        a0 = sys_sbrk(a0);
        break;
#endif
#if HP_CH >= 10
    case SYS_read:
        a0 = sys_read(a0, a1, a2);
        break;
    case SYS_close:
        a0 = sys_close(a0);
        break;
#endif
#if HP_CH >= 12
    case SYS_open:
        a0 = sys_open(a0, a1);
        break;
#endif
#if HP_CH >= 13
    case SYS_spawn:
        a0 = spawn_impl(a0, a1);
        break;
    case SYS_wait:
        a0 = wait_impl(a0);
        break;
#endif
    default:
        a0 = -1;
        break;
    }
    tf->a0 = (unsigned long)a0;
    tf->sepc += 4; /* past the ecall */
}

The table has two entries and a refusal in this chapter’s image: syscall 1 is exit (the HP_CH < 8 branch: the proc is done, the kernel says so, PASS, halt(0) — the other branch is chapter 8’s, where death becomes a state and a switch), syscall 2 is write(fd, buf, n), which copies the buffer in through copy_in_user and prints it on the UART itself. The SYS_yield case sits behind HP_CH >= 8 for the same reason: the file is compiled by every chapter from 7 on, and each chapter’s additions are gated to it. The kernel is the syscall: the user program never touches the UART’s MMIO page, because its page table has no such page — device access must trap or isolation is a story, and exercise (e) derives why from the map. Later chapters extend this table; the numbering never moves.

And the program — the ecall wrapper, then run7’s two ecalls, nothing else. main branches on boot_mode, a fact chapter 8’s kernel places in a0 at launch and chapter 8’s _start captures; in this chapter’s image the frame’s a0 is zero and main runs run7:

static long syscall3(long n, long a0, long a1, long a2)
{
    register long a0r __asm__("a0") = a0;
    register long a1r __asm__("a1") = a1;
    register long a2r __asm__("a2") = a2;
    register long a7r __asm__("a7") = n;

    __asm__ volatile("ecall"
                     : "+r"(a0r)
                     : "r"(a1r), "r"(a2r), "r"(a7r)
                     : "memory");
    return a0r;
}

static void run8(void);

static void run7(void)
{
    /* Two ecalls: everything the program does, the kernel does. The
     * U: prefix is the book's convention — this line was printed by
     * the kernel, on the process's behalf, from a U page. */
    syscall3(2, 1, (long)"U: user: hello from U\r\n", 23); /* write */
    syscall3(1, 0, 0, 0);                                   /* exit  */
}

int main(void);
int main(void)
{
    if (boot_mode == 0) {
        run7(); /* chapter 7's shape: hello, then exit */
        return 0;
    }
    run8(); /* chapter 8's: alternate (1) or spin (2) */
    return 0; /* not reached: run8 exits */
}

_start zeroes .bss and sets sp from the link script’s stack_top before main — the fabricated frame’s sp points at the top of the one stack page, and _start’s job is to make that page a working stack (it aligns, it does not re-map; the frame’s value and the symbol’s value are the same number, frozen on both sides of the build).

The U: prefix on the greeting marks which world asked for the line, not which world printed it: the kernel printed it, through the trap, from bytes that live on a U=1 page — the two facts the capture pins in one line.

Walkthrough

ch07-user-prog (the two-ecall program), ch07-proc-create (the fabricated frame and the U pages), ch07-user-vec (the swap and the save), ch07-user-ret (the mirror), ch07-enter (proc_run’s parking order), ch07-copy-in (the boundary), ch07-syscall (the table). The capture pins both trap directions: S: kernel up before the first sret, U: user: hello from U printed by the kernel through the write trap, S: proc 1 exited, PASS.

Exercises

(a) Delete PTE_U from the user’s code page. Predict the scause on entry.

Answer

12, instruction page fault. The first fetch at the fabricated sepc is now a U-mode fetch of a U=0 page; stval is the entry address. The trap is taken (page faults are delegated), user_vec runs — the swap works, the save lands on the kernel stack — and trapper sees cause 12 and halts. The isolation held in the fetch direction before any instruction executed.

(b) Point the fabricated sp at a kernel page (an identity address). Predict.

Answer

15, store page fault, on the user’s first push. The program may run several instructions — until _start’s prologue or the first call needs the stack — then a U-mode store to a U=0 page faults with stval at the bad sp. Isolation holds in the data direction too: a wrong stack is a fault, not a window.

(c) Have the kernel dereference the user’s buffer pointer directly in sys_write — no SUM, no walk. Predict and explain.

Answer

Load page fault, cause 13, stval at the user VA. The kernel’s satp is the same table and the page is U=1: S-mode data access to a U page faults without SUM. The fault traps through trap_entry (the kernel was running) and reaches trapper as cause 13 — visible, loud, debuggable. That visibility is the reason this kernel walks instead of setting SUM.

(c′) Leave stvec at trap_entry and ecall. What does the first sd in the frozen entry do, and why does the fault never reach a handler you can see?

Answer

The entry runs addi sp, sp, -280 on the user sp, then the first sd is an S-mode store to a U=1 page: cause 15. That fault traps — back to trap_entry, still — which pushes another −280 on the same user sp and faults on the same store, identically, forever. Each iteration is a fault whose handler faults before saving anything: no counter increments, no line prints, the hart spins on a cause-15 loop. This is why stvec must be switched per privilege, and why the swap instruction lives at the very top of user_vec.

(d) Remove medeleg bit 8 and ecall. Where does it land, and why?

Answer

The M shim, cause 8, by trap-not-delegated. From M, mtval is 0 and the shim prints and halts — chapter 3’s dead-end path. Delegation is a mask, not a suggestion (chapter 5’s exercise (a) said so for illegal instructions; this is the same rule one bit over): the ecall goes to whichever privilege the mask says, with no regard for who executed it.

(e) Make the user program store to the UART’s MMIO address. Derive what happens and why user device access must trap.

Answer

Cause 15: the identity map’s UART page is U=0, and no user entry for that PA exists anywhere in the table. The user’s only route to the device is a syscall that copies bytes across copy_in_user — the kernel speaks for the device, the process asks. If U could reach MMIO directly, any program could program the UART (or later the PLIC, the block device, the finisher at 0x00100000 and halt the machine) — isolation that excludes the devices is not isolation.

(f) Compute what the mode bit alone — no page tables — would and would not stop.

Answer

Would stop: CSR access (satp, stvec, medeleg… are U-mode illegal), privileged instructions (sret, sfence.vma), and — if the OS parks a kernel sp in sscratch — nothing about memory. Would not stop: every load, store, and fetch anywhere in the address space, because without translation every address is physical and the mode bit does not gate the bus. A U program could read the kernel’s bytes, rewrite its code, and jump to it. The mode bit confines actions; the U bit confines addresses; this chapter needed both.

Lab

make lab CH=07
make lab CH=07 IMPL=mine

The capture pins the transcript across both trap directions: S: kernel up, then U: user: hello from U — printed by the kernel, on the process’s behalf, from a U page — then S: proc 1 exited, then PASS. One process, no clocks, no input: deterministic by construction. IMPL=mine copies exactly the objects chapter 7 links and stubs user_ret to print MINE: user_ret stub and halt — the lab boots, prints S: kernel up, and fails loudly with no user lines.

Further reading

  • The RISC-V Instruction Set Manual, Volume II: Privileged Architecture (RISC-V International, v20260120, January 2026) — ecall, sret, sstatus.SPP/SPIE/SUM, sscratch, stvec, U-bit fault causes.
  • xv6-riscv (MIT PDOS) — kernel/trampoline.S’s uservec/userret as a sibling: same sscratch swap, same per-privilege stvec, with a trampoline page this kernel does not need because it never switches satp.

results matching ""

    No results matching ""