some rewrite of mmu_init concerning the initialization of the memory bitmap
This commit is contained in:
parent
0d7aa3d0ca
commit
df99b4dfff
1 changed files with 35 additions and 36 deletions
71
mm/memory.c
71
mm/memory.c
|
@ -170,7 +170,6 @@ int put_pages(size_t phyaddr, size_t npages)
|
|||
|
||||
int mmu_init(void)
|
||||
{
|
||||
size_t kernel_size;
|
||||
unsigned int i;
|
||||
size_t addr;
|
||||
int ret = 0;
|
||||
|
@ -211,6 +210,20 @@ int mmu_init(void)
|
|||
kputs("Unable to initialize the memory management subsystem\n");
|
||||
while (1) HALT;
|
||||
}
|
||||
|
||||
// mark mb_info as used
|
||||
page_set_mark((size_t) mb_info >> PAGE_SHIFT);
|
||||
atomic_int32_inc(&total_allocated_pages);
|
||||
atomic_int32_dec(&total_available_pages);
|
||||
|
||||
// mark modules list as used
|
||||
if (mb_info->flags & MULTIBOOT_INFO_MODS) {
|
||||
for(addr=mb_info->mods_addr; addr<mb_info->mods_addr+mb_info->mods_count*sizeof(multiboot_module_t); addr+=PAGE_SIZE) {
|
||||
page_set_mark(addr >> PAGE_SHIFT);
|
||||
atomic_int32_inc(&total_allocated_pages);
|
||||
atomic_int32_dec(&total_available_pages);
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif defined(CONFIG_ROCKCREEK)
|
||||
// of course, the first slots belong to the private memory
|
||||
|
@ -219,7 +232,7 @@ int mmu_init(void)
|
|||
if (addr > addr + PAGE_SIZE)
|
||||
break;
|
||||
atomic_int32_inc(&total_pages);
|
||||
atomic_int32_inc(&total_available_pages);
|
||||
atomic_int32_inc(&total_available_pages);
|
||||
}
|
||||
|
||||
// Note: The last slot belongs always to the private memory.
|
||||
|
@ -240,28 +253,20 @@ int mmu_init(void)
|
|||
#error Currently, MetalSVM supports only the Multiboot specification or the RockCreek processor!
|
||||
#endif
|
||||
|
||||
kernel_size = (size_t) &kernel_end - (size_t) &kernel_start;
|
||||
if (kernel_size & (PAGE_SIZE-1))
|
||||
kernel_size += PAGE_SIZE - (kernel_size & (PAGE_SIZE-1));
|
||||
atomic_int32_add(&total_allocated_pages, kernel_size >> PAGE_SHIFT);
|
||||
atomic_int32_sub(&total_available_pages, kernel_size >> PAGE_SHIFT);
|
||||
|
||||
// set kernel space as used
|
||||
for(i=(size_t) &kernel_start >> PAGE_SHIFT; i < (size_t) &kernel_end >> PAGE_SHIFT; i++)
|
||||
page_set_mark(i);
|
||||
if ((size_t) &kernel_end & (PAGE_SIZE-1))
|
||||
page_set_mark(i);
|
||||
|
||||
alloc_start = (size_t) &kernel_end >> PAGE_SHIFT;
|
||||
if ((size_t) &kernel_end & (PAGE_SIZE-1))
|
||||
alloc_start++;
|
||||
// mark kernel as used
|
||||
for(addr=(size_t) &kernel_start; addr<(size_t) &kernel_end; addr+=PAGE_SIZE) {
|
||||
page_set_mark(addr >> PAGE_SHIFT);
|
||||
atomic_int32_inc(&total_allocated_pages);
|
||||
atomic_int32_dec(&total_available_pages);
|
||||
}
|
||||
|
||||
#if MAX_CORES > 1
|
||||
// reserve physical page for SMP boot code
|
||||
page_set_mark(SMP_SETUP_ADDR >> PAGE_SHIFT);
|
||||
atomic_int32_add(&total_allocated_pages, 1);
|
||||
atomic_int32_sub(&total_available_pages, 1);
|
||||
atomic_int32_inc(&total_allocated_pages);
|
||||
atomic_int32_dec(&total_available_pages);
|
||||
#endif
|
||||
|
||||
// enable paging and map SMP, VGA, Multiboot modules etc.
|
||||
ret = paging_init();
|
||||
if (ret) {
|
||||
kprintf("Failed to initialize paging: %d\n", ret);
|
||||
|
@ -273,25 +278,19 @@ int mmu_init(void)
|
|||
* Modules like the init ram disk are already loaded.
|
||||
* Therefore, we set these pages as used.
|
||||
*/
|
||||
if (mb_info && (mb_info->flags & MULTIBOOT_INFO_MODS)) {
|
||||
multiboot_module_t* mmodule = (multiboot_module_t*) ((size_t) mb_info->mods_addr);
|
||||
if (mb_info) {
|
||||
|
||||
// mark the mb_info as used.
|
||||
page_set_mark((size_t)mb_info >> PAGE_SHIFT);
|
||||
atomic_int32_inc(&total_allocated_pages);
|
||||
atomic_int32_dec(&total_available_pages);
|
||||
if (mb_info->flags & MULTIBOOT_INFO_MODS) {
|
||||
multiboot_module_t* mmodule = (multiboot_module_t*) ((size_t) mb_info->mods_addr);
|
||||
|
||||
for(addr = mb_info->mods_addr; addr < mb_info->mods_addr + mb_info->mods_count * sizeof(multiboot_module_t); addr += PAGE_SIZE) {
|
||||
page_set_mark(addr >> PAGE_SHIFT);
|
||||
atomic_int32_inc(&total_allocated_pages);
|
||||
atomic_int32_dec(&total_available_pages);
|
||||
}
|
||||
|
||||
for(i=0; i<mb_info->mods_count; i++, mmodule++) {
|
||||
for(addr=mmodule->mod_start; addr<mmodule->mod_end; addr+=PAGE_SIZE) {
|
||||
page_set_mark(addr >> PAGE_SHIFT);
|
||||
atomic_int32_inc(&total_allocated_pages);
|
||||
atomic_int32_dec(&total_available_pages);
|
||||
for(i=0; i<mb_info->mods_count; i++) {
|
||||
|
||||
for(addr=mmodule[i].mod_start; addr<mmodule[i].mod_end; addr+=PAGE_SIZE) {
|
||||
page_set_mark(addr >> PAGE_SHIFT);
|
||||
atomic_int32_inc(&total_allocated_pages);
|
||||
atomic_int32_dec(&total_available_pages);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue