Kernel: [T0] Physical memory allocation works.
parent
b08dfe120d
commit
c2b7afe6db
|
@ -20,6 +20,7 @@
|
|||
// happens that we run out of memory... We're probably badly screwed, anyway.
|
||||
|
||||
#include "Tier0/physmem.h"
|
||||
#include "Tier0/system.h"
|
||||
#include "Tier0/kstdio.h"
|
||||
#include "Tier0/panic.h"
|
||||
|
||||
|
@ -36,19 +37,26 @@ void physmem_init(u64 MemorySize)
|
|||
|
||||
u64 physmem_allocate_page(void)
|
||||
{
|
||||
PANIC("Not implemented!");
|
||||
return 0;
|
||||
u64 NextPageStart = g_TopFrame;
|
||||
|
||||
while (!system_memory_available(NextPageStart, PHYSMEM_PAGE_SIZE))
|
||||
{
|
||||
NextPageStart += PHYSMEM_PAGE_SIZE;
|
||||
|
||||
if (NextPageStart > g_MemorySize)
|
||||
PANIC("Out of memory!");
|
||||
}
|
||||
|
||||
return NextPageStart / PHYSMEM_PAGE_SIZE;
|
||||
}
|
||||
|
||||
|
||||
u64 physmem_page_to_physical(u64 Page)
|
||||
{
|
||||
PANIC("Not implemented!");
|
||||
return 0;
|
||||
return Page * PHYSMEM_PAGE_SIZE;
|
||||
}
|
||||
|
||||
u64 physmem_physical_to_page(u64 Physical)
|
||||
{
|
||||
PANIC("Not implemented!");
|
||||
return 0;
|
||||
return Physical / PHYSMEM_PAGE_SIZE;
|
||||
}
|
||||
|
|
|
@ -60,6 +60,8 @@ void system_parse_load_context(T_LOAD_CONTEXT *LoadContext)
|
|||
|
||||
Area->Base = Node->Base;
|
||||
Area->Size = Node->Length;
|
||||
|
||||
kprintf("[i] Unavailable memory: %x - %x\n", Node->Base, Node->Base + Node->Length);
|
||||
|
||||
if (Area->Base > HighestUnavailable)
|
||||
HighestUnavailable = Area->Base;
|
||||
|
@ -121,7 +123,7 @@ u8 system_memory_available(u64 Start, u64 Length)
|
|||
return 0;
|
||||
|
||||
// If the request spans accross an invalid area
|
||||
if (Area.Base >= Start && Start + Length < Area.Base + Area.Size)
|
||||
if (Area.Base >= Start && Start + Length > Area.Base + Area.Size)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
|
Loading…
Reference in New Issue