📂
build a OS
  • Learn OS with me
  • OS Interfaces
    • OS interfaces
    • I/O and File descriptors
    • Process and Memory
    • Pipes
    • File
  • OS Organization
    • OS Organization
    • Challenge yourself
  • Memory Management
    • XV6 Virtual Memory
    • Page Table
      • Part 1: How to translate address
      • Part 2: Create an Address Space
      • Part 3: How Page Table is used
      • Part 4: Page Fault and Swap
      • Part 5: How to operate on page tables
    • xv6 buddy allocator
      • How to display physical memory
    • Memory Management Walk Through
  • Traps and Interrupts
    • Trap Home Page
      • 系统调用的核心原理
    • What is trapframe
    • What is trampoline
    • Traps from kernel space
    • How fork() works
    • How system calls get into/out of the kernel
    • How exec() works
  • Scheduling
    • XV6 CPU Scheduling
    • How unix pipes work?
    • How does wait(), exit(), kill() work?
  • File System
    • Overview and Disk Layout
    • Buffer Cache
    • Design Inode Layer
    • Inode Content
    • Block Allocator
    • Design a log system for crash recovery
    • Directory Layer
    • Path names
    • File Descriptor Layer
    • FS System Calls
    • XV6 VS Real World
    • Make Xv6 File disk management system
    • Write FS simulator in python
    • How Redirect Shell command works
  • Concurrency
    • Spinlock
    • How linux select work
    • Hardware Support Locking
    • Exercise: Implement atomic counter
    • Locking in Xv6
    • Concurrency in Xv6
    • Exercise: Socket Programming with Event loop
  • Labs
    • Lab 1 Xv6 and Unix utilities
    • Lab 2 Shell
    • Lab 3 Buddy Allocator
    • Lab 4 Lazy
    • Lab 5 Copy-on-Write Fork for xv6
    • Lab 6 RISC-V assembly
    • Lab 6 Uthread: switching between threads
    • Lab 6 Alarm
    • Lab 7 Lock
    • Lab 8 File System: Large Files
    • Lab 8 File System: Symbolic links
    • Lab 9 mmap
    • Lab 10 Networking Part 1
    • Lab 10 Networking Part 2
  • Hardware, Device, Assembly
    • RISC-V assembly
    • Assembly: Access and Store information in Memory
    • Start xv6 and the first process
    • Why first user process loads another program?
    • What does kernel.ld do in XV6?
    • XV6 Device Driver
Powered by GitBook
On this page

Was this helpful?

  1. Hardware, Device, Assembly

Start xv6 and the first process

  1. RISC-V powers on, it runs a boot loader which is stored in read-only memory.

  2. Boot loader loads xv6 kernel into memory.

  3. Load kernel at physical address at 0x80000000, instead of 0x0. Because 0x0:0x8000000 contains I/O devices.

  4. CPU executes xv6 starting at _entry, to set up a stack so xv6 can run C code.

  5. Each CPU has own stack.

  6. Move stack pointer register sp points to stack0 + 4096, since stacks grows down.

  7. _entry calls into C code start().

  8. start() perform configurations in machine mode.

  9. start() set return address to main() by writing main’s address into register mepc.

  10. start() disable paging.

  11. start() initialize clock interrupts.

  12. Then start() enter supervisor mode by calling mret.

  13. Program counter changes to main().

  14. 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.

  15. main() creates first process by calling userinit().

  16. The function loads an assembly file 'initcode.S’ and execute instructions. It re-enters kernel mode by invoking the exec system call.

  17. exec() replaces the memory and registers with new program /init

  18. /init program create file descriptor 0, 1, 2, and starts a console shell.

  19. Child is shell, parent loops and handles orphaned zombies repeatly.

  20. The system is up.

PreviousAssembly: Access and Store information in MemoryNextWhy first user process loads another program?

Last updated 5 years ago

Was this helpful?

https://pdos.csail.mit.edu/6.828/2019/xv6/book-riscv-rev0.pdf