From 6d4ed94d98bbe812805ed6ab71df0badbb8b9101 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Tue, 20 Feb 2018 21:23:01 +0000 Subject: [PATCH] lualoader: Prepare for interception of "boot" CLI cmd core.boot and core.autoboot may both take arguments; add a helper to cleanly append an argstring to the given loader command. Also provide a popFrontTable() that we'll use pop the command name off of an argv table. We don't have the table library included, and including it is non-trivial, so we'll implement this one function that we need in lua for the time being. --- stand/lua/core.lua | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/stand/lua/core.lua b/stand/lua/core.lua index 3c51cc3d5442..e9c96a86ccbd 100644 --- a/stand/lua/core.lua +++ b/stand/lua/core.lua @@ -30,6 +30,13 @@ local config = require('config'); local core = {}; +local compose_loader_cmd = function(cmd_name, argstr) + if (argstr ~= nil) then + cmd_name = cmd_name .. " " .. argstr; + end + return cmd_name; +end + -- Module exports -- Commonly appearing constants core.KEY_BACKSPACE = 8; @@ -182,14 +189,14 @@ function core.setDefaults() core.setVerbose(false); end -function core.autoboot() +function core.autoboot(argstr) config.loadelf(); - loader.perform("autoboot"); + loader.perform(compose_loader_cmd("autoboot", argstr)); end -function core.boot() +function core.boot(argstr) config.loadelf(); - loader.perform("boot"); + loader.perform(compose_loader_cmd("boot", argstr)); end function core.isSingleUserBoot() @@ -235,6 +242,29 @@ function core.shallowCopyTable(tbl) return new_tbl; end +-- XXX This should go away if we get the table lib into shape for importing. +-- As of now, it requires some 'os' functions, so we'll implement this in lua +-- for our uses +function core.popFrontTable(tbl) + -- Shouldn't reasonably happen + if (#tbl == 0) then + return nil, nil; + elseif (#tbl == 1) then + return tbl[1], {}; + end + + local first_value = tbl[1]; + local new_tbl = {}; + -- This is not a cheap operation + for k, v in ipairs(tbl) do + if (k > 1) then + new_tbl[k - 1] = v; + end + end + + return first_value, new_tbl; +end + -- On i386, hint.acpi.0.rsdp will be set before we're loaded. On !i386, it will -- generally be set upon execution of the kernel. Because of this, we can't (or -- don't really want to) detect/disable ACPI on !i386 reliably. Just set it