Initial page allocator
This commit is contained in:
parent
11c151b60e
commit
35dc79b899
@ -14,14 +14,14 @@
|
||||
|
||||
typedef struct FreePage
|
||||
{
|
||||
LIST_ENTRY(FreePage) entries;
|
||||
TAILQ_ENTRY(FreePage) entries;
|
||||
} FreePage;
|
||||
|
||||
LIST_HEAD(FreeListHead, FreePage) freeList;
|
||||
TAILQ_HEAD(FreeListHead, FreePage) freeList;
|
||||
|
||||
void PAlloc_Init()
|
||||
{
|
||||
LIST_INIT(&freeList);
|
||||
TAILQ_INIT(&freeList);
|
||||
}
|
||||
|
||||
void PAlloc_AddRegion(uintptr_t start, uintptr_t len)
|
||||
@ -39,15 +39,29 @@ void PAlloc_AddRegion(uintptr_t start, uintptr_t len)
|
||||
for (i = 0; i < len; i += PGSIZE)
|
||||
{
|
||||
pg = (void *)(start + i);
|
||||
LIST_INSERT_HEAD(&freeList, pg, entries);
|
||||
TAILQ_INSERT_TAIL(&freeList, pg, entries);
|
||||
}
|
||||
}
|
||||
|
||||
void *PAlloc_AllocPage()
|
||||
{
|
||||
FreePage *pg = TAILQ_FIRST(&freeList);
|
||||
|
||||
TAILQ_REMOVE(&freeList, pg, entries);
|
||||
|
||||
// Assert page aligned
|
||||
ASSERT((((uintptr_t)pg) & PGMASK) == 0);
|
||||
|
||||
return (void *)pg;
|
||||
}
|
||||
|
||||
void PAlloc_FreePage(void *region)
|
||||
{
|
||||
FreePage *pg = (FreePage *)region;
|
||||
|
||||
// Assert page aligned
|
||||
ASSERT((((uintptr_t)region) & PGMASK) == 0);
|
||||
|
||||
TAILQ_INSERT_HEAD(&freeList, pg, entries);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user