made dev files (includeing tern) also fixed differnt keyboard layouts hopefully

This commit is contained in:
2026-02-13 17:01:00 -05:00
parent 33cd291c21
commit 403178c832
26 changed files with 728 additions and 683 deletions

View File

@@ -1,71 +1,79 @@
--:Minify:-- --:Minify:--
syscall.TTY_clear() syscall.open("/dev/tty/TTY1","r")
syscall.TTY_setTextColor(1) syscall.open("/dev/tty/TTY1","w")
syscall.TTY_setCursorPos(1, 1) syscall.open("/dev/null","r")
syscall.TTY_print("HyperionOS Bash Shell") syscall.devctl(1,"clear")
syscall.devctl(1,"sfgc",1)
syscall.devctl(1,"spos",1,1)
print("HyperionOS Bash Shell")
local str="" local str=""
local stopInput=false local stopInput=false
local inputIO=syscall.IO_getBoundQueue()
local pid=syscall.getpid()
local proc=0 local proc=0
local fs=require("sys.fs") local fs=require("sys.fs")
local timeout=false local timeout=false
syscall.setEnviron("SHELL","simpleshell") syscall.setEnviron("SHELL","simpleshell")
printInline("> ") printInline("> ")
syscall.sigcatch(function(sig)
if sig==1 then
syscall.kill(proc)
print("Terminated")
printInline("> ")
stopInput=false
end
end)
while true do while true do
local event = {syscall.IO_pullEvent()} if not stopInput then
if event[1] then local input=syscall.read(0)
if not stopInput then if input then
if event[1]=="keyTyped" then if input=="\b" then
if event[3]=="\b" then if #str>0 then
if #str>0 then str=str:sub(1,#str-1)
str=str:sub(1,#str-1) printInline("\b")
printInline("\b") end
elseif input=="\n" then
print("")
stopInput=true
if str == "" then
printInline("> ")
stopInput=false
else
local path=nil
local split=string.split(str, " ")
if fs.exists("/bin/"..split[1]) then
path="/bin/"..split[1]
elseif fs.exists("/bin/"..split[1]..".lua") then
path="/bin/"..split[1]..".lua"
end end
elseif event[3]=="\n" then if not path then
print("") print("Program not found")
stopInput=true
if str == "" then
printInline("> ") printInline("> ")
stopInput=false stopInput=false
else else
local path=nil local text = fs.readAllText(path)
local split=string.split(str, " ") local program, err = load(text, path)
if fs.exists("/bin/"..split[1]) then if not program then
path="/bin/"..split[1] print(err)
elseif fs.exists("/bin/"..split[1]..".lua") then
path="/bin/"..split[1]..".lua"
end
if not path then
print("Program not found")
printInline("> ") printInline("> ")
stopInput=false
else
local text = fs.readAllText(path)
local program, err = load(text, path)
if not program then
print(err)
printInline("> ")
end
syscall.IO_bind("bash:"..tostring(pid))
proc = syscall.spawn(program, path, nil, {table.unpack(split, 2)})
syscall.IO_bind(inputIO)
end end
str="" proc = syscall.spawn(function(...)
syscall.open("/dev/tty/TTY1","r")
syscall.open("/dev/tty/TTY1","w")
syscall.open("/dev/null","r")
program(...)
end, path, nil, {table.unpack(split, 2)})
end end
elseif event[1]=="keyTyped" and event[3]=="^d" then str=""
syscall.exit(0)
else
str=str..event[3]
printInline(event[3])
end end
else
str=str..input
printInline(input)
end end
timeout=false
else
timeout=true
end end
timeout=false
else else
timeout=true
end
if stopInput then
local exited, code = syscall.collect(proc) local exited, code = syscall.collect(proc)
if exited then if exited then
if code then if code then
@@ -73,20 +81,14 @@ while true do
end end
printInline("> ") printInline("> ")
stopInput=false stopInput=false
else
if event[1] then
if event[1]=="keyTyped" and event[3]=="^c" then
syscall.kill(proc)
print("Terminated")
printInline("> ")
stopInput=false
else
syscall.IO_pushEvent("bash:"..tostring(pid), table.unpack(event))
end
end
end end
timeout=true
end end
if timeout then if timeout then
sleep(.05) if stopInput then
sleep(.5)
else
sleep(.05)
end
end end
end end

View File

@@ -3,6 +3,6 @@ local file = syscall.open(args[1], "r")
local content="" local content=""
while content~=nil do while content~=nil do
content=syscall.read(file, 1024) content=syscall.read(file, 1024)
syscall.TTY_printInline(content) printInline(content)
end end
syscall.close(file) syscall.close(file)

View File

@@ -1 +1 @@
syscall.TTY_clear() syscall.devctl(1,"clear")

View File

@@ -1,49 +1,50 @@
--:Minify:-- --:Minify:--
syscall.TTY_print("HyperionOS lua") print("HyperionOS lua")
local str="" local str=""
local stopInput=false local stopInput=false
local timeout=false local timeout=false
local luaEnv=setmetatable({},{__index=_ENV}) local luaEnv=setmetatable({},{__index=_ENV})
printInline("> ") printInline("> ")
while true do while true do
local event = {syscall.IO_pullEvent()} local input=syscall.read(0)
if event[1] then if input then
if not stopInput then if input=="\b" then
if event[1]=="keyTyped" then if #str>0 then
if event[3]=="\b" then str=str:sub(1,#str-1)
if #str>0 then printInline("\b")
str=str:sub(1,#str-1)
printInline("\b")
end
elseif event[3]=="\n" then
print("")
stopInput=true
if str == "" then
printInline("> ")
stopInput=false
elseif str == "exit()" then
break
else
local func=load(str,"@Lua","t",luaEnv)
local ok,err = xpcall(func, debug.traceback)
if not ok then
print(err)
end
printInline("> ")
stopInput=false
str=""
end
else
str=str..event[3]
printInline(event[3])
end
end end
elseif input=="\n" then
print("")
stopInput=true
if str == "" then
printInline("> ")
stopInput=false
elseif str == "exit()" then
break
else
local func=load(str,"@Lua","t",luaEnv)
local ok,err = xpcall(func, debug.traceback)
if not ok then
print(err)
end
printInline("\n> ")
str=""
end
str=""
else
str=str..input
printInline(input)
end end
timeout=false timeout=false
else else
timeout=true timeout=true
end end
if timeout then if timeout then
sleep(.05) if stopInput then
sleep(.5)
else
sleep(.05)
end
end end
end end

View File

@@ -0,0 +1,4 @@
local syscalls=syscall.sysdump()
for i=1, #syscalls do
print(syscalls[i])
end

6
Src/Hyperion-core/lib/io Normal file
View File

@@ -0,0 +1,6 @@
local io = {}
local fs = require("sys.fs")
function io.open(path, mode)
return fs.open(path, mode)
end

View File

@@ -1,8 +1,6 @@
--:Minify:-- --:Minify:--
local kernel=... local kernel=...
local fs=require("sys.fs") local fs=require("sys.fs")
syscall.TTY_bind("tty0")
syscall.IO_bind("raw")
for i,v in pairs(kernel.processes) do for i,v in pairs(kernel.processes) do
kernel.log("Spawning kernel task "..i) kernel.log("Spawning kernel task "..i)
@@ -16,7 +14,6 @@ for i,v in pairs(kernel.processes) do
end, i) end, i)
end end
local eventQueues = {}
local files = fs.list("/bin/startup") local files = fs.list("/bin/startup")
if not files then error("Failed to list /bin/startup") end if not files then error("Failed to list /bin/startup") end
for i,v in ipairs(files) do for i,v in ipairs(files) do
@@ -30,37 +27,18 @@ for i,v in ipairs(files) do
syscall.spawn(function() syscall.spawn(function()
syscall.setUsername("User") syscall.setUsername("User")
syscall.setuid(1) syscall.setuid(1)
syscall.IO_bind("eventQueue:"..tostring(i))
local spot = #eventQueues+1
eventQueues[spot]="eventQueue:"..tostring(i)
local status, err = pcall(startupFunc) local status, err = pcall(startupFunc)
if not status then if not status then
kernel.log("Error executing startup script '" .. filepath .. "': " .. err, "ERROR") kernel.log("Error executing startup script '" .. filepath .. "': " .. err, "ERROR")
else else
kernel.log("Successfully executed startup script: " .. filepath, "INFO") kernel.log("Successfully executed startup script: " .. filepath, "INFO")
end end
local event={true}
while #event~=0 do
event={syscall.IO_pullEvent()}
end
end, "startup:" .. v) end, "startup:" .. v)
end end
end end
end end
local timeout=false
while true do while true do
local event = {syscall.IO_pullEvent()} sleep(1)
if event[1] then
for i,v in ipairs(eventQueues) do
syscall.IO_pushEvent(v, table.unpack(event))
end
timeout=false
else
timeout=true
end
if timeout then
sleep(.05)
end
kernel.saveLog() kernel.saveLog()
end end

View File

@@ -104,6 +104,12 @@ local ok, err = xpcall(function()
end end
end end
local acekeys={
[apis.keys.enter]="\n",
[apis.keys.tab]="\t",
[apis.keys.backspace]="\b"
}
function sleep(time) function sleep(time)
local stoptime = apis.os.clock() + (time) local stoptime = apis.os.clock() + (time)
while stoptime > apis.os.clock() do end while stoptime > apis.os.clock() do end
@@ -139,12 +145,10 @@ local ok, err = xpcall(function()
local Kernel = load(getFile(BOOT_DRIVE_PATH .. "/boot/kernel.lua"),"@Kernel") local Kernel = load(getFile(BOOT_DRIVE_PATH .. "/boot/kernel.lua"),"@Kernel")
local initFs = load(getFile(BOOT_DRIVE_PATH .. "/boot/cct/initdisks"),"@Init_disks")(apis) local initFs = load(getFile(BOOT_DRIVE_PATH .. "/boot/cct/initdisks"),"@Init_disks")(apis)
local fs = load(getFile(BOOT_DRIVE_PATH .. "/boot/initfs"), "@InitFs")() local fs = load(getFile(BOOT_DRIVE_PATH .. "/boot/initfs"), "@InitFs")()
local key = load(getFile(BOOT_DRIVE_PATH .. "/boot/cct/keys.lua"),"@keyhelper")(apis)
if not Kernel then displaySuperBadError("Could not load kernel.") end if not Kernel then displaySuperBadError("Could not load kernel.") end
if not initFs then displaySuperBadError("Could not load initdisks.") end if not initFs then displaySuperBadError("Could not load initdisks.") end
if not fs then displaySuperBadError("Could not load initfs.") end if not fs then displaySuperBadError("Could not load initfs.") end
if not key then displaySuperBadError("Could not load key helper.") end
local eventQueue = {} local eventQueue = {}
@@ -275,10 +279,13 @@ local ok, err = xpcall(function()
local event = {coroutine.yield()} local event = {coroutine.yield()}
if event[1] == "key" then if event[1] == "key" then
queueEvent("keyPressed", 1, event[2]) queueEvent("keyPressed", 1, event[2])
key(event, queueEvent) if acekeys[event[2]] then
queueEvent("keyTyped", 1, acekeys[event[2]])
end
elseif event[1] == "char" then
queueEvent("keyTyped", 1, event[2])
elseif event[1] == "key_up" then elseif event[1] == "key_up" then
queueEvent("keyReleased", 1, event[2]) queueEvent("keyReleased", 1, event[2])
key(event, queueEvent)
elseif event[1] == "disk" then elseif event[1] == "disk" then
queueEvent("componentAdded", "disk") queueEvent("componentAdded", "disk")
elseif event[1] == "disk_eject" then elseif event[1] == "disk_eject" then

View File

@@ -1,211 +0,0 @@
-- :Minify:--
local apis = ...
local keys = apis.keys
local tKeys = {}
tKeys[keys.space] = ' '
tKeys[keys.grave] = '`'
tKeys[keys.comma] = ','
tKeys[keys.minus] = '-'
tKeys[keys.period] = '.'
tKeys[keys.slash] = '/'
tKeys[keys.zero] = '0'
tKeys[keys.one] = '1'
tKeys[keys.two] = '2'
tKeys[keys.three] = '3'
tKeys[keys.four] = '4'
tKeys[keys.five] = '5'
tKeys[keys.six] = '6'
tKeys[keys.seven] = '7'
tKeys[keys.eight] = '8'
tKeys[keys.nine] = '9'
tKeys[keys.semicolon or keys.semiColon] = ';'
tKeys[keys.equals] = '='
tKeys[keys.a] = 'a'
tKeys[keys.b] = 'b'
tKeys[keys.c] = 'c'
tKeys[keys.d] = 'd'
tKeys[keys.e] = 'e'
tKeys[keys.f] = 'f'
tKeys[keys.g] = 'g'
tKeys[keys.h] = 'h'
tKeys[keys.i] = 'i'
tKeys[keys.j] = 'j'
tKeys[keys.k] = 'k'
tKeys[keys.l] = 'l'
tKeys[keys.m] = 'm'
tKeys[keys.n] = 'n'
tKeys[keys.o] = 'o'
tKeys[keys.p] = 'p'
tKeys[keys.q] = 'q'
tKeys[keys.r] = 'r'
tKeys[keys.s] = 's'
tKeys[keys.t] = 't'
tKeys[keys.u] = 'u'
tKeys[keys.v] = 'v'
tKeys[keys.w] = 'w'
tKeys[keys.x] = 'x'
tKeys[keys.y] = 'y'
tKeys[keys.z] = 'z'
tKeys[keys.leftBracket] = '['
tKeys[keys.backslash] = '\\'
tKeys[keys.rightBracket] = ']'
tKeys[keys.apostrophe] = "'"
tKeys[keys.enter] = '\n'
tKeys[keys.tab] = '\t'
tKeys[keys.backspace] = '\b'
tKeys[keys.insert] = '\x1b[2~'
tKeys[keys.delete] = '\x1b[3~'
tKeys[keys.right] = '\x1b[C'
tKeys[keys.left] = '\x1b[D'
tKeys[keys.down] = '\x1b[B'
tKeys[keys.up] = '\x1b[A'
tKeys[keys.pageUp] = '\x1b[5~'
tKeys[keys.pageDown] = '\x1b[6~'
tKeys[keys.home] = '\x1b[1~'
tKeys[keys["end"]] = '\x1b[4~'
-- tKeys[keys.capsLock] = '\x1b[capsLock'
-- tKeys[keys.scrollLock] = '\x1b[scrollLock'
-- tKeys[keys.numLock] = '\x1b[numLock'
-- if keys.printScreen then
-- tKeys[keys.printScreen] = '\x1b[printScreen'
-- end
-- tKeys[keys.pause] = '\x1b[pause'
tKeys[keys.f1] = '\x1b[11~'
tKeys[keys.f2] = '\x1b[12~'
tKeys[keys.f3] = '\x1b[13~'
tKeys[keys.f4] = '\x1b[14~'
tKeys[keys.f5] = '\x1b[15~'
tKeys[keys.f6] = '\x1b[17~'
tKeys[keys.f7] = '\x1b[18~'
tKeys[keys.f8] = '\x1b[19~'
tKeys[keys.f9] = '\x1b[20~'
tKeys[keys.f10] = '\x1b[21~'
tKeys[keys.f11] = '\x1b[23~'
tKeys[keys.f12] = '\x1b[24~'
-- tKeys[keys.f13] = '\x1b[25~'
-- tKeys[keys.f14] = '\x1b[26~'
-- tKeys[keys.f15] = '\x1b[28~'
-- tKeys[keys.f16] = '\x1b[29~'
-- tKeys[keys.f17] = '\x1b[31~'
-- tKeys[keys.f18] = '\x1b[32~'
-- tKeys[keys.f19] = '\x1b[33~'
-- tKeys[keys.f20] = '\x1b[34~'
-- tKeys[keys.f21] = '\x1b[42~'
-- tKeys[keys.f22] = '\x1b[43~'
-- tKeys[keys.f23] = '\x1b[44~'
-- tKeys[keys.f24] = '\x1b[45~'
-- tKeys[keys.f25] = '\x1b[46~'
-- Numpad
tKeys[keys.numPad0] = '0'
tKeys[keys.numPad1] = '1'
tKeys[keys.numPad2] = '2'
tKeys[keys.numPad3] = '3'
tKeys[keys.numPad4] = '4'
tKeys[keys.numPad5] = '5'
tKeys[keys.numPad6] = '6'
tKeys[keys.numPad7] = '7'
tKeys[keys.numPad8] = '8'
tKeys[keys.numPad9] = '9'
-- tKeys[340] = 'leftShift'
-- tKeys[341] = 'leftCtrl'
-- tKeys[342] = 'leftAlt'
-- tKeys[343] = 'leftSuper'
-- tKeys[344] = 'rightShift'
-- tKeys[345] = 'rightCtrl'
-- tKeys[346] = 'rightAlt'
-- tKeys[347] = 'rightSuper'
-- tKeys[348] = 'menu'
local shift = false
local ctrl = false
local alt = false
local function s(char)
if not shift then return char end
-- Letters
if char == "a" then return "A" end
if char == "b" then return "B" end
if char == "c" then return "C" end
if char == "d" then return "D" end
if char == "e" then return "E" end
if char == "f" then return "F" end
if char == "g" then return "G" end
if char == "h" then return "H" end
if char == "i" then return "I" end
if char == "j" then return "J" end
if char == "k" then return "K" end
if char == "l" then return "L" end
if char == "m" then return "M" end
if char == "n" then return "N" end
if char == "o" then return "O" end
if char == "p" then return "P" end
if char == "q" then return "Q" end
if char == "r" then return "R" end
if char == "s" then return "S" end
if char == "t" then return "T" end
if char == "u" then return "U" end
if char == "v" then return "V" end
if char == "w" then return "W" end
if char == "x" then return "X" end
if char == "y" then return "Y" end
if char == "z" then return "Z" end
-- Symbols
if char == "`" then return "~" end
if char == "1" then return "!" end
if char == "2" then return "@" end
if char == "3" then return "#" end
if char == "4" then return "$" end
if char == "5" then return "%" end
if char == "6" then return "^" end
if char == "7" then return "&" end
if char == "8" then return "*" end
if char == "9" then return "(" end
if char == "0" then return ")" end
if char == "-" then return "_" end
if char == "=" then return "+" end
if char == "[" then return "{" end
if char == "]" then return "}" end
if char == "\\" then return "|" end
if char == ";" then return ":" end
if char == "'" then return '"' end
if char == "," then return "<" end
if char == "." then return ">" end
if char == "/" then return "?" end
return char or ""
end
local function p()
local str = ""
if alt then str = str .. "\x1b" end
if ctrl then str = str .. "^" end
return str
end
return function(event, q)
if event[1] == "key" then
if event[2] == keys.leftCtrl or event[2] == keys.rightCtrl then
ctrl = true
return
elseif event[2] == keys.leftAlt or event[2] == keys.rightAlt then
alt = true
return
elseif event[2] == keys.leftShift or event[2] == keys.rightCtrl then
shift = true
return
end
q("keyTyped", 1, p() .. s(tKeys[event[2]]))
elseif event[1] == "key_up" then
if event[2] == keys.leftCtrl or event[2] == keys.rightCtrl then
ctrl = false
return
elseif event[2] == keys.leftAlt or event[2] == keys.rightAlt then
alt = false
return
elseif event[2] == keys.leftShift or event[2] == keys.rightCtrl then
shift = false
return
end
end
end

View File

@@ -0,0 +1,363 @@
-- :Minify:--
local kernel = ...
local apis = kernel.apis
local native = apis.peripheral
local sides = {"top", "bottom", "left", "right", "front", "back"}
local peripheral={}
function peripheral.getNames()
local results = {}
for n = 1, #sides do
local side = sides[n]
if native.isPresent(side) then
table.insert(results, side)
if native.hasType(side, "peripheral_hub") then
local remote = native.call(side, "getNamesRemote")
for _, name in ipairs(remote) do
table.insert(results, name)
end
end
end
end
return results
end
function peripheral.isPresent(name)
if native.isPresent(name) then
return true
end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
return true
end
end
return false
end
function peripheral.getType(peripheral)
if type(peripheral) == "string" then -- Peripheral name passed
if native.isPresent(peripheral) then
return native.getType(peripheral)
end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", peripheral) then
return native.call(side, "getTypeRemote", peripheral)
end
end
return nil
else
local mt = getmetatable(peripheral)
if not mt or mt.__name ~= "peripheral" or type(mt.types) ~= "table" then
error("bad argument #1 (table is not a peripheral)", 2)
end
return table.unpack(mt.types)
end
end
function peripheral.hasType(peripheral, peripheral_type)
if type(peripheral) == "string" then -- Peripheral name passed
if native.isPresent(peripheral) then
return native.hasType(peripheral, peripheral_type)
end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", peripheral) then
return native.call(side, "hasTypeRemote", peripheral, peripheral_type)
end
end
return nil
else
local mt = getmetatable(peripheral)
if not mt or mt.__name ~= "peripheral" or type(mt.types) ~= "table" then
error("bad argument #1 (table is not a peripheral)", 2)
end
return mt.types[peripheral_type] ~= nil
end
end
function peripheral.getMethods(name)
if native.isPresent(name) then
return native.getMethods(name)
end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
return native.call(side, "getMethodsRemote", name)
end
end
return nil
end
function peripheral.getName(peripheral)
local mt = getmetatable(peripheral)
if not mt or mt.__name ~= "peripheral" or type(mt.name) ~= "string" then
error("bad argument #1 (table is not a peripheral)", 2)
end
return mt.name
end
function peripheral.call(name, method, ...)
if native.isPresent(name) then
return native.call(name, method, ...)
end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and native.call(side, "isPresentRemote", name) then
return native.call(side, "callRemote", name, method, ...)
end
end
return nil
end
function peripheral.wrap(name)
local methods = peripheral.getMethods(name)
if not methods then
return nil
end
local types = { peripheral.getType(name) }
for i = 1, #types do types[types[i]] = true end
local result = setmetatable({}, {
__name = "peripheral",
name = name,
type = types[1],
types = types,
})
for _, method in ipairs(methods) do
result[method] = function(...)
return peripheral.call(name, method, ...)
end
end
return result
end
function peripheral.find(ty, filter)
local results = {}
for _, name in ipairs(peripheral.getNames()) do
if peripheral.hasType(name, ty) then
local wrapped = peripheral.wrap(name)
if filter == nil or filter(name, wrapped) then
table.insert(results, wrapped)
end
end
end
return table.unpack(results)
end
local icolors = {
[0x1] = 1, -- #000000
[0x2] = 2, -- #FFFFFF
[0x4] = 3, -- #FF0000
[0x8] = 4, -- #00FF00
[0x10] = 5, -- #0000FF
[0x20] = 6, -- #00FFFF
[0x40] = 7, -- #FF00FF
[0x80] = 8, -- #FFFF00
[0x100] = 9, -- #FF6D00
[0x200] = 10, -- #6DFF55
[0x400] = 11, -- #24FFFF
[0x800] = 12, -- #924900
[0x1000] = 13, -- #6D6D55
[0x2000] = 14, -- #DBDBAA
[0x4000] = 15, -- #6D00FF
[0x8000] = 16 -- #B6FF00
}
local colors = {
0x0001, -- #000000
0x0002, -- #FFFFFF
0x0004, -- #FF0000
0x0008, -- #00FF00
0x0010, -- #0000FF
0x0020, -- #00FFFF
0x0040, -- #FF00FF
0x0080, -- #FFFF00
0x0100, -- #FF6D00
0x0200, -- #6DFF55
0x0400, -- #24FFFF
0x0800, -- #924900
0x1000, -- #6D6D55
0x2000, -- #DBDBAA
0x4000, -- #6D00FF
0x8000 -- #B6FF00
}
local function write(text, term)
local x, y = term.getCursorPos()
local w, h = term.getSize()
for i = 1, #text do
local c = text:sub(i, i)
if c == "\n" then
y = y + 1
x = 1
elseif c == "\t" then
local tabSize = 4
local spaces = tabSize - ((x - 1) % tabSize)
term.write(string.rep(" ", spaces))
x = x + spaces
elseif c == "\b" then
if x > 1 then
x = x - 1
term.setCursorPos(x, y)
term.write(" ")
term.setCursorPos(x, y)
end
else
if x <= w and y <= h then
term.setCursorPos(x, y)
term.write(c)
x = x + 1
end
end
if x > w then
x = 1
y = y + 1
end
if y - 1 >= h then
term.scroll(1)
y = h
term.setCursorPos(x, y)
end
end
term.setCursorPos(x, y)
end
kernel.devfs.data.tty={}
local ctrl,alt = false, false
local function s(bool)
if bool then
return "T"
else
return "F"
end
end
local function newtty(obj, id, ev)
kernel.devfs.data["tty"][id] = function(op, mode)
if op=="type" then
return "character device"
elseif op=="open" then
local h = {
read=function(amount)
local rv=""
for i=1, amount or 1 do
local event = {ev()}
if event[1] then
rv=rv..event[1]
end
end
if rv=="" then rv=nil end
return rv
end,
write=function(content)
write(content, obj)
end,
size=function()
local s={obj.getSize()}
return table.concat(s,";")
end,
clear=function()
obj.clear()
obj.setCursorPos(1,1)
end,
gpos=function()
local s={obj.getCursorPos()}
return table.concat(s,";")
end,
spos=function(x,y)
return obj.setCursorPos(x,y)
end,
sfgc=function(c)
return obj.setTextColor(colors[c])
end,
sbgc=function(c)
return obj.setBackgroundColor(colors[c])
end,
gfgc=function()
return icolors[obj.getTextColor()]
end,
gbgc=function()
return icolors[obj.getBackgroundColor()]
end,
gctrl=function()
return s(ctrl)..";"..s(alt)
end
}
if mode=="rw" then
return h
elseif mode=="r" then
h["write"]=nil
return h
elseif mode=="w" then
h["read"]=nil
return h
end
end
end
end
local fifo = kernel.newFifo()
kernel.processes.cctmond = function()
local timeout = false
while true do
local event = {kernel.computer:getMachineEvent()}
if event[1] then
local eventType = event[1]
local charOrKey = event[3]
-- Update modifier keys
if eventType == "keyPressed" then
if charOrKey == apis.keys.leftCtrl or charOrKey == apis.keys.rightCtrl then
ctrl = true
elseif charOrKey == apis.keys.leftAlt or charOrKey == apis.keys.rightAlt then
alt = true
end
-- Handle Ctrl+C
if ctrl and charOrKey == apis.keys.c then
for _, task in ipairs(syscall.getTasks()) do
syscall.sigsend(task, 1) -- SIGINT
end
end
elseif eventType == "keyReleased" then
if charOrKey == apis.keys.leftCtrl or charOrKey == apis.keys.rightCtrl then
ctrl = false
elseif charOrKey == apis.keys.leftAlt or charOrKey == apis.keys.rightAlt then
alt = false
end
elseif eventType == "keyTyped" then
if charOrKey then fifo.push(charOrKey) end
end
timeout = false
else
timeout = true
end
if timeout then
sleep(0.05)
end
end
end
newtty(apis.term, "TTY1", fifo.pop)
for i,v in ipairs({peripheral.find("monitor")}) do
v.setTextScale(.5)
v.write("Initializing...")
newtty(v,"TTY"..tostring(i+1),function () end)
end

View File

@@ -1,164 +0,0 @@
-- :Minify:--
local kernel = ...
local apis = kernel.apis
local main = apis.term
local native = apis.peripheral
local sides = {"top", "bottom", "left", "right", "front", "back"}
local function getType(name)
if native.isPresent(name) then return native.getType(name) end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and
native.call(side, "isPresentRemote", name) then
return native.call(side, "getTypeRemote", name)
end
end
return nil
end
local function getNames()
local names = {}
for n = 1, #sides do
local side = sides[n]
if native.isPresent(side) then table.insert(names, side) end
if native.hasType(side, "peripheral_hub") then
local hubSides = native.call(side, "getConnectedSides")
for _, hubSide in ipairs(hubSides) do
table.insert(names, hubSide)
end
end
end
return names
end
local function wrapPeripheral(name)
if native.isPresent(name) then return wrapPeripheral(name) end
for n = 1, #sides do
local side = sides[n]
if native.hasType(side, "peripheral_hub") and
native.call(side, "isPresentRemote", name) then
return native.call(side, "wrapRemote", name)
end
end
return nil
end
local icolors = {
[0x1] = 1, -- #000000
[0x2] = 2, -- #FFFFFF
[0x4] = 3, -- #FF0000
[0x8] = 4, -- #00FF00
[0x10] = 5, -- #0000FF
[0x20] = 6, -- #00FFFF
[0x40] = 7, -- #FF00FF
[0x80] = 8, -- #FFFF00
[0x100] = 9, -- #FF6D00
[0x200] = 10, -- #6DFF55
[0x400] = 11, -- #24FFFF
[0x800] = 12, -- #924900
[0x1000] = 13, -- #6D6D55
[0x2000] = 14, -- #DBDBAA
[0x4000] = 15, -- #6D00FF
[0x8000] = 16 -- #B6FF00
}
local colors = {
0x0001, -- #000000
0x0002, -- #FFFFFF
0x0004, -- #FF0000
0x0008, -- #00FF00
0x0010, -- #0000FF
0x0020, -- #00FFFF
0x0040, -- #FF00FF
0x0080, -- #FFFF00
0x0100, -- #FF6D00
0x0200, -- #6DFF55
0x0400, -- #24FFFF
0x0800, -- #924900
0x1000, -- #6D6D55
0x2000, -- #DBDBAA
0x4000, -- #6D00FF
0x8000 -- #B6FF00
}
local function write(text, term)
local x, y = term.getCursorPos()
local w, h = term.getSize()
for i = 1, #text do
local c = text:sub(i, i)
if c == "\n" then
y = y + 1
x = 1
elseif c == "\t" then
local tabSize = 4
local spaces = tabSize - ((x - 1) % tabSize)
term.write(string.rep(" ", spaces))
x = x + spaces
elseif c == "\b" then
if x > 1 then
x = x - 1
term.setCursorPos(x, y)
term.write(" ")
term.setCursorPos(x, y)
end
else
if x <= w and y <= h then
term.setCursorPos(x, y)
term.write(c)
x = x + 1
end
end
if x > w then
x = 1
y = y + 1
end
if y - 1 >= h then
term.scroll(1)
y = h
term.setCursorPos(x, y)
end
end
term.setCursorPos(x, y)
end
local function newTTY(term)
local ret = {}
function ret.print(text) write(text .. "\n", term) end
function ret.printInline(text) write(text, term) end
function ret.clear()
term.clear()
term.setCursorPos(1, 1)
end
function ret.setCursorPos(x, y) term.setCursorPos(x, y) end
function ret.getCursorPos() return term.getCursorPos() end
function ret.getSize() return term.getSize() end
function ret.setBackgroundColor(color)
term.setBackgroundColor(colors[color])
end
function ret.setTextColor(color) term.setTextColor(colors[color]) end
function ret.getBackgroundColor()
return icolors[term.getBackgroundColor()]
end
function ret.getTextColor() return icolors[term.getTextColor()] end
return ret
end
kernel.tty.register("tty0", newTTY(main))
for _, name in ipairs(getNames()) do
local t = getType(name)
if t == "monitor" then
local monitorTerm = wrapPeripheral(name)
if not monitorTerm then
error("Failed to wrap monitor peripheral")
end
monitorTerm.setTextScale(0.5)
kernel.tty.register(name, newTTY(monitorTerm))
end
end

View File

@@ -34,8 +34,8 @@ function kernel.log(msg, level, c)
elseif kernel.status == "init" then elseif kernel.status == "init" then
kernel.standbyTask=kernel.currentTask kernel.standbyTask=kernel.currentTask
kernel.currentTask=kernel.kernelTask kernel.currentTask=kernel.kernelTask
kernel.tty.setTextColor(c) kernel.vfs.devctl(1,"sfgc",c)
kernel.tty.print(tostring(computer:time()).." "..kernel.username.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg) kernel.vfs.write(1,tostring(computer:time()).." "..kernel.username.." "..kernel.process.."["..tostring(level or "INFO").."]: "..msg)
kernel.currentTask=kernel.standbyTask kernel.currentTask=kernel.standbyTask
end end
end end
@@ -239,12 +239,19 @@ kernel.syscalls["version"]=function() return kernel.version end
kernel.syscalls["setHostname"]=function(name) if kernel.uid~=0 then error("Permission denied") end kernel.hostname=name end kernel.syscalls["setHostname"]=function(name) if kernel.uid~=0 then error("Permission denied") end kernel.hostname=name end
kernel.syscalls["setUsername"]=function(user) if kernel.uid~=0 then error("Permission denied") end kernel.currentTask.username=user end kernel.syscalls["setUsername"]=function(user) if kernel.uid~=0 then error("Permission denied") end kernel.currentTask.username=user end
kernel.syscalls["arch"]=function() return arch end kernel.syscalls["arch"]=function() return arch end
kernel.syscalls["sysdump"]=function()
local rv={}
for i,v in pairs(kernel.syscalls) do
rv[#rv+1] = i
end
return rv
end
kernel.syscalls["test"]=function() return true end kernel.syscalls["test"]=function() return true end
kernel.log("Running modules") kernel.log("Running modules")
for _,p in ipairs(modules) do for _,p in ipairs(modules) do
for _,v in ipairs(p) do for _,v in ipairs(p) do
if kernel.config.showModLoad then kernel.log("Loading module "..v, "DBUG") end if kernel.config.showModLoad then kernel.log("Loading module "..v, "DBUG", 5) end
local code=ifs.readAllText(v) local code=ifs.readAllText(v)
if not code then if not code then
kernel.log("ModuReadErr: "..v, "WARN", 8) kernel.log("ModuReadErr: "..v, "WARN", 8)
@@ -254,7 +261,7 @@ for _,p in ipairs(modules) do
if not func then kernel.panic("ModuLoadErr: "..tostring(err)) goto skip end if not func then kernel.panic("ModuLoadErr: "..tostring(err)) goto skip end
local status, err = xpcall(func,debug.traceback, kernel) local status, err = xpcall(func,debug.traceback, kernel)
if not status then kernel.panic("ModuRunErr: "..tostring(err)) end if not status then kernel.panic("ModuRunErr: "..tostring(err)) end
if kernel.config.showModLoad then kernel.log("Loaded module "..v, "DBUG") end if kernel.config.showModLoad then kernel.log("Loaded module "..v, "DBUG", 5) end
::skip:: ::skip::
end end
end end

View File

@@ -1,41 +0,0 @@
-- :Minify:--
local kernel = ...
local io = {}
kernel.io = io
io.eventq = {}
function io.pushEvent(queue, ...)
queue = tostring(queue)
if not io.eventq[queue] then io.eventq[queue] = {} end
io.eventq[queue][#io.eventq[queue] + 1] = {...}
end
function io.bind(queue)
queue = tostring(queue)
kernel.currentTask.eventq = queue
end
function io.pullEvent()
if io.eventq[kernel.currentTask.eventq] then
if #io.eventq[kernel.currentTask.eventq] == 1 then
local event = table.remove(io.eventq[kernel.currentTask.eventq] or {}, 1)
io.eventq[kernel.currentTask.eventq] = nil
return table.unpack(event)
end
local event =
table.remove(io.eventq[kernel.currentTask.eventq] or {}, 1)
if not event then return end
return table.unpack(event)
end
end
function io.getBoundQueue() return kernel.currentTask.eventq end
kernel.syscalls["IO_pushEvent"] = io.pushEvent
kernel.syscalls["IO_pullEvent"] = io.pullEvent
kernel.syscalls["IO_bind"] = io.bind
kernel.syscalls["IO_getBoundQueue"] = io.getBoundQueue
kernel.log("IO pipeline initialized")

View File

@@ -82,7 +82,8 @@ local function newFileObj(handle, mode, path, meta, type)
mode = mode, mode = mode,
path = path, path = path,
meta = meta, meta = meta,
type = type type = type,
refcount = 1
} }
end end
@@ -321,7 +322,9 @@ function vfs.open(path, mode)
end end
task.fd[fd] = newFileObj(handle, mode, path, meta, disk:type(diskPath)) task.fd[fd] = newFileObj(handle, mode, path, meta, disk:type(diskPath))
total = total + 1 if not disk.isvirt then
total = total + 1
end
return fd return fd
end end
@@ -331,17 +334,16 @@ function vfs.read(fd, count)
local file = task.fd[fd] local file = task.fd[fd]
if not file then error("EBADF") end if not file then error("EBADF") end
if not file.handle.read then error("EBADF") end if not file.handle.read then error("EBADF") end
if file.mode ~= "r" then error("EBADF") end
return file.handle.read(count or 1) return file.handle.read(count or 1)
end end
-- Write -- Write
function vfs.write(fd, content) function vfs.write(fd, content)
kernel.log(tostring(fd).."|"..content)
local task = kernel.currentTask local task = kernel.currentTask
local file = task.fd[fd] local file = task.fd[fd]
if not file then error("EBADF") end if not file then error("EBADF") end
if not file.handle.write then error("EBADF") end if not file.handle.write then error("EBADF") end
if file.mode ~= "w" and file.mode ~= "a" then error("EBADF") end
return file.handle.write(content) return file.handle.write(content)
end end
@@ -352,7 +354,6 @@ function vfs.pread(fd, count, offset)
if not file then error("EBADF") end if not file then error("EBADF") end
if not file.handle.read then error("EBADF") end if not file.handle.read then error("EBADF") end
if not file.handle.seek then error("EBADF") end if not file.handle.seek then error("EBADF") end
if file.mode ~= "r" then error("EBADF") end
file.handle.seek("set", offset) file.handle.seek("set", offset)
return file.handle.read(count or 1) return file.handle.read(count or 1)
end end
@@ -363,7 +364,6 @@ function vfs.pwrite(fd, content, offset)
if not file then error("EBADF") end if not file then error("EBADF") end
if not file.handle.write then error("EBADF") end if not file.handle.write then error("EBADF") end
if not file.handle.seek then error("EBADF") end if not file.handle.seek then error("EBADF") end
if file.mode ~= "w" and file.mode ~= "a" then error("EBADF") end
file.handle.seek("set", offset) file.handle.seek("set", offset)
return file.handle.write(content) return file.handle.write(content)
end end
@@ -392,11 +392,16 @@ function vfs.close(fd)
local task = kernel.currentTask local task = kernel.currentTask
local file = task.fd[fd] local file = task.fd[fd]
if not file then error("EBADF") end if not file then error("EBADF") end
if file.handle.close then
file.handle.close()
end
task.fd[fd] = nil task.fd[fd] = nil
total = total - 1 total = total - 1
file.refcount = file.refcount - 1
if file.refcount <= 0 then
if file.handle.close then
file.handle.close()
end
end
end end
-- Sendfile -- Sendfile
@@ -405,9 +410,7 @@ function vfs.sendfile(outfd, infd, count)
local inFile = task.fd[infd] local inFile = task.fd[infd]
local outFile = task.fd[outfd] local outFile = task.fd[outfd]
if not inFile or not outFile then error("EBADF") end if not inFile or not outFile then error("EBADF") end
if inFile.mode ~= "r" then error("EBADF") end
if not inFile.handle.read then error("EBADF") end if not inFile.handle.read then error("EBADF") end
if outFile.mode ~= "w" and outFile.mode ~= "a" then error("EBADF") end
if not outFile.handle.write then error("EBADF") end if not outFile.handle.write then error("EBADF") end
local data = inFile.handle.read(count or 1024) local data = inFile.handle.read(count or 1024)
if not data or data == "" then return end if not data or data == "" then return end
@@ -548,6 +551,52 @@ function vfs.getcwd() return kernel.currentTask.cwd end
function vfs.chdir(path) kernel.currentTask.cwd = path end function vfs.chdir(path) kernel.currentTask.cwd = path end
function vfs.dup(oldfd)
local task = kernel.currentTask
local file = task.fd[oldfd]
if not file then error("EBADF") end
checkSystemLimit()
local newfd = allocFD(task)
file.refcount = file.refcount + 1
task.fd[newfd] = file
total = total + 1
return newfd
end
function vfs.dup2(oldfd, newfd)
local task = kernel.currentTask
local file = task.fd[oldfd]
if not file then error("EBADF") end
if newfd < 0 or newfd >= kernel.config.maxFilesPerTask then
error("EBADF")
end
if oldfd == newfd then
return newfd
end
if task.fd[newfd] then
vfs.close(newfd)
end
checkSystemLimit()
file.refcount = file.refcount + 1
task.fd[newfd] = file
total = total + 1
return newfd
end
function vfs.devctl(fd, method, ...)
if not kernel.currentTask.fd[fd] then error("EBADF") end
if not kernel.currentTask.fd[fd].handle[method] then error("EINVAL") end
kernel.currentTask.fd[fd].handle[method](...)
end
-- Export syscalls -- Export syscalls
local sys = kernel.syscalls local sys = kernel.syscalls
sys["open"] = vfs.open sys["open"] = vfs.open
@@ -574,5 +623,8 @@ sys["mount"] = vfs.mount
sys["umount"] = vfs.umount sys["umount"] = vfs.umount
sys["getcwd"] = vfs.getcwd sys["getcwd"] = vfs.getcwd
sys["chdir"] = vfs.chdir sys["chdir"] = vfs.chdir
sys["dup"] = vfs.dup
sys["dup2"] = vfs.dup2
sys["devctl"] = vfs.devctl
kernel.log("VFS module loaded") kernel.log("VFS module loaded")

View File

@@ -5,6 +5,7 @@ local proxy = {}
local data = {} local data = {}
proxy.address = "devfs0000" proxy.address = "devfs0000"
proxy.isvirt = true
proxy.isReadOnly = function() return false end proxy.isReadOnly = function() return false end
proxy.spaceUsed = function() return 0 end proxy.spaceUsed = function() return 0 end
proxy.spaceTotal = function() return 0 end proxy.spaceTotal = function() return 0 end
@@ -140,4 +141,7 @@ function data.zero(op, mode)
end end
data["disk"]={} data["disk"]={}
kernel.devfs={}
kernel.devfs.data=data
kernel.devfs.proxy=proxy
kernel.disks["devfs0000"]=proxy kernel.disks["devfs0000"]=proxy

View File

@@ -4,6 +4,7 @@ local proxy = {}
local data = {} local data = {}
proxy.address = "tmpfs0000" proxy.address = "tmpfs0000"
proxy.isvirt = true
proxy.isReadOnly = function() return false end proxy.isReadOnly = function() return false end
-- Space functions (just placeholders) -- Space functions (just placeholders)
@@ -102,7 +103,7 @@ function proxy:type(path)
if #steps == 0 then return "directory" end if #steps == 0 then return "directory" end
for i=1,#steps do for i=1,#steps do
step = step[steps[i]] step = step[steps[i]]
if not step then error("ENOENT") end if not step then return false end
end end
if type(step) == "table" then return "directory" end if type(step) == "table" then return "directory" end
if type(step) == "string" then return "file" end if type(step) == "string" then return "file" end

View File

@@ -1,23 +1,22 @@
-- :Minify:-- ---- :Minify:--
local kernel = ... --local kernel = ...
--
local timeout = false --local timeout = false
kernel.processes.keventd = function() --kernel.processes.keventd = function()
while true do -- while true do
local event = {kernel.computer:getMachineEvent()} -- local event = {kernel.computer:getMachineEvent()}
if event[1] then -- if event[1] then
if event[1] == "keyTyped" then -- if event[1] == "keyTyped" then
if event[3] == "\x1b^s" then -- if event[3] == "\x1b^s" then
kernel.shutdown() -- kernel.shutdown()
elseif event[3] == "\x1b^r" then -- elseif event[3] == "\x1b^r" then
kernel.reboot() -- kernel.reboot()
end -- end
end -- end
kernel.io.pushEvent("raw", table.unpack(event)) -- timeout = false
timeout = false -- else
else -- timeout = true
timeout = true -- end
end -- if timeout then sleep(.05) end
if timeout then sleep(.05) end -- end
end --end
end

View File

@@ -0,0 +1,27 @@
--:Minify:--
local kernel = ...
local signal = {}
kernel.signal=signal
function signal.sigsend(pid, sig)
if sig<0 or sig>256 then error("EINVAL") end
local task = kernel.tasks[tostring(pid)]
if not task then error("ENOENT") end
if not task.sigq then return end
task.sigq[#task.sigq+1] = sig
end
function signal.sigcatch(handler)
kernel.currentTask.sigh=handler
if not kernel.currentTask.sigq then kernel.currentTask.sigq={} end
end
function signal.sigignore()
kernel.currentTask.sigh=nil
kernel.currentTask.sigq=nil
end
local s=kernel.syscalls
s["sigsend"] = signal.sigsend
s["sigcatch"] = signal.sigcatch
s["sigignore"] = signal.sigignore

View File

@@ -10,11 +10,5 @@ function socket.bind()
end end
kernel.syscalls["ioctl"]=function(fd, method, ...)
if not kernel.currentTask.fd[fd] then error("EBADF") end
if not kernel.currentTask.fd[fd][method] then error("EINVAL") end
end
kernel.socket=socket kernel.socket=socket
kernel.log("Loaded socket module") kernel.log("Loaded socket module")

View File

@@ -0,0 +1,5 @@
--:Minify:--
local kernel=...
kernel.vfs.open("/dev/null", "r")
kernel.vfs.open("/dev/tty/TTY1", "w")
kernel.vfs.open("/dev/null", "w")

View File

@@ -48,11 +48,7 @@ function sys.spawn(func, name, envars, args, tgid)
tgid = tgid or kernel.currentTask.tgid, tgid = tgid or kernel.currentTask.tgid,
username = kernel.username, username = kernel.username,
uid = kernel.uid, uid = kernel.uid,
fd = { fd = {},
[0]=kernel.currentTask.fd[0],
[1]=kernel.currentTask.fd[1],
[2]=kernel.currentTask.fd[2]
},
sleep = 0, sleep = 0,
ivs = 0, ivs = 0,
vs = 0, vs = 0,
@@ -64,10 +60,7 @@ function sys.spawn(func, name, envars, args, tgid)
timeSlice = 0, timeSlice = 0,
lastTime = 0, lastTime = 0,
totalTime = 0, totalTime = 0,
numRuns = 0, numRuns = 0
privacy = 0,
debugger = false,
eventq = kernel.currentTask.eventq
} }
table.insert(kernel.currentTask.children, tasks[tostring(id)]) table.insert(kernel.currentTask.children, tasks[tostring(id)])
@@ -135,8 +128,7 @@ function sys.kill(pid)
if not tasks[tostring(pid)] then if not tasks[tostring(pid)] then
return false, "Task does not exist" return false, "Task does not exist"
elseif not isEqualToAny(tasks[tostring(pid)].pid, table.unpack(children)) and elseif not isEqualToAny(tasks[tostring(pid)].pid, table.unpack(children)) and kernel.uid ~= 0 then
kernel.uid ~= 0 then
return false, "You do not own this task" return false, "You do not own this task"
elseif tasks[tostring(pid)].status == "Z" then elseif tasks[tostring(pid)].status == "Z" then
@@ -155,10 +147,9 @@ function sys.stop(pid)
if not tasks[tostring(pid)] then if not tasks[tostring(pid)] then
return false, "Task does not exist" return false, "Task does not exist"
elseif not isEqualToAny(tasks[tostring(pid)].pid, table.unpack(children)) and elseif not isEqualToAny(tasks[tostring(pid)].pid, table.unpack(children)) and kernel.uid ~= 0 then
kernel.uid ~= 0 then
return false, "You do not own this task" return false, "You do not own this task"
elseif tasks[tostring(pid)].status ~= "R" then elseif tasks[tostring(pid)].status ~= "R" then
return false, "Cannot stop non running task" return false, "Cannot stop non running task"
@@ -174,10 +165,9 @@ function sys.continue(pid)
if not tasks[tostring(pid)] then if not tasks[tostring(pid)] then
return false, "Task does not exist" return false, "Task does not exist"
elseif not isEqualToAny(tasks[tostring(pid)].pid, table.unpack(children)) and elseif not isEqualToAny(tasks[tostring(pid)].pid, table.unpack(children)) and kernel.uid ~= 0 then
kernel.uid ~= 0 then
return false, "You do not own this task" return false, "You do not own this task"
elseif tasks[tostring(pid)].status ~= "T" then elseif tasks[tostring(pid)].status ~= "T" then
return false, "Task is not stopped" return false, "Task is not stopped"
@@ -256,10 +246,8 @@ local function reapDeadTasks()
task.timeSlice = nil task.timeSlice = nil
task.syscallReturn = nil task.syscallReturn = nil
task.sleep = nil task.sleep = nil
for v, _ in ipairs(task.fd) do kernel.vfs.close(v) end for v, _ in ipairs(task.fd) do pcall(kernel.vfs.close,v) end
task.fd = nil task.fd = nil
task.debugger = nil
task.privacy = nil
task.reapTime = kernel.computer:time() + 30000 task.reapTime = kernel.computer:time() + 30000
elseif task.reapTime and kernel.computer:time() > task.reapTime and elseif task.reapTime and kernel.computer:time() > task.reapTime and
@@ -314,106 +302,118 @@ function kernel.main()
kernel.uid = task.uid kernel.uid = task.uid
kernel.process = task.name kernel.process = task.name
N = N + 1 N = N + 1
-- assign adaptive time slice -- assign adaptive time slice
task.timeSlice = math.min(Tmax, math.max(Tmin, B / (N ^ alpha))) task.timeSlice = math.min(Tmax, math.max(Tmin, B / (N ^ alpha)))
-- measure execution time if task.sigq and #task.sigq~=0 and task.sigh then
local startTime = kernel.computer:time() local coro = coroutine.create(task.sigh)
local ret if kernel.config.preempt then
if kernel.config.preempt then coroutine.resumeWithTimeout(coro, task.timeSlice, table.remove(task.sigq, 1))
ret = { else
coroutine.resumeWithTimeout( coroutine.resume(coro, table.remove(task.sigq, 1))
task.coro, end
task.timeSlice,
table.unpack(task.syscallReturn)
)
}
else
ret = {
coroutine.resume(
task.coro,
table.unpack(task.syscallReturn)
)
}
end end
local elapsed = kernel.computer:time() - startTime -- check for exit/stop
task.lastTime = elapsed if task.status=="R" then
task.totalTime = (task.totalTime or 0) + elapsed -- measure execution time
task.numRuns = (task.numRuns or 0) + 1 local startTime = kernel.computer:time()
local ret
if kernel.config.preempt then
ret = {
coroutine.resumeWithTimeout(
task.coro,
task.timeSlice,
table.unpack(task.syscallReturn)
)
}
else
ret = {
coroutine.resume(
task.coro,
table.unpack(task.syscallReturn)
)
}
end
taskTimes[#taskTimes + 1] = elapsed local elapsed = kernel.computer:time() - startTime
totalTaskTime = totalTaskTime + elapsed task.lastTime = elapsed
task.totalTime = (task.totalTime or 0) + elapsed
task.numRuns = (task.numRuns or 0) + 1
if elapsed <= Tmin then Tmin_hit = Tmin_hit + 1 end taskTimes[#taskTimes + 1] = elapsed
if elapsed >= Tmax then Tmax_hit = Tmax_hit + 1 end totalTaskTime = totalTaskTime + elapsed
-- handle task results if elapsed <= Tmin then Tmin_hit = Tmin_hit + 1 end
if ret[1] == "error" or ret[1] == false then if elapsed >= Tmax then Tmax_hit = Tmax_hit + 1 end
kernel.log("processHandlerException: " .. ret[2], "ERROR", 2)
task.status = "Z"
task.exit = "processHandlerException: " .. ret[2]
elseif ret[1] == "timeout" then -- handle task results
task.ivs = task.ivs + 1 if ret[1] == "error" or ret[1] == false then
task.syscallReturn = {} kernel.log("processHandlerException: " .. ret[2], "ERROR", 2)
task.status = "Z"
task.exit = "processHandlerException: " .. ret[2]
elseif ret[1] == "success" or ret[1] == true then elseif ret[1] == "timeout" then
task.vs = task.vs + 1 task.ivs = task.ivs + 1
task.syscallReturn = {}
if ret[2] == "syscall" then elseif ret[1] == "success" or ret[1] == true then
if kernel.syscalls[ret[3]] then task.vs = task.vs + 1
if kernel.config.debugSyscalls then
kernel.log("Task " .. task.pid .. " invoking syscall: " .. ret[3], "DBUG", 5)
for i = 4, #ret do if ret[2] == "syscall" then
kernel.log(" inval[" .. tostring(i - 3) .. "] = " .. tostring(ret[i]), "DBUG", 5) if kernel.syscalls[ret[3]] then
if kernel.config.debugSyscalls then
kernel.log("Task " .. task.pid .. " invoking syscall: " .. ret[3], "DBUG", 5)
for i = 4, #ret do
kernel.log(" inval[" .. tostring(i - 3) .. "] = " .. tostring(ret[i]), "DBUG", 5)
end
end end
end
local sysret = { local sysret = {
xpcall(kernel.syscalls[ret[3]], debug.traceback, table.unpack(ret, 4)) xpcall(kernel.syscalls[ret[3]], debug.traceback, table.unpack(ret, 4))
} }
if kernel.config.debugSyscalls then if kernel.config.debugSyscalls then
if not sysret[1] then if not sysret[1] then
kernel.log( kernel.log(
"Task " .. task.pid .. " syscall " .. ret[3] .. " failed: " .. tostring(sysret[2]), "ERROR", 2 "Task " .. task.pid .. " syscall " .. ret[3] .. " failed: " .. tostring(sysret[2]), "ERROR", 2
) )
else else
kernel.log( kernel.log(
"Task " .. task.pid .. " syscall " .. ret[3] .. " completed returning " .. tostring(#sysret - 1) .. " values", "DBUG", 5 "Task " .. task.pid .. " syscall " .. ret[3] .. " completed returning " .. tostring(#sysret - 1) .. " values", "DBUG", 5
) )
for i = 2, #sysret do for i = 2, #sysret do
if type(sysret[i]) == "table" then if type(sysret[i]) == "table" then
kernel.log( kernel.log(
" retval[" .. tostring(i - 1) .. "] = " .. table.serialize(sysret[i]),"DBUG", 5 " retval[" .. tostring(i - 1) .. "] = " .. table.serialize(sysret[i]),"DBUG", 5
) )
else else
kernel.log( kernel.log(
" retval[" .. tostring(i - 1) .. "] = " .. tostring(sysret[i]), "DBUG", 5 " retval[" .. tostring(i - 1) .. "] = " .. tostring(sysret[i]), "DBUG", 5
) )
end
end end
end end
end end
end
if not sysret[1] then if not sysret[1] then
task.syscallReturn = {false, sysret[2]} task.syscallReturn = {false, sysret[2]}
else
task.syscallReturn = {
true, table.unpack(sysret, 2)
}
end
else else
task.syscallReturn = { task.syscallReturn = {
true, table.unpack(sysret, 2) false, "Unknown syscall: " .. tostring(ret[3])
} }
end end
else
task.syscallReturn = {
false, "Unknown syscall: " .. tostring(ret[3])
}
end end
end end
end end

View File

@@ -1,3 +0,0 @@
--:Minify:--
local kernel=...
kernel.tty.bind("tty0")

View File

@@ -5,13 +5,13 @@ function print(...)
local output = "" local output = ""
for i = 1, #args do output = output .. tostring(args[i]) .. "\t" end for i = 1, #args do output = output .. tostring(args[i]) .. "\t" end
output = output:sub(1, -2) output = output:sub(1, -2)
syscall.TTY_print(output) syscall.write(1, output.."\n")
end end
function printf(fmt, ...) function printf(fmt, ...)
coroutine.yield() coroutine.yield()
local output = string.format(fmt, ...) local output = string.format(fmt, ...)
syscall.TTY_print(output) syscall.write(1, output.."\n")
end end
function printInline(...) function printInline(...)
@@ -20,5 +20,5 @@ function printInline(...)
local output = "" local output = ""
for i = 1, #args do output = output .. tostring(args[i]) .. "\t" end for i = 1, #args do output = output .. tostring(args[i]) .. "\t" end
output = output:sub(1, -2) output = output:sub(1, -2)
syscall.TTY_printInline(output) syscall.write(1, output)
end end

View File

@@ -0,0 +1,14 @@
256 signals
| ID | Name / Description |
| -- | ---------------------------------------------------------------------------------------------------------------------------|
| 01 | SIGINT / send with ctrl + c
| 02 |
| 03 |
| 04 |
| 05 |
| 06 |
| 07 |
| 08 |
| 09 |
| 0A |