mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
100 lines
2.3 KiB
Plaintext
100 lines
2.3 KiB
Plaintext
/*
|
|
hyve is a hypervisor for tsvm.
|
|
|
|
## hyve boot sequence
|
|
|
|
0. bios starts up
|
|
1. bootloader calls hyve.js
|
|
2. hyve sets up itself, spawns new context which runs TVDOS.SYS
|
|
3. hands the control over to the TVDOS until SysRq sequence is struck
|
|
*/
|
|
|
|
const bios = `
|
|
// probe bootable device
|
|
|
|
var _BIOS = {};
|
|
|
|
// Syntax: [Port, Drive-number]
|
|
// Port #0-3: Serial port 1-4
|
|
// #4+ : Left for future extension
|
|
// Drive-number always starts at 1
|
|
_BIOS.HYVE = true;
|
|
_BIOS.FIRST_BOOTABLE_PORT = [0,1]; // ah screw it
|
|
|
|
Object.freeze(_BIOS);
|
|
|
|
// load a bootsector using 'LOADBOOT'
|
|
let portNumber = 0;
|
|
let driveStatus = 0;
|
|
let guestExit = false;
|
|
while (portNumber < 4) {
|
|
if (com.areYouThere(portNumber)) {
|
|
com.sendMessage(portNumber,"DEVRST\x17");
|
|
com.sendMessage(portNumber, 'OPENR"tvdos/TVDOS.SYS",'+_BIOS.FIRST_BOOTABLE_PORT[1]);
|
|
driveStatus = com.getStatusCode(portNumber);
|
|
if (driveStatus == 0) break;
|
|
}
|
|
portNumber += 1;
|
|
}
|
|
if (portNumber < 4) {
|
|
com.sendMessage(portNumber,"READ");
|
|
let r = com.getStatusCode(portNumber);
|
|
if (r == 0) {
|
|
let g = com.pullMessage(portNumber);
|
|
eval(g);
|
|
}
|
|
else {
|
|
println("I/O Error");
|
|
}
|
|
}
|
|
else {
|
|
printerrln("No bootable medium found.");
|
|
}
|
|
`
|
|
|
|
let runner = undefined
|
|
|
|
function startNewInstance() {
|
|
runner = parallel.attachProgram("TVDOS", parallel.spawnNewContext(), bios)
|
|
serial.println("Starting new instance "+runner)
|
|
parallel.launch(runner)
|
|
sys.sleep(1000)
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
// initial kickstart
|
|
graphics.setBackground(34,51,68)
|
|
println("== h y v e ============================================== Hypervisor for tsvm ==")
|
|
|
|
startNewInstance()
|
|
|
|
while (parallel.isRunning(runner)) {
|
|
if (sys.peek(-49) >>> 7 == 1) {
|
|
sys.poke(-49, 0)
|
|
|
|
parallel.kill(runner)
|
|
|
|
graphics.clearText()
|
|
graphics.clearPixels(255)
|
|
|
|
startNewInstance()
|
|
}
|
|
else if (sys.peek(-49) >>> 6 == 1) {
|
|
sys.poke(-49, 0)
|
|
|
|
let threads = parallel.getThreadPool()
|
|
|
|
serial.println("======================")
|
|
for (let i = 0; i < threads.size; i++) {
|
|
serial.println(`Thread #${i+1}: ${threads[i]}`)
|
|
}
|
|
serial.println("======================")
|
|
|
|
sys.sleep(300)
|
|
}
|
|
sys.sleep(0)
|
|
}
|
|
|
|
println(" LX4 cya!") |