LuPPC/src/lua/core/boot.lua

60 lines
1.5 KiB
Lua
Raw Normal View History

2016-01-05 04:20:40 +11:00
local boot = {}
function boot.boot()
2016-01-07 07:32:53 +11:00
local gpu = modules.component.api.proxy(modules.component.api.list("gpu", true)())
local w, h = gpu.getResolution()
2016-01-07 08:25:01 +11:00
2016-01-10 05:39:48 +11:00
local function bsod(...)
2016-02-10 03:40:51 +11:00
local arg = {...}
pcall(function()
native.log("> LuPI BSOD")
for n, v in pairs(arg) do
native.log(tostring(v))
end
end)
pcall(function()
gpu.setBackground(0x0000FF)
gpu.setForeground(0xFFFFFF)
gpu.fill(1, 1, w, h, " ")
gpu.set(2, 2, "CRITICAL ERROR OCCURED")
gpu.set(2, 3, "Lua BIOS has failed:")
for n, v in pairs(arg) do
gpu.set(2, 4 + n, tostring(v))
end
gpu.set(2, h-1, "SYSTEM WILL STOP")
gpu.setForeground(0xFFFFFF)
gpu.setBackground(0x000000)
2016-01-07 08:25:01 +11:00
2016-02-10 03:40:51 +11:00
native.sleep(4000000)
os.exit(1)
end)
2016-01-10 05:39:48 +11:00
end
2016-01-07 07:32:53 +11:00
2016-01-10 05:39:48 +11:00
gpu.fill(1, 1, w, h, " ")
gpu.set(1, h - 2, "LuPI L2 INIT")
2016-01-07 07:32:53 +11:00
local code = modules.component.api.invoke(modules.component.api.list("eeprom", true)(), "get")
if not code then
2016-01-10 05:39:48 +11:00
bsod("No bootcode")
2016-01-07 07:32:53 +11:00
end
2016-01-10 05:39:48 +11:00
local f, reason = load(code, "=USERBIOS", nil, modules.sandbox)
2016-01-07 07:32:53 +11:00
if not f then
2016-01-10 05:39:48 +11:00
bsod(reason)
2016-01-07 07:32:53 +11:00
else
2016-02-10 03:40:51 +11:00
local crash = false
2016-01-10 05:39:48 +11:00
xpcall(f, function(e)
local trace = {}
2016-01-10 05:39:48 +11:00
for s in string.gmatch(debug.traceback(e, 2), "[^\r\n]+") do
trace[#trace + 1] = s
end
bsod("System crashed", "Stack traceback:", table.unpack(trace))
2016-02-10 03:40:51 +11:00
crash = true
2016-01-10 05:39:48 +11:00
end)
2016-02-10 03:40:51 +11:00
if not crash then
bsod("System quit")
end
2016-01-07 07:32:53 +11:00
end
2016-01-05 04:20:40 +11:00
end
return boot