core.lua (3af64f03119a159ac15eb75b92d346705b490385) core.lua (1613f09199eb198b62f81df8fa92ec163a01c78f)
1--
2-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3--
4-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
6-- All rights reserved.
7--
8-- Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29-- $FreeBSD$
30--
31
32local config = require("config")
33local hook = require("hook")
34
35local core = {}
36
1--
2-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3--
4-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
6-- All rights reserved.
7--
8-- Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29-- $FreeBSD$
30--
31
32local config = require("config")
33local hook = require("hook")
34
35local core = {}
36
37local default_safe_mode = false
38local default_single_user = false
39local default_verbose = false
40
37local function composeLoaderCmd(cmd_name, argstr)
38 if argstr ~= nil then
39 cmd_name = cmd_name .. " " .. argstr
40 end
41 return cmd_name
42end
43
41local function composeLoaderCmd(cmd_name, argstr)
42 if argstr ~= nil then
43 cmd_name = cmd_name .. " " .. argstr
44 end
45 return cmd_name
46end
47
48local function recordDefaults()
49 -- On i386, hint.acpi.0.rsdp will be set before we're loaded. On !i386,
50 -- it will generally be set upon execution of the kernel. Because of
51 -- this, we can't (or don't really want to) detect/disable ACPI on !i386
52 -- reliably. Just set it enabled if we detect it and leave well enough
53 -- alone if we don't.
54 local boot_acpi = core.isSystem386() and core.getACPIPresent(false)
55 local boot_single = loader.getenv("boot_single") or "no"
56 local boot_verbose = loader.getenv("boot_verbose") or "no"
57 default_single_user = boot_single:lower() ~= "no"
58 default_verbose = boot_verbose:lower() ~= "no"
59
60 if boot_acpi then
61 core.setACPI(true)
62 end
63 core.setSingleUser(default_single_user)
64 core.setVerbose(default_verbose)
65end
66
67
44-- Globals
45-- try_include will return the loaded module on success, or nil on failure.
46-- A message will also be printed on failure, with one exception: non-verbose
47-- loading will suppress 'module not found' errors.
48function try_include(module)
49 local status, ret = pcall(require, module)
50 -- ret is the module if we succeeded.
51 if status then

--- 211 unchanged lines hidden (view full) ---

263 unique[curenv] = true
264 end
265 end
266 return bootenvs
267end
268
269function core.setDefaults()
270 core.setACPI(core.getACPIPresent(true))
68-- Globals
69-- try_include will return the loaded module on success, or nil on failure.
70-- A message will also be printed on failure, with one exception: non-verbose
71-- loading will suppress 'module not found' errors.
72function try_include(module)
73 local status, ret = pcall(require, module)
74 -- ret is the module if we succeeded.
75 if status then

--- 211 unchanged lines hidden (view full) ---

287 unique[curenv] = true
288 end
289 end
290 return bootenvs
291end
292
293function core.setDefaults()
294 core.setACPI(core.getACPIPresent(true))
271 core.setSafeMode(false)
272 core.setSingleUser(false)
273 core.setVerbose(false)
295 core.setSafeMode(default_safe_mode)
296 core.setSingleUser(default_single_user)
297 core.setVerbose(default_verbose)
274end
275
276function core.autoboot(argstr)
277 -- loadelf() only if we've not already loaded a kernel
278 if loader.getenv("kernelname") == nil then
279 config.loadelf()
280 end
281 loader.perform(composeLoaderCmd("autoboot", argstr))

--- 80 unchanged lines hidden (view full) ---

362 if k > 1 then
363 new_tbl[k - 1] = v
364 end
365 end
366
367 return first_value, new_tbl
368end
369
298end
299
300function core.autoboot(argstr)
301 -- loadelf() only if we've not already loaded a kernel
302 if loader.getenv("kernelname") == nil then
303 config.loadelf()
304 end
305 loader.perform(composeLoaderCmd("autoboot", argstr))

--- 80 unchanged lines hidden (view full) ---

386 if k > 1 then
387 new_tbl[k - 1] = v
388 end
389 end
390
391 return first_value, new_tbl
392end
393
370-- On i386, hint.acpi.0.rsdp will be set before we're loaded. On !i386, it will
371-- generally be set upon execution of the kernel. Because of this, we can't (or
372-- don't really want to) detect/disable ACPI on !i386 reliably. Just set it
373-- enabled if we detect it and leave well enough alone if we don't.
374if core.isSystem386() and core.getACPIPresent(false) then
375 core.setACPI(true)
376end
377
394recordDefaults()
378hook.register("config.reloaded", core.clearCachedKernels)
379return core
395hook.register("config.reloaded", core.clearCachedKernels)
396return core