Files
ksOS/Kernel/Include/VM/VMM.h
T
karina 359eaeb405 fix(VMM): use correct APTable encoding for table descriptors
fix(VMM): use correct APTable encoding for table descriptors

fix(vmm): changed flags to match ARMv8
2026-05-03 10:47:15 +04:00

60 lines
2.2 KiB
C

#pragma once
#include <Types.h>
#include <VM/PMM.h>
#include "../Common/bootinfo.h"
enum VMPTEFlags {
// Descriptor type (bits [1:0])
kPTEValid = (1ULL << 0), // 1 = Valid (fault if 0)
kPTETable = (1ULL << 1), // For L0/L1/L2: table descriptor (bits[1:0]=11)
kPTEPage = (1ULL << 1), // For L3: page descriptor (same bit, bits[1:0]=11)
// MAIR attribute index (bits [4:2])
kPTENormalMem = (0ULL << 2), // AttrIndx 0 → MAIR[7:0] = 0xFF (Normal, WB Cacheable)
kPTEDeviceMem = (1ULL << 2), // AttrIndx 1 → MAIR[15:8] = 0x00 (Device-nGnRnE)
// Leaf entry AP[2:1] (bits [7:6]):
// AP[1] (bit 6): 0 = EL0 blocked, 1 = EL0 allowed
// AP[2] (bit 7): 0 = Read/Write, 1 = Read-only
kPTEUser = (1ULL << 6), // AP[1]=1: allow EL0 access
kPTEAccessRW = (0ULL << 7), // AP[2]=0: writable for permitted levels
kPTEAccessRO = (1ULL << 7), // AP[2]=1: read-only for all levels
// Table descriptor APTable[1:0] (bits [62:61]):
// 00 = no restriction, 01 = block EL0, 10 = reserved, 11 = read-only for all
kPTETableNoEL0 = (1ULL << 61), // APTable[0]=1: prevent EL0 table walk
kPTEInnerShare = (3ULL << 8), // Inner Shareable (SMP safe)
kPTEAccessFlag = (1ULL << 10), // Access Flag (MUST be 1 to avoid faults)
kPTEPrivNX = (1ULL << 53), // PXN: Privileged Execute Never
kPTEUserNX = (1ULL << 54) // UXN: Unprivileged Execute Never
};
enum {
kVMKernelVMA = 0xFFFFFFFF80000000,
kHHDMOffset = 0xFFFF888000000000,
kVMFbVirtBase = 0xFFFFFFFFFC000000,
kKernelPhysBase = 0x40100000,
};
static inline Address VMKernelVirtToPhys(Address virt) {
return virt - 0xFFFFFFFF80100000 + kKernelPhysBase;
}
static inline Address VMPhysToHHDM(Address phys) {
return phys + kHHDMOffset;
}
static inline Address VMHHDMToPhys(Address virt) {
return virt - kHHDMOffset;
}
extern Address* gVMKernelL0Table;
extern Address gVMKernelL0Physical;
Address* VMMMapPage(Address* l0Table, Address phys, Address virt, UInt64 flags);
void VMMUnmapPage(Address* l0Table, Address virt);
Pointer VMMGetOrAllocatePage(Address* l0Table, Address virt, UInt64 flags);
void VMMInitialize(VMBootMemoryMap* bootMap, Bootinfo* info);