xref: /openbsd-src/sys/arch/amd64/stand/libsa/machdep.c (revision 43d589df8f0b964bc0e1c8d84508c2db27bb316d)
1 /*	$OpenBSD: machdep.c,v 1.8 2019/05/10 21:20:43 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/specialreg.h>
35 #include <machine/vmmvar.h>
36 
37 volatile struct BIOS_regs	BIOS_regs;
38 
39 #if defined(DEBUG)
40 #define CKPT(c)	(*(u_int16_t*)0xb8148 = 0x4700 + (c))
41 #else
42 #define CKPT(c) /* c */
43 #endif
44 
45 const char *vmm_hv_signature = VMM_HV_SIGNATURE;
46 
47 void
machdep(void)48 machdep(void)
49 {
50 	int i, j, vmm = 0;
51 	struct i386_boot_probes *pr;
52 	uint32_t dummy, ebx, ecx, edx;
53 	dev_t dev;
54 
55 	/*
56 	 * The list of probe routines is now in conf.c.
57 	 */
58 	for (i = 0; i < nibprobes; i++) {
59 		pr = &probe_list[i];
60 		if (pr != NULL) {
61 			printf("%s:", pr->name);
62 
63 			for (j = 0; j < pr->count; j++) {
64 				(*(pr->probes)[j])();
65 			}
66 
67 			printf("\n");
68 		}
69 	}
70 
71 	CPUID(0x1, dummy, dummy, ecx, dummy);
72 	if (ecx & CPUIDECX_HV) {
73 		CPUID(0x40000000, dummy, ebx, ecx, edx);
74 		if (memcmp(&ebx, &vmm_hv_signature[0], sizeof(uint32_t)) == 0 &&
75 		    memcmp(&ecx, &vmm_hv_signature[4], sizeof(uint32_t)) == 0 &&
76 		    memcmp(&edx, &vmm_hv_signature[8], sizeof(uint32_t)) == 0)
77 			vmm = 1;
78 	}
79 
80 	/* Set console to com0/115200 by default in vmm */
81 	if (vmm) {
82 		dev = ttydev("com0");
83 		cnspeed(dev, 115200);
84 		cnset(dev);
85 	}
86 }
87 
88 int
check_skip_conf(void)89 check_skip_conf(void)
90 {
91 	/* Return non-zero (skip boot.conf) if Control "shift" key down */
92 	return (pc_getshifts(0) & 0x04);
93 }
94