1bf21cd9Tycho Nightingale/*-
24c87aefPatrick Mooney * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
34c87aefPatrick Mooney *
4bf21cd9Tycho Nightingale * Copyright (c) 2011 NetApp, Inc.
5bf21cd9Tycho Nightingale * All rights reserved.
6bf21cd9Tycho Nightingale *
7bf21cd9Tycho Nightingale * Redistribution and use in source and binary forms, with or without
8bf21cd9Tycho Nightingale * modification, are permitted provided that the following conditions
9bf21cd9Tycho Nightingale * are met:
10bf21cd9Tycho Nightingale * 1. Redistributions of source code must retain the above copyright
11bf21cd9Tycho Nightingale *    notice, this list of conditions and the following disclaimer.
12bf21cd9Tycho Nightingale * 2. Redistributions in binary form must reproduce the above copyright
13bf21cd9Tycho Nightingale *    notice, this list of conditions and the following disclaimer in the
14bf21cd9Tycho Nightingale *    documentation and/or other materials provided with the distribution.
15bf21cd9Tycho Nightingale *
16bf21cd9Tycho Nightingale * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
17bf21cd9Tycho Nightingale * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18bf21cd9Tycho Nightingale * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19bf21cd9Tycho Nightingale * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
20bf21cd9Tycho Nightingale * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21bf21cd9Tycho Nightingale * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22bf21cd9Tycho Nightingale * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23bf21cd9Tycho Nightingale * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24bf21cd9Tycho Nightingale * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25bf21cd9Tycho Nightingale * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26bf21cd9Tycho Nightingale * SUCH DAMAGE.
27bf21cd9Tycho Nightingale *
284c87aefPatrick Mooney * $FreeBSD$
29bf21cd9Tycho Nightingale */
30bf21cd9Tycho Nightingale/*
31bf21cd9Tycho Nightingale * This file and its contents are supplied under the terms of the
32bf21cd9Tycho Nightingale * Common Development and Distribution License ("CDDL"), version 1.0.
33bf21cd9Tycho Nightingale * You may only use this file in accordance with the terms of version
34bf21cd9Tycho Nightingale * 1.0 of the CDDL.
35bf21cd9Tycho Nightingale *
36bf21cd9Tycho Nightingale * A full copy of the text of the CDDL should have accompanied this
37bf21cd9Tycho Nightingale * source.  A copy of the CDDL is also available via the Internet at
38bf21cd9Tycho Nightingale * http://www.illumos.org/license/CDDL.
39bf21cd9Tycho Nightingale *
40bf21cd9Tycho Nightingale * Copyright 2013 Pluribus Networks Inc.
41bf21cd9Tycho Nightingale */
42bf21cd9Tycho Nightingale
43bf21cd9Tycho Nightingale#include <sys/cdefs.h>
444c87aefPatrick Mooney__FBSDID("$FreeBSD$");
45bf21cd9Tycho Nightingale
46bf21cd9Tycho Nightingale#include <sys/param.h>
47bf21cd9Tycho Nightingale#include <sys/libkern.h>
48bf21cd9Tycho Nightingale
49bf21cd9Tycho Nightingale#include <machine/md_var.h>
50bf21cd9Tycho Nightingale
51bf21cd9Tycho Nightingale#include "vmm_util.h"
52bf21cd9Tycho Nightingale
5384659b2Michael Zellerbool
54bf21cd9Tycho Nightingalevmm_is_intel(void)
55bf21cd9Tycho Nightingale{
56bf21cd9Tycho Nightingale
5784659b2Michael Zeller	return (strcmp(cpu_vendor, "GenuineIntel") == 0);
58bf21cd9Tycho Nightingale}
59bf21cd9Tycho Nightingale
6084659b2Michael Zellerbool
61154972aPatrick Mooneyvmm_is_svm(void)
62bf21cd9Tycho Nightingale{
63154972aPatrick Mooney	return (strcmp(cpu_vendor, "AuthenticAMD") == 0 ||
64154972aPatrick Mooney	    strcmp(cpu_vendor, "HygonGenuine") == 0);
65bf21cd9Tycho Nightingale}
66bf21cd9Tycho Nightingale
6784659b2Michael Zellerbool
68bf21cd9Tycho Nightingalevmm_supports_1G_pages(void)
69bf21cd9Tycho Nightingale{
70bf21cd9Tycho Nightingale	unsigned int regs[4];
71bf21cd9Tycho Nightingale
72bf21cd9Tycho Nightingale	/*
73bf21cd9Tycho Nightingale	 * CPUID.80000001:EDX[bit 26] = 1 indicates support for 1GB pages
74bf21cd9Tycho Nightingale	 *
75bf21cd9Tycho Nightingale	 * Both Intel and AMD support this bit.
76bf21cd9Tycho Nightingale	 */
77bf21cd9Tycho Nightingale	if (cpu_exthigh >= 0x80000001) {
78bf21cd9Tycho Nightingale		do_cpuid(0x80000001, regs);
79bf21cd9Tycho Nightingale		if (regs[3] & (1 << 26))
8084659b2Michael Zeller			return (true);
81bf21cd9Tycho Nightingale	}
8284659b2Michael Zeller	return (false);
83bf21cd9Tycho Nightingale}
84bf21cd9Tycho Nightingale
85bf21cd9Tycho Nightingale#ifdef	__FreeBSD__
86bf21cd9Tycho Nightingale#include <sys/proc.h>
87bf21cd9Tycho Nightingale#include <machine/frame.h>
88bf21cd9Tycho Nightingale#define	DUMP_REG(x)	printf(#x "\t\t0x%016lx\n", (long)(tf->tf_ ## x))
89bf21cd9Tycho Nightingale#define	DUMP_SEG(x)	printf(#x "\t\t0x%04x\n", (unsigned)(tf->tf_ ## x))
90bf21cd9Tycho Nightingalevoid
91bf21cd9Tycho Nightingaledump_trapframe(struct trapframe *tf)
92bf21cd9Tycho Nightingale{
93bf21cd9Tycho Nightingale	DUMP_REG(rdi);
94bf21cd9Tycho Nightingale	DUMP_REG(rsi);
95bf21cd9Tycho Nightingale	DUMP_REG(rdx);
96bf21cd9Tycho Nightingale	DUMP_REG(rcx);
97bf21cd9Tycho Nightingale	DUMP_REG(r8);
98bf21cd9Tycho Nightingale	DUMP_REG(r9);
99bf21cd9Tycho Nightingale	DUMP_REG(rax);
100bf21cd9Tycho Nightingale	DUMP_REG(rbx);
101bf21cd9Tycho Nightingale	DUMP_REG(rbp);
102bf21cd9Tycho Nightingale	DUMP_REG(r10);
103bf21cd9Tycho Nightingale	DUMP_REG(r11);
104bf21cd9Tycho Nightingale	DUMP_REG(r12);
105bf21cd9Tycho Nightingale	DUMP_REG(r13);
106bf21cd9Tycho Nightingale	DUMP_REG(r14);
107bf21cd9Tycho Nightingale	DUMP_REG(r15);
108bf21cd9Tycho Nightingale	DUMP_REG(trapno);
109bf21cd9Tycho Nightingale	DUMP_REG(addr);
110bf21cd9Tycho Nightingale	DUMP_REG(flags);
111bf21cd9Tycho Nightingale	DUMP_REG(err);
112bf21cd9Tycho Nightingale	DUMP_REG(rip);
113bf21cd9Tycho Nightingale	DUMP_REG(rflags);
114bf21cd9Tycho Nightingale	DUMP_REG(rsp);
115bf21cd9Tycho Nightingale	DUMP_SEG(cs);
116bf21cd9Tycho Nightingale	DUMP_SEG(ss);
117bf21cd9Tycho Nightingale	DUMP_SEG(fs);
118bf21cd9Tycho Nightingale	DUMP_SEG(gs);
119bf21cd9Tycho Nightingale	DUMP_SEG(es);
120bf21cd9Tycho Nightingale	DUMP_SEG(ds);
121bf21cd9Tycho Nightingale}
122bf21cd9Tycho Nightingale#endif
123