2 * Copyright (c) 2008 The FreeBSD Project
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/kernel.h>
33 #include <vm/vm_extern.h>
34 #include <vm/vm_map.h>
35 #include <vm/vm_object.h>
36 #include <vm/vm_param.h>
37 #include <machine/_inttypes.h>
38 #include <machine/specialreg.h>
40 struct vmspace
*sp
= NULL
;
41 vm_object_t obj
= NULL
;
44 fkvm_make_vm_map(void)
48 sp
= vmspace_alloc(0, 0xffffffffffffffff);
50 printf("vmspace_alloc failed\n");
54 obj
= vm_object_allocate(OBJT_DEFAULT
, 0xffffffffffffffff >> PAGE_SHIFT
);
56 vm_object_reference(obj
);
57 rc
= vm_map_insert(&sp
->vm_map
,
59 0, 0, 0xffffffffffffffff >> PAGE_SHIFT
,
60 VM_PROT_ALL
, VM_PROT_ALL
,
62 if (rc
!= KERN_SUCCESS
) {
63 printf("vm_map_insert failed: %d\n", rc
);
64 vm_object_deallocate(obj
);
68 return vtophys(vmspace_pmap(sp
)->pm_pml4
);
72 vm_object_deallocate(obj
);
84 fkvm_load(void *unused
)
89 printf("fkvm_load\n");
91 /* TODO: check for the presense of extensions */
92 efer
= rdmsr(MSR_EFER
);
93 printf("EFER = %" PRIx64
"\n", efer
);
94 wrmsr(MSR_EFER
, efer
| EFER_SVME
);
95 efer
= rdmsr(MSR_EFER
);
96 printf("new EFER = %" PRIx64
"\n", efer
);
98 ncr3
= fkvm_make_vm_map();
99 printf("ncr3: %" PRIx64
"\n", ncr3
);
101 SYSINIT(fkvm
, SI_SUB_PSEUDO
, SI_ORDER_MIDDLE
, fkvm_load
, NULL
);
104 fkvm_unload(void *unused
)
106 printf("fkvm_unload\n");
109 SYSUNINIT(fkvm
, SI_SUB_PSEUDO
, SI_ORDER_MIDDLE
, fkvm_unload
, NULL
);