-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.lua
More file actions
92 lines (80 loc) · 2.74 KB
/
kernel.lua
File metadata and controls
92 lines (80 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-- Phoenix Kernel v0.0.9
--
-- Copyright (c) 2021-2025 JackMacWindows. All rights reserved.
-- This is a PRE-RELEASE BUILD! Redistribution of this file is not permitted.
-- See the Phoenix EULA (https://github.com/Phoenix-ComputerCraft/kernel/blob/master/LICENSE.md) for more information.
if _ENV ~= _G then error("Phoenix must be run in the global environment, with a bootloader such as pxboot or UnBIOS. It cannot be run as a normal program.") end
--- Version number of Phoenix.
PHOENIX_VERSION = "0.0.9"
--- Build string of Phoenix.
PHOENIX_BUILD = "PRERELEASE NONFREE $BUILD_DATE$"
--- Stores the start time of the kernel.
systemStartTime = os.epoch "utc"
--- Stores all kernel arguments passed on the command line.
args = {
init = "/sbin/init.lua",
root = "/root",
rootfstype = "craftos",
preemptive = true,
quantum = 20000,
splitkernpath = "/boot/kernel.lua.d",
loglevel = 1,
console = "tty1",
traceback = true
}
--- Contains every syscall defined in the kernel.
syscalls = {}
--- Stores all currently running processes.
---@type Process[]
processes = {
[0] = {
name = "kernel",
id = 0,
user = "root",
dir = "/",
root = "/",
env = _G,
vars = {},
dependents = {}
}
}
--- Stores a quick reference to the kernel process object.
KERNEL = processes[0]
--- Stores all currently loaded kernel modules.
modules = {}
--- Stores a list of hooks to call on certain CraftOS events. Each entry has the
-- event name as a key, and a list of functions to call as the value. The
-- functions are called with a single table parameter with the event parameters.
eventHooks = {}
-- Stores a list of functions to call before clean shutdown.
shutdownHooks = {}
-- Stores functions that are used for debug hooks.
debugHooks = setmetatable({}, {__mode = "k"})
-- Unique keys for certain internal uses.
kSyscallYield = {}
kSyscallComplete = {}
--- Process API
process = {}
--- Filesystem API
filesystem = {}
--- Terminal API
terminal = {}
--- System logger API
syslog = {}
--- Hardware API
hardware = {}
if discord then discord("Phoenix", "Booting Phoenix " .. PHOENIX_VERSION) end
-- ==== LOADER ====
for _, v in ipairs(fs.list(fs.combine(args.root, args.splitkernpath))) do
local file, err = fs.open(fs.combine(args.root, args.splitkernpath, v), "rb")
if not file then (panic or error)("Could not read kernel part " .. v .. ": " .. err) end
local fn, err = (loadstring or load)(file.readAll(), "=kernel:" .. v, "t", _ENV)
file.close()
if not fn then (panic or error)("Could not load kernel part " .. v .. ": " .. err) end
fn(...)
end
-- == END LOADER ==
if init_retval ~= nil then
syslog.log({level = 4}, "init exited with result", init_retval)
end
panic("init program exited")