1
0

Properly detect memory using atags and add it to the memory-management subsystem

This commit is contained in:
2012-09-25 22:44:19 -04:00
parent d6e3899fc1
commit afba079256
8 changed files with 171 additions and 24 deletions

View File

@ -32,12 +32,13 @@ void mm_add_free_region(void *start, void *end) {
void *page;
//make sure both start and end address are aligned to the size of a page
if ((unsigned int)start & MM_PAGE_SIZE || (unsigned int)(end+1) & MM_PAGE_SIZE) {
print("Error: Supplied memory area(%x,%x) is not aligned to the page size (%d)\n", (unsigned int)start, (unsigned int)end, MM_PAGE_SIZE);
return;
}
if ((char *)end - (char *)start < MM_PAGE_SIZE<<1) {
print("Error: Supplied memory area(%x,%x) is not aligned to the page size (%d)\n", (unsigned int)start, (unsigned int)end, MM_PAGE_SIZE);
if ((unsigned int)start % MM_PAGE_SIZE != 0)
start = (char*)start + (MM_PAGE_SIZE - ((unsigned int)start % MM_PAGE_SIZE));
if (((unsigned int)end + 1) % MM_PAGE_SIZE != 0)
end = (char*)end - ((unsigned int)end + 1) % MM_PAGE_SIZE;
if ((char *)end + 1 - (char *)start < MM_PAGE_SIZE<<1) {
print("Error: Supplied memory area(%x,%x) is smaller than the page size (%d)\n", (unsigned int)start, (unsigned int)end, MM_PAGE_SIZE);
return;
}
@ -46,7 +47,7 @@ void mm_add_free_region(void *start, void *end) {
//TODO we're potentially losing memory here because we're calculating
//the number of page structs we need even for those pages that will contain only page structs
num_pages = ((char *)end - (char *)start) / MM_PAGE_SIZE;
num_pages = ((char *)end + 1 - (char *)start) / MM_PAGE_SIZE;
usable_pages = num_pages - num_pages * sizeof(struct page) / MM_PAGE_SIZE;
if (num_pages * sizeof(struct page) % MM_PAGE_SIZE)
usable_pages--;