x86.c revision 221828
1/*-
2 * Copyright (c) 2011 NetApp, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD$");
31
32#include <sys/types.h>
33
34#include <machine/cpufunc.h>
35#include <machine/specialreg.h>
36
37#include "x86.h"
38
39int
40x86_emulate_cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
41{
42	unsigned int 	func, regs[4];
43
44	func = *eax;
45
46	cpuid_count(*eax, *ecx, regs);
47
48	switch(func) {
49		case CPUID_0000_0000:
50		case CPUID_0000_0002:
51		case CPUID_0000_0003:
52		case CPUID_0000_0004:
53		case CPUID_0000_000A:
54			break;
55
56		case CPUID_8000_0000:
57		case CPUID_8000_0001:
58		case CPUID_8000_0002:
59		case CPUID_8000_0003:
60		case CPUID_8000_0004:
61		case CPUID_8000_0006:
62		case CPUID_8000_0007:
63		case CPUID_8000_0008:
64
65			break;
66
67		case CPUID_0000_0001:
68			/*
69			 * Override the APIC ID only in ebx
70			 */
71			regs[1] &= ~(CPUID_0000_0001_APICID_MASK);
72			/*
73			 * XXX fixme for MP case, set apicid properly for cpu.
74			 */
75			regs[1] |= (0 << CPUID_0000_0001_APICID_SHIFT);
76
77			/*
78			 * Don't expose VMX capability.
79			 * Advertise x2APIC capability.
80			 */
81			regs[2] &= ~CPUID_0000_0001_FEAT0_VMX;
82			regs[2] |= CPUID2_X2APIC;
83
84			/*
85			 * Machine check handling is done in the host.
86			 * Hide MTRR capability.
87			 */
88			regs[3] &= ~(CPUID_MCA | CPUID_MCE | CPUID_MTRR);
89
90			break;
91
92		case CPUID_0000_000B:
93			/*
94			 * XXXSMP fixme
95			 * Processor topology enumeration
96			 */
97			regs[0] = 0;
98			regs[1] = 0;
99			regs[2] = *ecx & 0xff;
100			regs[3] = 0;
101			break;
102
103		default:
104			return (0);
105	}
106
107	*eax = regs[0];
108	*ebx = regs[1];
109	*ecx = regs[2];
110	*edx = regs[3];
111	return (1);
112}
113
114