svn commit: r354230 - in stable/12/stand: . efi/loader ficl ficl/amd64 ficl/i386 ficl/x86 i386/loader libsa libsa/x86
Simon J. Gerraty
sjg at FreeBSD.org
Thu Oct 31 21:33:01 UTC 2019
Author: sjg
Date: Thu Oct 31 21:32:59 2019
New Revision: 354230
URL: https://svnweb.freebsd.org/changeset/base/354230
Log:
Add support for hypervisor check on x86
Add ficl words for isvirtualized
and move ficl inb and outb words to ficl/x86/sysdep.c
so can be shared by i386 and amd64
MFC of r354043, r354055
Reviewed by: imp bdrewery
Sponsored by: Juniper Networks
Differential Revision: https://reviews.freebsd.org/D22069
Added:
stable/12/stand/ficl/x86/
- copied from r354043, head/stand/ficl/x86/
stable/12/stand/libsa/x86/
- copied from r354043, head/stand/libsa/x86/
Modified:
stable/12/stand/defs.mk
stable/12/stand/efi/loader/main.c
stable/12/stand/ficl/amd64/sysdep.c
stable/12/stand/ficl/i386/sysdep.c
stable/12/stand/ficl/loader.c
stable/12/stand/i386/loader/main.c
stable/12/stand/libsa/Makefile
stable/12/stand/libsa/stand.h
Modified: stable/12/stand/defs.mk
==============================================================================
--- stable/12/stand/defs.mk Thu Oct 31 21:01:34 2019 (r354229)
+++ stable/12/stand/defs.mk Thu Oct 31 21:32:59 2019 (r354230)
@@ -182,14 +182,15 @@ CFLAGS+=-I.
all: ${PROG}
.if !defined(NO_OBJ)
-_ILINKS=machine
+_ILINKS=include/machine
.if ${MACHINE} != ${MACHINE_CPUARCH} && ${MACHINE} != "arm64"
-_ILINKS+=${MACHINE_CPUARCH}
+_ILINKS+=include/${MACHINE_CPUARCH}
.endif
.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
-_ILINKS+=x86
+_ILINKS+=include/x86
.endif
-CLEANFILES+=${_ILINKS}
+CFLAGS+= -Iinclude
+CLEANDIRS+= include
beforedepend: ${_ILINKS}
beforebuild: ${_ILINKS}
@@ -204,8 +205,8 @@ ${OBJS}: ${_link}
.NOPATH: ${_ILINKS}
-${_ILINKS}:
- @case ${.TARGET} in \
+${_ILINKS}: .NOMETA
+ @case ${.TARGET:T} in \
machine) \
if [ ${DO32:U0} -eq 0 ]; then \
path=${SYSDIR}/${MACHINE}/include ; \
@@ -215,8 +216,11 @@ ${_ILINKS}:
*) \
path=${SYSDIR}/${.TARGET:T}/include ;; \
esac ; \
+ case ${.TARGET} in \
+ */*) mkdir -p ${.TARGET:H};; \
+ esac ; \
path=`(cd $$path && /bin/pwd)` ; \
- ${ECHO} ${.TARGET:T} "->" $$path ; \
- ln -fhs $$path ${.TARGET:T}
+ ${ECHO} ${.TARGET} "->" $$path ; \
+ ln -fhs $$path ${.TARGET}
.endif # !NO_OBJ
.endif # __BOOT_DEFS_MK__
Modified: stable/12/stand/efi/loader/main.c
==============================================================================
--- stable/12/stand/efi/loader/main.c Thu Oct 31 21:01:34 2019 (r354229)
+++ stable/12/stand/efi/loader/main.c Thu Oct 31 21:32:59 2019 (r354230)
@@ -863,6 +863,9 @@ main(int argc, CHAR16 *argv[])
archsw.arch_getdev = efi_getdev;
archsw.arch_copyin = efi_copyin;
archsw.arch_copyout = efi_copyout;
+#ifdef __amd64__
+ archsw.arch_hypervisor = x86_hypervisor;
+#endif
archsw.arch_readin = efi_readin;
archsw.arch_zfs_probe = efi_zfs_probe;
Modified: stable/12/stand/ficl/amd64/sysdep.c
==============================================================================
--- stable/12/stand/ficl/amd64/sysdep.c Thu Oct 31 21:01:34 2019 (r354229)
+++ stable/12/stand/ficl/amd64/sysdep.c Thu Oct 31 21:32:59 2019 (r354230)
@@ -17,6 +17,8 @@
#endif
#include "ficl.h"
+#include "../x86/sysdep.c"
+
/*
******************* FreeBSD P O R T B E G I N S H E R E ******************** Michael Smith
*/
Modified: stable/12/stand/ficl/i386/sysdep.c
==============================================================================
--- stable/12/stand/ficl/i386/sysdep.c Thu Oct 31 21:01:34 2019 (r354229)
+++ stable/12/stand/ficl/i386/sysdep.c Thu Oct 31 21:32:59 2019 (r354230)
@@ -14,12 +14,11 @@
#include <stdlib.h>
#else
#include <stand.h>
-#ifdef __i386__
-#include <machine/cpufunc.h>
#endif
-#endif
#include "ficl.h"
+#include "../x86/sysdep.c"
+
/*
******************* FreeBSD P O R T B E G I N S H E R E ******************** Michael Smith
*/
@@ -80,53 +79,6 @@ void ficlFree (void *p)
free(p);
}
-#ifndef TESTMAIN
-/*
- * outb ( port# c -- )
- * Store a byte to I/O port number port#
- */
-void
-ficlOutb(FICL_VM *pVM)
-{
- u_char c;
- uint32_t port;
-
- port=stackPopUNS(pVM->pStack);
- c=(u_char)stackPopINT(pVM->pStack);
- outb(port,c);
-}
-
-/*
- * inb ( port# -- c )
- * Fetch a byte from I/O port number port#
- */
-void
-ficlInb(FICL_VM *pVM)
-{
- u_char c;
- uint32_t port;
-
- port=stackPopUNS(pVM->pStack);
- c=inb(port);
- stackPushINT(pVM->pStack,c);
-}
-
-/*
- * 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
/*
** Stub function for dictionary access control - does nothing
Modified: stable/12/stand/ficl/loader.c
==============================================================================
--- stable/12/stand/ficl/loader.c Thu Oct 31 21:01:34 2019 (r354229)
+++ stable/12/stand/ficl/loader.c Thu Oct 31 21:32:59 2019 (r354230)
@@ -287,6 +287,32 @@ ficlFindfile(FICL_VM *pVM)
return;
}
+#ifndef TESTMAIN
+
+/* isvirtualized? - Return whether the loader runs under a
+ * hypervisor.
+ *
+ * isvirtualized? ( -- flag )
+ */
+static void
+ficlIsvirtualizedQ(FICL_VM *pVM)
+{
+ FICL_INT flag;
+ const char *hv;
+
+#if FICL_ROBUST > 1
+ vmCheckStack(pVM, 0, 1);
+#endif
+
+ hv = (archsw.arch_hypervisor != NULL)
+ ? (*archsw.arch_hypervisor)()
+ : NULL;
+ flag = (hv != NULL) ? FICL_TRUE : FICL_FALSE;
+ stackPushINT(pVM->pStack, flag);
+}
+
+#endif /* ndef TESTMAIN */
+
void
ficlCcall(FICL_VM *pVM)
{
@@ -840,7 +866,10 @@ void ficlCompilePlatform(FICL_SYSTEM *pSys)
dictAppendWord(dp, "ccall", ficlCcall, FW_DEFAULT);
dictAppendWord(dp, "uuid-from-string", ficlUuidFromString, FW_DEFAULT);
dictAppendWord(dp, "uuid-to-string", ficlUuidToString, FW_DEFAULT);
-
+#ifndef TESTMAIN
+ dictAppendWord(dp, "isvirtualized?",ficlIsvirtualizedQ, FW_DEFAULT);
+#endif
+
SET_FOREACH(fnpp, Xficl_compile_set)
(*fnpp)(pSys);
Modified: stable/12/stand/i386/loader/main.c
==============================================================================
--- stable/12/stand/i386/loader/main.c Thu Oct 31 21:01:34 2019 (r354229)
+++ stable/12/stand/i386/loader/main.c Thu Oct 31 21:32:59 2019 (r354230)
@@ -167,6 +167,7 @@ main(void)
archsw.arch_readin = i386_readin;
archsw.arch_isainb = isa_inb;
archsw.arch_isaoutb = isa_outb;
+ archsw.arch_hypervisor = x86_hypervisor;
#ifdef LOADER_ZFS_SUPPORT
archsw.arch_zfs_probe = i386_zfs_probe;
Modified: stable/12/stand/libsa/Makefile
==============================================================================
--- stable/12/stand/libsa/Makefile Thu Oct 31 21:01:34 2019 (r354229)
+++ stable/12/stand/libsa/Makefile Thu Oct 31 21:32:59 2019 (r354230)
@@ -71,6 +71,11 @@ SRCS+= divmoddi4.c divmodsi4.c divdi3.c divsi3.c m
SRCS+= udivmoddi4.c udivmodsi4.c udivdi3.c udivsi3.c umoddi3.c umodsi3.c
SRCS+= ashldi3.c ashrdi3.c lshrdi3.c
+.if ${MACHINE_CPUARCH:Namd64:Ni386} == ""
+.PATH: ${SASRC}/x86
+SRCS+= hypervisor.c
+.endif
+
.if ${MACHINE_CPUARCH} == "powerpc"
SRCS+= syncicache.c
.endif
Modified: stable/12/stand/libsa/stand.h
==============================================================================
--- stable/12/stand/libsa/stand.h Thu Oct 31 21:01:34 2019 (r354229)
+++ stable/12/stand/libsa/stand.h Thu Oct 31 21:32:59 2019 (r354230)
@@ -435,6 +435,8 @@ void *Reallocf(void *, size_t, const char *, int);
void Free(void *, const char *, int);
extern void mallocstats(void);
+const char *x86_hypervisor(void);
+
#ifdef DEBUG_MALLOC
#define malloc(x) Malloc(x, __FILE__, __LINE__)
#define memalign(x, y) Memalign(x, y, __FILE__, __LINE__)
More information about the svn-src-all
mailing list