FreeNOS
ARM64Constant.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_CONSTANT_H
20#define __LIBARCH_ARM64_CONSTANT_H
21
45#define L1_DIRSHIFT 30UL
46#define L2_DIRSHIFT 21UL
47#define L3_DIRSHIFT 12UL
48#define DIR_MASK 0x1FFUL
49
51#define PAGESIZE 4096
52
59#define PAGEDIR_MAX 512
60#define PAGEDIR_SIZE (PAGEDIR_MAX * sizeof(u64))
61
70#define PAGETAB_MAX 256
71#define PAGETAB_SIZE (PAGETAB_MAX * sizeof(u32))
72#define PAGETAB_SPAN (PAGETAB_MAX*PAGESIZE)
73
75#define PAGEMASK 0x3FFFFFFFFF000UL
76
78#define L1_BLOCK_MASK 0x3FFFFC0000000UL
79#define L1_BLOCK_SIZE 0x40000000UL
80#define L1_BLOCK_RANGE (L1_BLOCK_SIZE-1)
82#define L2_BLOCK_MASK 0x3FFFFFFE00000UL
83#define L2_BLOCK_SIZE 0x200000UL
84#define L2_BLOCK_RANGE (L2_BLOCK_SIZE-1)
85
86#define L1_IDX(va) (((va) >> L1_DIRSHIFT) & DIR_MASK)
87#define L2_IDX(va) (((va) >> L2_DIRSHIFT) & DIR_MASK)
88#define L3_IDX(va) (((va) >> L3_DIRSHIFT) & DIR_MASK)
89
91#define MEMALIGN 4
92
93// descriptor types
94#define PT_NONE 0
95#define PT_PAGE 0b11 //page/table descriptor
96#define PT_BLOCK 0b01 //block descriptor
97#define PT_TYPE_MASK 0b11
98#define GET_PT_TYPE(entry) ((entry) & PT_TYPE_MASK)
99#define IS_PT_PAGE_TBL(entry) (GET_PT_TYPE(entry) == PT_PAGE)
100#define IS_PT_BLOCK(entry) (GET_PT_TYPE(entry) == PT_BLOCK)
101
102// accessibility
103#define PT_KERNEL (0<<6) // privileged, supervisor EL1 access only (default)
104#define PT_USER (1<<6) // unprivileged, EL0 access allowed
105#define PT_RW (0<<7) // read-write (default)
106#define PT_RO (1<<7) // read-only
107#define PT_AF (1<<10) // access flag
108#define PT_NX (1UL<<54) // no execute
109
110// shareability
111#define PT_OSH (2<<8) // outter shareable
112#define PT_ISH (3<<8) // inner shareable
113
114// define in MAIR register
115#define PT_MEM (0<<2) // normal memory
116#define PT_DEV (1<<2) // device MMIO
117#define PT_NC (2<<2) // non-cachable
118
119#define TTBR_CNP 1
120
121#define contain_flags(val, flags) (((val)&(flags))==(flags))
122
130#endif /* __LIBARCH_ARM64_CONSTANT_H */