Deleted Added
full compact
svm.h (249967) svm.h (271939)
1/*-
2 * Copyright (c) 2013 Anish Gupta (akgupt3@gmail.com)
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
10 * disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2013 Anish Gupta (akgupt3@gmail.com)
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
10 * disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: projects/bhyve_svm/sys/amd64/vmm/amd/svm.h 249967 2013-04-27 04:49:51Z neel $
26 * $FreeBSD: projects/bhyve_svm/sys/amd64/vmm/amd/svm.h 271939 2014-09-21 23:42:54Z neel $
27 */
28
29#ifndef _SVM_H_
30#define _SVM_H_
31
32#define BIT(n) (1ULL << n)
33#define ERR(fmt, args...) \
34 printf("SVM ERROR:%s " fmt "\n", __func__, ##args);
35
36/*
37 * Software saved machine state for guest and host.
38 */
39
40/* Additional guest register state */
41struct svm_gctx {
42 register_t sctx_rdx;
43 register_t sctx_rdi;
44 register_t sctx_rsi;
45 /* Points to host context area. */
46 register_t sctx_hostctx_base;
47};
48
49/* Additional host register state */
50struct svm_hctx {
51 uint16_t sctx_fs;
52 uint16_t sctx_gs;
53
54 register_t sctx_rsp;
55};
56
57/* Common register context area for guest and host. */
58struct svm_regctx {
59 register_t sctx_rbp;
60
61 register_t sctx_rbx;
62 register_t sctx_rcx;
63
64 register_t sctx_r8;
65 register_t sctx_r9;
66 register_t sctx_r10;
67 register_t sctx_r11;
68 register_t sctx_r12;
69 register_t sctx_r13;
70 register_t sctx_r14;
71 register_t sctx_r15;
72
73 union {
74 struct svm_hctx h; /* host-specific register state */
75 struct svm_gctx g; /* guest-specific register state */
76 } e;
77};
78
79void svm_launch(uint64_t pa, struct svm_regctx *, struct svm_regctx *);
80
81static __inline void
82disable_gintr(void)
83{
84
85 __asm __volatile("clgi" : : :);
86}
87
88static __inline void
89enable_gintr(void)
90{
91
92 __asm __volatile("stgi" : : :);
93}
94
27 */
28
29#ifndef _SVM_H_
30#define _SVM_H_
31
32#define BIT(n) (1ULL << n)
33#define ERR(fmt, args...) \
34 printf("SVM ERROR:%s " fmt "\n", __func__, ##args);
35
36/*
37 * Software saved machine state for guest and host.
38 */
39
40/* Additional guest register state */
41struct svm_gctx {
42 register_t sctx_rdx;
43 register_t sctx_rdi;
44 register_t sctx_rsi;
45 /* Points to host context area. */
46 register_t sctx_hostctx_base;
47};
48
49/* Additional host register state */
50struct svm_hctx {
51 uint16_t sctx_fs;
52 uint16_t sctx_gs;
53
54 register_t sctx_rsp;
55};
56
57/* Common register context area for guest and host. */
58struct svm_regctx {
59 register_t sctx_rbp;
60
61 register_t sctx_rbx;
62 register_t sctx_rcx;
63
64 register_t sctx_r8;
65 register_t sctx_r9;
66 register_t sctx_r10;
67 register_t sctx_r11;
68 register_t sctx_r12;
69 register_t sctx_r13;
70 register_t sctx_r14;
71 register_t sctx_r15;
72
73 union {
74 struct svm_hctx h; /* host-specific register state */
75 struct svm_gctx g; /* guest-specific register state */
76 } e;
77};
78
79void svm_launch(uint64_t pa, struct svm_regctx *, struct svm_regctx *);
80
81static __inline void
82disable_gintr(void)
83{
84
85 __asm __volatile("clgi" : : :);
86}
87
88static __inline void
89enable_gintr(void)
90{
91
92 __asm __volatile("stgi" : : :);
93}
94
95static __inline void
96save_cr2(uint64_t *cr2)
97{
98
99 __asm __volatile(
100 "mov %%cr2, %%rax; movq %%rax, %0"
101 :"=m"(*cr2)
102 :
103 :"rax", "memory");
104}
105
106static __inline void
107load_cr2(uint64_t *cr2)
108{
109 __asm __volatile(
110 "movq %0, %%rax; movq %%rax, %%cr2"
111 :
112 :"m"(*cr2)
113 :"rax");
114}
115
116#endif /* _SVM_H_ */
95#endif /* _SVM_H_ */