xref: /freebsd/lib/libkvm/kvm_i386.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * Copyright (c) 2015 John H. Baldwin <jhb@FreeBSD.org>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25 
26 #ifndef __KVM_I386_H__
27 #define	__KVM_I386_H__
28 
29 #ifdef __i386__
30 #include <vm/vm.h>
31 #include <vm/pmap.h>
32 #endif
33 
34 typedef uint32_t	i386_physaddr_t;
35 typedef uint32_t	i386_pte_t;
36 typedef uint32_t	i386_pde_t;
37 typedef uint64_t	i386_physaddr_pae_t;
38 typedef	uint64_t	i386_pte_pae_t;
39 typedef	uint64_t	i386_pde_pae_t;
40 
41 #define	I386_PAGE_SHIFT		12
42 #define	I386_PAGE_SIZE		(1 << I386_PAGE_SHIFT)
43 #define	I386_PAGE_MASK		(I386_PAGE_SIZE - 1)
44 #define	I386_NPTEPG		(I386_PAGE_SIZE / sizeof(i386_pte_t))
45 #define	I386_PDRSHIFT		22
46 #define	I386_NBPDR		(1 << I386_PDRSHIFT)
47 #define	I386_PAGE_PS_MASK	(I386_NBPDR - 1)
48 #define	I386_NPTEPG_PAE		(I386_PAGE_SIZE / sizeof(i386_pte_pae_t))
49 #define	I386_PDRSHIFT_PAE	21
50 #define	I386_NBPDR_PAE		(1 << I386_PDRSHIFT_PAE)
51 #define	I386_PAGE_PS_MASK_PAE	(I386_NBPDR_PAE - 1)
52 
53 /* Source: i386/include/pmap.h */
54 #define	I386_PG_V		0x001
55 #define	I386_PG_RW		0x002
56 #define	I386_PG_PS		0x080
57 #define	I386_PG_NX		(1ULL << 63)
58 #define	I386_PG_FRAME_PAE	(0x000ffffffffff000ull)
59 #define	I386_PG_PS_FRAME_PAE	(0x000fffffffe00000ull)
60 #define	I386_PG_FRAME		(0xfffff000)
61 #define	I386_PG_PS_FRAME	(0xffc00000)
62 
63 #ifdef __i386__
64 _Static_assert(PAGE_SHIFT == I386_PAGE_SHIFT, "PAGE_SHIFT mismatch");
65 _Static_assert(PAGE_SIZE == I386_PAGE_SIZE, "PAGE_SIZE mismatch");
66 _Static_assert(PAGE_MASK == I386_PAGE_MASK, "PAGE_MASK mismatch");
67 #if 0
68 _Static_assert(NPTEPG == I386_NPTEPG, "NPTEPG mismatch");
69 _Static_assert(NBPDR == I386_NBPDR, "NBPDR mismatch");
70 #endif
71 _Static_assert(PDRSHIFT_NOPAE == I386_PDRSHIFT, "PDRSHIFT mismatch");
72 
73 _Static_assert(PG_V == I386_PG_V, "PG_V mismatch");
74 _Static_assert(PG_PS == I386_PG_PS, "PG_PS mismatch");
75 _Static_assert((u_int)PG_FRAME_NOPAE == I386_PG_FRAME, "PG_FRAME mismatch");
76 _Static_assert(PG_PS_FRAME_NOPAE == I386_PG_PS_FRAME, "PG_PS_FRAME mismatch");
77 #endif
78 
79 int	_i386_native(kvm_t *);
80 
81 #endif /* !__KVM_I386_H__ */
82