T-Kernel Specification | Section 2: Boot & Initialization Sequence
← Return to T-Kernel Index

T-Kernel 2.0 Startup & Initialization

System Boot Lifecycle

The initialization sequence of T-Kernel 2.0 starts at low-level assembly reset routines (`reset_main`), transitions through T-Monitor hardware probing, calls `tkstart()` to initialize memory pools and interrupt vectors, and finally creates the system main task (`sysmain`).

1. Boot Phases & Control Flow

The T-Kernel initialization sequence is partitioned into four deterministic phases:

  1. Phase 1: Reset & T-Monitor Initialization: CPU registers, stack pointers, cache invalidate, MMU/Paging tables, and debug serial UART are setup by T-Monitor.
  2. Phase 2: T-Kernel Kernel Startup (`tkstart.c`): Invoked from T-Monitor. Initializes system queues, memory managers, interrupt dispatchers, and system timer ticks.
  3. Phase 3: Device Driver Subsystem Loading (`sysinit`): Registers VirtIO MMIO/PCI drivers, console streams, block devices, and display blitters.
  4. Phase 4: User Main Task Handover (`sysmain.c`): The kernel creates and launches the `sysmain` task which starts application services and the BTRON desktop environment.

2. C99 Initialization Entry Point (`tkstart.c`)

The core kernel startup function tkstart() performs internal data structure setup and spawns the initial system task:

/* System Main Entry Task Configuration */
LOCAL const T_CTSK c_sysmain_task = {
    .exinf   = NULL,
    .tskatr  = TA_HLNG | TA_ACT,
    .task    = (FP)sysmain,
    .itskpri = 1,              /* Highest System Priority */
    .stksz   = 8192,           /* System Task Stack Size */
};

/* Core Entry Point Called from Low-Level Reset Routine */
EXPORT ER tkstart( void ) {
    /* Initialize Kernel Data Structures & Ready Queues */
    knl_init();
    
    /* Initialize System Tick Timer */
    timer_initialize();
    
    /* Initialize VirtIO Drivers & Subsystems */
    virtio_driver_init_all();
    
    /* Start Scheduling & Spawn System Main Task */
    return tk_cre_tsk(&c_sysmain_task);
}

3. Application Handover (`sysmain.c`)

The sysmain function serves as the top-level application initialization task:

EXPORT INT sysmain( INT argc, CHAR *argv[] ) {
    printf("[T-KERNEL] System Main Task started successfully.\n");
    
    /* Launch BTRON Window Manager & Accessories */
    btron_kernel_init(1);
    
    return 0;
}