2 * Copyright (c) 2003-2013 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Mihai Carabas <mihai.carabas@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #ifndef _VMM_VMX_INSTR_H_
36 #define _VMM_VMX_INSTR_H_
41 * Chapter 30 VMX Instruction Reference
42 * Section 30.3 "Conventions"
43 * from Intel Architecture Manual 3C.
46 #define VM_FAIL_INVALID 1
47 #define VM_FAIL_VALID 2
50 #define GET_ERROR_CODE \
57 "3: mov $0, %[err];" \
61 vmxon(char *vmx_region)
66 paddr = vtophys(vmx_region);
67 __asm __volatile("vmxon %[paddr];"
80 __asm __volatile("vmxoff");
84 vmclear(char *vmcs_region)
89 paddr = vtophys(vmcs_region);
90 __asm __volatile("vmclear %[paddr];"
99 vmptrst(uint64_t *addr)
102 __asm __volatile("vmptrst %[addr]"
114 paddr = vtophys(vmcs);
115 __asm __volatile("vmptrld %[paddr];"
118 : [paddr] "m" (paddr)
124 vmwrite(uint64_t reg, uint64_t val)
128 __asm __volatile("vmwrite %[val], %[reg];"
131 : [val] "r" (val), [reg] "r" (reg)
138 vmread(uint64_t reg, uint64_t *addr)
142 __asm __volatile("vmread %[reg], %[addr];"
145 : [reg] "r" (reg), [addr] "m" (*addr)
152 invept(uint64_t type, uint64_t *desc_addr)
156 __asm __volatile("invept %[desc_addr], %[type];"
159 : [desc_addr] "m" (*desc_addr), [type] "r" (type)