Start xv6 and the first process
RISC-V powers on, it runs a boot loader which is stored in read-only memory.
Boot loader loads xv6 kernel into memory.
Load kernel at physical address at 0x80000000, instead of 0x0. Because 0x0:0x8000000 contains I/O devices.
CPU executes xv6 starting at _entry, to set up a stack so xv6 can run C code.
Each CPU has own stack.
Move stack pointer register sp points to stack0 + 4096, since stacks grows down.
_entry calls into C code start().
start() perform configurations in machine mode.
start() set return address to main() by writing main’s address into register mepc.
start() disable paging.
start() initialize clock interrupts.
Then start() enter supervisor mode by calling mret.
Program counter changes to main().
main() does all initialization devices and subsystems, set up address space, create kernel page table, allocate a page for the process’s kernel stack, etc.
main() creates first process by calling userinit().
The function loads an assembly file 'initcode.S’ and execute instructions. It re-enters kernel mode by invoking the exec system call.
exec() replaces the memory and registers with new program /init
/init program create file descriptor 0, 1, 2, and starts a console shell.
Child is shell, parent loops and handles orphaned zombies repeatly.
The system is up.
https://pdos.csail.mit.edu/6.828/2019/xv6/book-riscv-rev0.pdf
Last updated