Change entrypoint function
This commit is contained in:
@@ -128,28 +128,40 @@ EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
|
|||||||
|
|
||||||
initKC(ctx);
|
initKC(ctx);
|
||||||
|
|
||||||
JSValue val = JS_Eval(ctx, SYSTEM_PROG_JS, strlen(SYSTEM_PROG_JS), "<input>", JS_EVAL_TYPE_GLOBAL);
|
JSValue val;
|
||||||
|
JSValue eval_result = JS_Eval(ctx, SYSTEM_PROG_JS, strlen(SYSTEM_PROG_JS), "<input>", JS_EVAL_TYPE_GLOBAL);
|
||||||
|
if (JS_IsException(eval_result)) val = eval_result;
|
||||||
|
else {
|
||||||
|
JS_FreeValue(ctx, eval_result);
|
||||||
|
|
||||||
|
JSValue global_obj = JS_GetGlobalObject(ctx);
|
||||||
|
JSValue kentry_func = JS_GetPropertyStr(ctx, global_obj, "KEntry");
|
||||||
|
|
||||||
|
if (JS_IsFunction(ctx, kentry_func)) val = JS_Call(ctx, kentry_func, JS_UNDEFINED, 0, NULL);
|
||||||
|
else val = JS_ThrowReferenceError(ctx, "KEntry function not found or not callable");
|
||||||
|
|
||||||
|
JS_FreeValue(ctx, kentry_func);
|
||||||
|
JS_FreeValue(ctx, global_obj);
|
||||||
|
}
|
||||||
|
|
||||||
if (JS_IsException(val)) {
|
if (JS_IsException(val)) {
|
||||||
JSValue ex = JS_GetException(ctx);
|
JSValue ex = JS_GetException(ctx);
|
||||||
const char *str = JS_ToCString(ctx, ex);
|
const char *str = JS_ToCString(ctx, ex);
|
||||||
|
|
||||||
if (str) {
|
if (str) {
|
||||||
printf("!!! Kernel panic: %s !!!\n", str);
|
printf("!!! Kernel panic: %s !!!\n", str);
|
||||||
JS_FreeCString(ctx, str);
|
JS_FreeCString(ctx, str);
|
||||||
} else {
|
} else printf("!!! Kernel panic: [unknown] !!!\n");
|
||||||
printf("!!! Kernel panic: [unknown] !!!\n");
|
|
||||||
}
|
JS_FreeValue(ctx, ex);
|
||||||
JS_FreeValue(ctx, ex);
|
|
||||||
} else {
|
} else {
|
||||||
const char *str = JS_ToCString(ctx, val);
|
const char *str = JS_ToCString(ctx, val);
|
||||||
if (str) {
|
if (str) {
|
||||||
printf("!!! Kernel panic: %s !!!\n", str);
|
printf("!!! Kernel panic: %s !!!\n", str);
|
||||||
JS_FreeCString(ctx, str);
|
JS_FreeCString(ctx, str);
|
||||||
} else {
|
} else printf("!!! Kernel panic: [unknown] !!!\n");
|
||||||
printf("!!! Kernel panic: [unknown] !!!\n");
|
|
||||||
}
|
JS_FreeValue(ctx, val);
|
||||||
JS_FreeValue(ctx, val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_FreeContext(ctx);
|
JS_FreeContext(ctx);
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ set -e
|
|||||||
mkdir -p out
|
mkdir -p out
|
||||||
mkdir -p out/system
|
mkdir -p out/system
|
||||||
|
|
||||||
bun build --outdir out/system src/system/src/index.ts
|
bun build --outdir out/system src/system/src/__.ts
|
||||||
@@ -4,9 +4,25 @@ set -e
|
|||||||
echo "#ifndef SYSTEM_PROG_H" > out/system/system_prog.h
|
echo "#ifndef SYSTEM_PROG_H" > out/system/system_prog.h
|
||||||
echo "#define SYSTEM_PROG_H" >> out/system/system_prog.h
|
echo "#define SYSTEM_PROG_H" >> out/system/system_prog.h
|
||||||
echo "const char* SYSTEM_PROG_JS = \\" >> out/system/system_prog.h
|
echo "const char* SYSTEM_PROG_JS = \\" >> out/system/system_prog.h
|
||||||
|
|
||||||
|
remove_mode=false
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
|
if [ "$remove_mode" = true ]; then
|
||||||
|
remove_mode=false
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
ESCAPED_LINE=$(echo "$line" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
|
ESCAPED_LINE=$(echo "$line" | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')
|
||||||
|
|
||||||
|
if echo "$line" | grep -q "___remove_next_line"; then
|
||||||
|
remove_mode=true
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
echo "\"${ESCAPED_LINE}\\n\"" >> out/system/system_prog.h
|
echo "\"${ESCAPED_LINE}\\n\"" >> out/system/system_prog.h
|
||||||
done < out/system/index.js
|
|
||||||
|
done < out/system/__.js
|
||||||
|
|
||||||
echo ";" >> out/system/system_prog.h
|
echo ";" >> out/system/system_prog.h
|
||||||
|
|
||||||
echo "#endif" >> out/system/system_prog.h
|
echo "#endif" >> out/system/system_prog.h
|
||||||
15
src/system/README.md
Normal file
15
src/system/README.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# lints-system
|
||||||
|
|
||||||
|
To install dependencies:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun install
|
||||||
|
```
|
||||||
|
|
||||||
|
To run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun run src/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.
|
||||||
10
src/system/src/__.ts
Normal file
10
src/system/src/__.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// DO NOT EDIT, REMOVE OR IMPORT THIS FILE
|
||||||
|
// This is used for bundler to not remove the KEntry function (called by C code)
|
||||||
|
// The function will be removed after bundling
|
||||||
|
|
||||||
|
import { KEntry } from "./entry";
|
||||||
|
declare function ___remove_next_line(): void;
|
||||||
|
|
||||||
|
// Mark the KEntry for removal
|
||||||
|
___remove_next_line();
|
||||||
|
KEntry();
|
||||||
3
src/system/src/entry.ts
Normal file
3
src/system/src/entry.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function KEntry() {
|
||||||
|
kc.println("Kernel entry point reached!");
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
kc.println("Kernel works!");
|
|
||||||
Reference in New Issue
Block a user