See also: Kernel Index, Arch, CPU

This directory defines architecture-neutral operation tables and binds them to architecture-specific implementations using a function-pointer struct pattern.

Operation Tables

The HAL defines the following operation tables, each with a global pointer variable and arch-specific bindings:

IO Operations (hal/io.h)

g_HalIoOperations — Port I/O, interrupt control, halt, panic.

  • inb(), outb(), inw(), outw(), inl(), outl()

  • EnableInterrupts(), DisableInterrupts()

  • Halt(), Panic()

IRQ Operations (hal/irq.h)

g_HalIrqOperations — Interrupt request management.

  • RegisterHandler(), Unmask(), Mask()

Paging Operations (hal/mem.h)

g_HalPagingOperations — Full paging abstraction.

  • Page table manipulation, TLB flushing, address space switching

Scheduler Operations (hal/scheduler.h)

g_HalSchedulerOperations — Context switch interface.

  • Context save/restore, process switch

Syscall Operations (hal/syscall.h)

g_HalSyscallOperations — Syscall entry point.

  • Syscall handler registration and dispatch

Stack Operations (hal/stack.h)

g_HalStackOperations — Stack register access.

  • GetEBP(), GetESP(), stack setup

TSS Operations (hal/tss.h)

g_HalTssOperations — Task State Segment for ring transitions.

  • Kernel stack pointer update for privilege level switches

Video Operations (hal/video.h)

g_HalVideoOperations — Display output.

  • PutChar(), Clear(), cursor management

Architecture Mapping

Each HAL header maps architecture-specific functions to HAL_ARCH_* macros using preprocessor conditionals:

#if defined(I686)
#include <arch/i686/cpu/stack.h>
#define HAL_ARCH_Stack_GetEBP i686_Stack_GetEBP
#endif

hal.c then populates the operation structs with these macros:

const HAL_StackOperations *g_HalStackOperations = &(HAL_StackOperations){
   .GetEBP = HAL_ARCH_Stack_GetEBP,
};

Design Principle

Kernel code must never reference architecture-specific names directly:

// Correct: architecture-agnostic
g_HalStackOperations->GetEBP();

// Wrong: ties code to i686
i686_Stack_GetEBP();

Typical Work in This Area

  • Add new cross-arch operation interfaces

  • Wire arch-specific functions into HAL tables

  • Verify kernel modules use HAL calls consistently

  • Port to new architectures (x86_64, aarch64)

Revision History

v2.0

Updated for v0.28: detailed all eight operation tables with their purposes, added architecture mapping description

v1.0

Initial HAL subsystem summary