From: mlarkin Date: Wed, 11 Jul 2018 18:08:05 +0000 (+0000) Subject: Detect vmm(4) in the bootloader and automatically switch to the serial X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=dbaca21c856755abb3d5b686aced4236a5861790;p=openbsd Detect vmm(4) in the bootloader and automatically switch to the serial console at 115200 baud. ok deraadt --- diff --git a/sys/arch/i386/stand/boot/conf.c b/sys/arch/i386/stand/boot/conf.c index 46338319244..8609b1ef196 100644 --- a/sys/arch/i386/stand/boot/conf.c +++ b/sys/arch/i386/stand/boot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.62 2017/09/08 05:36:51 deraadt Exp $ */ +/* $OpenBSD: conf.c,v 1.63 2018/07/11 18:08:05 mlarkin Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -41,7 +41,7 @@ #include #include "debug.h" -const char version[] = "3.31"; +const char version[] = "3.32"; int debug = 1; diff --git a/sys/arch/i386/stand/cdboot/conf.c b/sys/arch/i386/stand/cdboot/conf.c index 1daefd490e6..df50d2e23e0 100644 --- a/sys/arch/i386/stand/cdboot/conf.c +++ b/sys/arch/i386/stand/cdboot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.31 2017/09/08 05:36:52 deraadt Exp $ */ +/* $OpenBSD: conf.c,v 1.32 2018/07/11 18:08:05 mlarkin Exp $ */ /* * Copyright (c) 2004 Tom Cosgrove @@ -42,7 +42,7 @@ #include #include "debug.h" -const char version[] = "3.28"; +const char version[] = "3.29"; int debug = 1; void (*sa_cleanup)(void) = NULL; diff --git a/sys/arch/i386/stand/libsa/machdep.c b/sys/arch/i386/stand/libsa/machdep.c index f0abd6613f7..37a9f2559d6 100644 --- a/sys/arch/i386/stand/libsa/machdep.c +++ b/sys/arch/i386/stand/libsa/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.38 2015/09/18 13:30:56 miod Exp $ */ +/* $OpenBSD: machdep.c,v 1.39 2018/07/11 18:08:05 mlarkin Exp $ */ /* * Copyright (c) 2004 Tom Cosgrove @@ -31,6 +31,9 @@ #include "biosdev.h" #include #include +#include +#include +#include #ifdef EFIBOOT #include "efiboot.h" @@ -44,11 +47,15 @@ volatile struct BIOS_regs BIOS_regs; #define CKPT(c) /* c */ #endif +const char *vmm_hv_signature = VMM_HV_SIGNATURE; + void machdep(void) { - int i, j; + int i, j, vmm = 0, psl_check; struct i386_boot_probes *pr; + uint32_t dummy, ebx, ecx, edx; + dev_t dev; /* * The list of probe routines is now in conf.c. @@ -65,6 +72,55 @@ machdep(void) printf("\n"); } } + + /* + * The following is a simple check to see if cpuid is supported. + * We try to toggle bit 21 (PSL_ID) in eflags. If it works, then + * cpuid is supported. If not, there's no cpuid, and we don't + * try it (don't want /boot to get an invalid opcode exception). + * + * XXX The NexGen Nx586 does not support this bit, so this is not + * a good method to detect the presence of cpuid on this + * processor. That's fine: the purpose here is to detect the + * absence of cpuid. We don't mind if the instruction's not + * there - this is not intended to determine exactly what + * processor is there, just whether it's i386 or amd64. + * + * The only thing that would cause us grief is a processor which + * does not support cpuid but which does allow the PSL_ID bit + * in eflags to be toggled. + */ + __asm volatile( + "pushfl\n\t" + "popl %2\n\t" + "xorl %2, %0\n\t" + "pushl %0\n\t" + "popfl\n\t" + "pushfl\n\t" + "popl %0\n\t" + "xorl %2, %0\n\t" /* If %2 == %0, no cpuid */ + : "=r" (psl_check) + : "0" (PSL_ID), "r" (0) + : "cc"); + + if (psl_check != PSL_ID) + return; + + CPUID(0x1, dummy, dummy, ecx, dummy); + if (ecx & CPUIDECX_HV) { + CPUID(0x40000000, dummy, ebx, ecx, edx); + if (memcmp(&ebx, &vmm_hv_signature[0], sizeof(uint32_t)) == 0 && + memcmp(&ecx, &vmm_hv_signature[4], sizeof(uint32_t)) == 0 && + memcmp(&edx, &vmm_hv_signature[8], sizeof(uint32_t)) == 0) + vmm = 1; + } + + /* Set console to com0/115200 by default in vmm */ + if (vmm) { + dev = ttydev("com0"); + cnspeed(dev, 115200); + cnset(dev); + } } int check_skip_conf(void) diff --git a/sys/arch/i386/stand/pxeboot/conf.c b/sys/arch/i386/stand/pxeboot/conf.c index 705a054e8d3..2ffe11c1adc 100644 --- a/sys/arch/i386/stand/pxeboot/conf.c +++ b/sys/arch/i386/stand/pxeboot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.36 2017/09/08 05:36:52 deraadt Exp $ */ +/* $OpenBSD: conf.c,v 1.37 2018/07/11 18:08:05 mlarkin Exp $ */ /* * Copyright (c) 2004 Tom Cosgrove @@ -44,7 +44,7 @@ #include "pxeboot.h" #include "pxe_net.h" -const char version[] = "3.28"; +const char version[] = "3.29"; int debug = 1; void (*sa_cleanup)(void) = pxe_shutdown;