xref: /illumos-gate/usr/src/uts/intel/io/vmm/vmm_support.S (revision 012e6ce759c490003aed29439cc47d3d73a99ad3)
1/*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source.  A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 *
11 * Copyright 2019 Joyent, Inc.
12 */
13/* This file is dual-licensed; see usr/src/contrib/bhyve/LICENSE */
14
15#include <sys/asm_linkage.h>
16#include <sys/segments.h>
17
18/*
19 * %rdi = trapno
20 *
21 * This variant is for any explicit exception injection that we need: in this
22 * case, we can't just, for example, do a direct "int $2", as that will then
23 * trash our %cr3 via tr_nmiint due to KPTI, so we have to fake a trap frame.
24 * Both NMIs and MCEs don't push an 'err' into the frame.
25 */
26ENTRY_NP(vmm_call_trap)
27	pushq	%rbp
28	movq	%rsp, %rbp
29	movq	%rsp, %r11
30	andq	$~0xf, %rsp	/* align stack */
31	pushq	$KDS_SEL	/* %ss */
32	pushq	%r11		/* %rsp */
33	pushfq			/* %rflags */
34	pushq	$KCS_SEL	/* %cs */
35	leaq	.trap_iret_dest(%rip), %rcx
36	pushq	%rcx		/* %rip */
37	cli
38	cmpq	$T_NMIFLT, %rdi
39	je	nmiint
40	cmpq	$T_MCE, %rdi
41	je	mcetrap
42
43	pushq	%rdi		/* save our bad trapno... */
44	leaq	__vmm_call_bad_trap(%rip), %rdi
45	xorl	%eax, %eax
46	call	panic
47	/*NOTREACHED*/
48
49.trap_iret_dest:
50	popq	%rbp
51	ret
52SET_SIZE(vmm_call_trap)
53
54__vmm_call_bad_trap:
55	.string	"bad trapno for vmm_call_trap()"
56