From owner-svn-src-stable-12@freebsd.org Thu Oct 31 21:33:01 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 6113C167892; Thu, 31 Oct 2019 21:33:01 +0000 (UTC) (envelope-from sjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 473z7x1xW5z3NsY; Thu, 31 Oct 2019 21:33:01 +0000 (UTC) (envelope-from sjg@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 2567CDB6; Thu, 31 Oct 2019 21:33:01 +0000 (UTC) (envelope-from sjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9VLX1Fp066376; Thu, 31 Oct 2019 21:33:01 GMT (envelope-from sjg@FreeBSD.org) Received: (from sjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9VLWxAO066341; Thu, 31 Oct 2019 21:32:59 GMT (envelope-from sjg@FreeBSD.org) Message-Id: <201910312132.x9VLWxAO066341@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sjg set sender to sjg@FreeBSD.org using -f From: "Simon J. Gerraty" Date: Thu, 31 Oct 2019 21:32:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r354230 - in stable/12/stand: . efi/loader ficl ficl/amd64 ficl/i386 ficl/x86 i386/loader libsa libsa/x86 X-SVN-Group: stable-12 X-SVN-Commit-Author: sjg X-SVN-Commit-Paths: in stable/12/stand: . efi/loader ficl ficl/amd64 ficl/i386 ficl/x86 i386/loader libsa libsa/x86 X-SVN-Commit-Revision: 354230 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-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Oct 2019 21:33:01 -0000 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 #else #include -#ifdef __i386__ -#include #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__)