/* Based off of code from Leonard Kevin McGuire Jr (www.kmcg3413.net) ([email protected]) http://wiki.osdev.org/User:Pancakes/BitmapHeapImplementation */ void main_heap_init() { kheap_init(&main_heap); for (uint8_t i = 0; i < 15; i++) { void * block = memory_alloc_page(0); kheap_add_block(&main_heap, (uint32_t) block, PAGE_SIZE, 16); } }
void kernel_entry (multiboot_info* bootinfo) { clear_screen(); puts("Kernel loaded.\n"); gdt_install(); puts("GDT initialised.\n"); idt_install(); puts("IDT initialised.\n"); memman_init(bootinfo); kheap_init(); fat32_init(); // TODO: figure out how to do it safely //acpi_init(); apic_init(); ioapic_init(); // keyboard only for now register_handler(0x21, keyboard_handler); register_handler(0xD, gpf_handler); syscalls_init(); // maybe syscalls_init() like acpi_init, apic_init, etc... there should be common naming timer_init(0x20, 0x002fffff, 0xB, 1); // vector, counter, divider, periodic -- check manual before using // sets up kernel task and registers handler for timer scheduler_init(); // registers locking sys monitor_init(); keyboard_init(); // testing scheduler if (fork_kernel() == 0) { if (!exec("SHELL")) { // something horrible happend // exit() } exit(); } else { for(;;) { asm volatile("hlt"); } } asm ("sti"); // release monsters, it can be set earlier, but fails horribly if set before acpi_init for(;;); }
void pmem_init() { bmap_init(&first_bmap, first_storage, (sizeof(first_storage) * 8)); first_region.bmap = &first_bmap; first_region.start = 0; first_region.length = ((first_bmap.bits - (1 /* savety zone */)) * PMEM_PAGESIZE); first_region.next = NULL; pmem_region_head = &first_region; pmem_region_tail = pmem_region_head; spl_init(&pmem_lock); /* reserve the page at address zero, as most people don't * know how to handle it. rm_init() needs to spare this * page when reserving real mode memory! */ pmem_reserve(0, PMEM_PAGESIZE); /* from 4K to 0xa0000 (start of kernel memory) for * real mode */ pmem_reserve(PMEM_PAGESIZE, PMEM_PAGESIZE * 158); /* reserve the kernel's physical memory, so nobody * else tries to use it */ if(!pmem_reserve(0xA0000, (((size_t)&_core_lma_end) - 0xA0000))) { error("failed to protect physical lower and kernel memory\n"); } /* here we are sufficiently initialized, so virtual memory * can allocate physical memory for the initial mappings, * required to get the kernel heap working. this in turn * enables us, to allocate more memory to add additional * regions to the physical memory. */ kheap_init(); extp_iterate(EXTP_PMEM_REGION, pmem_iterate_extp); /* some debugging information */ pmem_region_t* current = pmem_region_head; while(current) { trace("pmem: %p - %p (%dKB)\n", current->start, current->start + current->length, current->length / 1024); current = current->next; } }