int main(multiboot_t * mbp) { cpu_state_t *cpu; // first is to save critical info from bootloader // and get symbol tables so we can print back traces mbootp = mbp; init_debug(mbp); // reset text-mode c80_clear(); printk_color(rc_black, rc_red, "\t\t\t\tRed Magic\n"); // init processors init_bootstrap_processor(); cpu = get_boot_processor(); ASSERT(cpu != NULL); // initialize descriptors init_global_descriptor_table(cpu); init_interrupt_descriptor_table(); init_io_apic(); // interrupt on local_irq_enable(); // memory management show_kernel_pos(); show_ARDS_from_multiboot(mbp); init_paging(); init_kheap(); // initialize devices and rootfs init_dev(); //init_root_fs(); // start all APs if (mpinfo.ismp) start_smp(); // start system clock if (!mpinfo.ismp) init_pit_timer(CLOCK_INT_HZ); else init_apic_timer(CLOCK_INT_HZ); // initialize kernel task and scheduling setup_init_task(); init_sched(); // All our initialisation calls will go in here. return 0xDEADBABA; }
int start_kernel(unsigned long magic, unsigned long addr) { multiboot_info_t *mbi; int i=0; /* Initialize GDT */ initialize_gdt(); screen_init_early(); screen_reset(0); printf("Welcome to StarxOS!\n"); /* Am I booted by a Multiboot-compliant boot loader? */ if (magic != MULTIBOOT_BOOTLOADER_MAGIC) { printf("Invalid magic number: %x\n", (unsigned) magic); return -1; } /* Set MBI to the address of the Multiboot information structure. */ mbi = (multiboot_info_t *) addr; /* Print out the flags. */ printf_bochs("Welcome to StarxOS!\n"); printf_bochs("flags = 0x%x\n", (unsigned) mbi->flags); /* Are mem_* valid? */ if ( mbi->flags != 0) printf_bochs ("mem_lower = %x Byte, mem_upper = %x Byte\n", (unsigned) mbi->mem_lower * 0x400, (unsigned) mbi->mem_upper * 0x400); printf_bochs("kernel code: %p\n", &code); printf_bochs("kernel data: %p\n", &data); printf_bochs("kernel bss : %p\n", &bss); printf_bochs("kernel end : %p\n", &end); /* Initialize IDT */ initialize_idt(); /* Initialize Timer */ init_timer(50); /* Enable Interrupt */ asm volatile("sti"); mem_lower = mbi->mem_lower * 0x400; mem_upper = mbi->mem_upper * 0x400; /* Setup memory, and init frame_bitmap */ setup_memory(mem_lower, mem_upper); /* Enable Paging */ init_paging(); /* Init heap */ init_kheap(); u32int *ptr = (u32int*)kmalloc(0x1000+2); *ptr = 0x1234; printf_bochs("ptr:%x *ptr:%x\n", ptr, *ptr); u32int *ptr2 = (u32int*)kmalloc(0x1000+2); *ptr2 = 0x4567; printf_bochs("ptr2:%x *ptr2:%x\n", ptr2, *ptr2); bochs_enter_debugger(); bochs_shutdown(); return 0xBAD; }
int kmain(UInt32 initial_stack, MultibootHeader* mboot, UInt32 mboot_magic) { initial_esp = initial_stack; CLI_Init(); Cls(); UInt32 initrd_end = *(UInt32*)(mboot->mods_addr+4); placement_address = (Pointer) initrd_end; // Set up our new stack here. //UInt32 stack = (UInt32) kmalloc_a(8192, TRUE); MultibootHeader* mboot_hdr = mboot; //kmalloc(sizeof(MultibootHeader)); //memcpy(mboot_hdr, mboot, sizeof(MultibootHeader)); kprintf("Starting init...\n"); //new_start(stack, mboot_hdr); GDT_Init(); IDT_Init(); ISR_Init(); asm volatile("sti"); kprintf("Basics\t\t\t[OK]\n"); PIT_Init(PIT_MSTIME); kprintf("PIT\t\t\t[OK]\n"); init_kheap(); InitPaging((mboot_hdr->mem_lower+mboot_hdr->mem_upper)&~3); InitKernelHeap(); kprintf("Heap\t\t\t[OK]\n"); VFS_Init(); DevFS_Init(); kprintf("VFS\t\t\t[OK]\n"); DriversInit(); kprintf("Drivers\t\t\t[OK]\n"); Screen_Init(); FloppyInit(); checkAllBuses(); DumpPCIDeviceData(); kprintf("PCI\t\t\t[OK]\n"); /*kprintf("Keyboard Init... "); KB_Init(0); kprintf("[ok]\n");*/ FAT12_Init(FAT12_GetContext(FloppyGetDevice()), "/", "sys"); InitTasking(); KernelSymbolsLoad(); //Cls(); kprintf("kOS v0.6.13\n"); VFS_Node* rd = GetNodeFromFile(GetFileFromPath("/sys")); kprintf("rd = %x\n", rd); ArrayList* list = ListFiles(rd); ALIterator* itr = ALGetItr(list); while(ALItrHasNext(itr)) { VFS_Node* node = ALItrNext(itr); kprintf("file: %s\n", node->name); } ALFreeItr(itr); ALFreeList(list); //kprintf("kprintf symbol = %x\n", getKernelSymbol("kprintf")); File* initScript = GetFileFromPath("/sys/init.script"); FileSeek(0, initScript); // Due to these being global objects, we have to do such ugly things as this. #ifdef INIT_DEBUG kprintf("initScript=%x\n", initScript); #endif char* lineBuf = kalloc(256); int doBreak = 0; while(!doBreak) { if(fgetline(initScript, lineBuf, 256, '\n')==-1) { if(strlen(lineBuf) > 0) { doBreak = 1; } else { break; // We've processed everything that needs to be processed. } } // Now parse it. char* tok = strtok(lineBuf, " "); kprintf("%s, %x\n", tok,tok); if(!strcmp(tok, "load_driver")) { #ifdef INIT_DEBUG kprintf("load_driver "); #endif tok = strtok(NULL, " "); // Load the driver specified. File* drv = GetFileFromPath(tok); if(drv != NULL) { int drvLength = FileSeek(SEEK_EOF, drv); FileSeek(0, drv); void* drvBuf = kalloc(drvLength); #ifdef INIT_DEBUG kprintf("%s\n", GetNodeFromFile(drv)->name); #endif ReadFile(drvBuf, drvLength, drv); ELF* elf = LoadKernelDriver(drvBuf); #ifdef INIT_DEBUG kprintf("elf->start=%x\n", elf->start); #endif if(elf->error == 0) { void (*driverInit)() = (void (*)()) elf->start; driverInit(); } kfree(drvBuf); drvBuf = NULL; CloseFile(drv); } } } CloseFile(initScript); kfree(lineBuf); kprintf("Kernel init done...\n"); File* elf = GetFileFromPath("/sys/helloworld"); FileSeek(SEEK_EOF, elf); int length = FileTell(elf); FileSeek(0, elf); UInt8* elfBuf = kalloc(length); ReadFile(elfBuf, length, elf); ELF* elfExe = Parse_ELF(elfBuf); CreateTaskFromELF(elfExe); // Kernel main logic loop while(1) { asm volatile("hlt"); } return 0; }