mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-29 07:47:59 +00:00
Updated memory initializator
This commit is contained in:
parent
0775a2662b
commit
aa45396d5b
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
namespace Memory
|
namespace Memory
|
||||||
{
|
{
|
||||||
bool Virtual::Check(void *VirtualAddress)
|
bool Virtual::Check(void *VirtualAddress, PTFlag Flag)
|
||||||
{
|
{
|
||||||
// 0x1000 aligned
|
// 0x1000 aligned
|
||||||
uint64_t Address = (uint64_t)VirtualAddress;
|
uint64_t Address = (uint64_t)VirtualAddress;
|
||||||
@ -13,9 +13,7 @@ namespace Memory
|
|||||||
|
|
||||||
PageMapIndexer Index = PageMapIndexer((uint64_t)Address);
|
PageMapIndexer Index = PageMapIndexer((uint64_t)Address);
|
||||||
PageDirectoryEntry PDE = this->Table->Entries[Index.PDP_i];
|
PageDirectoryEntry PDE = this->Table->Entries[Index.PDP_i];
|
||||||
if (!PDE.GetFlag(PTFlag::P))
|
return PDE.GetFlag(Flag) ? true : false;
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Virtual::Map(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags)
|
void Virtual::Map(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags)
|
||||||
@ -74,11 +72,10 @@ namespace Memory
|
|||||||
PDE.SetFlag(PTFlag::P, true);
|
PDE.SetFlag(PTFlag::P, true);
|
||||||
PDE.AddFlag(Flags);
|
PDE.AddFlag(Flags);
|
||||||
PT->Entries[Index.P_i] = PDE;
|
PT->Entries[Index.P_i] = PDE;
|
||||||
#if defined(__amd64__) || defined(__i386__)
|
#if defined(__amd64__)
|
||||||
asmv("invlpg (%0)"
|
CPU::x64::invlpg(VirtualAddress);
|
||||||
:
|
#elif defined(__i386__)
|
||||||
: "r"(VirtualAddress)
|
CPU::x86::invlpg(VirtualAddress);
|
||||||
: "memory");
|
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
asmv("dsb sy");
|
asmv("dsb sy");
|
||||||
asmv("tlbi vae1is, %0"
|
asmv("tlbi vae1is, %0"
|
||||||
@ -88,6 +85,23 @@ namespace Memory
|
|||||||
asmv("dsb sy");
|
asmv("dsb sy");
|
||||||
asmv("isb");
|
asmv("isb");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
/* https://stackoverflow.com/a/3208376/9352057 */
|
||||||
|
#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"
|
||||||
|
#define BYTE_TO_BINARY(byte) \
|
||||||
|
(byte & 0x80 ? '1' : '0'), \
|
||||||
|
(byte & 0x40 ? '1' : '0'), \
|
||||||
|
(byte & 0x20 ? '1' : '0'), \
|
||||||
|
(byte & 0x10 ? '1' : '0'), \
|
||||||
|
(byte & 0x08 ? '1' : '0'), \
|
||||||
|
(byte & 0x04 ? '1' : '0'), \
|
||||||
|
(byte & 0x02 ? '1' : '0'), \
|
||||||
|
(byte & 0x01 ? '1' : '0')
|
||||||
|
|
||||||
|
if (!this->Check(VirtualAddress, (PTFlag)Flags)) // quick workaround just to see where it fails
|
||||||
|
warn("Failed to map %#lx with flags: " BYTE_TO_BINARY_PATTERN, VirtualAddress, BYTE_TO_BINARY(Flags));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Virtual::Map(void *VirtualAddress, void *PhysicalAddress, uint64_t PageCount, uint64_t Flags)
|
void Virtual::Map(void *VirtualAddress, void *PhysicalAddress, uint64_t PageCount, uint64_t Flags)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user