/* 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) } function startNewInstanceOnVT(vtIndex) { if (isNaN(index) || index !== index) throw Error("VT index must be a numeric value") if (index <= 0) throw Error(`VT index cannot be zero or negative (${vtIndex})`) // Ensure VT exists if (!_TVDOS.VT_CONTEXTS[vtIndex]) { mkdevvt(vtIndex) } // Create context with VT binding let contextInit = `_TVDOS.CURRENT_VT = ${vtIndex};${bios}` runner = parallel.attachProgram(`TVDOS-VT${vtIndex}`, parallel.spawnNewContext(), contextInit) serial.println(`Starting new instance ${runner} on VT${vtIndex}`) parallel.launch(runner) sys.sleep(50) } const randomkeypusher = ` while (1) { sys.poke(-38, 65 + (Math.random()*26)|0) sys.poke(-50, 1) sys.sleep(10) sys.poke(-50, 0) sys.sleep(90) } ` function startNewRandomKeyPusher() { runner = parallel.attachProgram("TVDOS", parallel.spawnNewContext(), randomkeypusher) parallel.launch(runner) } ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // initial kickstart graphics.setBackground(34,51,68) println("== h y v e ============================================== Hypervisor for tsvm ==") startNewInstance() //startNewRandomKeyPusher() while (parallel.isRunning(runner)) { if (sys.peek(-49) >>> 7 == 1) { sys.poke(-49, 0) parallel.kill(runner) sys.sleep(50) graphics.clearText() graphics.clearPixels(255) startNewInstance() } else if (sys.peek(-49) >>> 6 == 1) { sys.poke(-49, 0) let threads = parallel.getThreadPool() serial.println("======================") serial.println("Currently running threads:") for (let i = 0; i < threads.length; i++) { serial.println(`Thread #${i+1}: ${threads[i]}`) } serial.println("======================") sys.sleep(300) } sys.sleep(0) } println(" LX4 cya!")