PatchworkOS
Loading...
Searching...
No Matches
Initialization

Initialization and kmain(). More...

Functions

_NORETURN void init_early (const boot_info_t *bootInfo)
 Early kernel initialization.
 
_NORETURN void kmain (const boot_info_t *bootInfo)
 Kernel main function.
 

Detailed Description

Initialization and kmain().

Function Documentation

◆ init_early()

_NORETURN void init_early ( const boot_info_t bootInfo)

Early kernel initialization.

This will do the absolute minimum to get the scheduler and smp up and running. Note that having smp "running" does not mean the other cpus are started, just that we are keeping track of the currently active cpu.

Having the scheduler running then lets us load the boot thread which will jump to kmain() where we can do the rest of the kernel initialization. This thread will eventually become the idle thread of the bootstrap cpu.

Will be called in the _start() function found in start.s with interrupts disabled.

Will never return, instead it will jump to the boot thread.

Parameters
bootInfoInformation provided by the bootloader.

Definition at line 39 of file init.c.

References _std_init(), acpi_tables_init(), assert, atomic_store, bootThread, CLOCKS_NEVER, interrupt_frame_t::cs, sched_thread_ctx_t::deadline, thread_t::frame, GDT_CS_RING0, gdt_init(), GDT_SS_RING0, boot_info_t::gop, idt_init(), boot_info_t::kernel, thread_t::kernelStack, kmain(), LOG_DEBUG, log_init(), boot_memory_t::map, boot_info_t::memory, NULL, panic_symbols_init(), pmm_init(), interrupt_frame_t::rdi, interrupt_frame_t::rflags, RFLAGS_ALWAYS_SET, interrupt_frame_t::rip, boot_info_t::rsdp, interrupt_frame_t::rsp, sched_cpu_ctx_t::runThread, cpu_t::sched, thread_t::sched, smp_bootstrap_init(), smp_bootstrap_init_early(), smp_self_unsafe(), interrupt_frame_t::ss, thread_get_boot(), thread_jump(), THREAD_RUNNING, stack_pointer_t::top, and vmm_init().

◆ kmain()

_NORETURN void kmain ( const boot_info_t bootInfo)

Kernel main function.

This is the entry point for the boot thread. When init_early() jumps to the boot thread we will end up here. We can then perform the rest of the kernel initialization here, enable interrupts and start the init process.

Note that this function will never return, instead it will call sched_done_with_boot_thread() which will turn the boot thread into the idle thread of the bootstrap cpu.

Parameters
bootInfoInformation provided by the bootloader.

Definition at line 158 of file init.c.

References assert, init_finalize(), init_process_spawn(), LOG_DEBUG, LOG_INFO, PAGE_SIZE, rsp_read(), sched_done_with_boot_thread(), and VMM_KERNEL_STACKS_MAX.

Referenced by init_early().