local a=...a.beep(440,500)local b=a.screenCtl;local c=a.initfs;local d=a.disks;local e=a.architecture;local f={}f.LOG_Text=""f.version="HyperionOS V1.2.4"f.process="Kernel"f.users={[0]="root",[1]="User"}f.hostname="hyperion"f.groups={}f.uid=0;f.gid=0;f.status="start"f.key={}f.cache={}f.cache.preload={}f._G=_G;f.sleep=sleep;_G.sleep=nil;local g=false;function f.log(h,i,j)j=j or 0x6D6D6D;f.LOG_Text=f.LOG_Text..tostring(a:date()).." "..f.users[f.uid].." "..f.process.."["..tostring(i or"INFO").."]: "..h.."\n"if f.status=="start"then b:setTextColor(j)b:print(tostring(a:date()).." "..f.users[f.uid].." "..f.process.."["..tostring(i or"INFO").."]: "..h)elseif f.status=="term"then f.standbyTask=f.currentTask;f.currentTask=f.kernelTask;local k=f.vfs.open("/dev/console","w")f.vfs.devctl(k,"sfgc",j)f.vfs.write(k,tostring(a:date()).." "..f.users[f.uid].." "..f.process.."["..tostring(i or"INFO").."]: "..h.."\n")f.vfs.close(k)f.currentTask=f.standbyTask end end;function f.PANIC(h)if f.status~="Panic"then f.log("PANIC: "..h,"PANIC",0xFF0000)pcall(f["saveLog"])f.status="Panic"f.reason=h;b:enable()b:setTextColor(0xFF0000)b:setBackgroundColor(0x000000)b:clear()b:setCursorPos(1,1)b:print(f.LOG_Text)b:print("KERNEL PANIC!\n"..h.."\nSystem halted.")b:print("Press any key to continue...")f.exitMain=true end;while true do local l={a:getMachineEvent()}if l[1]=="keyPressed"then break end end;a.reboot=true;error("KERNEL PANIC")end;f.panic=f.PANIC;if g then b:setTextColor(0xFFFFFF)b:setBackgroundColor(0x0000FF)b:clear()local m,n=b:getSize()b:setCursorPos(3,5)b:print(":(")b:setCursorPos(3,7)b:print("Your PC ran into a problem and needs to restart. We're just collecting some error")b:setCursorPos(3,8)b:print("info, and then we'll restart for you.\n")b:setCursorPos(3,n-5)b:print("Stop code: average windows experience")b:setCursorPos(1,n)b:print("Press any key to continue... jk reboot it yourself lazy")while true do end end;f.log("Kernel loaded.")f.log("Mounting init disks...")d.refresh()c.update(d)f.disks={}for o,p in d.list()do f.disks[p.address]=p end;c.mount("$","/")local q=c.readAllText("/boot/fstab")local r=function(s,t,u)assert(#t==1,"only delim len 1 supported for now")u=(u or 0)-1;local v={}local w=""for x=1,#s do local j=string.sub(s,x,x)if#v~=u and j==t then table.insert(v,w)w=""else w=w..j end end;table.insert(v,w)return v end;if not c.isFile("/boot/boot.cfg")then f.log("First boot detected writing boot.cfg","INFO",0x00FF00)c.writeAllText("/boot/boot.cfg",c.readAllText("/boot/safeboot.cfg"))f.firstBoot=true end;local y,z=load(c.readAllText("/boot/boot.cfg"),"@boot.cfg")if not y then f.PANIC("Failed to load /boot/boot.cfg: "..tostring(z))end;local A,B=pcall(y)if not A then f.PANIC("Error in /boot/boot.cfg: "..tostring(B))end;f.config=B;local C=false;for x,p in ipairs(r(q,"\n"))do if p:sub(1,1)=="U"then local D=""for x=3,#p do if p:sub(x,x)==";"then if x==3 then f.log("Invalid fstab line... Skipping.","WARN",0xFF8800)C=true;break end;D=p:sub(3,x-1)end end;if not C then local E=p:sub(#D+4)c.mount(D,E)else C=false end end end;f.log("Disks initialized")function f.saveLog()if f.status=="running"then local k=f.vfs.open("/var/log/syslog.log","w")f.vfs.write(k,f.LOG_Text)f.vfs.close(k)else c.writeAllText("/var/log/syslog.log",f.LOG_Text)end end;function f.newFifo()local F={}F.push=function(G)table.insert(F,G)end;F.pop=function()return table.remove(F,1)end;return F end;function f.newUUID()local H="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"local I=""for x=1,#H do local j=H:sub(x,x)if j=="x"then I=I..string.format("%x",math.random(0,15))elseif j=="y"then I=I..string.format("%x",math.random(8,11))else I=I..j end end;return I end;f.syscalls={}local J={[0]={}}for x=0,100 do J[x]={}end;f.log("Gathering modules")for o,x in ipairs(c.list("/lib/modules"))do local K=c.list("/lib/modules/"..x)if not K then f.log("WARNING: could not list /lib/modules/"..x.." (skipping)","WARN",0xFF8800)else for o,p in ipairs(K)do local L=tonumber(p:sub(1,2))if L then J[L+1][#J[L+1]+1]="/lib/modules/"..x.."/"..p end end end end;f.ifs=c;f.apis=a.firmware;f.EFI=a;f.arch=e;f.initdisks=d;f.screen=b;f.processes={}f.fstab=q;f.kernelTask={name="kernel",status="R",pid=0,tgid=0,uid=0,fd={},exit="",sleep=0,ivs=0,vs=0,children={},syscallReturn={},cwd="/",timeSlice=0,lastTime=0,totalTime=0,numRuns=0}f.currentTask=f.kernelTask;function f.shutdown()f.exitMain=true;f.status="shutdown"end;function f.reboot()f.exitMain=true;f.status="reboot"end;f.syscalls["time"]=function()return f.EFI:getEpochMs()end;f.syscalls["date"]=function()return f.EFI:date()end;f.syscalls["log"]=f.log;f.syscalls["getUptime"]=function()return f.EFI:getUptime()end;f.syscalls["getUsername"]=function(M)return f.users[M or f.uid]end;f.syscalls["getHostname"]=function()return f.hostname end;f.syscalls["getHost"]=function()return f.apis._HOST end;f.syscalls["version"]=function()return f.version end;f.syscalls["setHostname"]=function(N)if f.uid~=0 then error("Permission denied")end;f.hostname=N end;f.syscalls["arch"]=function()return e end;f.syscalls["sysdump"]=function()local v={}for x,p in pairs(f.syscalls)do v[#v+1]=x end;return v end;f.syscalls["reboot"]=f.reboot;f.syscalls["shutdown"]=f.shutdown;f.log("Running modules")for o,O in ipairs(J)do for o,p in ipairs(O)do if f.config.showModLoad then f.log("Loading module "..p,"DBUG",0x00FFFF)end;local P=c.readAllText(p)if not P then f.panic("Failed to read module "..p)end;local Q,z=load(P,"@"..p)if not Q then f.panic("ModuLoadErr: "..tostring(z))end;local R,z=xpcall(Q,debug.traceback,f)if not R then f.panic("ModuRunErr: "..tostring(z))end;if f.config.showModLoad then f.log("Loaded module "..p,"DBUG",0x00FFFF)end end end;f.log("Kernel initialized successfully.")f.saveLog()f.status="running"b:disable()f.main()if f.status=="panic"then f.panic(f.reason)end;if f.status=="reboot"then a.reboot=true;return true end