]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/__vm.h
update
[l4.git] / l4 / pkg / l4sys / include / __vm.h
1 /**
2  * \internal
3  * \file
4  * \brief X86 virtualization interface.
5  */
6 /*
7  * (c) 2008-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 #include <l4/sys/__vm-svm.h>
27 #include <l4/sys/__vm-vmx.h>
28
29 /**
30  * \group Return location where to store GP-regs.
31  * \ingroup l4_vm_api
32  *
33  * \return Location of GP-regs.
34  * \see l4_vm_run
35  *
36  * Note that the function returns a location within the UTCB, i.e. between
37  * calling this function and l4_vm_run() the UTCB must not be used.
38  */
39 L4_INLINE
40 l4_vm_gpregs_t *
41 l4_vm_gpregs(void) L4_NOTHROW;
42
43 /**
44  * \internal
45  * \ingroup l4_vm_api
46  */
47 L4_INLINE
48 l4_vm_gpregs_t *
49 l4_vm_gpregs_u(l4_utcb_t *u) L4_NOTHROW;
50
51 /**
52  * \brief Run a VM
53  * \ingroup l4_vm_api
54  *
55  * \param vm         Capability selector for VM
56  * \param vmcb_fpage VMCB
57  * \param gpregs     General purpose registers
58  *
59  * The general purpose registers are stored in the UTCB before calling this
60  * function with the function l4_vm_gpregs().
61  */
62 L4_INLINE l4_msgtag_t
63 l4_vm_run(l4_cap_idx_t vm, l4_fpage_t vmcx_fpage) L4_NOTHROW;
64
65 /**
66  * \internal
67  * \ingroup l4_vm_api
68  */
69 L4_INLINE l4_msgtag_t
70 l4_vm_run_u(l4_cap_idx_t vm_task, l4_fpage_t const vmcb_fpage,
71             l4_utcb_t *u) L4_NOTHROW;
72
73
74 /**
75  * \internal
76  * \brief Operations on task objects.
77  * \ingroup l4_vm_api
78  */
79 enum
80 {
81   L4_VM_RUN_OP    = L4_TASK_VM_OPS + 0    /* Run a VM */
82 };
83
84
85 /****** Implementations ****************/
86
87 L4_INLINE
88 l4_vm_gpregs_t *
89 l4_vm_gpregs_u(l4_utcb_t *u) L4_NOTHROW
90 {
91   union cast
92   {
93     l4_vm_gpregs_t r;
94     l4_umword_t a[sizeof(l4_vm_gpregs_t) / sizeof(l4_umword_t)];
95   };
96   return &((union cast *)&l4_utcb_mr_u(u)->mr[1])->r;
97 }
98
99 L4_INLINE l4_msgtag_t
100 l4_vm_run_u(l4_cap_idx_t vm_task, l4_fpage_t const vmcx_fpage,
101             l4_utcb_t *u) L4_NOTHROW
102 {
103   l4_msgtag_t tag;
104   l4_msg_regs_t *v = l4_utcb_mr_u(u);
105   enum { GPREGS_WORDS = sizeof(l4_vm_gpregs_t) / sizeof(l4_umword_t) };
106   v->mr[0]  = L4_VM_RUN_OP;
107
108   v->mr[1 + GPREGS_WORDS] = l4_map_control(0, 0, 0);
109   v->mr[2 + GPREGS_WORDS] = vmcx_fpage.raw;
110
111   tag = l4_ipc_call(vm_task, u,
112                     l4_msgtag(L4_PROTO_TASK, 1 + GPREGS_WORDS, 1, 0),
113                     L4_IPC_NEVER);
114
115   return tag;
116 }
117
118 L4_INLINE
119 l4_vm_gpregs_t *
120 l4_vm_gpregs(void) L4_NOTHROW
121 {
122   return l4_vm_gpregs_u(l4_utcb());
123 }
124
125 L4_INLINE l4_msgtag_t
126 l4_vm_run(l4_cap_idx_t task, l4_fpage_t vmcx_fpage) L4_NOTHROW
127 {
128   return l4_vm_run_u(task, vmcx_fpage, l4_utcb());
129 }