1 /* $OpenBSD: machdep.c,v 1.39 2018/07/11 18:08:05 mlarkin Exp $ */ 2 3 /* 4 * Copyright (c) 2004 Tom Cosgrove 5 * Copyright (c) 1997-1999 Michael Shalayeff 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #include "libsa.h" 31 #include "biosdev.h" 32 #include <machine/apmvar.h> 33 #include <machine/biosvar.h> 34 #include <machine/psl.h> 35 #include <machine/specialreg.h> 36 #include <machine/vmmvar.h> 37 38 #ifdef EFIBOOT 39 #include "efiboot.h" 40 #endif 41 42 volatile struct BIOS_regs BIOS_regs; 43 44 #if defined(DEBUG) 45 #define CKPT(c) (*(u_int16_t*)0xb8148 = 0x4700 + (c)) 46 #else 47 #define CKPT(c) /* c */ 48 #endif 49 50 const char *vmm_hv_signature = VMM_HV_SIGNATURE; 51 52 void 53 machdep(void) 54 { 55 int i, j, vmm = 0, psl_check; 56 struct i386_boot_probes *pr; 57 uint32_t dummy, ebx, ecx, edx; 58 dev_t dev; 59 60 /* 61 * The list of probe routines is now in conf.c. 62 */ 63 for (i = 0; i < nibprobes; i++) { 64 pr = &probe_list[i]; 65 if (pr != NULL) { 66 printf("%s:", pr->name); 67 68 for (j = 0; j < pr->count; j++) { 69 (*(pr->probes)[j])(); 70 } 71 72 printf("\n"); 73 } 74 } 75 76 /* 77 * The following is a simple check to see if cpuid is supported. 78 * We try to toggle bit 21 (PSL_ID) in eflags. If it works, then 79 * cpuid is supported. If not, there's no cpuid, and we don't 80 * try it (don't want /boot to get an invalid opcode exception). 81 * 82 * XXX The NexGen Nx586 does not support this bit, so this is not 83 * a good method to detect the presence of cpuid on this 84 * processor. That's fine: the purpose here is to detect the 85 * absence of cpuid. We don't mind if the instruction's not 86 * there - this is not intended to determine exactly what 87 * processor is there, just whether it's i386 or amd64. 88 * 89 * The only thing that would cause us grief is a processor which 90 * does not support cpuid but which does allow the PSL_ID bit 91 * in eflags to be toggled. 92 */ 93 __asm volatile( 94 "pushfl\n\t" 95 "popl %2\n\t" 96 "xorl %2, %0\n\t" 97 "pushl %0\n\t" 98 "popfl\n\t" 99 "pushfl\n\t" 100 "popl %0\n\t" 101 "xorl %2, %0\n\t" /* If %2 == %0, no cpuid */ 102 : "=r" (psl_check) 103 : "0" (PSL_ID), "r" (0) 104 : "cc"); 105 106 if (psl_check != PSL_ID) 107 return; 108 109 CPUID(0x1, dummy, dummy, ecx, dummy); 110 if (ecx & CPUIDECX_HV) { 111 CPUID(0x40000000, dummy, ebx, ecx, edx); 112 if (memcmp(&ebx, &vmm_hv_signature[0], sizeof(uint32_t)) == 0 && 113 memcmp(&ecx, &vmm_hv_signature[4], sizeof(uint32_t)) == 0 && 114 memcmp(&edx, &vmm_hv_signature[8], sizeof(uint32_t)) == 0) 115 vmm = 1; 116 } 117 118 /* Set console to com0/115200 by default in vmm */ 119 if (vmm) { 120 dev = ttydev("com0"); 121 cnspeed(dev, 115200); 122 cnset(dev); 123 } 124 } 125 126 int check_skip_conf(void) 127 { 128 /* Return non-zero (skip boot.conf) if Control "shift" key down */ 129 #ifndef EFIBOOT 130 return (pc_getshifts(0) & 0x04); 131 #else 132 return (efi_cons_getshifts(0) & 0x04); 133 #endif 134 } 135