FreeNOS
ARM64SecondTable.cpp
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#include <FreeNOS/System.h>
20#include "ARM64Constant.h"
21#include "ARM64SecondTable.h"
22
31 Address phys,
32 Memory::Access access)
33{
34 u32 idx = L3_IDX(virt);
35 // Check if the address is already mapped
36 if (IS_PT_PAGE_TBL(m_pages[idx]))
38
39 // Insert mapping
40 m_pages[idx] = (phys & PAGEMASK) | PT_PAGE | flags(access);
42}
43
49
51{
52 u32 idx = L3_IDX(virt);
53
54 if (!IS_PT_PAGE_TBL(m_pages[idx]))
56
57 *phys = (m_pages[idx] & PAGEMASK);
59}
60
62{
63 u32 entry = m_pages[L3_IDX(virt)];
64
67
68 // Permissions
70
73
74 if (!(contain_flags(entry, PT_RO)))
76
77 // Caching
80 else if (contain_flags(entry, PT_OSH | PT_NC))
82 else
84
86}
87
89{
90 u64 f = PT_KERNEL | PT_AF;
91
92 // Permissions
93 if (!(access & Memory::Executable)) f |= PT_NX;
94 if ((access & Memory::User)) f |= PT_USER;
95 if (!(access & Memory::Writable)) f |= PT_RO;
96
97 // Cache
99 f |= PT_OSH | PT_DEV;
100 else
101 f |= PT_ISH | PT_NC; /* FIXME: Is PT_OSH appropriate? */
102 return f;
103}
u32 entry[]
Definition IntelACPI.h:1
u32 flags
Definition IntelACPI.h:3
u64 m_pages[512]
Array of second level page table entries.
MemoryContext::Result translate(Address virt, Address *phys) const
Translate virtual address to physical address.
MemoryContext::Result unmap(Address virt)
Remove virtual address mapping.
MemoryContext::Result access(Address virt, Memory::Access *access) const
Get Access flags for a virtual address.
MemoryContext::Result map(Address virt, Address phys, Memory::Access)
Map a virtual address to a physical address.
u32 flags(Memory::Access access) const
Convert MemoryAccess to page table flags.
Result
Result codes.
#define PT_AF
#define PT_DEV
#define PT_NX
#define PT_ISH
#define contain_flags(val, flags)
#define PT_KERNEL
#define PT_OSH
#define PT_USER
#define PT_NC
#define PAGEMASK
Mask to find the page.
#define L3_IDX(va)
#define PT_PAGE
#define PT_RO
#define IS_PT_PAGE_TBL(entry)
#define PT_NONE
unsigned int u32
Unsigned 32-bit number.
Definition Types.h:53
unsigned long Address
A memory address.
Definition Types.h:131
unsigned long long u64
Unsigned 64-bit number.
Definition Types.h:50
Access
Memory access flags.
Definition Memory.h:39
@ Executable
Definition Memory.h:43
@ InnerCached
Definition Memory.h:46
@ User
Definition Memory.h:44
@ Readable
Definition Memory.h:41
@ Device
Definition Memory.h:48
@ Uncached
Definition Memory.h:45
@ Writable
Definition Memory.h:42