System initialization

System initialization #

During boot, the kernel initializes the hardware and prepares the “init” task. The init process image (an ELF file) is provided to the kernel through the bootloader, such as (on x86_64) via multiboot modules, similar to an initramfs on Unix-like systems. The kernel will allocate an address space and physical pages to map the ELF sections into, as well as a capability space and various architecture-specific objects (such as an IOControl capability to manage I/O ports on x86_64). It places the capabilities for all of these objects into init’s own capability space, then enumerates remaining physical memory and places memory capabilities into this capability space as well, allowing init to make use of system resources at its discretion. The kernel additionally prepares a “bootinfo” structure, which provides the init task with some information about the system state, such as its command line arguments via the bootloader, the list and nature of memory regions on the system, and so on.

Initial capabilities #

The init task’s CSpace will include the following capabilities at the following addresses:

CSlot Capability type Notes
0 Null
1 CSpace The init task’s CSpace
2 VSpace The init task’s VSpace
3 ASID Control
4 ASID Pool The initial VSpace is assigned to this pool
5 Task The initial task
6 Page The initial task’s IPC page

A variable number of additional capabilities may be mapped from CSlot 16 and forwards, enumerating, for example, the pages allocated to store the init image. The nature of these assignments is detailed by the bootinfo structure.

aarch-specific #

(none)

x86_64-specific #

CSlot Capability type Notes
7 IOControl
8 IRQControl

Bootinfo structure #

A pointer to the bootinfo structure’s virtual address in the init task’s VSpace is provided to init in the ABI-appropriate first parameter register, e.g. %rcx on x86_64. The layout of this structure may be found here. The arch-specific arch_bootinfo structure may be found here:

Thread-local storage #

The kernel’s init loader will load the userspace thread-local sections, if present, into memory. The relevant pages will be included in the bootinfo image capabilities. This is the TLS master copy, and is mapped read-only. Userspace should allocate a copy of the master area for the initial thread read/write, and may allocate additional copies as necessary. Task::WRITE_TLS_BASE may be used to configure the appropriate arch-specific TLS base register (e.g. %fsbase on x86_64).

Image format #

The init image is an ELF file. Essentially any configuration is permitted, with the following caveats:

  • The TLS sections, if present, should have PHDRS set to PT_NULL and a base address of zero.
  • Some addresses are reserved for mapping initial data structures, such as the init stack.
Architecture Address range
aarch64 0x7fff80000000 and above
x86_64 0x7fff80000000 and above

A good starting point for preparing a suitable ELF file is vulcan’s hare.sc.