fix ps/2 mouse init, make Stall more precise, rename CurrentProcess to KeGetCurrentProcess, correct type about maneuvers, add file writing to win32

This commit is contained in:
maksw committed 2026-05-05 10:30:13 +02:00
1 parent 8c7564d5e1
commit a37f5b1581
14 files changed
+288 -75

No files matched your search

+3 -3
View File
@@ -32,9 +32,9 @@ __declspec(dllexport) void DbgPrint(const char* fmt, ...) {
KeReleaseSpinlock(&sl, flags);
}
// KePanic - Forces output even if debug was compiled out, then the macro halts.
// KePanic
__declspec(dllexport) _Noreturn void KePanic(const char *fmt, ...) {
// We are done, go away
// Silence! Stop the world!
_disable();
// Print a bright-red banner so the framebuffer is unmistakable.
@@ -50,7 +50,7 @@ __declspec(dllexport) _Noreturn void KePanic(const char *fmt, ...) {
vprintf(fmt, va);
va_end(va);
// Halt it!
// Die!
while (true) __halt();
}
+6 -14
View File
@@ -54,21 +54,13 @@ static const HAL_API* gHal;
void KeSyscallSetHal(const HAL_API* hal) { gHal = hal; }
// ---------------------------------------------------------------------------
// Helper: get the current process, or NULL if unavailable.
// ---------------------------------------------------------------------------
static inline PROCESS* CurrentProcess(void) {
THREAD* t = KeGetCurrentThread();
return t ? t->Owner : NULL;
}
// ---------------------------------------------------------------------------
// Helper: look up a handle and type-check it in one call.
// Bumps the refcount on success; caller must ObDereferenceObject when done.
// Returns NULL if the handle is invalid or the type does not match.
// ---------------------------------------------------------------------------
static OBJECT* HandleToObject(uint32_t handle, OBJECT_TYPE expected) {
PROCESS* proc = CurrentProcess();
PROCESS* proc = KeGetCurrentProcess();
if (!proc) return NULL;
OBJECT* obj = KeLookupHandle(proc, handle); // bumps refcount
if (!obj) return NULL;
@@ -85,7 +77,7 @@ static OBJECT* HandleToObject(uint32_t handle, OBJECT_TYPE expected) {
// On failure, drops the reference it would have stored.
// ---------------------------------------------------------------------------
static KSTATUS AllocHandleForCurrent(OBJECT* obj, uint32_t* handleOut) {
PROCESS* proc = CurrentProcess();
PROCESS* proc = KeGetCurrentProcess();
if (!proc) return STATUS_FAILURE;
KSTATUS s = KeAllocateHandle(proc, obj, handleOut);
if (!KSUCCESS(s)) ObDereferenceObject(obj);
@@ -126,7 +118,7 @@ static uint64_t SyscallExitThread(uint64_t a0, uint64_t a1, uint64_t a2,
static uint64_t SyscallCreateThread(uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t a3, uint64_t a4, uint64_t a5) {
(void)a4; (void)a5;
PROCESS* proc = CurrentProcess();
PROCESS* proc = KeGetCurrentProcess();
if (!proc) return STATUS_FAILURE;
if (a2 >= PriorityCount) return STATUS_INVALID_PARAMETER;
@@ -154,7 +146,7 @@ static uint64_t SyscallGetCurrentTid(uint64_t a0, uint64_t a1, uint64_t a2,
static uint64_t SyscallGetCurrentPid(uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t a3, uint64_t a4, uint64_t a5) {
(void)a0; (void)a1; (void)a2; (void)a3; (void)a4; (void)a5;
PROCESS* p = CurrentProcess();
PROCESS* p = KeGetCurrentProcess();
return p ? p->ProcessId : 0;
}
@@ -448,7 +440,7 @@ static uint64_t SyscallQueueRecv(uint64_t a0, uint64_t a1, uint64_t a2,
static uint64_t SyscallCloseHandle(uint64_t a0, uint64_t a1, uint64_t a2,
uint64_t a3, uint64_t a4, uint64_t a5) {
(void)a1; (void)a2; (void)a3; (void)a4; (void)a5;
PROCESS* proc = CurrentProcess();
PROCESS* proc = KeGetCurrentProcess();
if (!proc) return STATUS_FAILURE;
KeCloseHandle(proc, (uint32_t)a0);
return STATUS_SUCCESS;
@@ -733,7 +725,7 @@ static uint64_t SyscallCreateProcess(uint64_t a0, uint64_t a1, uint64_t a2,
if (!KSUCCESS(s)) { ObDereferenceObject(&proc->Header); return s; }
// Give the caller a handle to the new process so they can wait on it.
PROCESS* caller = CurrentProcess();
PROCESS* caller = KeGetCurrentProcess();
if (!caller) { ObDereferenceObject(&proc->Header); return STATUS_FAILURE; }
uint32_t handle;
+10 -6
View File
@@ -113,7 +113,7 @@ static void InitializeDrivers(BOOT_INFO* bootInfo, const HAL_API* hal) {
continue;
}
// memcpy manouvers
// memcpy maneuvers
memcpy(path, "drivers\\", 8);
memcpy(path + 8, runtimeKeys[i], len + 1);
@@ -329,7 +329,7 @@ void SystemInitThread(void* arg) {
DbgPrint("SystemInitThread: Failed to create watcher thread (%d) -- leaking proc ref.\n", ws);
}
}
MmFreePool(args);
}
@@ -340,7 +340,10 @@ extern void KernelMain(BOOT_INFO* bootInfo) {
//
// Physical & Virtual Memory initialization
//
MmInitializePhysical(&bootInfo->MemoryMap, bootInfo->PhysicalMapBase);
if (!MmInitializePhysical(&bootInfo->MemoryMap, bootInfo->PhysicalMapBase)) {
_disable(); while (true) __halt(); // there's nothing we can do
}
PHYSICAL_ADDRESS pml4 = (PHYSICAL_ADDRESS)__readcr3();
MmInitializeVirtual(pml4, 4 * 1024 * 1024 /* 4 MB initial pool */);
@@ -368,11 +371,12 @@ extern void KernelMain(BOOT_INFO* bootInfo) {
.RsdpPhysical = bootInfo->RsdpPhysical,
.DebugEnabled = bootInfo->DebugEnabled
};
KSTATUS s = HalInitialize(&halParams);
if (!KSUCCESS(s)) {
_disable();
while (true) __halt(); // there's nothing we can do.
_disable(); while (true) __halt(); // there's nothing we can do.
}
const HAL_API* hal = HalGetApi();
gKmainHal = hal;
@@ -416,7 +420,7 @@ extern void KernelMain(BOOT_INFO* bootInfo) {
DbgPrint("KernelMain: Handing over to scheduler...\n");
// Ignite the system
// Ignite the system!
_enable();
// The Idle Loop: The CPU rests here whenever all other threads are waiting on events.
+4 -5
View File
@@ -6,9 +6,6 @@
// bootloader at PhysicalWindowBase (always 0xFFFF880000000000).
//
// Lock: a single spinlock guards Push/Pop. O(1) for both operations.
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <mm_phys.h>
#include <ke_spinlock.h>
@@ -47,7 +44,7 @@ static void PushFrame(PHYSICAL_ADDRESS frame) {
// ---------------------------------------------------------------------------
// Initialisation
// ---------------------------------------------------------------------------
void MmInitializePhysical(const MEMORY_MAP* map, uint64_t physicalWindowBase) {
bool MmInitializePhysical(const MEMORY_MAP* map, uint64_t physicalWindowBase) {
gPhysBase = physicalWindowBase;
// --- Phase 0: Count total usable frames so we can size the stack
@@ -71,7 +68,7 @@ void MmInitializePhysical(const MEMORY_MAP* map, uint64_t physicalWindowBase) {
}
if (!stackPhys) {
while (true) { __halt(); }
return false;
}
gFrameStack.Stack = (PHYSICAL_ADDRESS *)PhysToVirt(stackPhys);
@@ -99,6 +96,8 @@ void MmInitializePhysical(const MEMORY_MAP* map, uint64_t physicalWindowBase) {
}
}
}
return true;
}
// ---------------------------------------------------------------------------
+2 -1
View File
@@ -3,6 +3,7 @@
// Stack allocator over 4 KB frames, seeded from MEMORY_MAP.
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <memory_map.h>
#define PAGE_SIZE 4096ULL
@@ -11,7 +12,7 @@
typedef uint64_t PHYSICAL_ADDRESS;
// Called once by KernelMain with the MEMORY_MAP from BOOT_INFO.
void MmInitializePhysical(const MEMORY_MAP* map,
bool MmInitializePhysical(const MEMORY_MAP* map,
uint64_t physicalWindowBase);
// Allocate / free a single 4 KB frame.