Kernelite 0.1.0
Kernelite is a minimalist, educational operating system kernel built from scratch. The project aims to recreate core components of the Linux architecture to explore the fundamentals of operating system design and hardware-software interaction.
Loading...
Searching...
No Matches
page_table.h
Go to the documentation of this file.
1
12#ifndef PAGE_TABLE_PAGE_TABLE_H
13#define PAGE_TABLE_PAGE_TABLE_H
14
15#include "fdt/fdt.h"
18
19#include <stdbool.h>
20#include <stdint.h>
21
25#define PAGE_SIZE LINKER_PAGE_SIZE
26
31#define PTRS_PER_TABLE 512
32
36#define NUM_PAGES(size) (((size) + PAGE_SIZE - 1) / PAGE_SIZE)
37
45typedef struct page_permissions_t {
47 bool read : 1;
48
50 bool write : 1;
51
54 bool execute : 1;
55
60
76
86typedef struct __attribute__((packed)) table_desc_t {
89 uint64_t valid : 1;
90
95 uint64_t is_table : 1;
96
98 uint64_t ignored_7_2 : 6;
99
102 uint64_t nlta_51_50 : 2;
103
107 uint64_t access_flag : 1;
108
110 uint64_t ignored_11 : 1;
111
114 uint64_t nlta_47_12 : 36;
115
118 uint64_t nlta_49_48 : 2;
119
121 uint64_t res_50 : 1;
122
124 uint64_t ignored_51 : 1;
125
128 uint64_t protected : 1;
129
131 uint64_t ignored_58_53 : 6;
132
136 uint64_t pxn_table : 1;
137
141 uint64_t xn_table : 1;
142
147 uint64_t ap_table : 2;
148
151 uint64_t ns_table : 1;
153
168typedef struct __attribute__((packed)) page_desc_t {
170 uint64_t valid : 1;
171
175 uint64_t is_page : 1;
176
180 uint64_t attr_indx : 3;
181
184 uint64_t non_secure : 1;
185
189 uint64_t ap : 2;
190
194 uint64_t sh : 2;
195
198 uint64_t access_flag : 1;
199
203 uint64_t non_global : 1;
204
208 uint64_t frame_addr_47_12 : 36;
209
212 uint64_t frame_addr_49_48 : 2;
213
216 uint64_t guarded_page : 1;
217
221 uint64_t dirty_bit : 1;
222
226 uint64_t contiguous : 1;
227
230 uint64_t pxn : 1;
231
235 uint64_t xn : 1;
236
240 uint64_t sw_reserved : 4;
241
245 uint64_t attr_indx_3 : 1;
246
251 uint64_t po_index : 3;
252
256 uint64_t amec : 1;
258
267typedef union __attribute__((packed)) page_table_entry_t {
272 uint64_t value;
273
280 struct __attribute__((packed)) {
283 uint64_t valid : 1;
284
287 uint64_t type : 1;
288
291 uint64_t rest : 62;
292 } generic;
294
302
309
311
319
344 page_permissions_t perms, mem_type_t mem_typ);
345
350void dump_memory_map(page_table_t *root);
351
363bool setup_kernel_id_map(phy_addr serial_device_addr_base);
364
377
378#endif /* PAGE_TABLE_PAGE_TABLE_H */
Header that interfaces with libfdt for Device Tree Blob (DTB) parsing.
Preprocessor define values used in the linker script and referenced in C code.
Memory layout definitions.
uint64_t virt_addr
Type for representing virtual addresses.
Definition mem_layout.h:20
uint64_t phy_addr
Type for representing physical addresses.
Definition mem_layout.h:17
bool setup_kernel_map(memory_map_t *mmap)
Set up the kernel's higher-half virtual-memory map.
Definition page_table.c:911
#define PTRS_PER_TABLE
Number of pointers per page table. from table D4-21 in the Armv8-A architecture reference manual.
Definition page_table.h:31
bool map_page(page_table_t *root, virt_addr v_addr, phy_addr phy_addr, page_permissions_t perms, mem_type_t mem_typ)
Map a virtual address to a physical address in the page table.
Definition page_table.c:748
bool setup_kernel_id_map(phy_addr serial_device_addr_base)
Set up the initial identity-mapped region for the kernel.
Definition page_table.c:840
void dump_memory_map(page_table_t *root)
Dump the memory map for debugging.
Definition page_table.c:833
mem_type_t
Memory type used as an index into the MAIR_EL1 register.
Definition page_table.h:68
@ DEVICE
Definition page_table.h:71
@ NORMAL
Definition page_table.h:74
Container for the system physical memory layout.
Definition fdt.h:39
FLAT BLOCK/PAGE DATA DESCRIPTOR LAYOUT — maps real physical memory.
Definition page_table.h:168
uint64_t valid
Definition page_table.h:170
uint64_t non_global
Definition page_table.h:203
uint64_t po_index
Definition page_table.h:251
uint64_t frame_addr_49_48
Definition page_table.h:212
uint64_t guarded_page
Definition page_table.h:216
uint64_t sw_reserved
Definition page_table.h:240
uint64_t attr_indx_3
Definition page_table.h:245
uint64_t ap
Definition page_table.h:189
uint64_t access_flag
Definition page_table.h:198
uint64_t attr_indx
Definition page_table.h:180
uint64_t pxn
Definition page_table.h:230
uint64_t non_secure
Definition page_table.h:184
uint64_t contiguous
Definition page_table.h:226
uint64_t sh
Definition page_table.h:194
uint64_t xn
Definition page_table.h:235
uint64_t is_page
Definition page_table.h:175
uint64_t amec
Definition page_table.h:256
uint64_t dirty_bit
Definition page_table.h:221
uint64_t frame_addr_47_12
Definition page_table.h:208
Software representation of architectural page mapping privileges.
Definition page_table.h:45
bool user_accessible
Definition page_table.h:58
bool write
Definition page_table.h:50
bool execute
Definition page_table.h:54
bool read
Definition page_table.h:47
Represents a single page table level (512 entries).
Definition page_table.h:315
TABLE DESCRIPTOR LAYOUT (Lookup levels 0, 1, or 2).
Definition page_table.h:86
uint64_t ap_table
Definition page_table.h:147
uint64_t ns_table
Definition page_table.h:151
uint64_t xn_table
Definition page_table.h:141
uint64_t nlta_51_50
Definition page_table.h:102
uint64_t access_flag
Definition page_table.h:107
uint64_t ignored_58_53
Definition page_table.h:131
uint64_t is_table
Definition page_table.h:95
uint64_t nlta_47_12
Definition page_table.h:114
uint64_t nlta_49_48
Definition page_table.h:118
uint64_t ignored_7_2
Definition page_table.h:98
uint64_t ignored_11
Definition page_table.h:110
uint64_t ignored_51
Definition page_table.h:124
uint64_t pxn_table
Definition page_table.h:136
uint64_t res_50
Definition page_table.h:121
uint64_t valid
Definition page_table.h:89
Flat, architecturally stable AArch64 Stage 1 Descriptor structure.
Definition page_table.h:267
uint64_t rest
Definition page_table.h:291
table_desc_t table_desc
full descriptor.
Definition page_table.h:301
uint64_t type
Definition page_table.h:287
page_desc_t page_desc
Structured layout for block mappings (L1/L2) or page mappings (L3). Maps physical memory output windo...
Definition page_table.h:308
uint64_t valid
Definition page_table.h:283
uint64_t value
Raw 64-bit integer presentation of the full descriptor. Useful for atomic page table writes or direct...
Definition page_table.h:272