]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/ia32/vm_factory-ia32.cpp
update
[l4.git] / kernel / fiasco / src / kern / ia32 / vm_factory-ia32.cpp
1 IMPLEMENTATION [vmx && svm]:
2
3 #include "ram_quota.h"
4 #include "svm.h"
5 #include "vm_svm.h"
6 #include "vmx.h"
7 #include "vm_vmx.h"
8 #include "vm_vmx_ept.h"
9
10 PRIVATE static inline
11 template< typename VM >
12 VM *
13 Vm_factory::allocate(Ram_quota *quota)
14 {
15   if (void *t = Vm::allocator<VM>()->q_alloc(quota))
16     {
17       VM *a = new (t) VM(quota);
18       if (a->initialize())
19         return a;
20
21       delete a;
22     }
23
24   return 0;
25 }
26
27 IMPLEMENT
28 Vm *
29 Vm_factory::create(Ram_quota *quota, int *err)
30 {
31   *err = -L4_err::ENomem;
32   if (Svm::cpus.current().svm_enabled())
33     return allocate<Vm_svm>(quota);
34   if (Vmx::cpus.current().vmx_enabled())
35     {
36       if (Vmx::cpus.current().info.procbased_ctls2.allowed(Vmx::PRB2_enable_ept))
37         return allocate<Vm_vmx_ept>(quota);
38       else
39         return allocate<Vm_vmx>(quota);
40     }
41   *err = L4_err::ENodev;
42   return 0;
43 }
44