commit 137861d5d901e52e892720801567f3e89c89a5b0 Author: sam Date: Fri May 8 23:51:05 2020 -0400 it's shit diff --git a/build.lua b/build.lua new file mode 100644 index 0000000..fc25987 --- /dev/null +++ b/build.lua @@ -0,0 +1,181 @@ +--[[---------------------------------------------------------------------------- + LZSS - encoder / decoder + This is free and unencumbered software released into the public domain. + Anyone is free to copy, modify, publish, use, compile, sell, or + distribute this software, either in source code form or as a compiled + binary, for any purpose, commercial or non-commercial, and by any + means. + In jurisdictions that recognize copyright laws, the author or authors + of this software dedicate any and all copyright interest in the + software to the public domain. We make this dedication for the benefit + of the public at large and to the detriment of our heirs and + successors. We intend this dedication to be an overt act of + relinquishment in perpetuity of all present and future rights to this + software under copyright law. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + For more information, please refer to +--]]---------------------------------------------------------------------------- +-------------------------------------------------------------------------------- +local M = {} +local string, table = string, table + +-------------------------------------------------------------------------------- +local POS_BITS = 12 +local LEN_BITS = 16 - POS_BITS +local POS_SIZE = 1 << POS_BITS +local LEN_SIZE = 1 << LEN_BITS +local LEN_MIN = 3 + +-------------------------------------------------------------------------------- +function M.compress(input) + local offset, output = 1, {} + local window = '' + + local function search() + for i = LEN_SIZE + LEN_MIN - 1, LEN_MIN, -1 do + local str = string.sub(input, offset, offset + i - 1) + local pos = string.find(window, str, 1, true) + if pos then + return pos, str + end + end + end + + while offset <= #input do + local flags, buffer = 0, {} + + for i = 0, 7 do + if offset <= #input then + local pos, str = search() + if pos and #str >= LEN_MIN then + local tmp = ((pos - 1) << LEN_BITS) | (#str - LEN_MIN) + buffer[#buffer + 1] = string.pack('>I2', tmp) + else + flags = flags | (1 << i) + str = string.sub(input, offset, offset) + buffer[#buffer + 1] = str + end + window = string.sub(window .. str, -POS_SIZE) + offset = offset + #str + else + break + end + end + + if #buffer > 0 then + output[#output + 1] = string.char(flags) + output[#output + 1] = table.concat(buffer) + end + end + + return table.concat(output) +end + +-------------------------------------------------------------------------------- +function M.decompress(input) + local offset, output = 1, {} + local window = '' + + while offset <= #input do + local flags = string.byte(input, offset) + offset = offset + 1 + + for i = 1, 8 do + local str = nil + if (flags & 1) ~= 0 then + if offset <= #input then + str = string.sub(input, offset, offset) + offset = offset + 1 + end + else + if offset + 1 <= #input then + local tmp = string.unpack('>I2', input, offset) + offset = offset + 2 + local pos = (tmp >> LEN_BITS) + 1 + local len = (tmp & (LEN_SIZE - 1)) + LEN_MIN + str = string.sub(window, pos, pos + len - 1) + end + end + flags = flags >> 1 + if str then + output[#output + 1] = str + window = string.sub(window .. str, -POS_SIZE) + end + end + end + + return table.concat(output) +end + + +local function struct(tbl) + local pat = tbl.endian or "=" + local args = {} + for i=1, #tbl do + local a, b = pairs(tbl[i]) + local k, v = a(b) + args[i] = k + pat = pat .. v + end + return setmetatable({}, {__call=function(_, arg) + --checkArg(1, arg, "string", "table") + if (type(arg) == "string") then + local sval = {string.unpack(pat, arg)} + local rtn = {} + for i=1, #args do + rtn[args[i]] = sval[i] + end + return rtn, sval[#sval] + elseif (type(arg) == "table") then + local sval = {} + for i=1, #args do + sval[i] = arg[args[i]] + end + return string.pack(pat, unpack(sval)) + end + end, __len=function() + return string.packsize(pat) + end}) +end + +local velx_spec = struct { + endian = "<", + {magic="c5"}, + {compression="B"}, + {lver="B"}, + {fver="B"}, + {os="B"}, + {psize="I3"}, + {lsize="I3"}, + {ssize="I3"}, + {rsize="I4"} +} + +-- This builds Tsuki into a VELX executable. +print("Compiling kernel...") +local h = io.popen("luacomp ksrc/init.lua") +print("Compressing kernel...") +local data = M.compress(h:read("*a")) +print("Writing out tkrnl.velx...") +local h = io.open("tkrnl.velx", "wb") +local header = velx_spec({ + magic = "\27VelX", + compression = 1, + lver = 0x53, + fver = 1, + os = 0xFF, + psize = #data, + lsize=0, + ssize=0, + rsize=0 +}) + +h:write(header) +h:write(data) +h:close() \ No newline at end of file diff --git a/docs/kargs.md b/docs/kargs.md new file mode 100644 index 0000000..8926e2a --- /dev/null +++ b/docs/kargs.md @@ -0,0 +1,22 @@ +# Kernel Arguments + + /boot/kernel/tsuki-0.1.velx [arguments ...] + +## --security +This argument changes the security enviroment of the Tsuki kernel. + +### --security=none +This disables most of Tsuki's security modules, leaving the system in a vulnerable state. + +### --security=noverify +This disables executable verification. This is default. + +### --security=full +This enables all security features. + +### --security=permissive +This makes all security errors into logged messages. + +## --root=partspec +This mounts the partition as the root (`/`). An example partspec would be `osdi(f81aa211-3552-4196-91f6-57cc51c3ebfb,2)` + diff --git a/ksrc/acl.lua b/ksrc/acl.lua new file mode 100644 index 0000000..e69de29 diff --git a/ksrc/arcs/cpio/header.lua b/ksrc/arcs/cpio/header.lua new file mode 100644 index 0000000..e69de29 diff --git a/ksrc/arcs/tsar/init.lua b/ksrc/arcs/tsar/init.lua new file mode 100644 index 0000000..3f0c841 --- /dev/null +++ b/ksrc/arcs/tsar/init.lua @@ -0,0 +1,79 @@ +local magic = 0x5f7d +local magic_rev = 0x7d5f +local header = "I2I2I2I2I2I6I6" + +local function read_header(dat) + local e = "<" + local m = string.unpack(" 0) then + self.seek(self.tbl[i].pos-self.seek(0)) + return self.read(self.tbl[i].filesize), self.tbl[i] + end + end + return nil, "file not found" +end + +function arc:exists(path) + for i=1, #self.tbl do + if (self.tbl[i].name == path) then + return true + end + end + return false +end + +function arc:list(path) + if path:sub(#path) ~= "/" then path = path .. "/" end + local ent = {} + for i=1, #self.tbl do + if (self.tbl[i].name:sub(1, #path) == path and not self.tbl[i].name:find("/", #path+1, false)) then + ent[#ent+1] = self.tbl[i].name + end + end + return ent +end + +function arc:meta(path) + for i=1, #self.tbl do + if (self.tbl[i].name == path) then + return self.tbl[i] + end + end + return nil, "file not found" +end + +function arc:close() + self.close() +end + +return { + read = function(read, seek, close) + local tbl = {} + local lname = "" + while lname ~= "TRAILER!!!" do + local dat = read(22) + local et = read_header(dat) + et.name = read(et.namesize) + et.pos = seek(et.namesize & 1) + seek(et.filesize + (et.filesize & 1)) + lname = et.name + if lname ~= "TRAILER!!!" then + tbl[#tbl+1] = et + end + end + return setmetatable({tbl = tbl, read = read, seek = seek, close = close}, {__index=arc}) + end +} \ No newline at end of file diff --git a/ksrc/bios/zoryalegacy/detect.lua b/ksrc/bios/zoryalegacy/detect.lua new file mode 100644 index 0000000..eaefdc4 --- /dev/null +++ b/ksrc/bios/zoryalegacy/detect.lua @@ -0,0 +1 @@ +return _LOAD == "Zorya" \ No newline at end of file diff --git a/ksrc/bios/zoryalegacy/info.lua b/ksrc/bios/zoryalegacy/info.lua new file mode 100644 index 0000000..215730c --- /dev/null +++ b/ksrc/bios/zoryalegacy/info.lua @@ -0,0 +1,5 @@ +return { + name = "Zorya", + version = {_ZVER//1, tonumber(tostring(_ZVER):match("%.(%d+)")), _ZPAT, string = _ZVER..".".._ZPAT}, + oefiver = oefi.getAPIVersion() +} \ No newline at end of file diff --git a/ksrc/bios/zoryalegacy/quirks.lua b/ksrc/bios/zoryalegacy/quirks.lua new file mode 100644 index 0000000..16593e3 --- /dev/null +++ b/ksrc/bios/zoryalegacy/quirks.lua @@ -0,0 +1 @@ +zorya = nil \ No newline at end of file diff --git a/ksrc/bios/zoryaneo/detect.lua b/ksrc/bios/zoryaneo/detect.lua new file mode 100644 index 0000000..7ef66ad --- /dev/null +++ b/ksrc/bios/zoryaneo/detect.lua @@ -0,0 +1 @@ +return _BIOS == "Zorya NEO" \ No newline at end of file diff --git a/ksrc/bios/zoryaneo/info.lua b/ksrc/bios/zoryaneo/info.lua new file mode 100644 index 0000000..631d3ab --- /dev/null +++ b/ksrc/bios/zoryaneo/info.lua @@ -0,0 +1,5 @@ +return { + name = "Zorya NEO", + version = {_ZVER//1, tonumber(tostring(_ZVER):match("%.(%d+)")), _ZPAT, git = _ZGIT, string = _ZVSTR}, + loader = _ZLOADER +} \ No newline at end of file diff --git a/ksrc/bios/zoryaneo/quirks.lua b/ksrc/bios/zoryaneo/quirks.lua new file mode 100644 index 0000000..e69de29 diff --git a/ksrc/biosfixes.lua b/ksrc/biosfixes.lua new file mode 100644 index 0000000..33b2c6e --- /dev/null +++ b/ksrc/biosfixes.lua @@ -0,0 +1,20 @@ +local _biossupport = {} +@[[function biosfix(bios)]] +_biossupport["@[{bios}]"] = { + quirks = function() +--#include @[{"ksrc/bios/"..bios.."/quirks.lua"}] + end, + info = function() +--#include @[{"ksrc/bios/"..bios.."/info.lua"}] + end, + detect = function() +--#include @[{"ksrc/bios/"..bios.."/detect.lua"}] + end, + name = "@[{bios}]" +} +@[[end]] + +@[[biosfix("zoryalegacy")]] +@[[biosfix("zoryaneo")]] + +@[[biosfix = nil]] \ No newline at end of file diff --git a/ksrc/buffer.lua b/ksrc/buffer.lua new file mode 100644 index 0000000..e69de29 diff --git a/ksrc/exec.lua b/ksrc/exec.lua new file mode 100644 index 0000000..62b5d31 --- /dev/null +++ b/ksrc/exec.lua @@ -0,0 +1,15 @@ + +local velx = (function() +--#include "ksrc/execs/velx_spec/init.lua" +end)() + +local zlua = (function() +--#include "ksrc/execs/zlua/init.lua" +end) + +-- Executable loading process: +-- - Link +-- - Load +-- - Execute + +if () \ No newline at end of file diff --git a/ksrc/execs/velx_spec/init.lua b/ksrc/execs/velx_spec/init.lua new file mode 100644 index 0000000..fd3f5cb --- /dev/null +++ b/ksrc/execs/velx_spec/init.lua @@ -0,0 +1 @@ +--#include "ksrc/execs/velx_spec/velxspec.lua" diff --git a/ksrc/execs/velx_spec/tsar.lua b/ksrc/execs/velx_spec/tsar.lua new file mode 100644 index 0000000..e69de29 diff --git a/ksrc/execs/velx_spec/velxspec.lua b/ksrc/execs/velx_spec/velxspec.lua new file mode 100644 index 0000000..1b0b46a --- /dev/null +++ b/ksrc/execs/velx_spec/velxspec.lua @@ -0,0 +1,81 @@ +local velx_spec = struct { + endian = "<", + {magic="c5"}, + {fver="B"}, + {compression="B"}, + {lver="B"}, + {os="B"}, + {psize="I3"}, + {lsize="I3"}, + {ssize="I3"}, + {rsize="I4"} +} + +local velx = {} + +local exec = {} + +function velx.identify(path) + local h = io.open(path, "rb") + local header = velx_spec(h:read(#velx_spec)) + h:close() + return header.magic == "\27VelX" +end + +function velx.load(path) + +end + +function velx.verify(path) + local h = io.open(path, "rb") + local header = velx_spec(h:read(#velx_spec)) + local code = h:read(header.psize) + h:seek("cur", lsize) + local sig = h:read(header.ssize) + h:close() + return security.verify(code, sig) +end + +function exec:link() + self.file:seek("set", #velx_spec+self.header.psize) + local linkinfo = self.file:read(self.header.lsize) + local linker = {} + local pos = 1 + while true do + local size = string.unpack("= computer.uptime()) then + rthd[#rthd+1] = threads[i] + end + end + table.sort(rthd, function(a, b) + if (a.priority == b.priority) then + return a.deadline < b.deadline + end + return a.priority < b.priority + end) + local starttime = computer.uptime() + local mindl = math.huge + for i=1, #rthd do + local ok, dl = coroutine.resume(rthd[i].coro, table.unpack(rthd[i].args or lastsig)) + if (not ok or coroutine.status(rthd[i].coro) == "dead") then + signal.push(thd.get(rthd[i].parent), {"subproc", "dead", rthd[i].pid, (rthd[i].exitcode or (dl and 1) or 0)}) + for j=1, #thd do + if (threads[j] == rthd[i]) then + mfd[#mfd+1] = j + break + end + end + else + mindl = ((mindl > dl) and dl) or mindl + buffers.update(rthd[i]) + if (rthd[i].sigpushed) then + mindl = 0 + rthd[i].sigpushed = false + end + end + if (computer.uptime() >= starttime+max_proctime) then + goto cleanup + end + end + ::cleanup:: + for i=#mfd, 1, -1 do + table.remove(threads, mfd[i]) + end + lastsig = table.pack(computer.pullSignal(mindl)) +end + +function thd.add(tinfo) + +end \ No newline at end of file diff --git a/ksrc/tty.lua b/ksrc/tty.lua new file mode 100644 index 0000000..ba0ce8f --- /dev/null +++ b/ksrc/tty.lua @@ -0,0 +1,15 @@ +local tty = {} +do + local _tty = {} + function _tty:getgpu() + return self.gpu.address + end + + function _tty:getkb() + return self.kb.address + end + + function _tty:getscreen() + return self.screen.address + end +end \ No newline at end of file diff --git a/tkrnl.velx b/tkrnl.velx new file mode 100644 index 0000000..57c815a Binary files /dev/null and b/tkrnl.velx differ