diff --git a/arch/x86/kernel/entry.asm b/arch/x86/kernel/entry.asm index 459d2e0..42a443f 100644 --- a/arch/x86/kernel/entry.asm +++ b/arch/x86/kernel/entry.asm @@ -83,9 +83,9 @@ cpu_init: mov cr3, eax ; Set CR4 - mov cr4, eax - and eax, ~(1 << 9) ; disable SSE - or eax, (1 << 4) ; enable PSE + mov eax, cr4 + and eax, 0xfffbf9ff ; disable SSE + or eax, (1 << 4) ; enable PSE mov cr4, eax ; Set CR0 diff --git a/arch/x86/mm/page.c b/arch/x86/mm/page.c index a19e7c8..290c091 100644 --- a/arch/x86/mm/page.c +++ b/arch/x86/mm/page.c @@ -282,7 +282,7 @@ int page_init() for(i=0; imods_count; i++) { addr = mmodule[i].mod_start; npages = PAGE_FLOOR(mmodule[i].mod_end - mmodule[i].mod_start) >> PAGE_BITS; - page_map(addr, addr, npages, PG_USER | PG_GLOBAL); + page_map(addr, addr, npages, PG_GLOBAL); } } } diff --git a/kernel/main.c b/kernel/main.c index 6415928..d69205c 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -143,7 +143,8 @@ int main(void) kprintf("Kernel starts at %p and ends at %p\n", &kernel_start, &kernel_end); kprintf("Processor frequency: %u MHz\n", get_cpu_frequency()); kprintf("Total memory: %lu KiB\n", atomic_int32_read(&total_pages) * PAGE_SIZE / 1024); - kprintf("Total memory available: %lu KiB\n", atomic_int32_read(&total_available_pages) * PAGE_SIZE / 1024); + kprintf("Current allocated memory: %lu KiB\n", atomic_int32_read(&total_allocated_pages) * PAGE_SIZE / 1024); + kprintf("Curren available memory: %lu KiB\n", atomic_int32_read(&total_available_pages) * PAGE_SIZE / 1024); create_kernel_task(&id1, foo, "foo1", NORMAL_PRIO); diff --git a/mm/memory.c b/mm/memory.c index c0d3773..04db566 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -169,22 +169,27 @@ int memory_init(void) // parse multiboot information for available memory if (mb_info) { if (mb_info->flags & MULTIBOOT_INFO_MEM_MAP) { + size_t end_addr; multiboot_memory_map_t* mmap = (multiboot_memory_map_t*) ((size_t) mb_info->mmap_addr); multiboot_memory_map_t* mmap_end = (void*) ((size_t) mb_info->mmap_addr + mb_info->mmap_length); // mark available memory as free while (mmap < mmap_end) { if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) { - for (addr=mmap->addr; addr < mmap->addr + mmap->len; addr += PAGE_SIZE) { + /* set the available memory as "unused" */ + addr = mmap->addr; + end_addr = addr + mmap->len; + + while ((addr < end_addr) && (addr < (BITMAP_SIZE*8*PAGE_SIZE))) { page_clear_mark(addr >> PAGE_BITS); + addr += PAGE_SIZE; atomic_int32_inc(&total_pages); atomic_int32_inc(&total_available_pages); } } mmap++; } - } - else if (mb_info->flags & MULTIBOOT_INFO_MEM) { + } else if (mb_info->flags & MULTIBOOT_INFO_MEM) { size_t page; size_t pages_lower = mb_info->mem_lower >> 2; /* KiB to page number */ size_t pages_upper = mb_info->mem_upper >> 2; @@ -192,6 +197,9 @@ int memory_init(void) for (page=0; page BITMAP_SIZE*8-256) + pages_upper = BITMAP_SIZE*8-256; + for (page=0; page