From 137861d5d901e52e892720801567f3e89c89a5b0 Mon Sep 17 00:00:00 2001 From: sam Date: Fri, 8 May 2020 23:51:05 -0400 Subject: [PATCH] it's shit --- build.lua | 181 ++++++++++++++++++++++++++++++ docs/kargs.md | 22 ++++ ksrc/acl.lua | 0 ksrc/arcs/cpio/header.lua | 0 ksrc/arcs/tsar/init.lua | 79 +++++++++++++ ksrc/bios/zoryalegacy/detect.lua | 1 + ksrc/bios/zoryalegacy/info.lua | 5 + ksrc/bios/zoryalegacy/quirks.lua | 1 + ksrc/bios/zoryaneo/detect.lua | 1 + ksrc/bios/zoryaneo/info.lua | 5 + ksrc/bios/zoryaneo/quirks.lua | 0 ksrc/biosfixes.lua | 20 ++++ ksrc/buffer.lua | 0 ksrc/exec.lua | 15 +++ ksrc/execs/velx_spec/init.lua | 1 + ksrc/execs/velx_spec/tsar.lua | 0 ksrc/execs/velx_spec/velxspec.lua | 81 +++++++++++++ ksrc/execs/zlua/init.lua | 3 + ksrc/fs/foxfs/blkstream.lua | 1 + ksrc/fs/foxfs/dir.lua | 6 + ksrc/fs/foxfs/init.lua | 11 ++ ksrc/fs/foxfs/inode.lua | 33 ++++++ ksrc/fs/foxfs/mkfoxfs.lua | 0 ksrc/fs/foxfs/superblock.lua | 13 +++ ksrc/init.lua | 11 ++ ksrc/net/tsukinet/init.lua | 0 ksrc/security.lua | 14 +++ ksrc/stdlib/init.lua | 5 + ksrc/stdlib/thread.lua | 9 ++ ksrc/string.lua | 23 ++++ ksrc/struct.lua | 29 +++++ ksrc/threads.lua | 56 +++++++++ ksrc/tty.lua | 15 +++ tkrnl.velx | Bin 0 -> 2436 bytes 34 files changed, 641 insertions(+) create mode 100644 build.lua create mode 100644 docs/kargs.md create mode 100644 ksrc/acl.lua create mode 100644 ksrc/arcs/cpio/header.lua create mode 100644 ksrc/arcs/tsar/init.lua create mode 100644 ksrc/bios/zoryalegacy/detect.lua create mode 100644 ksrc/bios/zoryalegacy/info.lua create mode 100644 ksrc/bios/zoryalegacy/quirks.lua create mode 100644 ksrc/bios/zoryaneo/detect.lua create mode 100644 ksrc/bios/zoryaneo/info.lua create mode 100644 ksrc/bios/zoryaneo/quirks.lua create mode 100644 ksrc/biosfixes.lua create mode 100644 ksrc/buffer.lua create mode 100644 ksrc/exec.lua create mode 100644 ksrc/execs/velx_spec/init.lua create mode 100644 ksrc/execs/velx_spec/tsar.lua create mode 100644 ksrc/execs/velx_spec/velxspec.lua create mode 100644 ksrc/execs/zlua/init.lua create mode 100644 ksrc/fs/foxfs/blkstream.lua create mode 100644 ksrc/fs/foxfs/dir.lua create mode 100644 ksrc/fs/foxfs/init.lua create mode 100644 ksrc/fs/foxfs/inode.lua create mode 100644 ksrc/fs/foxfs/mkfoxfs.lua create mode 100644 ksrc/fs/foxfs/superblock.lua create mode 100644 ksrc/init.lua create mode 100644 ksrc/net/tsukinet/init.lua create mode 100644 ksrc/security.lua create mode 100644 ksrc/stdlib/init.lua create mode 100644 ksrc/stdlib/thread.lua create mode 100644 ksrc/string.lua create mode 100644 ksrc/struct.lua create mode 100644 ksrc/threads.lua create mode 100644 ksrc/tty.lua create mode 100644 tkrnl.velx 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 0000000000000000000000000000000000000000..57c815a6fc939eeb80758323b689e8e801309daf GIT binary patch literal 2436 zcmYL~dr%v70>^igK*>T$0=7ka>ask#DIpIYO^Zzlv8e5+C4`4Uy|CH+C0VoCU3NE= z$03B)X~mwrYHQWAfY%!xXRgpP+&S$?Vy`;Z(}MNYIZr~-Yk7D;tpZn?Txaf&`+ny8 z*XNJ#pWn?@fO!UXz%f<{{Xa3p9bid`=3*==NyCDLo&!0hr(Ck3H_uVZ9tSV9#KvTKne&@JCI_2AQ2MbVqySq zY1N@E&YzrcH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