NeKernel dev
Loading...
Searching...
No Matches
Paging.h
Go to the documentation of this file.
1/* ========================================
2
3 Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
4
5======================================== */
6
7#pragma once
8
14
15#ifdef __NE_ARM64__
16
17#include <NeKit/Config.h>
18
19#ifndef kPageMax
20#define kPageMax (0x200)
21#endif
22
23#ifndef kPageAlign
24#define kPageAlign (0x1000)
25#endif
26
27#ifndef kPageSize
28#define kPageSize (0x1000)
29#endif // !kPageSize
30
32
33#define c16KBPage 0b000
34#define c8KBPage 0b001
35#define c4KBPage 0b010
36#define c2KBPage 0b011
37#define c1KBPage 0b100
38#define c512BPage 0b101
39#define c256BPage 0b110
40#define c128BPage 0b111
41
43
44#define cPageMAll {0b000, 0b000}
45#define cPageMToMax(M) {M, 0b000}
46#define cPageMaxToM(M) {0b000, M}
47#define cPageMToN(M, N) {M, N}
48
49namespace Kernel::HAL {
50struct PACKED PTE_4KB final {
51 UInt64 Valid : 1;
52 UInt64 Table : 1;
53 UInt64 AttrIndex : 3;
54 UInt64 NS : 1;
55 UInt64 AP : 2;
56 UInt64 SH : 2;
57 UInt64 AF : 1;
58 UInt64 NG : 1;
59 UInt64 Reserved1 : 1;
60 UInt64 Contiguous : 1;
61 UInt64 Dirty : 1;
62 UInt64 Reserved : 2;
63 UInt64 PhysicalAddress : 36;
64 UInt64 Reserved3 : 4;
65 UInt64 PXN : 1;
66 UInt64 XN : 1;
67 UInt64 Reserved4 : 9;
68};
69
70namespace Detail {
71 enum class ControlRegisterBits {
72 ProtectedModeEnable = 0,
73 MonitorCoProcessor = 1,
74 Emulation = 2,
75 TaskSwitched = 3,
76 ExtensionType = 4,
77 NumericError = 5,
78 WriteProtect = 16,
79 AlignementMask = 18,
80 NotWriteThrough = 29,
81 CacheDisable = 30,
82 PageEnable = 31,
83 };
84
85 inline UInt8 control_register_cast(ControlRegisterBits reg) {
86 return static_cast<UInt8>(reg);
87 }
88} // namespace Detail
89
90struct PDE_4KB final {
91 PTE_4KB ALIGN(kPageAlign) fEntries[kPageMax];
92};
93
94auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page, SizeT pad = 0) -> VoidPtr;
95auto mm_free_bitmap(VoidPtr page_ptr) -> Bool;
96} // namespace Kernel::HAL
97
98namespace Kernel {
99typedef HAL::PTE_4KB PTE;
100typedef HAL::PDE_4KB PDE;
101} // namespace Kernel
102
104
105#endif // __NE_ARM64__
#define PACKED
#define ALIGN(X)
#define EXTERN_C
EXTERN_C void hal_flush_tlb()
Flush TLB.
Definition HalVirtualMemory.cc:44
Definition HalDescriptorLoader.cc:12
Hardware Abstraction Layer.
Definition ArchKit.h:62
auto mm_free_bitmap(VoidPtr ptr) -> Bool
Free Bitmap, and mark it as absent.
Definition BitMapMgr.cc:199
auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page, SizeT pad) -> VoidPtr
Allocate a new page to be used by the OS.
Definition BitMapMgr.cc:181
UPS inline definitions.
Definition Device.h:12
__SIZE_TYPE__ SizeT
Definition Config.h:60
__UINT8_TYPE__ UInt8
Definition Config.h:55
void * VoidPtr
Definition Config.h:33
bool Boolean
Definition Config.h:49
__UINT64_TYPE__ UInt64
Definition Config.h:48
bool Bool
Definition Config.h:50