]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - wimboot/wimboot-2.7.3/src/paging.h
1.1.07 release
[Ventoy.git] / wimboot / wimboot-2.7.3 / src / paging.h
1 #ifndef _PAGING_H
2 #define _PAGING_H
3
4 /*
5 * Copyright (C) 2021 Michael Brown <mbrown@fensystems.co.uk>.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 */
22
23 /**
24 * @file
25 *
26 * Paging
27 *
28 */
29
30 #include <stddef.h>
31
32 /** Get CPU features */
33 #define CPUID_FEATURES 0x00000001
34
35 /** CPU supports PAE */
36 #define CPUID_FEATURE_EDX_PAE 0x00000040
37
38 /* CR0: paging */
39 #define CR0_PG 0x80000000
40
41 /* CR4: physical address extensions */
42 #define CR4_PAE 0x00000020
43
44 /* Page: present */
45 #define PG_P 0x01
46
47 /* Page: read/write */
48 #define PG_RW 0x02
49
50 /* Page: user/supervisor */
51 #define PG_US 0x04
52
53 /* Page: page size */
54 #define PG_PS 0x80
55
56 /** 2MB page size */
57 #define PAGE_SIZE_2MB 0x200000
58
59 /** 32-bit address space size */
60 #define ADDR_4GB 0x100000000ULL
61
62 /** Saved paging state */
63 struct paging_state {
64 /** Control register 0 */
65 unsigned long cr0;
66 /** Control register 3 */
67 unsigned long cr3;
68 /** Control register 4 */
69 unsigned long cr4;
70 };
71
72 extern int paging;
73
74 extern void init_paging ( void );
75 extern void enable_paging ( struct paging_state *state );
76 extern void disable_paging ( struct paging_state *state );
77 extern uint64_t relocate_memory_high ( void *start, size_t len );
78
79 #endif /* _PAGING_H */