xref: /freebsd/lib/libkvm/kvm_i386.h (revision f39bffc62c1395bde25d152c7f68fdf7cbaab414)
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_I386_H__
30 #define	__KVM_I386_H__
31 
32 #ifdef __i386__
33 #include <vm/vm.h>
34 #include <vm/pmap.h>
35 #endif
36 
37 typedef uint32_t	i386_physaddr_t;
38 typedef uint32_t	i386_pte_t;
39 typedef uint32_t	i386_pde_t;
40 typedef uint64_t	i386_physaddr_pae_t;
41 typedef	uint64_t	i386_pte_pae_t;
42 typedef	uint64_t	i386_pde_pae_t;
43 
44 #define	I386_PAGE_SHIFT		12
45 #define	I386_PAGE_SIZE		(1 << I386_PAGE_SHIFT)
46 #define	I386_PAGE_MASK		(I386_PAGE_SIZE - 1)
47 #define	I386_NPTEPG		(I386_PAGE_SIZE / sizeof(i386_pte_t))
48 #define	I386_PDRSHIFT		22
49 #define	I386_NBPDR		(1 << I386_PDRSHIFT)
50 #define	I386_PAGE_PS_MASK	(I386_NBPDR - 1)
51 #define	I386_NPTEPG_PAE		(I386_PAGE_SIZE / sizeof(i386_pte_pae_t))
52 #define	I386_PDRSHIFT_PAE	21
53 #define	I386_NBPDR_PAE		(1 << I386_PDRSHIFT_PAE)
54 #define	I386_PAGE_PS_MASK_PAE	(I386_NBPDR_PAE - 1)
55 
56 /* Source: i386/include/pmap.h */
57 #define	I386_PG_V		0x001
58 #define	I386_PG_RW		0x002
59 #define	I386_PG_PS		0x080
60 #define	I386_PG_NX		(1ULL << 63)
61 #define	I386_PG_FRAME_PAE	(0x000ffffffffff000ull)
62 #define	I386_PG_PS_FRAME_PAE	(0x000fffffffe00000ull)
63 #define	I386_PG_FRAME		(0xfffff000)
64 #define	I386_PG_PS_FRAME	(0xffc00000)
65 
66 #ifdef __i386__
67 _Static_assert(PAGE_SHIFT == I386_PAGE_SHIFT, "PAGE_SHIFT mismatch");
68 _Static_assert(PAGE_SIZE == I386_PAGE_SIZE, "PAGE_SIZE mismatch");
69 _Static_assert(PAGE_MASK == I386_PAGE_MASK, "PAGE_MASK mismatch");
70 _Static_assert(NPTEPG == I386_NPTEPG, "NPTEPG mismatch");
71 _Static_assert(PDRSHIFT == I386_PDRSHIFT, "PDRSHIFT mismatch");
72 _Static_assert(NBPDR == I386_NBPDR, "NBPDR mismatch");
73 
74 _Static_assert(PG_V == I386_PG_V, "PG_V mismatch");
75 _Static_assert(PG_PS == I386_PG_PS, "PG_PS mismatch");
76 _Static_assert((u_int)PG_FRAME == I386_PG_FRAME, "PG_FRAME mismatch");
77 _Static_assert(PG_PS_FRAME == I386_PG_PS_FRAME, "PG_PS_FRAME mismatch");
78 #endif
79 
80 int	_i386_native(kvm_t *);
81 
82 #endif /* !__KVM_I386_H__ */
83