Skip to main content
The Hardware Abstraction Layer (HAL) abstracts platform-specific hardware devices behind a single, uniform interface. Rather than talking directly to the PS/2 controller, the Real-Time Clock (RTC), the PCI bus, or the Programmable Interval Timer (PIT), you call the corresponding hal_* function and receive a well-defined result. The HAL bundles keyboard input, wall-clock time, PCI device enumeration, and timer services into one cohesive API that is safe to use from any kernel context after hal_init returns.

Supporting Structures

rtc_time_t

Used by hal_clock_read to return the current wall-clock time read from the hardware RTC.
uint16_t
Full four-digit calendar year (e.g., 2025).
uint8_t
Month of the year, 112.
uint8_t
Day of the month, 131.
uint8_t
Hour of the day in 24-hour format, 023.
uint8_t
Minute of the hour, 059.
uint8_t
Second of the minute, 059.

pci_device_t

Used by hal_pci_scan to describe a single PCI device discovered on the bus.
uint8_t
PCI bus number (0255) on which the device resides.
uint8_t
PCI slot (device) number (031) on the bus.
uint8_t
PCI function number (07) within the slot.
uint8_t
PCI base class code identifying the broad device category (e.g., 0x01 = Mass Storage, 0x02 = Network).
uint8_t
PCI subclass code that refines the class category.
uint16_t
PCI Vendor ID assigned by the PCI-SIG (e.g., 0x8086 for Intel).
uint16_t
PCI Device ID assigned by the vendor.

Functions

hal_init

Initialize the entire Hardware Abstraction Layer. This function configures the PS/2 keyboard driver, the RTC, the PCI subsystem, and the PIT timer in a single call. You must invoke hal_init before using any other hal_* function.

hal_keyboard_read

Read one character from the PS/2 keyboard input buffer.
char
The ASCII character of the most recently pressed key, or 0 if no key is currently available in the input buffer. This function does not block — poll it in a loop if you need to wait for input.

hal_clock_read

Read the current date and time from the hardware Real-Time Clock (RTC) and store the result in a caller-supplied rtc_time_t struct.
rtc_time_t *
required
Pointer to an rtc_time_t struct that receives the current date and time. All fields are populated on return.

hal_pci_scan

Enumerate all PCI devices on the system bus and populate a caller-supplied array of pci_device_t structs.
pci_device_t *
required
Array of pci_device_t to receive discovered device descriptors. Results are written starting at index 0 and truncated to capacity if more devices are found.
uint32_t
required
Number of elements available in the devices array.
uint32_t
The number of PCI devices written into devices. Never exceeds capacity.

hal_ticks

Return the raw PIT tick counter maintained by the timer interrupt handler.
uint64_t
The cumulative number of PIT ticks since hal_init was called. The PIT fires at 100 Hz, so each tick represents 10 ms. Divide by hal_timer_frequency() to obtain elapsed seconds.

hal_uptime_seconds

Return the number of complete seconds that have elapsed since hal_init was called.
uint64_t
System uptime in whole seconds. Derived from the PIT tick counter; granularity is limited to the timer period (10 ms).

hal_timer_frequency

Return the configured PIT interrupt frequency.
uint32_t
Timer frequency in Hz. Always 100 in the current release (one tick per 10 ms).

hal_sleep_ms

Busy-sleep for at least the specified number of milliseconds. The function spins on the PIT tick counter and returns only after the requested delay has elapsed.
uint64_t
required
Number of milliseconds to sleep. Because the PIT resolution is 10 ms, actual sleep duration is rounded up to the nearest 10 ms boundary.
hal_sleep_ms is a busy-wait. It consumes CPU cycles for the entire duration and should not be used for long delays in latency-sensitive code paths.

hal_reboot

Reboot the system immediately. This function does not return.
hal_reboot triggers an immediate system reset. Any in-flight VFS or RAMFS data is discarded. Make sure all work is complete before calling this function.

Examples

Reading the Real-Time Clock

Scanning the PCI Bus

Sleeping for a Fixed Delay