1221828Sgrehan/*-
2221828Sgrehan * Copyright (c) 2011 NetApp, Inc.
3221828Sgrehan * All rights reserved.
4221828Sgrehan *
5221828Sgrehan * Redistribution and use in source and binary forms, with or without
6221828Sgrehan * modification, are permitted provided that the following conditions
7221828Sgrehan * are met:
8221828Sgrehan * 1. Redistributions of source code must retain the above copyright
9221828Sgrehan *    notice, this list of conditions and the following disclaimer.
10221828Sgrehan * 2. Redistributions in binary form must reproduce the above copyright
11221828Sgrehan *    notice, this list of conditions and the following disclaimer in the
12221828Sgrehan *    documentation and/or other materials provided with the distribution.
13221828Sgrehan *
14221828Sgrehan * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15221828Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16221828Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17221828Sgrehan * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18221828Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19221828Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20221828Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21221828Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22221828Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23221828Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24221828Sgrehan * SUCH DAMAGE.
25221828Sgrehan *
26221828Sgrehan * $FreeBSD: stable/11/sys/amd64/vmm/vmm_util.c 351753 2019-09-03 16:23:46Z emaste $
27221828Sgrehan */
28221828Sgrehan
29221828Sgrehan#include <sys/cdefs.h>
30221828Sgrehan__FBSDID("$FreeBSD: stable/11/sys/amd64/vmm/vmm_util.c 351753 2019-09-03 16:23:46Z emaste $");
31221828Sgrehan
32221828Sgrehan#include <sys/param.h>
33221828Sgrehan#include <sys/libkern.h>
34221828Sgrehan
35221828Sgrehan#include <machine/md_var.h>
36221828Sgrehan
37221828Sgrehan#include "vmm_util.h"
38221828Sgrehan
39351753Semastebool
40221828Sgrehanvmm_is_intel(void)
41221828Sgrehan{
42221828Sgrehan
43351753Semaste	return (strcmp(cpu_vendor, "GenuineIntel") == 0);
44221828Sgrehan}
45221828Sgrehan
46351753Semastebool
47221828Sgrehanvmm_is_amd(void)
48221828Sgrehan{
49351753Semaste	return (strcmp(cpu_vendor, "AuthenticAMD") == 0);
50221828Sgrehan}
51221828Sgrehan
52351753Semastebool
53221828Sgrehanvmm_supports_1G_pages(void)
54221828Sgrehan{
55221828Sgrehan	unsigned int regs[4];
56221828Sgrehan
57221828Sgrehan	/*
58221828Sgrehan	 * CPUID.80000001:EDX[bit 26] = 1 indicates support for 1GB pages
59221828Sgrehan	 *
60221828Sgrehan	 * Both Intel and AMD support this bit.
61221828Sgrehan	 */
62221828Sgrehan	if (cpu_exthigh >= 0x80000001) {
63221828Sgrehan		do_cpuid(0x80000001, regs);
64221828Sgrehan		if (regs[3] & (1 << 26))
65351753Semaste			return (true);
66221828Sgrehan	}
67351753Semaste	return (false);
68221828Sgrehan}
69221828Sgrehan
70221828Sgrehan#include <sys/proc.h>
71221828Sgrehan#include <machine/frame.h>
72221828Sgrehan#define	DUMP_REG(x)	printf(#x "\t\t0x%016lx\n", (long)(tf->tf_ ## x))
73221828Sgrehan#define	DUMP_SEG(x)	printf(#x "\t\t0x%04x\n", (unsigned)(tf->tf_ ## x))
74221828Sgrehanvoid
75221828Sgrehandump_trapframe(struct trapframe *tf)
76221828Sgrehan{
77221828Sgrehan	DUMP_REG(rdi);
78221828Sgrehan	DUMP_REG(rsi);
79221828Sgrehan	DUMP_REG(rdx);
80221828Sgrehan	DUMP_REG(rcx);
81221828Sgrehan	DUMP_REG(r8);
82221828Sgrehan	DUMP_REG(r9);
83221828Sgrehan	DUMP_REG(rax);
84221828Sgrehan	DUMP_REG(rbx);
85221828Sgrehan	DUMP_REG(rbp);
86221828Sgrehan	DUMP_REG(r10);
87221828Sgrehan	DUMP_REG(r11);
88221828Sgrehan	DUMP_REG(r12);
89221828Sgrehan	DUMP_REG(r13);
90221828Sgrehan	DUMP_REG(r14);
91221828Sgrehan	DUMP_REG(r15);
92221828Sgrehan	DUMP_REG(trapno);
93221828Sgrehan	DUMP_REG(addr);
94221828Sgrehan	DUMP_REG(flags);
95221828Sgrehan	DUMP_REG(err);
96221828Sgrehan	DUMP_REG(rip);
97221828Sgrehan	DUMP_REG(rflags);
98221828Sgrehan	DUMP_REG(rsp);
99221828Sgrehan	DUMP_SEG(cs);
100221828Sgrehan	DUMP_SEG(ss);
101221828Sgrehan	DUMP_SEG(fs);
102221828Sgrehan	DUMP_SEG(gs);
103221828Sgrehan	DUMP_SEG(es);
104221828Sgrehan	DUMP_SEG(ds);
105221828Sgrehan}
106