still reworking physical page allocator
git-svn-id: svn://anubis/hos/trunk@95 5b3e749e-e535-0410-8002-a9bb6afbdfca
This commit is contained in:
parent
96ba9fabb1
commit
08491bace9
@ -122,11 +122,12 @@ void mm_bootstrap()
|
||||
|
||||
for (int i = 0; i <= last_page_alloc_page; i++)
|
||||
{
|
||||
mm_early_map(mm_heap_base, page_alloc_page_numbers[i], 0, 1);
|
||||
/* move the heap back to after the page allocation pages */
|
||||
mm_heap_base += PAGE_SIZE;
|
||||
mm_early_map(&page_alloc_pages[i], page_alloc_page_numbers[i], 0, 1);
|
||||
}
|
||||
|
||||
/* move the heap back to after the page allocation pages */
|
||||
mm_heap_base = &page_alloc_pages[last_page_alloc_page + 1];
|
||||
|
||||
if (mm_num_free_pages < 10)
|
||||
{
|
||||
k_early_panic("Not enough free pages of RAM!");
|
||||
@ -153,7 +154,7 @@ void mm_bootstrap()
|
||||
/* map page_base to page_base - KERNEL_OFFSET */
|
||||
mm_early_map(page_base, page_base - KERNEL_OFFSET, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
/* map console memory */
|
||||
mm_early_map(CONSOLE_MEMORY, CONSOLE_MEMORY, 0, 1);
|
||||
|
||||
@ -195,23 +196,23 @@ void mm_bootstrap()
|
||||
*************************************************************************/
|
||||
static void record_phys_page(u32_t base_address)
|
||||
{
|
||||
static mm_page_alloc_page_t * current_page_alloc_page = NULL;
|
||||
if (page_alloc_page_index < 0
|
||||
|| page_alloc_page_index >= NUM_PAGETABLE_ENTRIES)
|
||||
if (page_alloc_page_index < 0)
|
||||
{
|
||||
/* allocate a new page alloc page */
|
||||
mm_page_alloc_page_t * old_page_alloc_page = current_page_alloc_page;
|
||||
current_page_alloc_page = (mm_page_alloc_page_t *)
|
||||
(base_address + KERNEL_OFFSET);
|
||||
current_page_alloc_page->next = old_page_alloc_page;
|
||||
page_alloc_page_index =
|
||||
sizeof(current_page_alloc_page->pages)
|
||||
/ sizeof(current_page_alloc_page->pages[0]) - 1;
|
||||
page_alloc_page_numbers[last_page_alloc_page++] = base_address;
|
||||
last_page_alloc_page++;
|
||||
page_alloc_pages_index++;
|
||||
page_alloc_page_numbers[last_page_alloc_page] = base_address;
|
||||
}
|
||||
else
|
||||
{
|
||||
current_page_alloc_page->pages[page_alloc_page_index--] = base_address;
|
||||
page_alloc_page_t * current_page_alloc_page = (page_alloc_page_t *)
|
||||
(page_alloc_page_numbers[page_alloc_pages_index] + KERNEL_OFFSET);
|
||||
page_alloc_page_index++;
|
||||
(*current_page_alloc_page)[page_alloc_page_index] = base_address;
|
||||
if (page_alloc_page_index == NUM_PAGETABLE_ENTRIES - 1)
|
||||
{
|
||||
page_alloc_page_index = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,23 +295,52 @@ int mm_map(u32_t virtual_address, u32_t physical_address,
|
||||
* Returns the physical base address of a page in RAM *
|
||||
* or 0 if no pages were available *
|
||||
*************************************************************************/
|
||||
u32_t mm_page_alloc()
|
||||
u32_t mm_early_page_alloc()
|
||||
{
|
||||
u32_t page_address = 0;
|
||||
if (current_page_alloc_page != NULL)
|
||||
if (page_alloc_pages_index >= 0)
|
||||
{
|
||||
if (page_alloc_page_index == sizeof(current_page_alloc_page->pages)
|
||||
/ sizeof(current_page_alloc_page->pages[0]) - 1)
|
||||
if (page_alloc_page_index >= 0)
|
||||
{
|
||||
page_address = ((u32_t) current_page_alloc_page) - KERNEL_OFFSET;
|
||||
current_page_alloc_page = current_page_alloc_page->next;
|
||||
page_alloc_page_index = 0;
|
||||
page_alloc_page_t * current_pap = (page_alloc_page_t *)
|
||||
(page_alloc_page_numbers[page_alloc_pages_index]
|
||||
+ KERNEL_OFFSET);
|
||||
page_address = (*current_pap)[page_alloc_page_index];
|
||||
page_alloc_page_index--;
|
||||
}
|
||||
else
|
||||
{
|
||||
page_alloc_page_index++;
|
||||
/* return the page allocation page itself */
|
||||
page_address = page_alloc_page_numbers[page_alloc_pages_index];
|
||||
page_alloc_pages_index--;
|
||||
page_alloc_page_index = NUM_PAGETABLE_ENTRIES - 1;
|
||||
}
|
||||
mm_num_free_pages--;
|
||||
}
|
||||
return page_address;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Returns the physical base address of a page in RAM *
|
||||
* or 0 if no pages were available *
|
||||
*************************************************************************/
|
||||
u32_t mm_page_alloc()
|
||||
{
|
||||
u32_t page_address = 0;
|
||||
if (page_alloc_pages_index >= 0)
|
||||
{
|
||||
if (page_alloc_page_index >= 0)
|
||||
{
|
||||
page_address =
|
||||
current_page_alloc_page->pages[page_alloc_page_index];
|
||||
page_alloc_pages[page_alloc_pages_index][page_alloc_page_index];
|
||||
page_alloc_page_index--;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* return the page allocation page itself */
|
||||
page_address = page_alloc_page_numbers[page_alloc_pages_index];
|
||||
page_alloc_pages_index--;
|
||||
page_alloc_page_index = NUM_PAGETABLE_ENTRIES - 1;
|
||||
}
|
||||
mm_num_free_pages--;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user