From owner-svn-src-stable-11@freebsd.org Thu Feb 8 02:50:50 2018 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 864ECEF2453; Thu, 8 Feb 2018 02:50:50 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 337F86DCC2; Thu, 8 Feb 2018 02:50:50 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2E4C77F86; Thu, 8 Feb 2018 02:50:50 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w182ooZ8097906; Thu, 8 Feb 2018 02:50:50 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w182olh7097879; Thu, 8 Feb 2018 02:50:47 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802080250.w182olh7097879@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 8 Feb 2018 02:50:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r329011 - in stable/11: sys/boot sys/boot/common sys/boot/efi/libefi sys/boot/efi/loader sys/boot/efi/loader/arch/amd64 sys/boot/efi/loader/arch/arm sys/boot/efi/loader/arch/arm64 sys/b... X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/11: sys/boot sys/boot/common sys/boot/efi/libefi sys/boot/efi/loader sys/boot/efi/loader/arch/amd64 sys/boot/efi/loader/arch/arm sys/boot/efi/loader/arch/arm64 sys/boot/efi/loader/arch/i386 ... X-SVN-Commit-Revision: 329011 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Feb 2018 02:50:51 -0000 Author: kevans Date: Thu Feb 8 02:50:47 2018 New Revision: 329011 URL: https://svnweb.freebsd.org/changeset/base/329011 Log: MFC r307322,r307323,r307324,r307326,r307327,r307338,r307879,r307908,r307911, r307942,r307950,r307951,r307954,r307955,r308125,r308195,r308476,r308534, r308535,r308776,r308843,r310236,r310726: Loader fixes, 2016q4 r307322: Remove /boot/boot.conf, deprecated for 16 years r307323: Remove fetching of pInterp. r307324: Create a new linker set, Xficl_compile_set which contains a list of functions to call to register new forth words. r307326: In UEFI mode expose the SMBIOS anchor base address via kenv r307327: Update i386 build of loader.efi (but leave it disabled) so that we at least build it now. r307338: Create a pcibios-version environment FORTH word. r307879: Preliminary support for EFI in boot loader. r307908: Fix the build on both arm64 and when WITHOUT_FORTH is defined. r307911: Add better comment... r307942: Really make WITHOUT_FORTH (MK_FORTH==no) work. r307950: Add it (Makefile.ficl) to the right place r307951: Fix two backwards tests. r307954: Back out the move to the loader script from -N. r307955: LIBSTAND goes last, so put it last here too. r308125: In loader.efi, instead of exiting directly, try to fallback. r308195: efinet_dev_print should honor verbose option. r308476: boot/forth spelling issue in forth word r308534: The file_loadraw function grew an argument, update install function r308535: Add support for LOADER_RC setting in the pkgfs manifes r308776: loader: zfs toplevel vdev must have spa set. r308843: loader: smbios version check is not correct r310236: Renumber license clauses to avoid skipping #3 r310726: cdboot: add explict suffix to ambiguous or instruction PR: 214375 Added: stable/11/sys/boot/Makefile.ficl - copied unchanged from r307950, head/sys/boot/Makefile.ficl stable/11/sys/boot/forth/efi.4th - copied unchanged from r307879, head/sys/boot/forth/efi.4th Deleted: stable/11/sys/boot/ficl/efi.c Modified: stable/11/sys/boot/common/Makefile.inc stable/11/sys/boot/common/bootstrap.h stable/11/sys/boot/common/install.c stable/11/sys/boot/common/interp.c stable/11/sys/boot/common/interp_forth.c stable/11/sys/boot/common/loader.8 stable/11/sys/boot/common/newvers.sh stable/11/sys/boot/common/pnp.c stable/11/sys/boot/efi/libefi/Makefile stable/11/sys/boot/efi/libefi/efinet.c stable/11/sys/boot/efi/libefi/env.c stable/11/sys/boot/efi/loader/Makefile stable/11/sys/boot/efi/loader/arch/amd64/ldscript.amd64 stable/11/sys/boot/efi/loader/arch/arm/ldscript.arm stable/11/sys/boot/efi/loader/arch/arm64/ldscript.arm64 stable/11/sys/boot/efi/loader/arch/i386/efimd.c stable/11/sys/boot/efi/loader/arch/i386/elf32_freebsd.c stable/11/sys/boot/efi/loader/arch/i386/exec.c stable/11/sys/boot/efi/loader/arch/i386/ldscript.i386 stable/11/sys/boot/efi/loader/main.c stable/11/sys/boot/ficl/Makefile stable/11/sys/boot/ficl/ficl.h stable/11/sys/boot/ficl/i386/sysdep.c stable/11/sys/boot/ficl/loader.c stable/11/sys/boot/ficl32/Makefile stable/11/sys/boot/forth/Makefile.inc stable/11/sys/boot/forth/loader.4th stable/11/sys/boot/forth/support.4th stable/11/sys/boot/i386/Makefile.inc stable/11/sys/boot/i386/cdboot/cdboot.S stable/11/sys/boot/i386/gptboot/Makefile stable/11/sys/boot/i386/gptzfsboot/Makefile stable/11/sys/boot/i386/libi386/Makefile stable/11/sys/boot/i386/libi386/biospci.c stable/11/sys/boot/i386/libi386/libi386.h stable/11/sys/boot/i386/libi386/smbios.c stable/11/sys/boot/i386/loader/Makefile stable/11/sys/boot/mips/beri/loader/loader.ldscript stable/11/sys/boot/pc98/libpc98/Makefile stable/11/sys/boot/zfs/zfsimpl.c stable/11/targets/pseudo/userland/misc/Makefile.depend Directory Properties: stable/11/ (props changed) Copied: stable/11/sys/boot/Makefile.ficl (from r307950, head/sys/boot/Makefile.ficl) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/11/sys/boot/Makefile.ficl Thu Feb 8 02:50:47 2018 (r329011, copy of r307950, head/sys/boot/Makefile.ficl) @@ -0,0 +1,43 @@ +# $FreeBSD$ + +# Common flags to build FICL related files + +FICLDIR?= ${SRCTOP}/sys/boot/ficl + +.if ${MACHINE_CPUARCH} == "amd64" && defined(FICL32) +FICL_CPUARCH= i386 +.elif ${MACHINE_ARCH} == "mips64" || ${MACHINE_ARCH} == "mips64el" +FICL_CPUARCH= mips64 +.else +FICL_CPUARCH= ${MACHINE_CPUARCH} +.endif + +.PATH: ${FICLDIR} ${FICLDIR}/${FICL_CPUARCH} + +.if ${MACHINE_CPUARCH} == "amd64" +.if defined(FICL32) +CFLAGS+= -m32 -I. +.else +CFLAGS+= -fPIC +.endif +.endif + +.if ${MACHINE_ARCH} == "powerpc64" +CFLAGS+= -m32 -mcpu=powerpc -I. +.endif + +CFLAGS+= -I${FICLDIR} -I${FICLDIR}/${FICL_CPUARCH} \ + -I${FICLDIR}/../common + +.if ${MACHINE_CPUARCH} == "amd64" && defined(FICL32) +.if !exists(machine) +${SRCS:M*.c:R:S/$/.o/g}: machine + +beforedepend ${OBJS}: machine +.endif + +machine: .NOMETA + ln -sf ${.CURDIR}/../../i386/include machine + +CLEANFILES+= machine +.endif Modified: stable/11/sys/boot/common/Makefile.inc ============================================================================== --- stable/11/sys/boot/common/Makefile.inc Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/common/Makefile.inc Thu Feb 8 02:50:47 2018 (r329011) @@ -65,6 +65,7 @@ SRCS+= pnp.c # Forth interpreter .if defined(BOOT_FORTH) SRCS+= interp_forth.c +.include "${SRCTOP}/sys/boot/Makefile.ficl" .endif .if defined(BOOT_PROMPT_123) Modified: stable/11/sys/boot/common/bootstrap.h ============================================================================== --- stable/11/sys/boot/common/bootstrap.h Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/common/bootstrap.h Thu Feb 8 02:50:47 2018 (r329011) @@ -142,8 +142,6 @@ struct pnpinfo STAILQ_HEAD(pnpinfo_stql, pnpinfo); -extern struct pnpinfo_stql pnp_devices; - extern struct pnphandler *pnphandlers[]; /* provided by MD code */ void pnp_addident(struct pnpinfo *pi, char *ident); Modified: stable/11/sys/boot/common/install.c ============================================================================== --- stable/11/sys/boot/common/install.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/common/install.c Thu Feb 8 02:50:47 2018 (r329011) @@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$"); #include "bootstrap.h" -extern struct in_addr rootip; extern struct in_addr servip; extern int pkgfs_init(const char *, struct fs_ops *); @@ -50,6 +49,7 @@ COMMAND_SET(install, "install", "install software pack static char *inst_kernel; static char **inst_modules; static char *inst_rootfs; +static char *inst_loader_rc; static int setpath(char **what, char *val) @@ -146,6 +146,8 @@ read_metatags(int fd) error = setmultipath(&inst_modules, val); else if (strcmp(tag, "ROOTFS") == 0) error = setpath(&inst_rootfs, val); + else if (strcmp(tag, "LOADER_RC") == 0) + error = setpath(&inst_loader_rc, val); tag = p; } @@ -173,6 +175,10 @@ cleanup(void) free(inst_rootfs); inst_rootfs = NULL; } + if (inst_loader_rc != NULL) { + free(inst_loader_rc); + inst_loader_rc = NULL; + } pkgfs_cleanup(); } @@ -275,6 +281,16 @@ install(char *pkgname) goto fail; } + /* If there is a loader.rc in the package, execute it */ + s = (inst_loader_rc == NULL) ? "/loader.rc" : inst_loader_rc; + fd = open(s, O_RDONLY); + if (fd != -1) { + close(fd); + error = include(s); + if (error == CMD_ERROR) + goto fail; + } + i = 0; while (inst_modules != NULL && inst_modules[i] != NULL) { error = mod_loadkld(inst_modules[i], 0, NULL); @@ -286,7 +302,7 @@ install(char *pkgname) } s = (inst_rootfs == NULL) ? "/install.iso" : inst_rootfs; - if (file_loadraw(s, "mfs_root") == NULL) { + if (file_loadraw(s, "mfs_root", 1) == NULL) { error = errno; command_errmsg = "cannot load root file system"; goto fail; Modified: stable/11/sys/boot/common/interp.c ============================================================================== --- stable/11/sys/boot/common/interp.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/common/interp.c Thu Feb 8 02:50:47 2018 (r329011) @@ -104,8 +104,7 @@ interact(const char *rc) if (rc == NULL) { /* Read our default configuration. */ - if (include("/boot/loader.rc") != CMD_OK) - include("/boot/boot.conf"); + include("/boot/loader.rc"); } else if (*rc != '\0') include(rc); Modified: stable/11/sys/boot/common/interp_forth.c ============================================================================== --- stable/11/sys/boot/common/interp_forth.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/common/interp_forth.c Thu Feb 8 02:50:47 2018 (r329011) @@ -63,7 +63,6 @@ extern unsigned bootprog_rev; FICL_SYSTEM *bf_sys; FICL_VM *bf_vm; -FICL_WORD *pInterp; /* * Shim for taking commands from BF and passing them out to 'standard' @@ -280,8 +279,6 @@ bf_init(const char *rc) ficlSetEnv(bf_sys, "FreeBSD_version", __FreeBSD_version); ficlSetEnv(bf_sys, "loader_version", bootprog_rev); - pInterp = ficlLookup(bf_sys, "interpret"); - /* try to load and run init file if present */ if (rc == NULL) rc = "/boot/boot.4th"; @@ -292,9 +289,6 @@ bf_init(const char *rc) close(fd); } } - - /* Do this again, so that interpret can be redefined. */ - pInterp = ficlLookup(bf_sys, "interpret"); } /* Modified: stable/11/sys/boot/common/loader.8 ============================================================================== --- stable/11/sys/boot/common/loader.8 Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/common/loader.8 Thu Feb 8 02:50:47 2018 (r329011) @@ -90,9 +90,7 @@ which is default. After that, .Pa /boot/loader.rc -is processed if available, and, failing that, -.Pa /boot/boot.conf -is read for historical reasons. +is processed if available. These files are processed through the .Ic include command, which reads all of them into memory before processing them, @@ -957,10 +955,6 @@ itself. Additional .Tn FICL initialization. -.It Pa /boot/boot.conf -.Nm -bootstrapping script. -Deprecated. .It Pa /boot/defaults/loader.conf .It Pa /boot/loader.conf .It Pa /boot/loader.conf.local Modified: stable/11/sys/boot/common/newvers.sh ============================================================================== --- stable/11/sys/boot/common/newvers.sh Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/common/newvers.sh Thu Feb 8 02:50:47 2018 (r329011) @@ -14,7 +14,7 @@ # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. -# 4. Neither the name of the University nor the names of its contributors +# 3. Neither the name of the University nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # Modified: stable/11/sys/boot/common/pnp.c ============================================================================== --- stable/11/sys/boot/common/pnp.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/common/pnp.c Thu Feb 8 02:50:47 2018 (r329011) @@ -17,8 +17,11 @@ __FBSDID("$FreeBSD$"); #include #include #include +#ifdef BOOT_FORTH +#include "ficl.h" +#endif -struct pnpinfo_stql pnp_devices; +static struct pnpinfo_stql pnp_devices; static int pnp_devices_initted = 0; static void pnp_discard(void); @@ -185,3 +188,49 @@ pnp_eisaformat(u_int8_t *data) return(idbuf); } +#ifdef BOOT_FORTH +void +ficlPnpdevices(FICL_VM *pVM) +{ + static int pnp_devices_initted = 0; +#if FICL_ROBUST > 1 + vmCheckStack(pVM, 0, 1); +#endif + + if(!pnp_devices_initted) { + STAILQ_INIT(&pnp_devices); + pnp_devices_initted = 1; + } + + stackPushPtr(pVM->pStack, &pnp_devices); + + return; +} + +void +ficlPnphandlers(FICL_VM *pVM) +{ +#if FICL_ROBUST > 1 + vmCheckStack(pVM, 0, 1); +#endif + + stackPushPtr(pVM->pStack, pnphandlers); + + return; +} + +/* + * Glue function to add the appropriate forth words to access pnp BIOS + * functionality. + */ +static void ficlCompilePnp(FICL_SYSTEM *pSys) +{ + FICL_DICT *dp = pSys->dp; + assert (dp); + + dictAppendWord(dp, "pnpdevices",ficlPnpdevices, FW_DEFAULT); + dictAppendWord(dp, "pnphandlers",ficlPnphandlers, FW_DEFAULT); +} + +FICL_COMPILE_SET(ficlCompilePnp); +#endif Modified: stable/11/sys/boot/efi/libefi/Makefile ============================================================================== --- stable/11/sys/boot/efi/libefi/Makefile Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/libefi/Makefile Thu Feb 8 02:50:47 2018 (r329011) @@ -1,16 +1,25 @@ # $FreeBSD$ +.include + +.if ${MK_FORTH} != "no" +.include "${.CURDIR}/../../Makefile.ficl" +.endif + LIB= efi INTERNALLIB= WARNS?= 2 -SRCS= delay.c devpath.c efi_console.c efinet.c efipart.c env.c errno.c \ +SRCS= delay.c devpath.c efi_console.c efinet.c efipart.c errno.c \ handles.c libefi.c .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386" SRCS+= time.c .elif ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "arm" SRCS+= time_event.c +.endif +.if ${MK_FORTH} != "no" +SRCS+= env.c .endif # We implement a slightly non-standard %S in that it always takes a Modified: stable/11/sys/boot/efi/libefi/efinet.c ============================================================================== --- stable/11/sys/boot/efi/libefi/efinet.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/libefi/efinet.c Thu Feb 8 02:50:47 2018 (r329011) @@ -360,10 +360,12 @@ efinet_dev_print(int verbose) for (unit = 0, h = efi_find_handle(&efinet_dev, 0); h != NULL; h = efi_find_handle(&efinet_dev, ++unit)) { printf(" %s%d:", efinet_dev.dv_name, unit); - text = efi_devpath_name(efi_lookup_devpath(h)); - if (text != NULL) { - printf(" %S", text); - efi_free_devpath_name(text); + if (verbose) { + text = efi_devpath_name(efi_lookup_devpath(h)); + if (text != NULL) { + printf(" %S", text); + efi_free_devpath_name(text); + } } if ((ret = pager_output("\n")) != 0) break; Modified: stable/11/sys/boot/efi/libefi/env.c ============================================================================== --- stable/11/sys/boot/efi/libefi/env.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/libefi/env.c Thu Feb 8 02:50:47 2018 (r329011) @@ -26,9 +26,16 @@ #include __FBSDID("$FreeBSD$"); +#include +#include #include #include +#include +#include "bootstrap.h" +#include "ficl.h" +int efi_variable_support = 1; + /* * Simple wrappers to the underlying UEFI functions. * See http://wiki.phoenix.com/wiki/index.php/EFI_RUNTIME_SERVICES @@ -53,3 +60,175 @@ efi_set_variable(CHAR16 *variable_name, EFI_GUID *vend { return RS->SetVariable(variable_name, vendor_guid, attributes, data_size, data); } + +/* + * FreeBSD's loader interaction words and extras + * + * efi-setenv ( value n name n guid n attr -- 0 | -1) + * efi-getenv ( guid n addr n -- addr' n' | -1 ) + * efi-unsetenv ( name n guid n'' -- ) + */ + +/* + * efi-setenv + * efi-setenv ( value n name n guid n attr -- 0 | -1) + * + * Set environment variables using the SetVariable EFI runtime service. + * + * Value and guid are passed through in binary form (so guid needs to be + * converted to binary form from its string form). Name is converted from + * ASCII to CHAR16. Since ficl doesn't have support for internationalization, + * there's no native CHAR16 interface provided. + * + * attr is an int in the bitmask of the following attributes for this variable. + * + * 1 Non volatile + * 2 Boot service access + * 4 Run time access + * (corresponding to the same bits in the UEFI spec). + */ +void +ficlEfiSetenv(FICL_VM *pVM) +{ +#ifndef TESTMAIN + char *value = NULL, *guid = NULL; + CHAR16 *name = NULL; + int i; +#endif + char *namep, *valuep, *guidp; + int names, values, guids, attr; + int status; + uuid_t u; + uint32_t ustatus; + +#if FICL_ROBUST > 1 + vmCheckStack(pVM, 6, 0); +#endif + attr = stackPopINT(pVM->pStack); + guids = stackPopINT(pVM->pStack); + guidp = (char*)stackPopPtr(pVM->pStack); + names = stackPopINT(pVM->pStack); + namep = (char*)stackPopPtr(pVM->pStack); + values = stackPopINT(pVM->pStack); + valuep = (char*)stackPopPtr(pVM->pStack); + +#ifndef TESTMAIN + guid = (char*)ficlMalloc(guids); + if (guid == NULL) + vmThrowErr(pVM, "Error: out of memory"); + memcpy(guid, guidp, guids); + uuid_from_string(guid, &u, &ustatus); + if (ustatus != uuid_s_ok) { + stackPushINT(pVM->pStack, -1); + goto out; + } + + name = (CHAR16 *)ficlMalloc((names + 1) * sizeof(CHAR16)); + if (name == NULL) + vmThrowErr(pVM, "Error: out of memory"); + for (i = 0; i < names; i++) + name[i] = namep[i]; + name[names] = (CHAR16)0; + + value = (char*)ficlMalloc(values + 1); + if (value == NULL) + vmThrowErr(pVM, "Error: out of memory"); + memcpy(value, valuep, values); + + status = efi_set_variable(name, (EFI_GUID *)&u, attr, values, value); + if (status == EFI_SUCCESS) + stackPushINT(pVM->pStack, 0); + else + stackPushINT(pVM->pStack, -1); +out: + ficlFree(name); + ficlFree(value); + ficlFree(guid); +#endif + + return; +} + +void +ficlEfiGetenv(FICL_VM *pVM) +{ +#ifndef TESTMAIN + char *name, *value; +#endif + char *namep; + int names; + +#if FICL_ROBUST > 1 + vmCheckStack(pVM, 2, 2); +#endif + names = stackPopINT(pVM->pStack); + namep = (char*) stackPopPtr(pVM->pStack); + +#ifndef TESTMAIN + name = (char*) ficlMalloc(names+1); + if (name == NULL) + vmThrowErr(pVM, "Error: out of memory"); + strncpy(name, namep, names); + name[names] = '\0'; + + value = getenv(name); + ficlFree(name); + + if(value != NULL) { + stackPushPtr(pVM->pStack, value); + stackPushINT(pVM->pStack, strlen(value)); + } else +#endif + stackPushINT(pVM->pStack, -1); + + return; +} + +void +ficlEfiUnsetenv(FICL_VM *pVM) +{ +#ifndef TESTMAIN + char *name; +#endif + char *namep; + int names; + +#if FICL_ROBUST > 1 + vmCheckStack(pVM, 2, 0); +#endif + names = stackPopINT(pVM->pStack); + namep = (char*) stackPopPtr(pVM->pStack); + +#ifndef TESTMAIN + name = (char*) ficlMalloc(names+1); + if (name == NULL) + vmThrowErr(pVM, "Error: out of memory"); + strncpy(name, namep, names); + name[names] = '\0'; + + unsetenv(name); + ficlFree(name); +#endif + + return; +} + +/************************************************************************** +** Add FreeBSD UEFI platform extensions into the system dictionary +**************************************************************************/ +void ficlEfiCompilePlatform(FICL_SYSTEM *pSys) +{ + FICL_DICT *dp = pSys->dp; + assert (dp); + + dictAppendWord(dp, "efi-setenv", ficlEfiSetenv, FW_DEFAULT); + dictAppendWord(dp, "efi-getenv", ficlEfiGetenv, FW_DEFAULT); + dictAppendWord(dp, "efi-unsetenv", ficlEfiUnsetenv, FW_DEFAULT); + + /* Would like to export the EFI version, but this will do for now */ + ficlSetEnv(pSys, "efi-boot", 1); + + return; +} + +FICL_COMPILE_SET(ficlEfiCompilePlatform); Modified: stable/11/sys/boot/efi/loader/Makefile ============================================================================== --- stable/11/sys/boot/efi/loader/Makefile Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/loader/Makefile Thu Feb 8 02:50:47 2018 (r329011) @@ -146,6 +146,7 @@ loader.efi: ${PROG} ${OBJCOPY} -j .peheader -j .text -j .sdata -j .data \ -j .dynamic -j .dynsym -j .rel.dyn \ -j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \ + -j set_Xficl_compile_set \ --output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET} LIBEFI= ${.OBJDIR}/../libefi/libefi.a Modified: stable/11/sys/boot/efi/loader/arch/amd64/ldscript.amd64 ============================================================================== --- stable/11/sys/boot/efi/loader/arch/amd64/ldscript.amd64 Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/loader/arch/amd64/ldscript.amd64 Thu Feb 8 02:50:47 2018 (r329011) @@ -40,6 +40,11 @@ SECTIONS *(set_Xcommand_set) __stop_set_Xcommand_set = .; } + set_Xficl_compile_set : { + __start_set_Xficl_compile_set = .; + *(set_Xficl_compile_set) + __stop_set_Xficl_compile_set = .; + } . = ALIGN(4096); __gp = .; .sdata : { Modified: stable/11/sys/boot/efi/loader/arch/arm/ldscript.arm ============================================================================== --- stable/11/sys/boot/efi/loader/arch/arm/ldscript.arm Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/loader/arch/arm/ldscript.arm Thu Feb 8 02:50:47 2018 (r329011) @@ -47,6 +47,11 @@ SECTIONS *(set_Xcommand_set) __stop_set_Xcommand_set = .; } + set_Xficl_compile_set : { + __start_set_Xficl_compile_set = .; + *(set_Xficl_compile_set) + __stop_set_Xficl_compile_set = .; + } __gp = .; .plt : { *(.plt) } .dynamic : { *(.dynamic) } Modified: stable/11/sys/boot/efi/loader/arch/arm64/ldscript.arm64 ============================================================================== --- stable/11/sys/boot/efi/loader/arch/arm64/ldscript.arm64 Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/loader/arch/arm64/ldscript.arm64 Thu Feb 8 02:50:47 2018 (r329011) @@ -43,6 +43,11 @@ SECTIONS *(set_Xcommand_set) __stop_set_Xcommand_set = .; } + set_Xficl_compile_set : { + __start_set_Xficl_compile_set = .; + *(set_Xficl_compile_set) + __stop_set_Xficl_compile_set = .; + } . = ALIGN(16); __gp = .; .sdata : { Modified: stable/11/sys/boot/efi/loader/arch/i386/efimd.c ============================================================================== --- stable/11/sys/boot/efi/loader/arch/i386/efimd.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/loader/arch/i386/efimd.c Thu Feb 8 02:50:47 2018 (r329011) @@ -48,7 +48,10 @@ static EFI_GUID hcdp_guid = HCDP_TABLE_GUID; static UINTN mapkey; -uint64_t +int ldr_bootinfo(struct bootinfo *, uint64_t *); +int ldr_enter(const char *); + +static uint64_t ldr_alloc(vm_offset_t va) { Modified: stable/11/sys/boot/efi/loader/arch/i386/elf32_freebsd.c ============================================================================== --- stable/11/sys/boot/efi/loader/arch/i386/elf32_freebsd.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/loader/arch/i386/elf32_freebsd.c Thu Feb 8 02:50:47 2018 (r329011) @@ -35,13 +35,17 @@ __FBSDID("$FreeBSD$"); #include #include +#include +#include + #include "bootstrap.h" #include "../libi386/libi386.h" #include "../btx/lib/btxv86.h" extern void __exec(caddr_t addr, ...); +extern int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp); +extern int ldr_enter(const char *kernel); - static int elf32_exec(struct preloaded_file *amp); static int elf32_obj_exec(struct preloaded_file *amp); @@ -72,14 +76,14 @@ elf32_exec(struct preloaded_file *fp) ehdr = (Elf_Ehdr *)&(md->md_data); efi_time_fini(); - err = bi_load(fp->f_args, &boothowto, &bootdev, &bootinfop, &modulep, &kernend); + err = bi_load(fp->f_args, &modulep, &kernend); if (err != 0) { efi_time_init(); return(err); } entry = ehdr->e_entry & 0xffffff; - printf("Start @ 0x%lx ...\n", entry); + printf("Start @ 0x%x ...\n", entry); ldr_enter(fp->f_name); Modified: stable/11/sys/boot/efi/loader/arch/i386/exec.c ============================================================================== --- stable/11/sys/boot/efi/loader/arch/i386/exec.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/loader/arch/i386/exec.c Thu Feb 8 02:50:47 2018 (r329011) @@ -36,6 +36,12 @@ __FBSDID("$FreeBSD$"); uint32_t __base; struct __v86 __v86; +/* XXX - Needed a definition here to implicitly define exit(); do not remove. */ +static void +exit(int x) +{ +} + void __v86int() { Modified: stable/11/sys/boot/efi/loader/arch/i386/ldscript.i386 ============================================================================== --- stable/11/sys/boot/efi/loader/arch/i386/ldscript.i386 Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/loader/arch/i386/ldscript.i386 Thu Feb 8 02:50:47 2018 (r329011) @@ -35,6 +35,11 @@ SECTIONS *(set_Xcommand_set) __stop_set_Xcommand_set = .; } + set_Xficl_compile_set : { + __start_set_Xficl_compile_set = .; + *(set_Xficl_compile_set) + __stop_set_Xficl_compile_set = .; + } . = ALIGN(4096); __gp = .; .sdata : { Modified: stable/11/sys/boot/efi/loader/main.c ============================================================================== --- stable/11/sys/boot/efi/loader/main.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/efi/loader/main.c Thu Feb 8 02:50:47 2018 (r329011) @@ -52,6 +52,22 @@ __FBSDID("$FreeBSD$"); extern char bootprog_info[]; +#ifdef BOOT_FORTH +/* + * Normally, efi.o from libefi.a would be brought in due to a function we call + * there that's defined there. However, none of its functions are callable from + * here since it just adds words to the FORTH environment or implement those + * words. So, add a reference to a symbol in efi.o to force it to be be brought + * in so the init function there gets added to the "compile" linker set happens + * correctly. + * + * This assumes there's no global analysys that notices dummy1 isn't used + * anywhere and tries to eliminate it. + */ +extern int efi_variable_support; +int *dummy1 = &efi_variable_support; +#endif + struct arch_switch archsw; /* MI/MD interface boundary */ EFI_GUID acpi = ACPI_TABLE_GUID; @@ -218,6 +234,11 @@ find_currdev(EFI_LOADED_IMAGE *img, struct devsw **dev } } + /* Try to fallback on first device */ + if (devsw[0] != NULL) { + *dev = devsw[0]; + return (0); + } return (ENOENT); } @@ -232,6 +253,7 @@ main(int argc, CHAR16 *argv[]) uint64_t pool_guid; UINTN k; int has_kbd; + char buf[40]; archsw.arch_autoload = efi_autoload; archsw.arch_getdev = efi_getdev; @@ -442,6 +464,9 @@ main(int argc, CHAR16 *argv[]) for (k = 0; k < ST->NumberOfTableEntries; k++) { guid = &ST->ConfigurationTable[k].VendorGuid; if (!memcmp(guid, &smbios, sizeof(EFI_GUID))) { + snprintf(buf, sizeof(buf), "%p", + ST->ConfigurationTable[k].VendorTable); + setenv("hint.smbios.0.mem", buf, 1); smbios_detect(ST->ConfigurationTable[k].VendorTable); break; } @@ -613,7 +638,8 @@ command_configuration(int argc, char *argv[]) else if (!memcmp(guid, &acpi20, sizeof(EFI_GUID))) printf("ACPI 2.0 Table"); else if (!memcmp(guid, &smbios, sizeof(EFI_GUID))) - printf("SMBIOS Table"); + printf("SMBIOS Table %p", + ST->ConfigurationTable[i].VendorTable); else if (!memcmp(guid, &dxe, sizeof(EFI_GUID))) printf("DXE Table"); else if (!memcmp(guid, &hoblist, sizeof(EFI_GUID))) @@ -915,8 +941,8 @@ command_efi_show(int argc, char *argv[]) return (rv); } - if (argc != 0) { - printf("Too many args\n"); + if (argc > 0) { + printf("Too many args %d\n", argc); pager_close(); return (CMD_ERROR); } Modified: stable/11/sys/boot/ficl/Makefile ============================================================================== --- stable/11/sys/boot/ficl/Makefile Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/ficl/Makefile Thu Feb 8 02:50:47 2018 (r329011) @@ -1,15 +1,8 @@ # $FreeBSD$ # -FICLDIR?= ${.CURDIR} +.include "${.CURDIR}/../Makefile.ficl" -.if defined(FICL32) -.PATH: ${FICLDIR}/${MACHINE_CPUARCH:S/amd64/i386/} -.elif ${MACHINE_ARCH} == "mips64" || ${MACHINE_ARCH} == "mips64el" -.PATH: ${FICLDIR}/mips64 -.else -.PATH: ${FICLDIR}/${MACHINE_CPUARCH} -.endif BASE_SRCS= dict.c ficl.c fileaccess.c float.c loader.c math64.c \ prefix.c search.c stack.c tools.c vm.c words.c @@ -41,42 +34,6 @@ SOFTWORDS= softcore.fr jhlocal.fr marker.fr freebsd.fr # Optional OO extension softwords #SOFTWORDS+= oo.fr classes.fr -.if ${MACHINE_CPUARCH} == "amd64" -.if defined(FICL32) -CFLAGS+= -m32 -I. -.else -CFLAGS+= -fPIC -.endif -.endif - -.if ${MACHINE_ARCH} == "powerpc64" -CFLAGS+= -m32 -mcpu=powerpc -I. -.endif - -.if ${MACHINE_CPUARCH} == "amd64" && defined(FICL32) -FICL_CPUARCH= i386 -.elif ${MACHINE_ARCH} == "mips64" || ${MACHINE_ARCH} == "mips64el" -FICL_CPUARCH= mips64 -.else -FICL_CPUARCH= ${MACHINE_CPUARCH} -.endif - -CFLAGS+= -I${FICLDIR} -I${FICLDIR}/${FICL_CPUARCH} \ - -I${FICLDIR}/../common - softcore.c: ${SOFTWORDS} softcore.awk (cd ${FICLDIR}/softwords; cat ${SOFTWORDS} \ | awk -f softcore.awk -v datestamp="`LC_ALL=C date`") > ${.TARGET} - -.if ${MACHINE_CPUARCH} == "amd64" && defined(FICL32) -.if !exists(machine) -${SRCS:M*.c:R:S/$/.o/g}: machine - -beforedepend ${OBJS}: machine -.endif - -machine: .NOMETA - ln -sf ${.CURDIR}/../../i386/include machine - -CLEANFILES+= machine -.endif Modified: stable/11/sys/boot/ficl/ficl.h ============================================================================== --- stable/11/sys/boot/ficl/ficl.h Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/ficl/ficl.h Thu Feb 8 02:50:47 2018 (r329011) @@ -1150,6 +1150,13 @@ typedef struct ficlFILE } ficlFILE; #endif +#include + +typedef void ficlCompileFcn(FICL_SYSTEM *); +#define FICL_COMPILE_SET(func) \ + DATA_SET(Xficl_compile_set, func) +SET_DECLARE(Xficl_compile_set, ficlCompileFcn); + #ifdef __cplusplus } #endif Modified: stable/11/sys/boot/ficl/i386/sysdep.c ============================================================================== --- stable/11/sys/boot/ficl/i386/sysdep.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/ficl/i386/sysdep.c Thu Feb 8 02:50:47 2018 (r329011) @@ -81,7 +81,6 @@ void ficlFree (void *p) } #ifndef TESTMAIN -#ifdef __i386__ /* * outb ( port# c -- ) * Store a byte to I/O port number port# @@ -111,7 +110,22 @@ ficlInb(FICL_VM *pVM) c=inb(port); stackPushINT(pVM->pStack,c); } -#endif + +/* + * Glue function to add the appropriate forth words to access x86 special cpu + * functionality. + */ +static void ficlCompileCpufunc(FICL_SYSTEM *pSys) +{ + FICL_DICT *dp = pSys->dp; + assert (dp); + + dictAppendWord(dp, "outb", ficlOutb, FW_DEFAULT); + dictAppendWord(dp, "inb", ficlInb, FW_DEFAULT); +} + +FICL_COMPILE_SET(ficlCompileCpufunc); + #endif /* Modified: stable/11/sys/boot/ficl/loader.c ============================================================================== --- stable/11/sys/boot/ficl/loader.c Thu Feb 8 02:44:21 2018 (r329010) +++ stable/11/sys/boot/ficl/loader.c Thu Feb 8 02:50:47 2018 (r329011) @@ -287,44 +287,7 @@ ficlFindfile(FICL_VM *pVM) return; } -#ifndef TESTMAIN -#ifdef HAVE_PNP - void -ficlPnpdevices(FICL_VM *pVM) -{ - static int pnp_devices_initted = 0; -#if FICL_ROBUST > 1 - vmCheckStack(pVM, 0, 1); -#endif - - if(!pnp_devices_initted) { - STAILQ_INIT(&pnp_devices); - pnp_devices_initted = 1; - } - - stackPushPtr(pVM->pStack, &pnp_devices); - - return; -} - -void -ficlPnphandlers(FICL_VM *pVM) -{ -#if FICL_ROBUST > 1 - vmCheckStack(pVM, 0, 1); -#endif - - stackPushPtr(pVM->pStack, pnphandlers); - - return; -} - -#endif - -#endif /* ndef TESTMAIN */ - -void ficlCcall(FICL_VM *pVM) { int (*func)(int, ...); @@ -800,142 +763,7 @@ static void fkey(FICL_VM *pVM) } -#ifdef __i386__ /* - * pcibios-device-count (devid -- count) - * - * Returns the PCI BIOS' count of how many devices matching devid are in the system. - * devid is the 32-bit vendor + device. - */ -static void -ficlPciBiosCountDevices(FICL_VM *pVM) -{ - uint32_t devid; - int i; - - devid = stackPopINT(pVM->pStack); - - i = biospci_count_device_type(devid); - - stackPushINT(pVM->pStack, i); -} - -/* - * pcibios-write-config (locator offset width value -- ) - * - * Writes the specified config register. - * Locator is bus << 8 | device << 3 | fuction - * offset is the pci config register - * width is 0 for byte, 1 for word, 2 for dword - * value is the value to write - */ -static void -ficlPciBiosWriteConfig(FICL_VM *pVM) -{ - uint32_t value, width, offset, locator; - - value = stackPopINT(pVM->pStack); - width = stackPopINT(pVM->pStack); - offset = stackPopINT(pVM->pStack); - locator = stackPopINT(pVM->pStack); - - biospci_write_config(locator, offset, width, value); -} - -/* - * pcibios-read-config (locator offset width -- value) - * - * Reads the specified config register. - * Locator is bus << 8 | device << 3 | fuction - * offset is the pci config register - * width is 0 for byte, 1 for word, 2 for dword - * value is the value to read from the register - */ -static void -ficlPciBiosReadConfig(FICL_VM *pVM) -{ - uint32_t value, width, offset, locator; - - width = stackPopINT(pVM->pStack); - offset = stackPopINT(pVM->pStack); - locator = stackPopINT(pVM->pStack); - - biospci_read_config(locator, offset, width, &value); - - stackPushINT(pVM->pStack, value); -} - -/* - * pcibios-find-devclass (class index -- locator) - * - * Finds the index'th instance of class in the pci tree. - * must be an exact match. - * class is the class to search for. - * index 0..N (set to 0, increment until error) - * - * Locator is bus << 8 | device << 3 | fuction (or -1 on error) - */ -static void -ficlPciBiosFindDevclass(FICL_VM *pVM) -{ - uint32_t index, class, locator; - - index = stackPopINT(pVM->pStack); - class = stackPopINT(pVM->pStack); - - if (biospci_find_devclass(class, index, &locator)) - locator = 0xffffffff; - - stackPushINT(pVM->pStack, locator); -} - -/* - * pcibios-find-device(devid index -- locator) - * - * Finds the index'th instance of devid in the pci tree. - * must be an exact match. - * class is the class to search for. - * index 0..N (set to 0, increment until error) - * - * Locator is bus << 8 | device << 3 | fuction (or -1 on error) - */ -static void -ficlPciBiosFindDevice(FICL_VM *pVM) -{ - uint32_t index, devid, locator; - - index = stackPopINT(pVM->pStack); - devid = stackPopINT(pVM->pStack); - - if (biospci_find_device(devid, index, &locator)) - locator = 0xffffffff; - - stackPushINT(pVM->pStack, locator); -} - *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***