int kern_entry() { init_debug(); console_clear(); printk_color(rc_black, rc_green, "Hello, OS kernel!\n"); //panic("test"); printk("kernel in memory start: 0x%08X\n", kern_start); printk("kernel in memory end: 0x%08X\n", kern_end); printk("kernel in memory used: %d KB\n\n", (kern_end - kern_start) / 1024); show_memory_map(); init_pmm(); printk_color(rc_black, rc_red, "\nThe Count of Physical Memory Page is: %u\n\n", phy_page_count); uint32_t allc_addr = NULL; printk_color(rc_black, rc_light_brown, "Test Physical Memory Alloc :\n"); allc_addr = pmm_alloc_page(); printk_color(rc_black, rc_light_brown, "Alloc Physical Addr: 0x%08X\n", allc_addr); allc_addr = pmm_alloc_page(); printk_color(rc_black, rc_light_brown, "Alloc Physical Addr: 0x%08X\n", allc_addr); allc_addr = pmm_alloc_page(); printk_color(rc_black, rc_light_brown, "Alloc Physical Addr: 0x%08X\n", allc_addr); allc_addr = pmm_alloc_page(); printk_color(rc_black, rc_light_brown, "Alloc Physical Addr: 0x%08X\n", allc_addr); return 0; }
int main(multiboot_t *mboot_ptr) { monitor_clear(); init_gdt (); init_idt (); init_timer (20); init_pmm (mboot_ptr->mem_upper); init_vmm (); // Find all the usable areas of memory and inform the physical memory manager about them. uint32_t i = mboot_ptr->mmap_addr; while (i < mboot_ptr->mmap_addr + mboot_ptr->mmap_length) { mmap_entry_t *me = (mmap_entry_t*) i; // Does this entry specify usable RAM? if (me->type == 1) { uint32_t j; // For every page in this entry, add to the free page stack. for (j = me->base_addr_low; j < me->base_addr_low+me->length_low; j += 0x1000) { pmm_free_page (j); } } // The multiboot specification is strange in this respect - the size member does not include "size" itself in its calculations, // so we must add sizeof (uint32_t). i += me->size + sizeof (uint32_t); } printk ("Paging initialised.\n"); printk ("Mapping page...\n"); uint32_t addr = 0x900000; map (addr, 0x500000, PAGE_PRESENT|PAGE_WRITE); printk ("Accessing page...\n"); volatile uint32_t *_addr = (volatile uint32_t*)addr; *_addr = 0x567; printk ("*addr: %x\n", *_addr); printk ("Unmapping page...\n"); unmap (addr); printk ("Trying to access again (should page fault)...\n"); *_addr = 0x678; printk ("*addr: %x\n", *_addr); asm volatile ("sti"); for (;;); return 0xdeadbeef; }
int kmain(multiboot_t *mboot_ptr) { monitor_clear(); printk("8888888888 d8b 888 .d88888b. .d8888b.\n"); printk("888 Y8P 888 d88P\" \"Y88b d88P Y88b\n"); printk("888 888 888 888 Y88b.\n"); printk("8888888 88888b.d88b. 888 888 888 888 \"Y888b.\n"); printk("888 888 \"888 \"88b 888 888 888 888 \"Y88b.\n"); printk("888 888 888 888 888 888 888 888 \"888\n"); printk("888 888 888 888 888 888 Y88b. .d88P Y88b d88P\n"); printk("8888888888 888 888 888 888 888 \"Y88888P\" \"Y8888P\"\n"); init_gdt (); init_idt (); init_keyboard(); setup_x87_fpu (); init_timer (20); init_pmm (mboot_ptr->mem_upper); init_vmm (); init_heap (); // Find all the usable areas of memory and inform the physical memory manager about them. uint32_t i = mboot_ptr->mmap_addr; while (i < mboot_ptr->mmap_addr + mboot_ptr->mmap_length) { mmap_entry_t *me = (mmap_entry_t*) i; // Does this entry specify usable RAM? if (me->type == 1) { uint32_t j; // For every page in this entry, add to the free page stack. for (j = me->base_addr_low; j < me->base_addr_low+me->length_low; j += 0x1000) { pmm_free_page (j); } } // The multiboot specification is strange in this respect - the size member does not include "size" itself in its calculations, // so we must add sizeof (uint32_t). i += me->size + sizeof (uint32_t); } kernel_elf = elf_from_multiboot (mboot_ptr); asm volatile ("sti"); panic ("Testing panic mechanism"); for (;;); return 0xdeadbeef; }
//写个struct mulitboot 省着老有警告 用的时候再改 //grub标准里有这个http://gnu.april.org/software/grub/manual/multiboot/multiboot.html //struct multiboot{}; int kmain(struct multiboot_info* mboot_ptr)//name is mentioned in boot.s { init_gdt(); init_idt(); monitor_write("qhello!!@#$%^&*()[]+= bcdef:wworld! 1234"); monitor_write("\n"); monitor_write_hex(256); monitor_write("finished"); monitor_write_dec(256); monitor_write("done ss"); monitor_write_hex(kss); monitor_write("done esp"); monitor_write_hex(kesp); monitor_put('\n'); //init_gdt(); //init_idt(); asm volatile("int $0x3"); asm volatile("int $0x4"); prtf("aa bb %x %u %s 11\t \nbb\n", 10, 10, "str"); //asm volatile("sti"); //init_timer(500); //monitor_write_hex((u32int)&end); prtf("1\tend is at addr :%x end itself:%x kend:%x &kend:%x\n", (u32int)&end, end, kend, &kend); /*旧的paging实现 init_paging(); prtf("paging enabled!\n"); u32int* ptr = (u32int*)0xa0000000; *ptr = 1; */ //新的paging //换了个管理物理内存的方法 这个没啥大区别 //分割物理内存管理 虚拟内存管理 //显式映射虚拟地址 //pmm里搞的都是物理地址 函数返回的也是物理地址 init_pmm ((u32int)&end, 1 << 25);//32MB init_vmm (); /*prtf("mboot_ptr : %x\n", mboot_ptr);//大概0x2d000 没到640k呢 prtf("mem_upper %x\n", mboot_ptr->mem_upper);*/ map(0xa0000000, 0x300000, PAGE_WRITE|PAGE_PRESENT); prtf("mapped!\n"); u32int* ptr = (u32int*)0xa0000000; *ptr = 1; prtf("assigned!\n"); unmap(0xa0000000); prtf("unmapped!\n"); *ptr = 2; prtf("end!\n"); return 0xdeadbeef; }
int main(multiboot_t *mboot_ptr) { monitor_clear(); init_gdt (); init_idt (); init_timer (20); init_pmm (mboot_ptr->mem_upper); init_vmm (); init_heap (); // Find all the usable areas of memory and inform the physical memory manager about them. uint32_t i = mboot_ptr->mmap_addr; while (i < mboot_ptr->mmap_addr + mboot_ptr->mmap_length) { mmap_entry_t *me = (mmap_entry_t*) i; // Does this entry specify usable RAM? if (me->type == 1) { uint32_t j; // For every page in this entry, add to the free page stack. for (j = me->base_addr_low; j < me->base_addr_low+me->length_low; j += 0x1000) { pmm_free_page (j); } } // The multiboot specification is strange in this respect - the size member does not include "size" itself in its calculations, // so we must add sizeof (uint32_t). i += me->size + sizeof (uint32_t); } kernel_elf = elf_from_multiboot (mboot_ptr); asm volatile ("sti"); void *a = kmalloc (8); void *b = kmalloc (8); void *c = kmalloc (8); kfree (a); kfree (b); void *d = kmalloc (24); printk ("a: %x, b: %x, c: %x, d: %x\n", a, b, c, d); panic ("Testing panic mechanism"); for (;;); return 0xdeadbeef; }
void kmain(uint32_t magic) { if ( magic != 0x2BADB002 ) { print("Something went not according to specs."); exit(); } kclear(); char printbuf[256]; snprintf(printbuf, 256, "kernel loaded at %p, ends at %p\n", kernel_start, kernel_end); print(printbuf); print("initializing GDT...\n"); init_gdt(); print("initializing IDT...\n"); init_idt(); print("initializing physical memory manager...\n"); init_pmm(); if (pmm_is_free((paddr_t)kernel_start) || pmm_is_free((paddr_t)kernel_end)) panic("kernel memory is not reserved"); if (pmm_is_free((paddr_t)0xb8000)) panic("video ram is not reserved"); print("initializing virtual memory manager...\n"); init_vmm(); print("initializing PICs...\n"); init_pics(0x20, 0x28); print("initializing keyboard...\n"); init_keyboard(); print("enabling keyboard interrupts...\n"); enable_irq(1); send_eoi(0); __asm__ __volatile__ ("sti"); print("initializing symbol table...\n"); init_stacktrace(); print("initializing timer...\n"); init_timer(10); enable_irq(0); print("initializing speaker...\n"); print("initializing ACPI...\n"); init_acpi(); print("reclaiming ACPI memory...\n"); acpi_reclaim_memory(); print("initializing shell...\n"); init_shell_builtins(); beep(100, 100); cprint("Hello OS\n", 2); update_cursor(); shell(); }
int main(void) { init_pmm(); if (init_mm()) return(1); vid_init(); vid_set_attr(FG_COLOR, RED); printf("\naMOS BOSS V.%s %s\n", STRING_VERSION, BUILD_ARCH); printf("Build %s %s by %s on %s\n\n", COMPILE_DATE, COMPILE_TIME, COMPILE_BY, COMPILE_HOST); vid_set_attr(FG_COLOR, WHITE); init_pit(); init_tss(); if (init_intr()) return(1); init_cpu(); if (init_sched()) return(1); init_fd(); printf("System memory: %d Mb\n\n", (int)pmm_get_size_mb()); printf("Free kernel mem: %d bytes\nUsed kernel mem: %d bytes\n", (int)get_free_mem(), (int)get_used_mem()); for (;;) {} return(0); }
void init(uint32_t memory_size) { init_pmm(memory_size); init_paging(); init_pic(); init_idt(); }