xref: /freebsd/lib/libkvm/kvm_amd64.h (revision 0957b409)
1 /*-
2  * Copyright (c) 2015 John H. Baldwin <jhb@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef __KVM_AMD64_H__
30 #define	__KVM_AMD64_H__
31 
32 #ifdef __amd64__
33 #include <vm/vm.h>
34 #include <vm/pmap.h>
35 #endif
36 
37 typedef uint64_t	amd64_physaddr_t;
38 typedef uint64_t	amd64_pte_t;
39 typedef uint64_t	amd64_pde_t;
40 typedef uint64_t	amd64_pdpe_t;
41 typedef	uint64_t	amd64_pml4e_t;
42 
43 #define	AMD64_NPTEPG		(AMD64_PAGE_SIZE / sizeof(amd64_pte_t))
44 #define	AMD64_PAGE_SHIFT	12
45 #define	AMD64_PAGE_SIZE		(1 << AMD64_PAGE_SHIFT)
46 #define	AMD64_PAGE_MASK		(AMD64_PAGE_SIZE - 1)
47 #define	AMD64_NPDEPG		(AMD64_PAGE_SIZE / sizeof(amd64_pde_t))
48 #define	AMD64_PDRSHIFT		21
49 #define	AMD64_NBPDR		(1 << AMD64_PDRSHIFT)
50 #define	AMD64_PDRMASK		(AMD64_NBPDR - 1)
51 #define	AMD64_NPDPEPG		(AMD64_PAGE_SIZE / sizeof(amd64_pdpe_t))
52 #define	AMD64_PDPSHIFT		30
53 #define	AMD64_NBPDP		(1 << AMD64_PDPSHIFT)
54 #define	AMD64_PDPMASK		(AMD64_NBPDP - 1)
55 #define	AMD64_NPML4EPG		(AMD64_PAGE_SIZE / sizeof(amd64_pml4e_t))
56 #define	AMD64_PML4SHIFT		39
57 
58 #define	AMD64_PG_NX		(1ULL << 63)
59 #define	AMD64_PG_V		0x001
60 #define	AMD64_PG_RW		0x002
61 #define	AMD64_PG_PS		0x080
62 #define	AMD64_PG_FRAME		(0x000ffffffffff000)
63 #define	AMD64_PG_PS_FRAME	(0x000fffffffe00000)
64 #define	AMD64_PG_1GB_FRAME	(0x000fffffc0000000)
65 
66 #ifdef __amd64__
67 _Static_assert(NPTEPG == AMD64_NPTEPG, "NPTEPG mismatch");
68 _Static_assert(PAGE_SHIFT == AMD64_PAGE_SHIFT, "PAGE_SHIFT mismatch");
69 _Static_assert(PAGE_SIZE == AMD64_PAGE_SIZE, "PAGE_SIZE mismatch");
70 _Static_assert(PAGE_MASK == AMD64_PAGE_MASK, "PAGE_MASK mismatch");
71 _Static_assert(NPDEPG == AMD64_NPDEPG, "NPDEPG mismatch");
72 _Static_assert(PDRSHIFT == AMD64_PDRSHIFT, "PDRSHIFT mismatch");
73 _Static_assert(NBPDR == AMD64_NBPDR, "NBPDR mismatch");
74 _Static_assert(PDRMASK == AMD64_PDRMASK, "PDRMASK mismatch");
75 _Static_assert(NPDPEPG == AMD64_NPDPEPG, "NPDPEPG mismatch");
76 _Static_assert(PDPSHIFT == AMD64_PDPSHIFT, "PDPSHIFT mismatch");
77 _Static_assert(NBPDP == AMD64_NBPDP, "NBPDP mismatch");
78 _Static_assert(PDPMASK == AMD64_PDPMASK, "PDPMASK mismatch");
79 _Static_assert(NPML4EPG == AMD64_NPML4EPG, "NPML4EPG mismatch");
80 _Static_assert(PML4SHIFT == AMD64_PML4SHIFT, "PML4SHIFT mismatch");
81 
82 _Static_assert(PG_V == AMD64_PG_V, "PG_V mismatch");
83 _Static_assert(PG_PS == AMD64_PG_PS, "PG_PS mismatch");
84 _Static_assert(PG_FRAME == AMD64_PG_FRAME, "PG_FRAME mismatch");
85 _Static_assert(PG_PS_FRAME == AMD64_PG_PS_FRAME, "PG_PS_FRAME mismatch");
86 #endif
87 
88 int	_amd64_native(kvm_t *);
89 
90 #endif /* !__KVM_AMD64_H__ */
91