summaryrefslogtreecommitdiffstats
path: root/sys/amd64/vmm/amd/svm_support.S
blob: 72327bdaf1387a9cab7639bce1be35bf12bc5562 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*-
 * Copyright (c) 2013, Anish Gupta (akgupt3@gmail.com)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#include <machine/asmacros.h>

#include "svm_assym.h"

/*
 * Be friendly to DTrace FBT's prologue/epilogue pattern matching.
 *
 * They are also responsible for saving/restoring the host %rbp across VMRUN.
 */
#define	VENTER  push %rbp ; mov %rsp,%rbp
#define	VLEAVE  pop %rbp

/*
 * svm_launch(uint64_t vmcb, struct svm_regctx *gctx)
 * %rdi: physical address of VMCB
 * %rsi: pointer to guest context
 */
ENTRY(svm_launch)
	VENTER

	/*
	 * Host register state saved across a VMRUN.
	 *
	 * All "callee saved registers" except:
	 * %rsp: because it is preserved by the processor across VMRUN.
	 * %rbp: because it is saved/restored by the function prologue/epilogue.
	 */
	push %rbx
	push %r12
	push %r13
	push %r14
	push %r15

	/* Save the physical address of the VMCB in %rax */
	movq %rdi, %rax

	push %rsi		/* push guest context pointer on the stack */

	/*
	 * Restore guest state.
	 */
	movq SCTX_R8(%rsi), %r8
	movq SCTX_R9(%rsi), %r9
	movq SCTX_R10(%rsi), %r10
	movq SCTX_R11(%rsi), %r11
	movq SCTX_R12(%rsi), %r12
	movq SCTX_R13(%rsi), %r13
	movq SCTX_R14(%rsi), %r14
	movq SCTX_R15(%rsi), %r15
	movq SCTX_RBP(%rsi), %rbp
	movq SCTX_RBX(%rsi), %rbx
	movq SCTX_RCX(%rsi), %rcx
	movq SCTX_RDX(%rsi), %rdx
	movq SCTX_RDI(%rsi), %rdi
	movq SCTX_RSI(%rsi), %rsi	/* %rsi must be restored last */

	vmload %rax
	vmrun %rax
	vmsave %rax

	pop %rax		/* pop guest context pointer from the stack */

	/*
	 * Save guest state.
	 */
	movq %r8, SCTX_R8(%rax)
	movq %r9, SCTX_R9(%rax)
	movq %r10, SCTX_R10(%rax)
	movq %r11, SCTX_R11(%rax)
	movq %r12, SCTX_R12(%rax)
	movq %r13, SCTX_R13(%rax)
	movq %r14, SCTX_R14(%rax)
	movq %r15, SCTX_R15(%rax)
	movq %rbp, SCTX_RBP(%rax)
	movq %rbx, SCTX_RBX(%rax)
	movq %rcx, SCTX_RCX(%rax)
	movq %rdx, SCTX_RDX(%rax)
	movq %rdi, SCTX_RDI(%rax)
	movq %rsi, SCTX_RSI(%rax)

	/* Restore host state */
	pop %r15
	pop %r14
	pop %r13
	pop %r12
	pop %rbx

	VLEAVE
	ret
END(svm_launch)
OpenPOWER on IntegriCloud