Rearrange memory bootstrapping code.

Move EFI-related code and initial memory manager bootstrap code
to memory_bootstrap.cpp, move memory page structs to their own
memory_page.h/cpp files.
This commit is contained in:
Justin C. Miller
2018-04-21 02:50:13 -07:00
parent 799ad8b264
commit da404f520d
6 changed files with 430 additions and 180 deletions

View File

@@ -0,0 +1,74 @@
#include "console.h"
#include "memory_pages.h"
page_block *
page_block::list_consolidate()
{
page_block *cur = this;
page_block *freed_head = nullptr, **freed = &freed_head;
while (cur) {
page_block *next = cur->next;
if (next && cur->flags == next->flags &&
cur->end() == next->physical_address)
{
cur->count += next->count;
cur->next = next->next;
next->next = 0;
*freed = next;
freed = &next->next;
continue;
}
cur = next;
}
return freed_head;
}
void
page_block::list_dump(const char *name)
{
console *cons = console::get();
cons->puts("Block list");
if (name) {
cons->puts(" ");
cons->puts(name);
}
cons->puts(":\n");
int count = 0;
for (page_block *cur = this; cur; cur = cur->next) {
cons->puts(" ");
cons->put_hex(cur->physical_address);
cons->puts(" ");
cons->put_hex((uint32_t)cur->flags);
if (cur->virtual_address) {
cons->puts(" ");
cons->put_hex(cur->virtual_address);
}
cons->puts(" [");
cons->put_dec(cur->count);
cons->puts("]\n");
count += 1;
}
cons->puts(" Total: ");
cons->put_dec(count);
cons->puts("\n");
}
void
page_table_indices::dump()
{
console *cons = console::get();
cons->puts("{");
for (int i = 0; i < 4; ++i) {
if (i) cons->puts(", ");
cons->put_dec(index[i]);
}
cons->puts("}");
}