x32 still not working (TODO: do 1:1 page mapping, except for kernel)

This commit is contained in:
Alex
2022-10-18 21:16:12 +03:00
parent 348aa69dcb
commit cb349ae620
15 changed files with 480 additions and 94 deletions

View File

@ -3,6 +3,7 @@
enum MemoryType
{
Unknown,
Usable,
Reserved,
ACPIReclaimable,
@ -10,8 +11,7 @@ enum MemoryType
BadMemory,
BootloaderReclaimable,
KernelAndModules,
Framebuffer,
Unknown
Framebuffer
};
#define MAX_FRAMEBUFFERS 16

View File

@ -104,7 +104,7 @@ namespace Video
{
Width = this->framebuffer.Width;
Height = this->framebuffer.Height;
debug("No width and height specified, using %ldx%ld", Width, Height);
debug("No width and height specified, using %ldx%lld", Width, Height);
}
uint64_t Size = this->framebuffer.Pitch * Height;

View File

@ -137,6 +137,7 @@ namespace Memory
{
struct
{
#if defined(__amd64__)
bool Present : 1;
bool ReadWrite : 1;
bool UserSupervisor : 1;
@ -152,6 +153,18 @@ namespace Memory
uint32_t Available2 : 7;
uint16_t ProtectionKey : 4;
bool ExecuteDisable : 1;
#elif defined(__i386__)
bool Present : 1;
bool ReadWrite : 1;
bool UserSupervisor : 1;
bool Accessed : 1;
bool Dirty : 1;
uint8_t Available : 7;
uint32_t Frame : 20;
// TODO: i386 PDEData is not tested
#elif defined(__aarch64__)
// TODO: aarch64 PDEData not implemented
#endif
};
uint64_t raw;
} PDEData;
@ -338,26 +351,26 @@ namespace Memory
class PageMapIndexer
{
public:
uint64_t PDP_i;
uint64_t PD_i;
uint64_t PT_i;
uint64_t P_i;
uint64_t PDP_i = 0;
uint64_t PD_i = 0;
uint64_t PT_i = 0;
uint64_t P_i = 0;
PageMapIndexer(uint64_t VirtualAddress)
{
#if defined(__amd64__)
PDP_i = (VirtualAddress & ((uint64_t)0x1FF << 39)) >> 39;
PD_i = (VirtualAddress & ((uint64_t)0x1FF << 30)) >> 30;
PT_i = (VirtualAddress & ((uint64_t)0x1FF << 21)) >> 21;
P_i = (VirtualAddress & ((uint64_t)0x1FF << 12)) >> 12;
this->PDP_i = (VirtualAddress & ((uint64_t)0x1FF << 39)) >> 39;
this->PD_i = (VirtualAddress & ((uint64_t)0x1FF << 30)) >> 30;
this->PT_i = (VirtualAddress & ((uint64_t)0x1FF << 21)) >> 21;
this->P_i = (VirtualAddress & ((uint64_t)0x1FF << 12)) >> 12;
#elif defined(__i386__)
PD_i = (VirtualAddress & ((uint64_t)0x3FF << 22)) >> 22;
PT_i = (VirtualAddress & ((uint64_t)0x3FF << 12)) >> 12;
P_i = (VirtualAddress & ((uint64_t)0xFFF << 0)) >> 0;
this->PD_i = (VirtualAddress & ((uint64_t)0x3FF << 22)) >> 22;
this->PT_i = (VirtualAddress & ((uint64_t)0x3FF << 12)) >> 12;
this->P_i = (VirtualAddress & ((uint64_t)0xFFF)) >> 0;
#elif defined(__aarch64__)
PD_i = (VirtualAddress & ((uint64_t)0x1FF << 30)) >> 30;
PT_i = (VirtualAddress & ((uint64_t)0x1FF << 21)) >> 21;
P_i = (VirtualAddress & ((uint64_t)0x1FF << 12)) >> 12;
this->PD_i = (VirtualAddress & ((uint64_t)0x1FF << 30)) >> 30;
this->PT_i = (VirtualAddress & ((uint64_t)0x1FF << 21)) >> 21;
this->P_i = (VirtualAddress & ((uint64_t)0x1FF << 12)) >> 12;
#endif
}
};
@ -409,8 +422,8 @@ namespace Memory
void InitializeMemoryManagement(BootInfo *Info);
void *operator new(uint64_t Size);
void *operator new[](uint64_t Size);
void *operator new(size_t Size);
void *operator new[](size_t Size);
void operator delete(void *Pointer);
void operator delete[](void *Pointer);
void operator delete(void *Pointer, long unsigned int Size);

View File

@ -25,7 +25,7 @@ public:
VectorCapacity = Size;
VectorSize = Size;
#ifdef DEBUG_MEM_ALLOCATION
debug("VECTOR ALLOCATION: Vector( %ld )", Size);
debug("VECTOR ALLOCATION: Vector( %lld )", Size);
#endif
VectorBuffer = new T[Size];
}
@ -35,7 +35,7 @@ public:
VectorSize = Size;
VectorCapacity = Size;
#ifdef DEBUG_MEM_ALLOCATION
debug("VECTOR ALLOCATION: Vector( %ld %llx )", Size, Initial);
debug("VECTOR ALLOCATION: Vector( %lld %llx )", Size, Initial);
#endif
VectorBuffer = new T[Size];
for (uint64_t i = 0; i < Size; i++)
@ -47,7 +47,7 @@ public:
VectorSize = Vector.VectorSize;
VectorCapacity = Vector.VectorCapacity;
#ifdef DEBUG_MEM_ALLOCATION
debug("VECTOR ALLOCATION: Vector( <vector> )->Size: %ld", VectorSize);
debug("VECTOR ALLOCATION: Vector( <vector> )->Size: %lld", VectorSize);
#endif
VectorBuffer = new T[VectorSize];
for (uint64_t i = 0; i < VectorSize; i++)
@ -117,7 +117,7 @@ public:
VectorCapacity = 0;
}
#ifdef DEBUG_MEM_ALLOCATION
debug("VECTOR ALLOCATION: reverse( %ld )", Capacity);
debug("VECTOR ALLOCATION: reverse( %lld )", Capacity);
#endif
T *Newbuffer = new T[Capacity];
uint64_t _Size = Capacity < VectorSize ? Capacity : VectorSize;
@ -125,7 +125,7 @@ public:
Newbuffer[i] = VectorBuffer[i];
VectorCapacity = Capacity;
#ifdef DEBUG_MEM_ALLOCATION
debug("VECTOR ALLOCATION: reverse( <Capacity> )->Buffer:~%ld", VectorBuffer);
debug("VECTOR ALLOCATION: reverse( <Capacity> )->Buffer:~%lld", VectorBuffer);
#endif
delete[] VectorBuffer;
VectorBuffer = Newbuffer;
@ -145,7 +145,7 @@ public:
VectorSize = Vector.VectorSize;
VectorCapacity = Vector.VectorCapacity;
#ifdef DEBUG_MEM_ALLOCATION
debug("VECTOR ALLOCATION: operator=( <vector> )->Size:%ld", VectorSize);
debug("VECTOR ALLOCATION: operator=( <vector> )->Size:%lld", VectorSize);
#endif
VectorBuffer = new T[VectorSize];
for (uint64_t i = 0; i < VectorSize; i++)