Skip to content

Boot Procedure

Joshua Barretto edited this page Aug 9, 2017 · 1 revision

Tupai's Boot Procedure

Tupai is a modular operating system kernel. The kernel contains simple hardware drivers for devices necessary to boot, with further drivers being loaded at later stages of the boot process.

To facilitate this bootstrapping procedure, Tupai comes with an initrd, a read-only ramdisk that provides all of the essential drivers and programs the system may need to create a functional system environment.

The Order Of Things

  1. Bootloader loads kernel into memory (Bootloader must be Multiboot 2 compliant)
  2. Bootloader loads initrd module into memory
  3. Bootloader jumps to protected-mode kernel entry point
  4. If the kernel is designed for amd64 (x86_64), the kernel will construct and install a temporary 64-bit GDT and 512 M of initial page tables. Once this is done, the kernel will perform a far call to reach the 64-bit entry point.
  5. The kernel now calls early(), a C++ function.
  6. The kernel performs platform-specific setup steps such as preserving the Multiboot header pointer, constructing and installing a new 64-bit GDT and IDT, etc.
  7. The kernel performs sets up a platform-independent page frame allocator, although with a kernel heap. Memory for the kernel and all Multiboot modules are preserved at this stage.
  8. The kernel returns to the assembly entry point and calls global C++ constructors now that all the necessary features are functional.
  9. The kernel calls the kmain() function to continue kernel setup.
  10. Low-level architecture-specific features (such as the x86's PIC, PIT, PCI, Keyboard, etc.) and drivers are initiated with arch_init().
  11. The main() function is called to start platform-independent kernel execution.
  12. 'Core' systems like the virtual filesystem (VFS), multitasking, scheduler, and syscall interface are initiated.
  13. 'Essential' systems required to support the boot process further such as the initrd filesystem are initiated.
  14. Virtual devices such as /dev/tty, /dev/stdin, /dev/stdout, /dev/ttySx, etc. are initiated to provide abstract hardware support.
  15. The 'init' process is created, and has an initial thread spawned.
  16. Finally, CPU interrupts are enable and the CPU halts ready for the next PIT preemption interrupt to occur.
  17. When the first preemption interrupt occurs, control is removed from the (now halted) initial execution and a context switch occurs to pass control to another thread.
  18. When the init process's primary thread is reached, it spawns a shell process and an associated thread.
  19. The operating system is now ready for user interaction!
Clone this wiki locally