vmm_util.c revision 259065
174298Ssos/*-
2178067Ssos * Copyright (c) 2011 NetApp, Inc.
374298Ssos * All rights reserved.
474298Ssos *
574298Ssos * Redistribution and use in source and binary forms, with or without
674298Ssos * modification, are permitted provided that the following conditions
774298Ssos * are met:
874298Ssos * 1. Redistributions of source code must retain the above copyright
974298Ssos *    notice, this list of conditions and the following disclaimer.
1074298Ssos * 2. Redistributions in binary form must reproduce the above copyright
1174298Ssos *    notice, this list of conditions and the following disclaimer in the
1274298Ssos *    documentation and/or other materials provided with the distribution.
1374298Ssos *
1474298Ssos * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
1574298Ssos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1674298Ssos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1774298Ssos * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
1874298Ssos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1974298Ssos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2074298Ssos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2174298Ssos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2274298Ssos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2374298Ssos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2474298Ssos * SUCH DAMAGE.
2574298Ssos *
2674298Ssos * $FreeBSD: releng/10.0/sys/amd64/vmm/vmm_util.c 245678 2013-01-20 03:42:49Z neel $
2774298Ssos */
2874298Ssos
2974298Ssos#include <sys/cdefs.h>
3074298Ssos__FBSDID("$FreeBSD: releng/10.0/sys/amd64/vmm/vmm_util.c 245678 2013-01-20 03:42:49Z neel $");
3174298Ssos
3274298Ssos#include <sys/param.h>
3374298Ssos#include <sys/libkern.h>
34119404Ssos
3593881Ssos#include <machine/md_var.h>
36146266Ssos
37146266Ssos#include "vmm_util.h"
38146266Ssos
39146266Ssosboolean_t
40146266Ssosvmm_is_intel(void)
41174682Sphk{
42146266Ssos
43146266Ssos	if (strcmp(cpu_vendor, "GenuineIntel") == 0)
44146266Ssos		return (TRUE);
45146266Ssos	else
46146266Ssos		return (FALSE);
47146266Ssos}
48146266Ssos
49146266Ssosboolean_t
50146266Ssosvmm_is_amd(void)
5193881Ssos{
52146266Ssos	if (strcmp(cpu_vendor, "AuthenticAMD") == 0)
53146266Ssos		return (TRUE);
54146266Ssos	else
55146266Ssos		return (FALSE);
56146266Ssos}
57146266Ssos
58146266Ssosboolean_t
59146266Ssosvmm_supports_1G_pages(void)
60146266Ssos{
61146266Ssos	unsigned int regs[4];
62146266Ssos
63146266Ssos	/*
64146266Ssos	 * CPUID.80000001:EDX[bit 26] = 1 indicates support for 1GB pages
65146266Ssos	 *
66146266Ssos	 * Both Intel and AMD support this bit.
67146266Ssos	 */
68146266Ssos	if (cpu_exthigh >= 0x80000001) {
69146266Ssos		do_cpuid(0x80000001, regs);
70197540Smav		if (regs[3] & (1 << 26))
71197540Smav			return (TRUE);
72146266Ssos	}
7393881Ssos	return (FALSE);
74146266Ssos}
75146266Ssos
76146266Ssos#include <sys/proc.h>
7774298Ssos#include <machine/frame.h>
78146266Ssos#define	DUMP_REG(x)	printf(#x "\t\t0x%016lx\n", (long)(tf->tf_ ## x))
79146266Ssos#define	DUMP_SEG(x)	printf(#x "\t\t0x%04x\n", (unsigned)(tf->tf_ ## x))
8074298Ssosvoid
81146266Ssosdump_trapframe(struct trapframe *tf)
82146266Ssos{
83146266Ssos	DUMP_REG(rdi);
84146266Ssos	DUMP_REG(rsi);
8574298Ssos	DUMP_REG(rdx);
86146266Ssos	DUMP_REG(rcx);
87146266Ssos	DUMP_REG(r8);
88146266Ssos	DUMP_REG(r9);
89146266Ssos	DUMP_REG(rax);
90146266Ssos	DUMP_REG(rbx);
91146266Ssos	DUMP_REG(rbp);
92146266Ssos	DUMP_REG(r10);
9393881Ssos	DUMP_REG(r11);
94146266Ssos	DUMP_REG(r12);
95146266Ssos	DUMP_REG(r13);
96146266Ssos	DUMP_REG(r14);
97146266Ssos	DUMP_REG(r15);
98146266Ssos	DUMP_REG(trapno);
9974298Ssos	DUMP_REG(addr);
100146266Ssos	DUMP_REG(flags);
101146266Ssos	DUMP_REG(err);
102146266Ssos	DUMP_REG(rip);
103146266Ssos	DUMP_REG(rflags);
104146266Ssos	DUMP_REG(rsp);
105146266Ssos	DUMP_SEG(cs);
106146266Ssos	DUMP_SEG(ss);
107146266Ssos	DUMP_SEG(fs);
108146266Ssos	DUMP_SEG(gs);
109146266Ssos	DUMP_SEG(es);
110146266Ssos	DUMP_SEG(ds);
111146266Ssos}
11274298Ssos