Add typescript kernel loader

This commit is contained in:
2025-11-29 23:14:51 +01:00
parent b7f619b8c3
commit af5d8c709b
15 changed files with 224 additions and 5 deletions

12
os/src/index.ts Normal file
View File

@@ -0,0 +1,12 @@
import { kmain } from "./kernel";
import { kpanic } from "./kernel/panic";
try {
const res = kmain();
if (res != 0) {
kpanic("Kernel returned non-zero exit code");
}
} catch (e) {
kpanic(e instanceof Error ? e.message : String(e));
}

13
os/src/kernel/index.ts Normal file
View File

@@ -0,0 +1,13 @@
import { Logger } from "../libs/logger";
import {
kmod_console_clearScreen,
kmod_console_outputString,
} from "./modules/console/console.kmod";
export function kmain() {
kmod_console_clearScreen();
Logger.log("[Kernel] Starting kernel...");
return 0;
}

View File

@@ -0,0 +1,11 @@
export function kmod_console_clearScreen() {
$___native_systable_conout_clearScreen();
}
export function kmod_console_setAttribute(attribute: number) {
$___native_systable_conout_setAttribute(attribute);
}
export function kmod_console_outputString(string: string) {
$___native_systable_conout_outputString(string);
}

12
os/src/kernel/panic.ts Normal file
View File

@@ -0,0 +1,12 @@
import {
kmod_console_clearScreen,
kmod_console_outputString,
kmod_console_setAttribute,
} from "./modules/console/console.kmod";
export function kpanic(message: string) {
kmod_console_clearScreen();
kmod_console_setAttribute(0x0c);
kmod_console_outputString("Kernel panic: \\r\\n");
kmod_console_outputString(message);
}

7
os/src/libs/logger.ts Normal file
View File

@@ -0,0 +1,7 @@
import { kmod_console_outputString } from "../kernel/modules/console/console.kmod";
export const Logger = {
log: function (message: string) {
kmod_console_outputString(message + "\\r\\n");
},
};

5
os/src/types/global_c_bindings.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
declare function $___native_systable_conout_outputString(string: string): void;
declare function $___native_systable_conout_clearScreen(): void;
declare function $___native_systable_conout_setAttribute(
attribute: number
): void;