it does work if you load compiled hypervisor

This commit is contained in:
minjaesong
2025-04-20 20:01:17 +09:00
parent 13061bc8fa
commit face633cfb
3 changed files with 40 additions and 8 deletions

View File

@@ -1,9 +1,26 @@
if (exec_args[1] === undefined) {
println("Usage: compile myfile.js")
println("The compiled file will be myfile.bin")
println("Usage: compile -le/-lo myfile.js")
println(" The compiled and linked file will be myfile.out")
return 1
}
const filenameWithoutExt = exec_args[1].substringBeforeLast(".")
_G.shell.execute(`gzip -c ${exec_args[1]} | writeto ${filenameWithoutExt}.gz`)
_G.shell.execute(`enc ${filenameWithoutExt}.gz ${filenameWithoutExt}.bin`)
_G.shell.execute(`rm ${filenameWithoutExt}.gz`)
// with linking
if (exec_args[2]) {
const filenameWithoutExt = exec_args[2].substringBeforeLast(".")
const tempFilename = generateRandomHashStr(32)
_G.shell.execute(`gzip -c ${exec_args[2]} | writeto ${tempFilename}.gz`)
_G.shell.execute(`enc ${tempFilename}.gz ${tempFilename}.bin`)
_G.shell.execute(`rm ${tempFilename}.gz`)
_G.shell.execute(`link -${exec_args[1][2]} ${tempFilename}.bin`)
_G.shell.execute(`mv ${tempFilename}.out ${filenameWithoutExt}.out`)
_G.shell.execute(`rm ${tempFilename}.bin`)
}
// with no linking
else {
const filenameWithoutExt = exec_args[1].substringBeforeLast(".")
_G.shell.execute(`gzip -c ${exec_args[1]} | writeto ${filenameWithoutExt}.gz`)
_G.shell.execute(`enc ${filenameWithoutExt}.gz ${filenameWithoutExt}.bin`)
_G.shell.execute(`rm ${filenameWithoutExt}.gz`)
}

View File

@@ -0,0 +1,14 @@
if (exec_args[1] === undefined) {
println("Usage: free ptr_in_hex")
println(" This will free the pointer loaded using 'load'")
return 1
}
// check for CUM header
const ptr = parseInt(exec_args[1], 16)
const magic = sys.peek(ptr)
if (magic != 0xA5) return 1
sys.free(ptr)

View File

@@ -12,7 +12,8 @@ if (magic != 0xA5) return 1
const source = sys.toObjectCode(ptr)
const wrapper = new Function("exec_args", `const g={exec_args};with(g){${source}}`);
//const wrapper = new Function("exec_args", `const g={exec_args};with(g){${source}}`);
const wrapper = new Function("_BIOS", "_G", "_TVDOS", "exec_args", source)
const newArgs = ["@ptr:"+ptr].concat(exec_args.slice(2))
wrapper(newArgs)
wrapper(_BIOS, _G, _TVDOS, newArgs)