95 lines
3.0 KiB
C
95 lines
3.0 KiB
C
#pragma once
|
|
// hal_api.h - HAL interface table exported as HalGetApi()
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <ntlite/status.h>
|
|
|
|
typedef struct BOOT_INFO BOOT_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);
|
|
void (*Scroll)(int lines);
|
|
void (*PutChar)(char c, int x, int y, uint32_t fg, uint32_t bg);
|
|
void (*PrintChar)(char c, uint32_t fg, uint32_t bg);
|
|
// Hardware mouse cursor: save/restore background and blit sprite
|
|
void (*DrawCursor)(int x, int y);
|
|
void (*EraseCursor)(void);
|
|
} HAL_SCREEN;
|
|
|
|
typedef struct HAL_TIMER {
|
|
uint64_t (*QueryTicks)(void);
|
|
void (*Stall)(uint32_t us);
|
|
void (*Isr)(void);
|
|
uint8_t IrqNumber;
|
|
} HAL_TIMER;
|
|
|
|
typedef struct HAL_PCI {
|
|
uint32_t (*Read32)(uint8_t bus, uint8_t dev,
|
|
uint8_t fn, uint8_t reg);
|
|
void (*Write32)(uint8_t bus, uint8_t dev,
|
|
uint8_t fn, uint8_t reg, uint32_t val);
|
|
bool (*FindDevice)(uint16_t vendor, uint16_t device,
|
|
uint8_t* bus, uint8_t* dev, uint8_t* fn);
|
|
bool (*FindClass)(uint8_t classCode, uint8_t subclass,
|
|
uint8_t* bus, uint8_t* dev, uint8_t* fn);
|
|
// Returns the IRQ line from PCI config space (register 0x3C, byte 0).
|
|
// Returns 0xFF if no interrupt is wired.
|
|
uint8_t (*GetIrqLine)(uint8_t bus, uint8_t dev, uint8_t fn);
|
|
|
|
// Program a PCI MSI capability to deliver to vector (0x20 + irqSlot).
|
|
// irqSlot must correspond to a kernel IRQ stub/vector slot.
|
|
KSTATUS (*EnableMsi)(uint8_t bus, uint8_t dev, uint8_t fn, uint8_t irqSlot);
|
|
} 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_TIMER Timer;
|
|
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;
|
|
|
|
#define HAL_API_VERSION 3
|
|
|
|
__declspec(dllexport) const HAL_API* HalGetApi(void);
|
|
__declspec(dllexport) void HalRegisterScheduler(void (*pKeSchedulerTick)(void));
|
|
__declspec(dllexport) KSTATUS HalInitialize(const HAL_INIT_PARAMS* params);
|