add system time, clean up pci into pci.sys, clean up syscall names, fix USERAPC1 typo

This commit is contained in:
maksw committed 2026-06-11 18:11:59 +02:00
1 parent c1a291c4c9
commit e41bf6e2c0
64 files changed
+4514 -2220

No files matched your search

+25 -1
View File
@@ -7,8 +7,29 @@
#define BOOT_INFO_MAGIC 0x424F4F54494E464FULL /* 'BOOTINFO' */
#define MAX_BOOT_MODULES 32
#define BOOT_TIME_FLAG_VALID 0x0001u
#define BOOT_TIME_FLAG_TZ_KNOWN 0x0002u
#define BOOT_TIME_FLAG_UEFI 0x0004u
#define BOOT_TIME_FLAG_FALLBACK 0x0008u
#define BOOT_TIME_FLAG_RTC 0x0010u
#define BOOT_TIME_UNSPECIFIED_TZ 2047
typedef struct BOOT_TIME {
uint16_t Year;
uint8_t Month;
uint8_t Day;
uint8_t Hour;
uint8_t Minute;
uint8_t Second;
uint8_t Daylight;
uint32_t Nanosecond;
int16_t TimeZoneMinutes;
uint16_t Flags;
uint32_t Reserved;
} BOOT_TIME;
typedef struct BOOT_MODULE {
char Name[32]; /* e.g. "hal.dll", "ide.sys" */
char Name[32]; /* e.g. "hal.dll", "ata.sys" */
uintptr_t VirtBase; /* Virtual address (mapped) */
uintptr_t PhysBase; /* Raw physical address (file) */
size_t ImageSize; /* File size / Image size */
@@ -44,4 +65,7 @@ typedef struct BOOT_INFO {
/* From boot.ini */
uint32_t Debug;
/* Firmware wall-clock snapshot taken before ExitBootServices. */
BOOT_TIME BootTime;
} BOOT_INFO;
+37 -16
View File
@@ -27,22 +27,42 @@ typedef struct HAL_TIMER {
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);
#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 {
@@ -63,6 +83,7 @@ typedef struct HAL_API {
void *(*PhysToVirt)(uint64_t physAddr);
HAL_SCREEN Screen;
HAL_TIMER Timer;
HAL_RTC Rtc;
HAL_PCI Pci;
HAL_INTC Intc;
HAL_POWER Power;
@@ -87,7 +108,7 @@ typedef struct HAL_INIT_PARAMS {
void* (*AllocatePool)(size_t size);
} HAL_INIT_PARAMS;
#define HAL_API_VERSION 3
#define HAL_API_VERSION 5
__declspec(dllexport) const HAL_API* HalGetApi(void);
__declspec(dllexport) void HalRegisterScheduler(void (*pKeSchedulerTick)(void));
+118
View File
@@ -0,0 +1,118 @@
#pragma once
// pci.h - PCI bus driver DDI exported by pci.sys
//
// Function drivers must not enumerate PCI or decode BARs themselves. They bind
// to PCI PDOs through the I/O manager and use these routines to access the PCI
// function represented by their PDO.
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <ntlite/status.h>
#include <ntlite/ddi/io_driver.h>
#ifndef PCI_API
# ifdef PCI_SYS_BUILD
# define PCI_API __declspec(dllexport)
# else
# define PCI_API __declspec(dllimport)
# endif
#endif
typedef struct PCI_ADDRESS {
uint16_t Segment;
uint8_t Bus;
uint8_t Device;
uint8_t Function;
} PCI_ADDRESS;
typedef struct PCI_DEVICE_INFO {
PCI_ADDRESS Address;
uint16_t VendorId;
uint16_t DeviceId;
uint16_t SubsystemVendorId;
uint16_t SubsystemId;
uint8_t RevisionId;
uint8_t ProgIf;
uint8_t Subclass;
uint8_t ClassCode;
uint8_t HeaderType;
uint8_t InterruptLine;
uint8_t InterruptPin;
} PCI_DEVICE_INFO;
typedef enum PCI_BAR_TYPE {
PciBarUnused = 0,
PciBarIo,
PciBarMemory32,
PciBarMemory64,
} PCI_BAR_TYPE;
typedef struct PCI_BAR {
PCI_BAR_TYPE Type;
uint8_t Index;
uint64_t Base;
uint64_t Length;
bool Prefetchable;
} PCI_BAR;
#define PCI_ENABLE_IO 0x00000001u
#define PCI_ENABLE_MEMORY 0x00000002u
#define PCI_ENABLE_BUSMASTER 0x00000004u
#define PCI_ENABLE_INTX 0x00000008u
#define PCI_DISABLE_INTX 0x00000010u
#define PCI_CONFIG_VENDOR_DEVICE 0x00u
#define PCI_CONFIG_COMMAND_STATUS 0x04u
#define PCI_CONFIG_REVISION_CLASS 0x08u
#define PCI_CONFIG_HEADER_TYPE 0x0Cu
#define PCI_CONFIG_BAR0 0x10u
#define PCI_CONFIG_INTERRUPT_LINE_PIN 0x3Cu
PCI_API uint32_t PciDriverAbiVersion(void);
PCI_API KSTATUS PciGetDeviceInfo(DEVICE_OBJECT* pdo,
PCI_DEVICE_INFO* outInfo);
PCI_API KSTATUS PciReadConfig8(DEVICE_OBJECT* pdo,
uint16_t offset,
uint8_t* outValue);
PCI_API KSTATUS PciReadConfig16(DEVICE_OBJECT* pdo,
uint16_t offset,
uint16_t* outValue);
PCI_API KSTATUS PciReadConfig32(DEVICE_OBJECT* pdo,
uint16_t offset,
uint32_t* outValue);
PCI_API KSTATUS PciWriteConfig8(DEVICE_OBJECT* pdo,
uint16_t offset,
uint8_t value);
PCI_API KSTATUS PciWriteConfig16(DEVICE_OBJECT* pdo,
uint16_t offset,
uint16_t value);
PCI_API KSTATUS PciWriteConfig32(DEVICE_OBJECT* pdo,
uint16_t offset,
uint32_t value);
PCI_API KSTATUS PciGetBar(DEVICE_OBJECT* pdo,
uint8_t index,
PCI_BAR* outBar);
PCI_API KSTATUS PciMapBar(DEVICE_OBJECT* pdo,
uint8_t index,
uint64_t pageFlags,
void** outVirtual,
uint64_t* outLength);
PCI_API KSTATUS PciEnableDevice(DEVICE_OBJECT* pdo,
uint32_t flags);
PCI_API KSTATUS PciGetInterrupt(DEVICE_OBJECT* pdo,
uint8_t* outIrq);
PCI_API KSTATUS PciEnableMsi(DEVICE_OBJECT* pdo,
uint8_t irqSlot);
+5
View File
@@ -2,6 +2,7 @@
// dirent.h - directory entry returned by SysReadDir.
#include <stdint.h>
#include <ntlite/time.h>
#define SYS_DIR_NAME_MAX 260
@@ -9,5 +10,9 @@
typedef struct SYS_DIR_ENTRY {
char Name[SYS_DIR_NAME_MAX];
uint8_t Attr;
uint8_t Reserved0[3];
uint32_t FileSize;
SYS_SYSTEM_TIME CreateTime;
SYS_SYSTEM_TIME LastAccessTime;
SYS_SYSTEM_TIME LastWriteTime;
} SYS_DIR_ENTRY;
+51 -50
View File
@@ -8,6 +8,7 @@
#include <ntlite/string_view.h>
#include <ntlite/dirent.h>
#include <ntlite/input.h>
#include <ntlite/time.h>
#define SYS_STATUS_SUCCESS 0u
#define SYS_STATUS_TIMEOUT 3u
@@ -24,7 +25,6 @@
// User process/thread environment
// ---------------------------------------------------------------------------
// GS base points at SYS_TEB. GS:[0] is the process PEB pointer.
// This is this OS' ABI, not a Windows compatibility layout.
#define SYS_PEB_MAGIC 0x30424550u /* "PEB0" */
#define SYS_TEB_MAGIC 0x30424554u /* "TEB0" */
#define SYS_ENV_VERSION 1u
@@ -104,7 +104,7 @@ typedef struct SYS_USER_APC_FRAME {
uint64_t SystemArgument2;
} SYS_USER_APC_FRAME;
#define SYS_USER_APC_FRAME_MAGIC 0x3143504152555355ULL
#define SYS_USER_APC_FRAME_MAGIC 0x3143504152455355ULL
void SysUserApcDispatcher(void);
@@ -165,9 +165,9 @@ typedef struct SYS_WRITE_CONSOLE_REQUEST {
SYS_STRING_VIEW Text;
} SYS_WRITE_CONSOLE_REQUEST;
typedef struct SYS_DEBUG_PRINT_REQUEST {
typedef struct SYS_PRINT_DEBUG_REQUEST {
SYS_STRING_VIEW Text;
} SYS_DEBUG_PRINT_REQUEST;
} SYS_PRINT_DEBUG_REQUEST;
typedef struct SYS_PUBLISH_QUEUE_REQUEST {
SYS_STRING_VIEW Name;
@@ -248,14 +248,14 @@ uint32_t SysApcReturn(const SYS_USER_APC_FRAME* frame);
// ---------------------------------------------------------------------------
// Virtual memory and handles
// ---------------------------------------------------------------------------
typedef enum SYS_VM_PROTECTION {
typedef enum SYS_PROTECT_VMION {
SYS_VM_NOACCESS = 0,
SYS_VM_READ = 1,
SYS_VM_READWRITE = 2,
SYS_VM_EXECUTE = 3,
SYS_VM_EXECUTE_READ = 4,
SYS_VM_EXECUTE_READWRITE = 5,
} SYS_VM_PROTECTION;
} SYS_PROTECT_VMION;
#define SYS_VM_FLAG_NONE 0u
#define SYS_VM_FLAG_FIXED 1u
@@ -269,40 +269,40 @@ typedef struct SYS_VM_REGION_INFO {
uint32_t OwnerPid;
} SYS_VM_REGION_INFO;
uint32_t SysVmAlloc(void* preferredBase, size_t pageCount, uint32_t protect, uint32_t flags, void** baseOut);
uint32_t SysVmFree(void* base);
uint32_t SysVmProtect(void* base, size_t pageCount, uint32_t protect, uint32_t* oldProtectOut);
uint32_t SysVmQuery(void* address, SYS_VM_REGION_INFO* out);
uint32_t SysAllocVm(void* preferredBase, size_t pageCount, uint32_t protect, uint32_t flags, void** baseOut);
uint32_t SysFreeVm(void* base);
uint32_t SysProtectVm(void* base, size_t pageCount, uint32_t protect, uint32_t* oldProtectOut);
uint32_t SysQueryVm(void* address, SYS_VM_REGION_INFO* out);
uint32_t SysCloseHandle(uint32_t handle);
// ---------------------------------------------------------------------------
// Synchronization primitives (19-31)
// ---------------------------------------------------------------------------
uint32_t SysMutexCreate(uint32_t* handleOut);
uint32_t SysMutexAcquire(uint32_t handle);
uint32_t SysMutexTryAcquire(uint32_t handle);
uint32_t SysMutexRelease(uint32_t handle);
uint32_t SysCreateMutex(uint32_t* handleOut);
uint32_t SysAcquireMutex(uint32_t handle);
uint32_t SysTryAcquireMutex(uint32_t handle);
uint32_t SysReleaseMutex(uint32_t handle);
uint32_t SysSemCreate(int32_t initial, int32_t max, uint32_t* handleOut);
uint32_t SysSemWait(uint32_t handle);
uint32_t SysSemTryWait(uint32_t handle);
uint32_t SysSemSignal(uint32_t handle);
uint32_t SysCreateSem(int32_t initial, int32_t max, uint32_t* handleOut);
uint32_t SysWaitSem(uint32_t handle);
uint32_t SysTryWaitSem(uint32_t handle);
uint32_t SysSignalSem(uint32_t handle);
uint32_t SysEventCreate(uint32_t type, uint32_t initialState, uint32_t* handleOut);
uint32_t SysEventSignal(uint32_t handle);
uint32_t SysEventClear(uint32_t handle);
uint32_t SysEventWait(uint32_t handle, uint32_t alertable);
uint32_t SysCreateEvent(uint32_t type, uint32_t initialState, uint32_t* handleOut);
uint32_t SysSignalEvent(uint32_t handle);
uint32_t SysClearEvent(uint32_t handle);
uint32_t SysWaitEvent(uint32_t handle, uint32_t alertable);
// ---------------------------------------------------------------------------
// Queues and named queues (32-38)
// ---------------------------------------------------------------------------
uint32_t SysQueueCreate(uint32_t* handleOut);
uint32_t SysQueueSend(uint32_t handle, const void* msg, bool blocking);
uint32_t SysQueueRecv(uint32_t handle, void* msg, bool blocking);
uint32_t SysCreateQueue(uint32_t* handleOut);
uint32_t SysSendQueue(uint32_t handle, const void* msg, bool blocking);
uint32_t SysRecvQueue(uint32_t handle, void* msg, bool blocking);
uint32_t SysPublishQueue(const SYS_PUBLISH_QUEUE_REQUEST* request);
uint32_t SysOpenNamedQueue(const SYS_OPEN_NAMED_QUEUE_REQUEST* request);
uint32_t SysQueueDuplicate(uint32_t handle, uint32_t targetPid, uint32_t* handleOut);
uint32_t SysNamedQueueOwnerPid(const SYS_NAMED_QUEUE_OWNER_REQUEST* request);
uint32_t SysDuplicateQueue(uint32_t handle, uint32_t targetPid, uint32_t* handleOut);
uint32_t SysGetNamedQueueOwnerPid(const SYS_NAMED_QUEUE_OWNER_REQUEST* request);
// ---------------------------------------------------------------------------
// Files, directories, and current directory (39-56)
@@ -332,23 +332,23 @@ uint32_t SysGetCwd(const SYS_GET_CWD_REQUEST* request);
// Console and graphics (57-61)
// ---------------------------------------------------------------------------
uint32_t SysWriteConsole(const SYS_WRITE_CONSOLE_REQUEST* request);
uint32_t SysScreenBlit(int x, int y, int w, int h, const uint32_t* pixels);
uint32_t SysScreenClear(uint32_t color);
uint32_t SysScreenGetSize(int* widthOut, int* heightOut);
uint32_t SysScreenPutChar(char c, int x, int y, uint32_t fg, uint32_t bg);
uint32_t SysBlitScreen(int x, int y, int w, int h, const uint32_t* pixels);
uint32_t SysClearScreen(uint32_t color);
uint32_t SysGetScreenSize(int* widthOut, int* heightOut);
uint32_t SysPutScreenChar(char c, int x, int y, uint32_t fg, uint32_t bg);
// ---------------------------------------------------------------------------
// Input (62-69)
// ---------------------------------------------------------------------------
uint64_t SysKbPoll(void);
uint64_t SysKbIsKeyDown(INPUT_KEY key);
char SysKbReadChar(void);
INPUT_KEY SysKbReadKey(void);
uint32_t SysKbGetModifiers(void);
uint64_t SysPollKeyboard(void);
uint64_t SysIsKeyDown(INPUT_KEY key);
char SysReadKeyboardChar(void);
INPUT_KEY SysReadKey(void);
uint32_t SysGetKeyModifiers(void);
uint64_t SysMousePoll(void);
uint64_t SysMouseRead(int* dx, int* dy, uint8_t* buttons);
void SysMouseGetPos(int* x, int* y);
uint64_t SysPollMouse(void);
uint64_t SysReadMouse(int* dx, int* dy, uint8_t* buttons);
void SysGetMousePos(int* x, int* y);
// ---------------------------------------------------------------------------
@@ -424,16 +424,16 @@ typedef struct SYS_POLLFD {
uint32_t ReturnedEvents;
} SYS_POLLFD;
uint32_t SysSocket(uint32_t domain, uint32_t type, uint32_t protocol, uint32_t* handleOut);
uint32_t SysBind(uint32_t socket, const SYS_SOCKET_ADDRESS_IPV4* address, size_t addressSize);
uint32_t SysListen(uint32_t socket, uint32_t backlog);
uint32_t SysAccept(uint32_t socket, SYS_SOCKET_ADDRESS_IPV4* remoteAddressOut, size_t* remoteAddressSizeInOut, uint32_t* acceptedHandleOut);
uint32_t SysConnect(uint32_t socket, const SYS_SOCKET_ADDRESS_IPV4* address, size_t addressSize);
uint32_t SysSend(uint32_t socket, const void* buffer, size_t length, uint32_t flags, size_t* sentOut);
uint32_t SysRecv(uint32_t socket, void* buffer, size_t length, uint32_t flags, size_t* receivedOut);
uint32_t SysShutdown(uint32_t socket, uint32_t how);
uint32_t SysSendTo(uint32_t socket, const SYS_SOCKET_SEND_TO_REQUEST* request);
uint32_t SysRecvFrom(uint32_t socket, const SYS_SOCKET_RECV_FROM_REQUEST* request);
uint32_t SysCreateSocket(uint32_t domain, uint32_t type, uint32_t protocol, uint32_t* handleOut);
uint32_t SysBindSocket(uint32_t socket, const SYS_SOCKET_ADDRESS_IPV4* address, size_t addressSize);
uint32_t SysListenSocket(uint32_t socket, uint32_t backlog);
uint32_t SysAcceptSocket(uint32_t socket, SYS_SOCKET_ADDRESS_IPV4* remoteAddressOut, size_t* remoteAddressSizeInOut, uint32_t* acceptedHandleOut);
uint32_t SysConnectSocket(uint32_t socket, const SYS_SOCKET_ADDRESS_IPV4* address, size_t addressSize);
uint32_t SysSendSocket(uint32_t socket, const void* buffer, size_t length, uint32_t flags, size_t* sentOut);
uint32_t SysRecvSocket(uint32_t socket, void* buffer, size_t length, uint32_t flags, size_t* receivedOut);
uint32_t SysShutdownSocket(uint32_t socket, uint32_t how);
uint32_t SysSendToSocket(uint32_t socket, const SYS_SOCKET_SEND_TO_REQUEST* request);
uint32_t SysRecvFromSocket(uint32_t socket, const SYS_SOCKET_RECV_FROM_REQUEST* request);
uint32_t SysResolveHost(const SYS_RESOLVE_HOST_REQUEST* request);
uint32_t SysSetSocketOption(uint32_t socket, const SYS_SOCKET_OPTION_REQUEST* request);
uint32_t SysGetSocketOption(uint32_t socket, const SYS_SOCKET_OPTION_REQUEST* request);
@@ -501,7 +501,8 @@ typedef struct SYS_CPU_STATS {
// Time and diagnostics
// ---------------------------------------------------------------------------
uint64_t SysGetTick(void);
uint32_t SysDebugPrint(const SYS_DEBUG_PRINT_REQUEST* request);
uint32_t SysGetSystemTime(SYS_SYSTEM_TIME* timeOut);
uint32_t SysPrintDebug(const SYS_PRINT_DEBUG_REQUEST* request);
uint32_t SysQueryTrapFrame(SYS_TRAP_FRAME_INFO* info);
uint32_t SysGetMemoryStatus(SYS_MEMORY_STATUS* statusOut);
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include <stdint.h>
#define SYS_TIME_FLAG_VALID 0x0001u
#define SYS_TIME_FLAG_TZ_KNOWN 0x0002u
#define SYS_TIME_FLAG_UEFI 0x0004u
#define SYS_TIME_FLAG_FALLBACK 0x0008u
#define SYS_TIME_FLAG_RTC 0x0010u
#define SYS_TIME_FLAG_DAYLIGHT 0x0020u
#define SYS_TIME_UNSPECIFIED_TZ 2047
// Calendar wall-clock time maintained by the kernel. DayOfWeek uses the
// Win32 convention: 0 = Sunday, 1 = Monday, ... 6 = Saturday.
// TimeZoneMinutes is minutes east of UTC for the returned local calendar.
// EpochSeconds is UTC seconds since 1970-01-01 00:00:00.
typedef struct SYS_SYSTEM_TIME {
uint16_t Year;
uint8_t Month;
uint8_t Day;
uint8_t Hour;
uint8_t Minute;
uint8_t Second;
uint8_t DayOfWeek;
uint16_t Millisecond;
uint16_t Flags;
uint32_t Nanosecond;
int16_t TimeZoneMinutes;
uint16_t Reserved0;
uint64_t EpochSeconds;
uint64_t TickMicroseconds;
} SYS_SYSTEM_TIME;