Kernelite 0.1.0
Kernelite is a minimalist, educational operating system kernel built from scratch. The project aims to recreate core components of the Linux architecture to explore the fundamentals of operating system design and hardware-software interaction.
Loading...
Searching...
No Matches
Functions | Variables
main.c File Reference

Main kernel entry point and primitive UART driver. More...

#include "allocator/kalloc.h"
#include "allocator/page_allocator.h"
#include "asm/asm_helper.h"
#include "drivers/uart.h"
#include "fdt/fdt.h"
#include "icu/icu.h"
#include "linker/symbols.h"
#include "mem_layout/mem_layout.h"
#include "mmu/mmu.h"
#include "page_table/page_table.h"
#include "timer/timer.h"
#include "utils/kprintf.h"
#include "utils/string.h"
#include "utils/utils.h"
#include <libfdt.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
Include dependency graph for main.c:

Functions

void switch_to_high_va (void)
 Switch to high virtual addresses.
 
static void uart0_putchar (char chr)
 UART0 Character Output Function.
 
static void timer_tick_handler (void *priv)
 Test handler invoked on every system timer tick.
 
static void setup_system_timer (const void *fdt)
 Configure the system timer to tick once per second.
 
static void high_half_main (phy_addr fdt_addr)
 High-half kernel entry, executed AFTER the switch to high VAs.
 
int main (const uint64_t *boot_args_ptr)
 Kernel Main Entry Point.
 

Variables

static uart_device_t uart0
 
uint64_t boot_args [4]
 Captured bootloader arguments.
 

Detailed Description

Main kernel entry point and primitive UART driver.

Handles early kernel initialization, UART setup, FDT parsing, page allocator bootstrapping, and the transition into the kernel runtime loop.

Author
Abhin Parekadan Jose
Date
2026-04-25

Function Documentation

◆ high_half_main()

static void high_half_main ( phy_addr  fdt_addr)
static

High-half kernel entry, executed AFTER the switch to high VAs.

Must be a separate, non-inlined function so that all PC-relative address materialisation (e.g. &uart0_putchar) happens while the PC is already in the high VA range. It must never return into the low-VA boot/exit path once TTBR0 is disabled.

Never returns: after initialization it parks the core in an infinite wfi loop. The trailing exit(0) is unreachable and exists only to satisfy the compiler/static analysis that every path terminates.

Parameters
fdt_addrPhysical address of the Device Tree Blob, passed through from main().

◆ main()

int main ( const uint64_t *  boot_args_ptr)

Kernel Main Entry Point.

Called from primary_entry (boot.s) after the stack has been initialized and the BSS section has been cleared.

Note
On success this function never returns: it hands off to high_half_main()
Parameters
boot_args_ptrPointer to an array containing the bootloader arguments passed in registers x0-x3.
Returns
1 on initialization failure (id map setup, UART mapping, or FDT memory map parsing failed). Does not return on success.

◆ setup_system_timer()

static void setup_system_timer ( const void *  fdt)
static

Configure the system timer to tick once per second.

Parameters
fdtPointer to the Flattened Device Tree (FDT) blob, which may be used to discover timer properties and configuration.

◆ timer_tick_handler()

static void timer_tick_handler ( void *  priv)
static

Test handler invoked on every system timer tick.

Registered as the tick handler via setup_sys_timer() to verify that the timer driver correctly fires once per configured period.

Parameters
privUnused; registered with NULL private data.

◆ uart0_putchar()

static void uart0_putchar ( char  chr)
static

UART0 Character Output Function.

This function is designed to be used as the 'putc' function in the serial_t structure for kprintf. It abstracts the hardware-specific details of writing a character to the UART0 data register.

Parameters
chrThe character to be transmitted over UART0.

Variable Documentation

◆ boot_args

uint64_t boot_args[4]

Captured bootloader arguments.

boot.s only ever saves x0 into boot_args[0]; boot_args[1..3] are never written and simply read as 0 because the array lives in zeroed BSS.

  • boot_args[0]: Physical address of the Device Tree Blob (FDT).
  • boot_args[1]: Unused (reads as 0 due to BSS zero-init).
  • boot_args[2]: Unused (reads as 0 due to BSS zero-init).
  • boot_args[3]: Unused (reads as 0 due to BSS zero-init).

◆ uart0

uart_device_t uart0
static

Global UART0 device instance