1088b4f5fSWarner Losh-- 2088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 3088b4f5fSWarner Losh-- All rights reserved. 4088b4f5fSWarner Losh-- 5088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without 6088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions 7088b4f5fSWarner Losh-- are met: 8088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright 9088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer. 10088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright 11088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer in the 12088b4f5fSWarner Losh-- documentation and/or other materials provided with the distribution. 13088b4f5fSWarner Losh-- 14088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17088b4f5fSWarner Losh-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24088b4f5fSWarner Losh-- SUCH DAMAGE. 25088b4f5fSWarner Losh-- 26088b4f5fSWarner Losh-- $FreeBSD$ 27088b4f5fSWarner Losh-- 28088b4f5fSWarner Losh 29088b4f5fSWarner Loshlocal core = {}; 30088b4f5fSWarner Losh 31fe672a15SKyle Evans-- Commonly appearing constants 32*1504bce3SKyle Evanscore.KEY_BACKSPACE = 8; 3327fac8ffSKyle Evanscore.KEY_ENTER = 13; 34*1504bce3SKyle Evanscore.KEY_DELETE = 127; 35fe672a15SKyle Evans 3639006570SKyle Evanscore.KEYSTR_ESCAPE = "\027"; 3739006570SKyle Evans 38a7cf0562SKyle Evanscore.MENU_RETURN = "return"; 39a7cf0562SKyle Evanscore.MENU_ENTRY = "entry"; 40a7cf0562SKyle Evanscore.MENU_SEPARATOR = "separator"; 41a7cf0562SKyle Evanscore.MENU_SUBMENU = "submenu"; 42a7cf0562SKyle Evanscore.MENU_CAROUSEL_ENTRY = "carousel_entry"; 43a7cf0562SKyle Evans 44088b4f5fSWarner Loshfunction core.setVerbose(b) 45088b4f5fSWarner Losh if (b == nil) then 46088b4f5fSWarner Losh b = not core.verbose; 47088b4f5fSWarner Losh end 48088b4f5fSWarner Losh 49088b4f5fSWarner Losh if (b == true) then 50088b4f5fSWarner Losh loader.setenv("boot_verbose", "YES"); 51088b4f5fSWarner Losh else 52088b4f5fSWarner Losh loader.unsetenv("boot_verbose"); 53088b4f5fSWarner Losh end 54088b4f5fSWarner Losh core.verbose = b; 55088b4f5fSWarner Loshend 56088b4f5fSWarner Losh 57088b4f5fSWarner Loshfunction core.setSingleUser(b) 58088b4f5fSWarner Losh if (b == nil) then 59088b4f5fSWarner Losh b = not core.su; 60088b4f5fSWarner Losh end 61088b4f5fSWarner Losh 62088b4f5fSWarner Losh if (b == true) then 63088b4f5fSWarner Losh loader.setenv("boot_single", "YES"); 64088b4f5fSWarner Losh else 65088b4f5fSWarner Losh loader.unsetenv("boot_single"); 66088b4f5fSWarner Losh end 67088b4f5fSWarner Losh core.su = b; 68088b4f5fSWarner Loshend 69088b4f5fSWarner Losh 706401094fSKyle Evansfunction core.getACPIPresent(checkingSystemDefaults) 716401094fSKyle Evans local c = loader.getenv("hint.acpi.0.rsdp"); 726401094fSKyle Evans 736401094fSKyle Evans if (c ~= nil) then 746401094fSKyle Evans if (checkingSystemDefaults == true) then 756401094fSKyle Evans return true; 766401094fSKyle Evans end 776401094fSKyle Evans -- Otherwise, respect disabled if it's set 786401094fSKyle Evans c = loader.getenv("hint.acpi.0.disabled"); 796401094fSKyle Evans return (c == nil) or (tonumber(c) ~= 1); 806401094fSKyle Evans end 816401094fSKyle Evans return false; 826401094fSKyle Evansend 836401094fSKyle Evans 84088b4f5fSWarner Loshfunction core.setACPI(b) 85088b4f5fSWarner Losh if (b == nil) then 86088b4f5fSWarner Losh b = not core.acpi; 87088b4f5fSWarner Losh end 88088b4f5fSWarner Losh 89088b4f5fSWarner Losh if (b == true) then 90088b4f5fSWarner Losh loader.setenv("acpi_load", "YES"); 91088b4f5fSWarner Losh loader.setenv("hint.acpi.0.disabled", "0"); 92088b4f5fSWarner Losh loader.unsetenv("loader.acpi_disabled_by_user"); 93088b4f5fSWarner Losh else 94088b4f5fSWarner Losh loader.unsetenv("acpi_load"); 95088b4f5fSWarner Losh loader.setenv("hint.acpi.0.disabled", "1"); 96088b4f5fSWarner Losh loader.setenv("loader.acpi_disabled_by_user", "1"); 97088b4f5fSWarner Losh end 98088b4f5fSWarner Losh core.acpi = b; 99088b4f5fSWarner Loshend 100088b4f5fSWarner Losh 101088b4f5fSWarner Loshfunction core.setSafeMode(b) 102088b4f5fSWarner Losh if (b == nil) then 103088b4f5fSWarner Losh b = not core.sm; 104088b4f5fSWarner Losh end 105088b4f5fSWarner Losh if (b == true) then 106088b4f5fSWarner Losh loader.setenv("kern.smp.disabled", "1"); 107088b4f5fSWarner Losh loader.setenv("hw.ata.ata_dma", "0"); 108088b4f5fSWarner Losh loader.setenv("hw.ata.atapi_dma", "0"); 109088b4f5fSWarner Losh loader.setenv("hw.ata.wc", "0"); 110088b4f5fSWarner Losh loader.setenv("hw.eisa_slots", "0"); 111088b4f5fSWarner Losh loader.setenv("kern.eventtimer.periodic", "1"); 112088b4f5fSWarner Losh loader.setenv("kern.geom.part.check_integrity", "0"); 113088b4f5fSWarner Losh else 114088b4f5fSWarner Losh loader.unsetenv("kern.smp.disabled"); 115088b4f5fSWarner Losh loader.unsetenv("hw.ata.ata_dma"); 116088b4f5fSWarner Losh loader.unsetenv("hw.ata.atapi_dma"); 117088b4f5fSWarner Losh loader.unsetenv("hw.ata.wc"); 118088b4f5fSWarner Losh loader.unsetenv("hw.eisa_slots"); 119088b4f5fSWarner Losh loader.unsetenv("kern.eventtimer.periodic"); 120088b4f5fSWarner Losh loader.unsetenv("kern.geom.part.check_integrity"); 121088b4f5fSWarner Losh end 122088b4f5fSWarner Losh core.sm = b; 123088b4f5fSWarner Loshend 124088b4f5fSWarner Losh 125088b4f5fSWarner Loshfunction core.kernelList() 126088b4f5fSWarner Losh local k = loader.getenv("kernel"); 127088b4f5fSWarner Losh local v = loader.getenv("kernels") or ""; 128088b4f5fSWarner Losh 129088b4f5fSWarner Losh local kernels = {}; 130088b4f5fSWarner Losh local i = 0; 131088b4f5fSWarner Losh if k ~= nil then 132088b4f5fSWarner Losh i = i + 1; 133088b4f5fSWarner Losh kernels[i] = k; 134088b4f5fSWarner Losh end 135088b4f5fSWarner Losh 136088b4f5fSWarner Losh for n in v:gmatch("([^; ]+)[; ]?") do 137088b4f5fSWarner Losh if n ~= k then 138088b4f5fSWarner Losh i = i + 1; 139088b4f5fSWarner Losh kernels[i] = n; 140088b4f5fSWarner Losh end 141088b4f5fSWarner Losh end 142088b4f5fSWarner Losh return kernels; 143088b4f5fSWarner Loshend 144088b4f5fSWarner Losh 145088b4f5fSWarner Loshfunction core.setDefaults() 1466401094fSKyle Evans core.setACPI(core.getACPIPresent(true)); 147088b4f5fSWarner Losh core.setSafeMode(false); 148088b4f5fSWarner Losh core.setSingleUser(false); 149088b4f5fSWarner Losh core.setVerbose(false); 150088b4f5fSWarner Loshend 151088b4f5fSWarner Losh 152088b4f5fSWarner Loshfunction core.autoboot() 153088b4f5fSWarner Losh loader.perform("autoboot"); 154088b4f5fSWarner Loshend 155088b4f5fSWarner Losh 156088b4f5fSWarner Loshfunction core.boot() 157088b4f5fSWarner Losh loader.perform("boot"); 158088b4f5fSWarner Loshend 159088b4f5fSWarner Losh 160088b4f5fSWarner Loshfunction core.bootserial() 161088b4f5fSWarner Losh local c = loader.getenv("console"); 162088b4f5fSWarner Losh 163088b4f5fSWarner Losh if c ~= nil then 164088b4f5fSWarner Losh if c:find("comconsole") ~= nil then 165088b4f5fSWarner Losh return true; 166088b4f5fSWarner Losh end 167088b4f5fSWarner Losh end 168088b4f5fSWarner Losh 169088b4f5fSWarner Losh local s = loader.getenv("boot_serial"); 170088b4f5fSWarner Losh if s ~= nil then 171088b4f5fSWarner Losh return true; 172088b4f5fSWarner Losh end 173088b4f5fSWarner Losh 174088b4f5fSWarner Losh local m = loader.getenv("boot_multicons"); 175088b4f5fSWarner Losh if m ~= nil then 176088b4f5fSWarner Losh return true; 177088b4f5fSWarner Losh end 178088b4f5fSWarner Losh return false; 179088b4f5fSWarner Loshend 180088b4f5fSWarner Losh 181ecdc7342SKyle Evanscore.setACPI(core.getACPIPresent(false)) 182088b4f5fSWarner Loshreturn core 183