// Public NTLite hal api ABI declarations shared between kernel, drivers, and user mode. #pragma once // hal_api.h - HAL interface table exported as HalGetApi(). #include #include #include #include typedef struct BOOT_INFO BOOT_INFO; typedef struct HAL_FRAMEBUFFER_INFO { uintptr_t Base; // kernel virtual address of the visible framebuffer uint32_t Width; uint32_t Height; uint32_t Stride; // pixels per scanline uint32_t Format; // currently 0x00RRGGBB / X8R8G8B8 } HAL_FRAMEBUFFER_INFO; typedef struct HAL_SCREEN { void (*Clear)(uint32_t color); void (*PutPixel)(int x, int y, uint32_t color); void (*Blit)(int x, int y, int w, int h, const uint32_t* pixels); void (*GetSize)(int* width, int* height); KSTATUS (*GetFramebuffer)(HAL_FRAMEBUFFER_INFO* outInfo); void (*Scroll)(int lines); void (*PutChar)(char c, int x, int y, uint32_t fg, uint32_t bg); // Writes only to the boot framebuffer text console. Stream routing belongs to HAL_OUTPUT_ROUTER. void (*PrintChar)(char c, uint32_t fg, uint32_t bg); // Legacy software cursor hooks kept for early-boot/panic fallback only. // Normal input cursor ownership lives in ke_display. void (*DrawCursor)(int x, int y); void (*EraseCursor)(void); } HAL_SCREEN; // Output streams describe the producer's intent. Endpoints subscribe by mask. #define HAL_OUTPUT_STREAM_DEBUG 0x00000001u #define HAL_OUTPUT_STREAM_CONSOLE 0x00000002u #define HAL_OUTPUT_STREAM_CRASH 0x00000004u #define HAL_OUTPUT_STREAM_PANIC 0x00000008u #define HAL_OUTPUT_STREAM_ALL 0x0000000Fu // Emergency writes bypass endpoints that cannot run without scheduler services. #define HAL_OUTPUT_WRITE_EMERGENCY 0x00000001u #define HAL_OUTPUT_ENDPOINT_PANIC_SAFE 0x00000001u #define HAL_OUTPUT_ENDPOINT_INVALID UINT32_MAX typedef struct HAL_OUTPUT_RECORD { // Exactly one HAL_OUTPUT_STREAM_* value. uint32_t Stream; // HAL_OUTPUT_WRITE_* flags. uint32_t Flags; // X8R8G8B8 text color hints. uint32_t Foreground; uint32_t Background; // The buffer remains valid only for the duration of Write(). const char* Buffer; size_t Length; } HAL_OUTPUT_RECORD; // Endpoint callbacks consume or copy the record synchronously and must not retain Buffer. typedef void (*HAL_OUTPUT_ENDPOINT_WRITE)(void* context, const HAL_OUTPUT_RECORD* record); typedef struct HAL_OUTPUT_ENDPOINT { // The name remains stable for the endpoint lifetime. const char* Name; uint32_t StreamMask; uint32_t Capabilities; HAL_OUTPUT_ENDPOINT_WRITE Write; void* Context; } HAL_OUTPUT_ENDPOINT; typedef struct HAL_OUTPUT_STATS { uint64_t RecordCount; uint64_t ByteCount; uint64_t EndpointWriteCount; uint64_t EmergencyRecordCount; uint32_t EndpointCount; } HAL_OUTPUT_STATS; typedef struct HAL_OUTPUT_ROUTER { // Registration is append-only; endpoint callbacks and context remain valid until shutdown. KSTATUS (*RegisterEndpoint)(const HAL_OUTPUT_ENDPOINT* endpoint, uint32_t* endpointIdOut); KSTATUS (*SetEndpointStreams)(uint32_t endpointId, uint32_t streamMask); void (*Write)(const HAL_OUTPUT_RECORD* record); void (*QueryStats)(HAL_OUTPUT_STATS* statsOut); uint32_t SerialEndpointId; uint32_t BootFramebufferEndpointId; } HAL_OUTPUT_ROUTER; typedef struct HAL_TIMER { uint64_t (*QueryTicks)(void); uint64_t (*QueryTickFrequency)(void); void (*Stall)(uint32_t us); void (*Isr)(void); uint8_t IrqNumber; } HAL_TIMER; #define HAL_RTC_TIME_FLAG_VALID 0x0001u #define HAL_RTC_TIME_FLAG_RTC 0x0002u typedef struct HAL_RTC_TIME { uint16_t Year; uint8_t Month; uint8_t Day; uint8_t Hour; uint8_t Minute; uint8_t Second; uint32_t Nanosecond; uint16_t Flags; uint16_t Reserved; } HAL_RTC_TIME; typedef struct HAL_RTC { KSTATUS (*QueryTime)(HAL_RTC_TIME* outTime); } HAL_RTC; typedef struct HAL_PCI { // Raw PCI configuration access. Policy-level operations such as // enumeration, BAR decoding, interrupt discovery, and MSI programming // belong to pci.sys. uint32_t (*Read32)(uint16_t segment, uint8_t bus, uint8_t dev, uint8_t fn, uint16_t offset); void (*Write32)(uint16_t segment, uint8_t bus, uint8_t dev, uint8_t fn, uint16_t offset, uint32_t value); } HAL_PCI; typedef struct HAL_INTC { void (*RouteIrq)(uint8_t irq); void (*MaskIrq)(uint8_t irq); void (*UnmaskIrq)(uint8_t irq); void (*SendEoi)(void); } HAL_INTC; typedef struct HAL_POWER { // ACPI S5 soft-off. Disables interrupts, writes SLP_EN to PM1a/b_CNT, // and halts if firmware doesn't respond. Does not return. void (*Shutdown)(void); } HAL_POWER; typedef struct HAL_API { uint32_t Version; void *(*PhysToVirt)(uint64_t physAddr); HAL_SCREEN Screen; HAL_OUTPUT_ROUTER Output; HAL_TIMER Timer; HAL_RTC Rtc; HAL_PCI Pci; HAL_INTC Intc; HAL_POWER Power; } HAL_API; typedef struct HAL_INIT_PARAMS { // Framebuffer. uintptr_t FramebufferBase; uint32_t FramebufferWidth; uint32_t FramebufferHeight; uint32_t FramebufferStride; // ACPI. uintptr_t RsdpPhysical; // Memory. uint64_t PhysicalWindowBase; // Debug. int Debug; void* (*AllocatePool)(size_t size); } HAL_INIT_PARAMS; // Increment when the HAL API layout or semantics change when we go from indev to alpha. #define HAL_API_VERSION 1 __declspec(dllexport) const HAL_API* HalGetApi(void); __declspec(dllexport) void HalRegisterScheduler(void (*pKeSchedulerTick)(void)); __declspec(dllexport) KSTATUS HalInitialize(const HAL_INIT_PARAMS* params); // Masks interrupts and returns the previous RFLAGS value. __declspec(dllexport) uintptr_t HalDisableInterrupts(void); // Restores the RFLAGS value returned by HalDisableInterrupts. __declspec(dllexport) void HalRestoreInterrupts(uintptr_t flags); // Enables maskable interrupts. __declspec(dllexport) void HalEnableInterrupts(void); // Enables interrupts and halts until the processor receives an interrupt. __declspec(dllexport) void HalWaitForInterrupt(void); // Halts once without changing the interrupt state. __declspec(dllexport) void HalHalt(void); // Masks interrupts and permanently stops the current processor. __declspec(dllexport) _Noreturn void HalStopProcessor(void);