KERNEL$ ./progFloating point exceptionrow 0row 14row 128row 2361big[500000] = 1;2while (i < 1e8) i++;3n = 10 / zero;CPUMODEuserTIMERbig[500000]14236001
Back: the kernel and the screen; middle: the interrupt tableFront: your program, its array page, the CPU, its mode bit and a timerTokens: event numbers going to their row, and the jump into the kernelAt the back, the kernel and the screen. In the middle, four rows of the interrupt table. In front, the program, the page for big[500000], and the CPU with its mode bit and a timer. Line 1 page-faults through row 14: the kernel maps a zeroed page and the line is retried. During line 2 the timer interrupts through row 236 and the loop carries on. Line 3's divide error goes through row 0 and the kernel ends the program with SIGFPE. The figure shows 4 of the table's 256 rows. Rows 0 (divide error) and 14 (page fault) are numbered by the CPU itself; rows 128 (int 0x80) and 236 (local timer) are the numbers Linux chooses on x86-64. On RISC-V, xv6 uses no table of rows: every trap enters at one address (stvec, in direct mode) and the CPU puts the cause number in scause.

The table

  1. Three kinds of event stop a program and run the kernel: a system call (the program asks), an exception (an instruction goes wrong) and an interrupt (a device needs attention). All three are traps: controlled jumps into kernel mode.

A fault, fixed

An interrupt

A fault, fatal

What happens

;; step 1/11 · three-ways
event         who causes it            when
system call   the program asks         when it chooses
exception     the instruction now      at that instruction
              (divide by zero, bad address, ...)
interrupt     a device (timer, disk)   any moment

all three: a trap into the kernel, in kernel mode

The figure shows 4 of the table's 256 rows. Rows 0 (divide error) and 14 (page fault) are numbered by the CPU itself; rows 128 (int 0x80) and 236 (local timer) are the numbers Linux chooses on x86-64. On RISC-V, xv6 uses no table of rows: every trap enters at one address (stvec, in direct mode) and the CPU puts the cause number in scause. In C, dividing an int by zero is undefined behaviour. On x86-64 the compiled divide instruction raises the divide error shown here. On 64-bit ARM, integer division by zero gives 0 and nothing traps, so the program would carry on.