FreeNOS
ARM64Paging.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Ivan Tan
3 * Copyright (C) 2015 Niek Linnenbank
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef __LIBARCH_ARM64_PAGING_H
20#define __LIBARCH_ARM64_PAGING_H
21
22#include <Types.h>
23#include "MemoryContext.h"
24#include "MemoryMap.h"
25
27class SplitAllocator;
28class ARM64FirstTable;
29
30//Learn the architecture - AArch64 memory attributes and properties
31#define MEM_ATTR_NORMAL 0xff //normal, IWBWA, OWBWA, NTR
32#define MEM_ATTR_DEV 0x04 //device, nGnRE
33#define MEM_ATTR_NC 0x44 //non cacheable
34#define MAIR_FIELD(val, idx) ((val)<<((idx)<<3))
35
51{
52 public:
53
61
69 ARM64Paging(MemoryMap *map, Address firstTableAddress, Address kernelBaseAddress);
70
74 virtual ~ARM64Paging();
75
81 virtual Result initialize();
82
92 virtual Result activate(bool initializeMMU = false);
93
103 virtual Result map(Address virt, Address phys, Memory::Access access);
104
115 virtual Result unmap(Address virt);
116
125 virtual Result lookup(Address virt, Address *phys) const;
126
135 virtual Result access(Address virt, Memory::Access *access) const;
136
149 virtual Result releaseSection(const Memory::Range & range,
150 const bool tablesOnly = false);
151
159 virtual Result releaseRange(Memory::Range *range);
160
161 private:
162
170 void setupPageTable(MemoryMap *map, Address firstTableAddress, Address kernelBaseAddress);
171
173
180
181 private:
182
185
188
191};
192
193namespace Arch
194{
195 typedef ARM64Paging Memory;
196};
197
204#endif /* __LIBARCH_ARM64_PAGING_H */
ARM64 first level page table.
ARM64 virtual memory implementation.
Definition ARM64Paging.h:51
Address m_kernelBaseAddr
Kernel base address.
virtual Result lookup(Address virt, Address *phys) const
Translate virtual address to physical address.
ARM64FirstTable * m_firstTable
Pointer to the first level page table.
virtual ~ARM64Paging()
Destructor.
Address m_firstTableAddr
Physical address of the first level page table.
virtual Result unmap(Address virt)
Unmap a virtual address.
virtual Result releaseSection(const Memory::Range &range, const bool tablesOnly=false)
Release memory sections.
MemoryContext::Result allocPageTable(Allocator::Range &phys, Allocator::Range &virt)
void setupPageTable(MemoryMap *map, Address firstTableAddress, Address kernelBaseAddress)
Installs default mappings on 1st level page table.
virtual Result activate(bool initializeMMU=false)
Activate the MemoryContext.
virtual Result releaseRange(Memory::Range *range)
Release range of memory.
virtual Result map(Address virt, Address phys, Memory::Access access)
Map a physical page to a virtual address.
virtual Result access(Address virt, Memory::Access *access) const
Get Access flags for a virtual address.
virtual Result initialize()
Initialize the MemoryContext.
Result enableMMU()
Enable the MMU.
Virtual memory abstract interface.
Result
Result codes.
Describes virtual memory map layout.
Definition MemoryMap.h:39
Allocator which separates kernel mapped memory at virtual and physical addresses.
unsigned long Address
A memory address.
Definition Types.h:131
ARMPaging Memory
Definition ARMPaging.h:189
Access
Memory access flags.
Definition Memory.h:39
Describes a range of memory.
Definition Allocator.h:66
Memory range.
Definition Memory.h:56