xref: /freebsd/stand/lua/core.lua (revision bac5966e2d1b4cd7cb4d0cfab7a013d2af8054e5)
1088b4f5fSWarner Losh--
272e39d71SKyle Evans-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
372e39d71SKyle Evans--
4088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5beaafe4fSKyle Evans-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
6088b4f5fSWarner Losh-- All rights reserved.
7088b4f5fSWarner Losh--
8088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without
9088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions
10088b4f5fSWarner Losh-- are met:
11088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright
12088b4f5fSWarner Losh--    notice, this list of conditions and the following disclaimer.
13088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright
14088b4f5fSWarner Losh--    notice, this list of conditions and the following disclaimer in the
15088b4f5fSWarner Losh--    documentation and/or other materials provided with the distribution.
16088b4f5fSWarner Losh--
17088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20088b4f5fSWarner Losh-- ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27088b4f5fSWarner Losh-- SUCH DAMAGE.
28088b4f5fSWarner Losh--
29088b4f5fSWarner Losh-- $FreeBSD$
30088b4f5fSWarner Losh--
31088b4f5fSWarner Losh
32011eae6cSKyle Evanslocal config = require("config")
33aea262bfSKyle Evanslocal hook = require("hook")
34fa4a2394SKyle Evans
35aedd6be5SKyle Evanslocal core = {}
36088b4f5fSWarner Losh
371613f091SKyle Evanslocal default_safe_mode = false
381613f091SKyle Evanslocal default_single_user = false
391613f091SKyle Evanslocal default_verbose = false
401613f091SKyle Evans
41322a2dddSKyle Evanslocal function composeLoaderCmd(cmd_name, argstr)
429f71d421SKyle Evans	if argstr ~= nil then
43aedd6be5SKyle Evans		cmd_name = cmd_name .. " " .. argstr
446d4ed94dSKyle Evans	end
45aedd6be5SKyle Evans	return cmd_name
466d4ed94dSKyle Evansend
476d4ed94dSKyle Evans
481613f091SKyle Evanslocal function recordDefaults()
491613f091SKyle Evans	-- On i386, hint.acpi.0.rsdp will be set before we're loaded. On !i386,
501613f091SKyle Evans	-- it will generally be set upon execution of the kernel. Because of
511613f091SKyle Evans	-- this, we can't (or don't really want to) detect/disable ACPI on !i386
521613f091SKyle Evans	-- reliably. Just set it enabled if we detect it and leave well enough
531613f091SKyle Evans	-- alone if we don't.
541613f091SKyle Evans	local boot_acpi = core.isSystem386() and core.getACPIPresent(false)
551613f091SKyle Evans	local boot_single = loader.getenv("boot_single") or "no"
561613f091SKyle Evans	local boot_verbose = loader.getenv("boot_verbose") or "no"
571613f091SKyle Evans	default_single_user = boot_single:lower() ~= "no"
581613f091SKyle Evans	default_verbose = boot_verbose:lower() ~= "no"
591613f091SKyle Evans
601613f091SKyle Evans	if boot_acpi then
611613f091SKyle Evans		core.setACPI(true)
621613f091SKyle Evans	end
631613f091SKyle Evans	core.setSingleUser(default_single_user)
641613f091SKyle Evans	core.setVerbose(default_verbose)
651613f091SKyle Evansend
661613f091SKyle Evans
671613f091SKyle Evans
6807faaf78SKyle Evans-- Globals
695beb5507SKyle Evans-- try_include will return the loaded module on success, or false and the error
705beb5507SKyle Evans-- message on failure.
7107faaf78SKyle Evansfunction try_include(module)
72*bac5966eSKyle Evans	if module:sub(1, 1) ~= "/" then
73*bac5966eSKyle Evans		local lua_path = loader.lua_paths
74*bac5966eSKyle Evans		-- XXX Temporary compat shim; this should be removed once the
75*bac5966eSKyle Evans		-- loader.lua_path export has sufficiently spread.
76*bac5966eSKyle Evans		if lua_path == nil then
77*bac5966eSKyle Evans			lua_path = "/boot/lua"
7807faaf78SKyle Evans		end
79*bac5966eSKyle Evans		module = lua_path .. "/" .. module
80*bac5966eSKyle Evans		-- We only attempt to append an extension if an absolute path
81*bac5966eSKyle Evans		-- wasn't specified.  This assumes that the caller either wants
82*bac5966eSKyle Evans		-- to treat this like it would require() and specify just the
83*bac5966eSKyle Evans		-- base filename, or they know what they're doing as they've
84*bac5966eSKyle Evans		-- specified an absolute path and we shouldn't impede.
85*bac5966eSKyle Evans		if module:match(".lua$") == nil then
86*bac5966eSKyle Evans			module = module .. ".lua"
87*bac5966eSKyle Evans		end
88*bac5966eSKyle Evans	end
89*bac5966eSKyle Evans	if lfs.attributes(module, "mode") ~= "file" then
90*bac5966eSKyle Evans		return
91*bac5966eSKyle Evans	end
92*bac5966eSKyle Evans
93*bac5966eSKyle Evans	return dofile(module)
9407faaf78SKyle Evansend
9507faaf78SKyle Evans
96b5746545SKyle Evans-- Module exports
97fe672a15SKyle Evans-- Commonly appearing constants
98aedd6be5SKyle Evanscore.KEY_BACKSPACE	= 8
99aedd6be5SKyle Evanscore.KEY_ENTER		= 13
100aedd6be5SKyle Evanscore.KEY_DELETE		= 127
101fe672a15SKyle Evans
102230061c5SKyle Evans-- Note that this is a decimal representation, despite the leading 0 that in
103230061c5SKyle Evans-- other contexts (outside of Lua) may mean 'octal'
104aedd6be5SKyle Evanscore.KEYSTR_ESCAPE	= "\027"
1052bb86aefSKyle Evanscore.KEYSTR_CSI		= core.KEYSTR_ESCAPE .. "["
10639006570SKyle Evans
107aedd6be5SKyle Evanscore.MENU_RETURN	= "return"
108aedd6be5SKyle Evanscore.MENU_ENTRY		= "entry"
109aedd6be5SKyle Evanscore.MENU_SEPARATOR	= "separator"
110aedd6be5SKyle Evanscore.MENU_SUBMENU	= "submenu"
111aedd6be5SKyle Evanscore.MENU_CAROUSEL_ENTRY	= "carousel_entry"
112a7cf0562SKyle Evans
11304af4229SKyle Evansfunction core.setVerbose(verbose)
11404af4229SKyle Evans	if verbose == nil then
11504af4229SKyle Evans		verbose = not core.verbose
116088b4f5fSWarner Losh	end
117088b4f5fSWarner Losh
11804af4229SKyle Evans	if verbose then
119aedd6be5SKyle Evans		loader.setenv("boot_verbose", "YES")
120088b4f5fSWarner Losh	else
121aedd6be5SKyle Evans		loader.unsetenv("boot_verbose")
122088b4f5fSWarner Losh	end
12304af4229SKyle Evans	core.verbose = verbose
124088b4f5fSWarner Loshend
125088b4f5fSWarner Losh
12604af4229SKyle Evansfunction core.setSingleUser(single_user)
12704af4229SKyle Evans	if single_user == nil then
12804af4229SKyle Evans		single_user = not core.su
129088b4f5fSWarner Losh	end
130088b4f5fSWarner Losh
13104af4229SKyle Evans	if single_user then
132aedd6be5SKyle Evans		loader.setenv("boot_single", "YES")
133088b4f5fSWarner Losh	else
134aedd6be5SKyle Evans		loader.unsetenv("boot_single")
135088b4f5fSWarner Losh	end
13604af4229SKyle Evans	core.su = single_user
137088b4f5fSWarner Loshend
138088b4f5fSWarner Losh
13904af4229SKyle Evansfunction core.getACPIPresent(checking_system_defaults)
140aedd6be5SKyle Evans	local c = loader.getenv("hint.acpi.0.rsdp")
1416401094fSKyle Evans
1429f71d421SKyle Evans	if c ~= nil then
14304af4229SKyle Evans		if checking_system_defaults then
144aedd6be5SKyle Evans			return true
1456401094fSKyle Evans		end
1466401094fSKyle Evans		-- Otherwise, respect disabled if it's set
147aedd6be5SKyle Evans		c = loader.getenv("hint.acpi.0.disabled")
1489f71d421SKyle Evans		return c == nil or tonumber(c) ~= 1
1496401094fSKyle Evans	end
150aedd6be5SKyle Evans	return false
1516401094fSKyle Evansend
1526401094fSKyle Evans
15304af4229SKyle Evansfunction core.setACPI(acpi)
15404af4229SKyle Evans	if acpi == nil then
15504af4229SKyle Evans		acpi = not core.acpi
156088b4f5fSWarner Losh	end
157088b4f5fSWarner Losh
15804af4229SKyle Evans	if acpi then
159aedd6be5SKyle Evans		loader.setenv("acpi_load", "YES")
160aedd6be5SKyle Evans		loader.setenv("hint.acpi.0.disabled", "0")
161aedd6be5SKyle Evans		loader.unsetenv("loader.acpi_disabled_by_user")
162088b4f5fSWarner Losh	else
163aedd6be5SKyle Evans		loader.unsetenv("acpi_load")
164aedd6be5SKyle Evans		loader.setenv("hint.acpi.0.disabled", "1")
165aedd6be5SKyle Evans		loader.setenv("loader.acpi_disabled_by_user", "1")
166088b4f5fSWarner Losh	end
16704af4229SKyle Evans	core.acpi = acpi
168088b4f5fSWarner Loshend
169088b4f5fSWarner Losh
17004af4229SKyle Evansfunction core.setSafeMode(safe_mode)
17104af4229SKyle Evans	if safe_mode == nil then
17204af4229SKyle Evans		safe_mode = not core.sm
173088b4f5fSWarner Losh	end
17404af4229SKyle Evans	if safe_mode then
175aedd6be5SKyle Evans		loader.setenv("kern.smp.disabled", "1")
176aedd6be5SKyle Evans		loader.setenv("hw.ata.ata_dma", "0")
177aedd6be5SKyle Evans		loader.setenv("hw.ata.atapi_dma", "0")
178aedd6be5SKyle Evans		loader.setenv("hw.ata.wc", "0")
179aedd6be5SKyle Evans		loader.setenv("hw.eisa_slots", "0")
180aedd6be5SKyle Evans		loader.setenv("kern.eventtimer.periodic", "1")
181aedd6be5SKyle Evans		loader.setenv("kern.geom.part.check_integrity", "0")
182088b4f5fSWarner Losh	else
183aedd6be5SKyle Evans		loader.unsetenv("kern.smp.disabled")
184aedd6be5SKyle Evans		loader.unsetenv("hw.ata.ata_dma")
185aedd6be5SKyle Evans		loader.unsetenv("hw.ata.atapi_dma")
186aedd6be5SKyle Evans		loader.unsetenv("hw.ata.wc")
187aedd6be5SKyle Evans		loader.unsetenv("hw.eisa_slots")
188aedd6be5SKyle Evans		loader.unsetenv("kern.eventtimer.periodic")
189aedd6be5SKyle Evans		loader.unsetenv("kern.geom.part.check_integrity")
190088b4f5fSWarner Losh	end
19104af4229SKyle Evans	core.sm = safe_mode
192088b4f5fSWarner Loshend
193088b4f5fSWarner Losh
194aea262bfSKyle Evansfunction core.clearCachedKernels()
19535b0c718SKyle Evans	-- Clear the kernel cache on config changes, autodetect might have
19635b0c718SKyle Evans	-- changed or if we've switched boot environments then we could have
19735b0c718SKyle Evans	-- a new kernel set.
19835b0c718SKyle Evans	core.cached_kernels = nil
19935b0c718SKyle Evansend
20035b0c718SKyle Evans
201088b4f5fSWarner Loshfunction core.kernelList()
20235b0c718SKyle Evans	if core.cached_kernels ~= nil then
20335b0c718SKyle Evans		return core.cached_kernels
20435b0c718SKyle Evans	end
20535b0c718SKyle Evans
206aedd6be5SKyle Evans	local k = loader.getenv("kernel")
2073f4eb56bSKyle Evans	local v = loader.getenv("kernels")
2083889e6cdSKyle Evans	local autodetect = loader.getenv("kernels_autodetect") or ""
209088b4f5fSWarner Losh
210aedd6be5SKyle Evans	local kernels = {}
211aedd6be5SKyle Evans	local unique = {}
212aedd6be5SKyle Evans	local i = 0
2139f71d421SKyle Evans	if k ~= nil then
214aedd6be5SKyle Evans		i = i + 1
215aedd6be5SKyle Evans		kernels[i] = k
216aedd6be5SKyle Evans		unique[k] = true
217088b4f5fSWarner Losh	end
218088b4f5fSWarner Losh
2193f4eb56bSKyle Evans	if v ~= nil then
220a5003419SKyle Evans		for n in v:gmatch("([^;, ]+)[;, ]?") do
2219f71d421SKyle Evans			if unique[n] == nil then
222aedd6be5SKyle Evans				i = i + 1
223aedd6be5SKyle Evans				kernels[i] = n
224aedd6be5SKyle Evans				unique[n] = true
225088b4f5fSWarner Losh			end
226088b4f5fSWarner Losh		end
2273889e6cdSKyle Evans	end
228a108046fSConrad Meyer
2293889e6cdSKyle Evans	-- Base whether we autodetect kernels or not on a loader.conf(5)
2303889e6cdSKyle Evans	-- setting, kernels_autodetect. If it's set to 'yes', we'll add
2313889e6cdSKyle Evans	-- any kernels we detect based on the criteria described.
2323889e6cdSKyle Evans	if autodetect:lower() ~= "yes" then
23335b0c718SKyle Evans		core.cached_kernels = kernels
23435b0c718SKyle Evans		return core.cached_kernels
2353f4eb56bSKyle Evans	end
2363f4eb56bSKyle Evans
237a108046fSConrad Meyer	-- Automatically detect other bootable kernel directories using a
238a108046fSConrad Meyer	-- heuristic.  Any directory in /boot that contains an ordinary file
239a108046fSConrad Meyer	-- named "kernel" is considered eligible.
240a108046fSConrad Meyer	for file in lfs.dir("/boot") do
241aedd6be5SKyle Evans		local fname = "/boot/" .. file
242a108046fSConrad Meyer
2439f71d421SKyle Evans		if file == "." or file == ".." then
244aedd6be5SKyle Evans			goto continue
245a108046fSConrad Meyer		end
246a108046fSConrad Meyer
2479f71d421SKyle Evans		if lfs.attributes(fname, "mode") ~= "directory" then
248aedd6be5SKyle Evans			goto continue
249a108046fSConrad Meyer		end
250a108046fSConrad Meyer
2519f71d421SKyle Evans		if lfs.attributes(fname .. "/kernel", "mode") ~= "file" then
252aedd6be5SKyle Evans			goto continue
253a108046fSConrad Meyer		end
254a108046fSConrad Meyer
2559f71d421SKyle Evans		if unique[file] == nil then
256aedd6be5SKyle Evans			i = i + 1
257aedd6be5SKyle Evans			kernels[i] = file
258aedd6be5SKyle Evans			unique[file] = true
259a108046fSConrad Meyer		end
260a108046fSConrad Meyer
261a108046fSConrad Meyer		::continue::
262a108046fSConrad Meyer	end
26335b0c718SKyle Evans	core.cached_kernels = kernels
26435b0c718SKyle Evans	return core.cached_kernels
265088b4f5fSWarner Loshend
266088b4f5fSWarner Losh
2677efc058fSKyle Evansfunction core.bootenvDefault()
2687efc058fSKyle Evans	return loader.getenv("zfs_be_active")
2697efc058fSKyle Evansend
2707efc058fSKyle Evans
2717efc058fSKyle Evansfunction core.bootenvList()
2727efc058fSKyle Evans	local bootenv_count = tonumber(loader.getenv("bootenvs_count"))
2737efc058fSKyle Evans	local bootenvs = {}
2747efc058fSKyle Evans	local curenv
2757efc058fSKyle Evans	local envcount = 0
2767efc058fSKyle Evans	local unique = {}
2777efc058fSKyle Evans
2787efc058fSKyle Evans	if bootenv_count == nil or bootenv_count <= 0 then
2797efc058fSKyle Evans		return bootenvs
2807efc058fSKyle Evans	end
2817efc058fSKyle Evans
2827efc058fSKyle Evans	-- Currently selected bootenv is always first/default
2837efc058fSKyle Evans	curenv = core.bootenvDefault()
2847efc058fSKyle Evans	if curenv ~= nil then
2857efc058fSKyle Evans		envcount = envcount + 1
2867efc058fSKyle Evans		bootenvs[envcount] = curenv
2877efc058fSKyle Evans		unique[curenv] = true
2887efc058fSKyle Evans	end
2897efc058fSKyle Evans
2907efc058fSKyle Evans	for curenv_idx = 0, bootenv_count - 1 do
2917efc058fSKyle Evans		curenv = loader.getenv("bootenvs[" .. curenv_idx .. "]")
2927efc058fSKyle Evans		if curenv ~= nil and unique[curenv] == nil then
2937efc058fSKyle Evans			envcount = envcount + 1
2947efc058fSKyle Evans			bootenvs[envcount] = curenv
2957efc058fSKyle Evans			unique[curenv] = true
2967efc058fSKyle Evans		end
2977efc058fSKyle Evans	end
2987efc058fSKyle Evans	return bootenvs
2997efc058fSKyle Evansend
3007efc058fSKyle Evans
301088b4f5fSWarner Loshfunction core.setDefaults()
302aedd6be5SKyle Evans	core.setACPI(core.getACPIPresent(true))
3031613f091SKyle Evans	core.setSafeMode(default_safe_mode)
3041613f091SKyle Evans	core.setSingleUser(default_single_user)
3051613f091SKyle Evans	core.setVerbose(default_verbose)
306088b4f5fSWarner Loshend
307088b4f5fSWarner Losh
3086d4ed94dSKyle Evansfunction core.autoboot(argstr)
309a2a7830eSKyle Evans	-- loadelf() only if we've not already loaded a kernel
310a2a7830eSKyle Evans	if loader.getenv("kernelname") == nil then
311aedd6be5SKyle Evans		config.loadelf()
312a2a7830eSKyle Evans	end
313322a2dddSKyle Evans	loader.perform(composeLoaderCmd("autoboot", argstr))
314088b4f5fSWarner Loshend
315088b4f5fSWarner Losh
3166d4ed94dSKyle Evansfunction core.boot(argstr)
317a2a7830eSKyle Evans	-- loadelf() only if we've not already loaded a kernel
318a2a7830eSKyle Evans	if loader.getenv("kernelname") == nil then
319aedd6be5SKyle Evans		config.loadelf()
320a2a7830eSKyle Evans	end
321322a2dddSKyle Evans	loader.perform(composeLoaderCmd("boot", argstr))
322088b4f5fSWarner Loshend
323088b4f5fSWarner Losh
324e07fc39cSKyle Evansfunction core.isSingleUserBoot()
325aedd6be5SKyle Evans	local single_user = loader.getenv("boot_single")
326aedd6be5SKyle Evans	return single_user ~= nil and single_user:lower() == "yes"
327e07fc39cSKyle Evansend
328e07fc39cSKyle Evans
3295f8cfbe1SKyle Evansfunction core.isUEFIBoot()
3305f8cfbe1SKyle Evans	local efiver = loader.getenv("efi-version")
3315f8cfbe1SKyle Evans
3325f8cfbe1SKyle Evans	return efiver ~= nil
3335f8cfbe1SKyle Evansend
3345f8cfbe1SKyle Evans
3357efc058fSKyle Evansfunction core.isZFSBoot()
3367efc058fSKyle Evans	local c = loader.getenv("currdev")
3377efc058fSKyle Evans
3387efc058fSKyle Evans	if c ~= nil then
3397efc058fSKyle Evans		return c:match("^zfs:") ~= nil
3407efc058fSKyle Evans	end
3417efc058fSKyle Evans	return false
3427efc058fSKyle Evansend
3437efc058fSKyle Evans
34490a25417SKyle Evansfunction core.isSerialConsole()
34590a25417SKyle Evans	local c = loader.getenv("console")
34690a25417SKyle Evans	if c ~= nil then
34790a25417SKyle Evans		if c:find("comconsole") ~= nil then
34890a25417SKyle Evans			return true
34990a25417SKyle Evans		end
35090a25417SKyle Evans	end
35190a25417SKyle Evans	return false
35290a25417SKyle Evansend
35390a25417SKyle Evans
354b140d14bSKyle Evansfunction core.isSerialBoot()
355aedd6be5SKyle Evans	local s = loader.getenv("boot_serial")
3569f71d421SKyle Evans	if s ~= nil then
357aedd6be5SKyle Evans		return true
358088b4f5fSWarner Losh	end
359088b4f5fSWarner Losh
360aedd6be5SKyle Evans	local m = loader.getenv("boot_multicons")
3619f71d421SKyle Evans	if m ~= nil then
362aedd6be5SKyle Evans		return true
363088b4f5fSWarner Losh	end
364aedd6be5SKyle Evans	return false
365088b4f5fSWarner Loshend
366088b4f5fSWarner Losh
367c1ab36f5SKyle Evansfunction core.isSystem386()
3689f71d421SKyle Evans	return loader.machine_arch == "i386"
369c1ab36f5SKyle Evansend
370c1ab36f5SKyle Evans
3719937e979SKyle Evans-- Is the menu skipped in the environment in which we've booted?
3729937e979SKyle Evansfunction core.isMenuSkipped()
373b83a355dSKyle Evans	return string.lower(loader.getenv("beastie_disable") or "") == "yes"
3749937e979SKyle Evansend
3759937e979SKyle Evans
3765c1b5165SKyle Evans-- This may be a better candidate for a 'utility' module.
377ee4e69f1SKyle Evansfunction core.deepCopyTable(tbl)
378aedd6be5SKyle Evans	local new_tbl = {}
3795c1b5165SKyle Evans	for k, v in pairs(tbl) do
3809f71d421SKyle Evans		if type(v) == "table" then
381ee4e69f1SKyle Evans			new_tbl[k] = core.deepCopyTable(v)
3825c1b5165SKyle Evans		else
383aedd6be5SKyle Evans			new_tbl[k] = v
3845c1b5165SKyle Evans		end
3855c1b5165SKyle Evans	end
386aedd6be5SKyle Evans	return new_tbl
3875c1b5165SKyle Evansend
3885c1b5165SKyle Evans
3896d4ed94dSKyle Evans-- XXX This should go away if we get the table lib into shape for importing.
3906d4ed94dSKyle Evans-- As of now, it requires some 'os' functions, so we'll implement this in lua
3916d4ed94dSKyle Evans-- for our uses
3926d4ed94dSKyle Evansfunction core.popFrontTable(tbl)
3936d4ed94dSKyle Evans	-- Shouldn't reasonably happen
3949f71d421SKyle Evans	if #tbl == 0 then
395aedd6be5SKyle Evans		return nil, nil
3969f71d421SKyle Evans	elseif #tbl == 1 then
397aedd6be5SKyle Evans		return tbl[1], {}
3986d4ed94dSKyle Evans	end
3996d4ed94dSKyle Evans
400aedd6be5SKyle Evans	local first_value = tbl[1]
401aedd6be5SKyle Evans	local new_tbl = {}
4026d4ed94dSKyle Evans	-- This is not a cheap operation
4036d4ed94dSKyle Evans	for k, v in ipairs(tbl) do
4049f71d421SKyle Evans		if k > 1 then
405aedd6be5SKyle Evans			new_tbl[k - 1] = v
4066d4ed94dSKyle Evans		end
4076d4ed94dSKyle Evans	end
4086d4ed94dSKyle Evans
409aedd6be5SKyle Evans	return first_value, new_tbl
4106d4ed94dSKyle Evansend
4116d4ed94dSKyle Evans
4121613f091SKyle EvansrecordDefaults()
413aea262bfSKyle Evanshook.register("config.reloaded", core.clearCachedKernels)
414aedd6be5SKyle Evansreturn core
415