Add typescript kernel loader
This commit is contained in:
34
os/.gitignore
vendored
Normal file
34
os/.gitignore
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# dependencies (bun install)
|
||||
node_modules
|
||||
|
||||
# output
|
||||
out
|
||||
dist
|
||||
*.tgz
|
||||
|
||||
# code coverage
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# logs
|
||||
logs
|
||||
_.log
|
||||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# caches
|
||||
.eslintcache
|
||||
.cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# IntelliJ based IDEs
|
||||
.idea
|
||||
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
||||
15
os/README.md
Normal file
15
os/README.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# os
|
||||
|
||||
To install dependencies:
|
||||
|
||||
```bash
|
||||
bun install
|
||||
```
|
||||
|
||||
To run:
|
||||
|
||||
```bash
|
||||
bun run index.ts
|
||||
```
|
||||
|
||||
This project was created using `bun init` in bun v1.2.20. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
||||
25
os/bun.lock
Normal file
25
os/bun.lock
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"lockfileVersion": 1,
|
||||
"workspaces": {
|
||||
"": {
|
||||
"name": "os",
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest",
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5",
|
||||
},
|
||||
},
|
||||
},
|
||||
"packages": {
|
||||
"@types/bun": ["@types/bun@1.3.3", "", { "dependencies": { "bun-types": "1.3.3" } }, "sha512-ogrKbJ2X5N0kWLLFKeytG0eHDleBYtngtlbu9cyBKFtNL3cnpDZkNdQj8flVf6WTZUX5ulI9AY1oa7ljhSrp+g=="],
|
||||
|
||||
"@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="],
|
||||
|
||||
"bun-types": ["bun-types@1.3.3", "", { "dependencies": { "@types/node": "*" } }, "sha512-z3Xwlg7j2l9JY27x5Qn3Wlyos8YAp0kKRlrePAOjgjMGS5IG6E7Jnlx736vH9UVI4wUICwwhC9anYL++XeOgTQ=="],
|
||||
|
||||
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
||||
|
||||
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
|
||||
}
|
||||
}
|
||||
12
os/package.json
Normal file
12
os/package.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "os",
|
||||
"module": "src/index.ts",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
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;
|
||||
29
os/tsconfig.json
Normal file
29
os/tsconfig.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Environment setup & latest features
|
||||
"lib": ["ESNext"],
|
||||
"target": "ESNext",
|
||||
"module": "Preserve",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noImplicitOverride": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user