Files
nt-lite/code/hal/hal_api.h
T

107 lines
3.4 KiB
C

#pragma once
// hal_api.h - HAL interface table exported as HalGetApi()
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <ke_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);
} HAL_SCREEN;
typedef struct HAL_KEYBOARD {
bool (*Poll)(void);
uint8_t (*ReadScancode)(void);
char (*ReadChar)(void);
uint32_t (*GetModifiers)(void);
void (*SetCallback)(void (*cb)(uint8_t scancode));
void (*Isr)(void);
uint8_t IrqNumber;
} HAL_KEYBOARD;
typedef struct HAL_DISK {
KSTATUS (*ReadSectors)(uint8_t drive, uint64_t lba,
uint32_t count, void* buf);
KSTATUS (*WriteSectors)(uint8_t drive, uint64_t lba,
uint32_t count, const void* buf);
bool (*DrivePresent)(uint8_t drive);
uint64_t (*DriveSectorCount)(uint8_t drive);
} HAL_DISK;
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);
} 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_KEYBOARD Keyboard;
HAL_DISK Disk;
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 DebugEnabled;
} HAL_INIT_PARAMS;
#define HAL_API_VERSION 1
const HAL_API* HalGetApi(void);
void HalRegisterScheduler(void (*pKeSchedulerTick)(void));
KSTATUS HalInitialize(const HAL_INIT_PARAMS* params);