Poke paging. Still a little strange. Removed excess debugging.

This commit is contained in:
Curle 2020-09-25 16:47:10 +01:00
parent 15165b1562
commit 0ff9705fc8
Signed by: TheCurle
GPG Key ID: 5942F13718443F79
2 changed files with 17 additions and 6 deletions

View File

@ -118,6 +118,8 @@ void InitPaging() {
Allocator = PhysAllocateZeroMem(Size); Allocator = PhysAllocateZeroMem(Size);
Allocator = CreateAllocatorWithPool(Allocator, Size); Allocator = CreateAllocatorWithPool(Allocator, Size);
SerialPrintf("Everything preallocated. Setting up paging.\n");
KernelAddressSpace = (address_space_t) { KernelAddressSpace = (address_space_t) {
.Lock = {0}, .Lock = {0},
.PML4 = PhysAllocateZeroMem(PAGE_SIZE) .PML4 = PhysAllocateZeroMem(PAGE_SIZE)
@ -125,6 +127,7 @@ void InitPaging() {
size_t* Pagetable = KernelAddressSpace.PML4; size_t* Pagetable = KernelAddressSpace.PML4;
SerialPrintf("About to identity map the higher half.\n");
// Identity map the higher half // Identity map the higher half
for(int i = 256; i < 512; i++) { for(int i = 256; i < 512; i++) {
Pagetable[i] = (size_t)PhysAllocateZeroMem(PAGE_SIZE); Pagetable[i] = (size_t)PhysAllocateZeroMem(PAGE_SIZE);
@ -132,12 +135,16 @@ void InitPaging() {
Pagetable[i] |= (PAGE_PRESENT | PAGE_RW); Pagetable[i] |= (PAGE_PRESENT | PAGE_RW);
} }
SerialPrintf("Identity mapping complete.\n");
MMapEnt* TopEntry = (MMapEnt*)(((&bootldr) + bootldr.size) - sizeof(MMapEnt)); MMapEnt* TopEntry = (MMapEnt*)(((&bootldr) + bootldr.size) - sizeof(MMapEnt));
size_t LargestAddress = TopEntry->ptr + TopEntry->size; size_t LargestAddress = TopEntry->ptr + TopEntry->size;
SerialPrintf("About to map lower memory into the Direct Region.\n");
for(size_t Address = 0; Address < AlignUpwards(LargestAddress, PAGE_SIZE); Address += PAGE_SIZE) { for(size_t Address = 0; Address < AlignUpwards(LargestAddress, PAGE_SIZE); Address += PAGE_SIZE) {
MapVirtualMemory(&KernelAddressSpace, (size_t*)(((char*)Address) + DIRECT_REGION), Address, MAP_WRITE); MapVirtualMemory(&KernelAddressSpace, (size_t*)(((char*)Address) + DIRECT_REGION), Address, MAP_WRITE);
} }
SerialPrintf("Lower half mapping complete.\n");
SerialPrintf("Mapping kernel into new memory map.\r\n"); SerialPrintf("Mapping kernel into new memory map.\r\n");

View File

@ -138,20 +138,20 @@ static directptr_t BuddyAllocate(buddy_t* Buddy, size_t Size) {
SerialPrintf("Searching for a valid order to allocate into. Condition: {\r\n\tOrder: %d,\r\n\tSize: 0x%x\r\n}\r\n\n", InitialOrder, WantedSize); SerialPrintf("Searching for a valid order to allocate into. Condition: {\r\n\tOrder: %d,\r\n\tSize: 0x%x\r\n}\r\n\n", InitialOrder, WantedSize);
for(int Order = InitialOrder; Order < Buddy->MaxOrder; Order++) { for(int Order = InitialOrder; Order < Buddy->MaxOrder; Order++) {
SerialPrintf("\tCurrent Order: %d, Buddy entry: %x\r\n", Order, Buddy->List[Order - MIN_ORDER]); //SerialPrintf("\tCurrent Order: %d, Buddy entry: %x\r\n", Order, Buddy->List[Order - MIN_ORDER]);
if(Buddy->List[Order - MIN_ORDER] != 0) { if(Buddy->List[Order - MIN_ORDER] != 0) {
SerialPrintf("\t\tFound a valid Order!\r\n"); SerialPrintf("\tFound a valid Order!\r\n");
directptr_t Address = Buddy->List[Order - MIN_ORDER]; directptr_t Address = Buddy->List[Order - MIN_ORDER];
Buddy->List[Order - MIN_ORDER] = PEEK(directptr_t, Address); Buddy->List[Order - MIN_ORDER] = PEEK(directptr_t, Address);
TicketUnlock(&Buddy->Lock); TicketUnlock(&Buddy->Lock);
size_t FoundSize = 1ull << Order; size_t FoundSize = 1ull << Order;
SerialPrintf("\t\tAdding area - Address 0x%p, Size 0x%x\r\n\n", Address, FoundSize); SerialPrintf("\tAdding area - Address 0x%p, Size 0x%x\r\n\n", Address, FoundSize);
AddRangeToBuddy(Buddy, (void*)((size_t)Address + WantedSize), FoundSize - WantedSize); AddRangeToBuddy(Buddy, (void*)((size_t)Address + WantedSize), FoundSize - WantedSize);
SerialPrintf("\t\tArea added!\r\n\n"); SerialPrintf("\tArea added!\r\n\n");
return Address; return Address;
} }
} }
@ -272,11 +272,15 @@ directptr_t PhysAllocateLowMem(size_t Size) {
directptr_t PhysAllocateMem(size_t Size) { directptr_t PhysAllocateMem(size_t Size) {
directptr_t Pointer = NULL; directptr_t Pointer = NULL;
if(HighBuddy.Base == 0) if(HighBuddy.Base == 0) {
SerialPrintf("Attempting allocation into high memory.\n");
Pointer = BuddyAllocate(&HighBuddy, Size); Pointer = BuddyAllocate(&HighBuddy, Size);
}
if(Pointer == NULL) if(Pointer == NULL) {
SerialPrintf("Attempting allocation into low memory.\n");
Pointer = BuddyAllocate(&LowBuddy, Size); Pointer = BuddyAllocate(&LowBuddy, Size);
}
ASSERT(Pointer != NULL, "PhysAllocateMem: Unable to allocate memory!"); ASSERT(Pointer != NULL, "PhysAllocateMem: Unable to allocate memory!");