Add typescript kernel loader
This commit is contained in:
12
os/src/index.ts
Normal file
12
os/src/index.ts
Normal 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
13
os/src/kernel/index.ts
Normal 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;
|
||||
}
|
||||
11
os/src/kernel/modules/console/console.kmod.ts
Normal file
11
os/src/kernel/modules/console/console.kmod.ts
Normal 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
12
os/src/kernel/panic.ts
Normal 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
7
os/src/libs/logger.ts
Normal 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
5
os/src/types/global_c_bindings.d.ts
vendored
Normal 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;
|
||||
Reference in New Issue
Block a user