]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/__vm-vmx.h
4083bc96425b9ba5d8488bb6f942a620ca00ab20
[l4.git] / l4 / pkg / l4sys / include / __vm-vmx.h
1 /**
2  * \internal
3  * \file
4  * \brief X86 virtualization interface.
5  */
6 /*
7  * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8  *          Alexander Warg <warg@os.inf.tu-dresden.de>
9  *     economic rights: Technische Universität Dresden (Germany)
10  *
11  * This file is part of TUD:OS and distributed under the terms of the
12  * GNU General Public License 2.
13  * Please see the COPYING-GPL-2 file for details.
14  *
15  * As a special exception, you may use this file as part of a free software
16  * library without restriction.  Specifically, if other files instantiate
17  * templates or use macros or inline functions from this file, or you compile
18  * this file and link it with other files to produce an executable, this
19  * file does not by itself cause the resulting executable to be covered by
20  * the GNU General Public License.  This exception does not however
21  * invalidate any other reasons why the executable file might be covered by
22  * the GNU General Public License.
23  */
24 #pragma once
25
26 /**
27  * \defgroup l4_vm_vmx_api VM API for VMX
28  * \brief Virtual machine API for VMX.
29  * \ingroup l4_vm_api
30  */
31
32
33 /**
34  * \brief Additional VMCS fields.
35  * \ingroup l4_vm_vmx_api
36  */
37 enum
38 {
39   L4_VM_VMX_VMCS_CR2              = 0x6830,
40 };
41
42 /**
43  * \brief Return length in bytes of a VMCS field.
44  * \ingroup l4_vm_vmx_api
45  *
46  * \param field  Field number.
47  * \return Width of field in bytes.
48  */
49 L4_INLINE
50 unsigned
51 l4_vm_vmx_field_len(unsigned field);
52
53 /**
54  * \brief Get pointer into VMCS.
55  * \ingroup l4_vm_vmx_api
56  *
57  * \param vmcs   Pointer to VMCS buffer.
58  * \param field  Field number.
59  *
60  * \param Pointer to field in the VMCS.
61  */
62 L4_INLINE
63 void *
64 l4_vm_vmx_field_ptr(void *vmcs, unsigned field);
65
66
67 /* Implementations */
68
69 L4_INLINE
70 unsigned
71 l4_vm_vmx_field_len(unsigned field)
72 {
73   static const char widths[4] = { 2, 8, 4, sizeof(l4_umword_t) };
74   return widths[field >> 13];
75 }
76
77 L4_INLINE
78 void *
79 l4_vm_vmx_field_ptr(void *vmcs, unsigned field)
80 {
81   return (void *)((char *)vmcs
82                           + ((field >> 13) * 4 + ((field >> 10) & 3) + 1) * 0x80
83                           + l4_vm_vmx_field_len(field) * ((field >> 1) & 0xff));
84 }