6 changed files with 159 additions and 9 deletions
@ -1,15 +1,29 @@ |
|||
local boot = {} |
|||
|
|||
function boot.boot() |
|||
local gpu = modules.component.api.proxy(modules.component.api.list("gpu", true)()) |
|||
local w, h = gpu.getResolution() |
|||
print("r= " .. tostring(w) .. " " .. tostring(h)) |
|||
gpu.fill(0, 0, w, h, " ") |
|||
gpu.set(10, 5, "HHHHHHHHHHHHH") |
|||
print("LuPI L2 INIT") |
|||
print("FIXME: boot stub") |
|||
native.sleep(1000000) |
|||
error("Unable to boot") |
|||
local gpu = modules.component.api.proxy(modules.component.api.list("gpu", true)()) |
|||
local w, h = gpu.getResolution() |
|||
print("r= " .. tostring(w) .. " " .. tostring(h)) |
|||
gpu.fill(0, 0, w, h, " ") |
|||
gpu.set(10, 5, "HHHHHHHHHHHHH") |
|||
gpu.set(11, 11, "VVVVVVVVVVVVVVVVV", true) |
|||
print("LuPI L2 INIT") |
|||
print("FIXME: boot stub") |
|||
native.sleep(1000000) |
|||
|
|||
local code = modules.component.api.invoke(modules.component.api.list("eeprom", true)(), "get") |
|||
if not code then |
|||
print("No bootcode") |
|||
error("No bootcode") |
|||
end |
|||
---PASS SANDBOX!!!!!! |
|||
local f, reason = load(code, "=BIOS") |
|||
if not f then |
|||
print(reason) |
|||
else |
|||
f() |
|||
print("System quit, Panic") |
|||
end |
|||
end |
|||
|
|||
return boot |
|||
|
@ -0,0 +1,68 @@ |
|||
local eeprom = {} |
|||
local default = moduleCode["eepromDefault"] |
|||
local size = 4092 |
|||
local dataSize = 256 |
|||
|
|||
function eeprom.register() |
|||
local component = {} |
|||
function component.get() |
|||
local h = io.open("usereeprom.lua", "r") |
|||
if h then |
|||
local data = h:read("*a") |
|||
h:close() |
|||
return data |
|||
else |
|||
return default |
|||
end |
|||
end |
|||
function component.set(data) |
|||
checkArg(1, data, "string") |
|||
data = data:sub(1, size) |
|||
local h = io.open("usereeprom.lua", "w") |
|||
if not h then |
|||
error("Critical: Cannot open EERPOM file") |
|||
end |
|||
h:write(data) |
|||
h:close() |
|||
end |
|||
function component.getLabel() |
|||
return "LUA BIOS" |
|||
end |
|||
function component.setLabel() |
|||
return nil, "Cannot set label" |
|||
end |
|||
function component.getSize() |
|||
return size |
|||
end |
|||
function component.getData() |
|||
local h = io.open("usereepromdata.lua", "r") |
|||
if h then |
|||
local data = h:read("*a") |
|||
h:close() |
|||
return data |
|||
else |
|||
return default |
|||
end |
|||
end |
|||
function component.setData(data) |
|||
checkArg(1, data, "string") |
|||
data = data:sub(1, dataSize) |
|||
local h = io.open("usereepromdata.lua", "w") |
|||
if not h then |
|||
error("Critical: Cannot open EERPOM file") |
|||
end |
|||
h:write(data) |
|||
h:close() |
|||
end |
|||
|
|||
--FIXME: Implement |
|||
function component.getChecksum() |
|||
error("Method stub") |
|||
end |
|||
function component.makeReadonly() |
|||
return false, "Method stub" |
|||
end |
|||
modules.component.api.register(nil, "eeprom", component) |
|||
end |
|||
|
|||
return eeprom |
@ -0,0 +1,61 @@ |
|||
local component_invoke = component.invoke |
|||
function boot_invoke(address, method, ...) |
|||
local result = table.pack(pcall(component_invoke, address, method, ...)) |
|||
if not result[1] then |
|||
return nil, result[2] |
|||
else |
|||
return table.unpack(result, 2, result.n) |
|||
end |
|||
end |
|||
|
|||
-- backwards compatibility, may remove later |
|||
local eeprom = component.list("eeprom")() |
|||
computer.getBootAddress = function() |
|||
return boot_invoke(eeprom, "getData") |
|||
end |
|||
computer.setBootAddress = function(address) |
|||
return boot_invoke(eeprom, "setData", address) |
|||
end |
|||
|
|||
do |
|||
local screen = component.list("screen")() |
|||
local gpu = component.list("gpu")() |
|||
if gpu and screen then |
|||
boot_invoke(gpu, "bind", screen) |
|||
end |
|||
end |
|||
local function tryLoadFrom(address) |
|||
local handle, reason = boot_invoke(address, "open", "/init.lua") |
|||
if not handle then |
|||
return nil, reason |
|||
end |
|||
local buffer = "" |
|||
repeat |
|||
local data, reason = boot_invoke(address, "read", handle, math.huge) |
|||
if not data and reason then |
|||
return nil, reason |
|||
end |
|||
buffer = buffer .. (data or "") |
|||
until not data |
|||
boot_invoke(address, "close", handle) |
|||
return load(buffer, "=init") |
|||
end |
|||
local init, reason |
|||
if computer.getBootAddress() then |
|||
init, reason = tryLoadFrom(computer.getBootAddress()) |
|||
end |
|||
if not init then |
|||
computer.setBootAddress() |
|||
for address in component.list("filesystem") do |
|||
init, reason = tryLoadFrom(address) |
|||
if init then |
|||
computer.setBootAddress(address) |
|||
break |
|||
end |
|||
end |
|||
end |
|||
if not init then |
|||
error("no bootable medium found" .. (reason and (": " .. tostring(reason)) or ""), 0) |
|||
end |
|||
computer.beep(1000, 0.2) |
|||
init() |
Loading…
issues.context.reference_issue