void idt_install() { idt_load(); isrs_install(); irq_install(); sti(); }
void kmain(multiboot_info_t* mbd, unsigned int magic){ // kernel entry point. //unsigned char* videoram = (unsigned char*) 0xb8000; //videoram[0] = 65; //videoram[1] = 0x07; //setMode(0x13); setMode(320, 200, 8); // HOLY SHIT THIS WORKS clrscr(); gdt_install(); idt_install(); isrs_install(); irq_install(); timer_install(); start_paging(mbd); keyboard_install(); init_genrand(get_timer_ticks()); __asm__ __volatile__ ("sti"); kprint("Hello, We have booted successfully!\n\tTip: type help for command info\n"); while(1){ if(todo != NULL){ void(*function)() = todo; function(todoCP); todo = NULL; } } }
void kmain(unsigned long magic, multiboot_info_t * mbi) { if (magic != MULTIBOOT_BOOTLOADER_MAGIC) { printk ("Invalid magic number: 0x%x\n", (unsigned) magic); return; } gdt_install(); idt_install(); init_video(); isrs_install(); irq_install(); timer_install(); sys_setup(mbi); test_inode(); __asm__ __volatile__ ("sti"); printk("EgGS:hello there!\n"); // int i = 10 / 0; for (;;); }
int irq_init(void) { idt_install(); isrs_install(); irq_install(); return 0; }
void kernel_main(struct mboot_info_struct *mbinfo) { // addr = (int*) kernel_main; // log("[LOAD] " DISTNAME " kernel is started. Disabling interrupts..."); log("[DISCLAIMER] " DISTNAME " is totally free. If you have bought it, please report us seller's contact information to prevent further project law violation."); asm("cli"); log("done."); log("[INFO] Setting up GDT..."); gdt_install(); log("done."); log("[INFO] Setting up IDT..."); idt_install(); log("done."); log("[INFO] Setting up ISRs..."); isrs_install(); log("done."); log("[INFO] Setting up IRQ handlers..."); irq_install(); log("done."); asm("sti"); log("[INFO] Setting up fonts..."); setupFonts(); log("done."); log("[INFO] Initializing PIC..."); //kprint("OS365 Kernel 1.0 is loaded.\nInitializing PIC...",0,0); init_pics(0x20,0x28); log("done."); //setupPaging(); //asm("int $8"); //kprint("\nAll pre-start processes are finished. Preparing to load shell...\n",0,8); log("[INFO] Setting VBE graphics mode..."); //sleep(18); //setGraphicsMode(); vbe_info_t* vbeInfo=(vbe_info_t*)(uint32_t)mbinfo->vbe_mode; framebuffer =(uint8_t*)(mbinfo->framebuffer_addr); fbpitch =mbinfo->framebuffer_pitch; fbbpp =mbinfo->framebuffer_bpp; //memset((void*)framebuffer,0x004DFF,1024*768*3); initKbd(); log("done."); //mouse_install(); log("[INFO] Setting up the timer..."); setupPIT(); log("done."); log("[INFO] Loading Z Window System..."); //abort(); while(true) { shellStart(); fRun=true; log("[WARNING] Error in program: Not returned to Z"); log("[INFO] Getting back to Z..."); } }
void idt_install() { printc("Installing ", BLACK, LIGHT_GREEN); printc("IDT\n", BLACK, LIGHT_RED); idtp.limit = (sizeof (struct idt_entry) * 256) - 1; idtp.base = (u32int)&idt; memset(&idt, 0, sizeof(struct idt_entry) * 256); isrs_install(); }
void x86_init() { gdt_install(); idt_install(); isrs_install(); apic_init(); /* apic */ irq_install(); console_init(); timer_install(); init_keyboard(); }
void main() { gdt_install(3) ; init_video(&sc) ; idt_install() ; isrs_install() ; irq_install() ; timer_install() ; keyboard_install() ; __asm__ __volatile__ ("sti"); int state = 0 ; screen sc ; //puts(&sc, "Hello world in new functions\n") ; print_int(&sc, state) ; /* Since there is no support for newlines in terminal_putchar yet, \n will produce some VGA specific character instead. This is normal. */ }
int kernel_main(uint32_t esp) { initial_esp = esp; gdt_install(); idt_install(); isrs_install(); irq_install(); asm volatile("sti"); timer_install(); keyboard_install(); ASSERT(mboot_ptr != 0); ASSERT(mboot_ptr->mods_count > 0); uint32_t initrd_location = *((uint32_t*)mboot_ptr->mods_addr); uint32_t initrd_end = *(uint32_t*)(mboot_ptr->mods_addr + 4); // move the start of our kernel heap to past the initrd placement_address = initrd_end; initialize_paging(); initialize_tasking(); fs_root = initialize_initrd(initrd_location); // Create a new process in a new address space which is a clone of this. int ret = fork(); printf("fork() returned %x, ", ret); printf(" getpid() returned %x\n", getpid()); printf("Loading initial ramdisk...\n"); asm volatile("cli"); traverse_initrd(); asm volatile("sti"); printf("That's all folks\n"); for(;;); return 0; }
void kernel_main(){ console_initialize(); gdt_install(); idt_install(); isrs_install(); irq_install(); timer_install(); keyboard_install(); __asm__ __volatile__ ("sti"); console_putString("Hello, kernel World!\n"); for (;;){ } }
void main(void) { gdt_install(); idt_install(); isrs_install(); irq_install(); timer_install(); keyboard_install(); mouse_install(); __asm__ __volatile__ ("sti"); clear_keyboard_buffers(); clear(BLACK,BLACK); bscreen(); for (;;); }
/* Installs the IDT */ void idt_install() { /* Sets the special IDT pointer up, just like in 'gdt.c' */ idtp.limit = (sizeof (struct idt_entry) * 256) - 1; idtp.base = (unsigned int)&idt; memset((unsigned char *)&idt,0,sizeof(struct idt_entry)*256); /* Add any new ISRs to the IDT here using idt_set_gate */ irq_remap(); isrs_install(); irq_install(); idt_load(); /* Points the processor's internal register to the new IDT */ print_k("%s\n",IDT_MESSAGE); }
void kernel_main() { terminal_initialize(); kprintf("Identifying CPU...", COLOR_WHITE); cpuid_t cpu_data = get_cpuid(); kprintf(cpu_data.make, COLOR_WHITE); kprintf("\n", COLOR_WHITE); kprintf("Type: ", COLOR_WHITE); kprintf(itoa(cpu_data.family), COLOR_WHITE); kprintf("\n", COLOR_WHITE); kprintf("Family: ", COLOR_WHITE); kprintf(cpu_data.family, COLOR_WHITE); kprintf("\n", COLOR_WHITE); kprintf("Model: ", COLOR_WHITE); kprintf(cpu_data.model, COLOR_WHITE); kprintf("\n", COLOR_WHITE); kprintf("Enabling A20 Line...\n", COLOR_WHITE); enable_a20(); kprintf("Initilizing VGA Driver....\n",COLOR_WHITE); kprintf("Installing Global Descriptor Table....\n",COLOR_WHITE); gdt_install(); kprintf("Installing Interrupt Descriptor Table....\n",COLOR_WHITE); idt_install(); kprintf("Enabling paging...\n", COLOR_WHITE); init_paging(); kprintf("Setting up ISRs...\n",COLOR_WHITE); isrs_install(); kprintf("Remapping the PIC and setting up IRQs...\n",COLOR_WHITE); install_irq(); kprintf("Initializing the Kernel Address Translation Table...\n", COLOR_WHITE); kATT_Init(); kprintf("Identifying ATA drives.....\n", COLOR_WHITE); ATA_Init(); kprintf(DRIVE_DATA, COLOR_WHITE); kprintf("Installing Timer ISR....\n",COLOR_WHITE); timer_install(); // kprintf("Checking PCI device vendors....\n",COLOR_WHITE); // init_PCI(); kprintf("Starting shell....\n",COLOR_WHITE); init_shell(); for (;;); }
void kmain ( void* mbd, unsigned int magic ) { if ( magic != 0x2BADB002 ) { /* there is something wrong */ } else { clearscreen(); printline ("akv's - code is running"); gdt_install (); idt_install (); isrs_install (); irq_install (); __asm__ __volatile__ ("sti"); timer_install (2); keyboard_install (); for(;;); } }
void kmain( void* mbd, unsigned int magic ) { /* Installations */ gdt_install(); idt_install(); isrs_install(); irq_install(); timer_install(); keyboard_install(); init_video(); __asm__ __volatile__ ("sti"); // Disable interrupts settextcolor(0x0F, 0x00); unsigned char string[] = "Welcome to Gulinux 0.01. For a list of commands, type help.\n"; putsa(string); for(;;); }
void kernel_main() { gdt_install(); idt_install(); isrs_install(); irq_install(); terminal_initialize(); memory_manager_init(); enable_interrupts(); timer_install(); keyboard_install(); shell_init(); terminal_writestring("Hello, kernel World!\n"); terminal_writestring("Here is some text in a new line\n"); terminal_writestring("Here is some more text\n"); terminal_writestring("Here is a new line\n"); terminal_writestring("Here is some text after terminal scroll\n"); char str[] = "A string"; char ch = 'c'; int integer = 45; printf("This is a test for printf.\nThis is a char %c and this a string %s\n", ch, str); printf("This is an int %d. This is the same in hex %x\n", integer, integer); for (size_t i = 0; i < 5; i++) { printf("This is line number %d\n", i); } puts("waiting for 2 sec\n"); timer_wait(2); puts("waiting complete\n"); char buffer[200]; gets(buffer); printf("%s\n", buffer); while(1) { shell(); } }
/* * multiboot i386 (pc) kernel entry point */ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) { initial_esp = esp; extern char * cmdline; uint32_t mboot_mods_count = 0; mboot_mod_t * mboot_mods = NULL; mboot_ptr = mboot; ENABLE_EARLY_BOOT_LOG(0); assert(mboot_mag == MULTIBOOT_EAX_MAGIC && "Didn't boot with multiboot, not sure how we got here."); debug_print(NOTICE, "Processing Multiboot information."); /* Initialize core modules */ gdt_install(); /* Global descriptor table */ idt_install(); /* IDT */ isrs_install(); /* Interrupt service requests */ irq_install(); /* Hardware interrupt requests */ if (mboot_ptr->flags & (1 << 3)) { debug_print(NOTICE, "There %s %d module%s starting at 0x%x.", mboot_ptr->mods_count == 1 ? "is" : "are", mboot_ptr->mods_count, mboot_ptr->mods_count == 1 ? "" : "s", mboot_ptr->mods_addr); debug_print(NOTICE, "Current kernel heap start point would be 0x%x.", &end); if (mboot_ptr->mods_count > 0) { uintptr_t last_mod = (uintptr_t)&end; uint32_t i; mboot_mods = (mboot_mod_t *)mboot_ptr->mods_addr; mboot_mods_count = mboot_ptr->mods_count; for (i = 0; i < mboot_ptr->mods_count; ++i ) { mboot_mod_t * mod = &mboot_mods[i]; uint32_t module_start = mod->mod_start; uint32_t module_end = mod->mod_end; if ((uintptr_t)mod + sizeof(mboot_mod_t) > last_mod) { /* Just in case some silly person put this *behind* the modules... */ last_mod = (uintptr_t)mod + sizeof(mboot_mod_t); } debug_print(NOTICE, "Module %d is at 0x%x:0x%x", i, module_start, module_end); if (last_mod < module_end) { last_mod = module_end; } } debug_print(NOTICE, "Moving kernel heap start to 0x%x", last_mod); kmalloc_startat(last_mod); } } paging_install(mboot_ptr->mem_upper + mboot_ptr->mem_lower); if (mboot_ptr->flags & (1 << 6)) { debug_print(NOTICE, "Parsing memory map."); mboot_memmap_t * mmap = (void *)mboot_ptr->mmap_addr; while ((uintptr_t)mmap < mboot_ptr->mmap_addr + mboot_ptr->mmap_length) { if (mmap->type == 2) { for (unsigned long long int i = 0; i < mmap->length; i += 0x1000) { if (mmap->base_addr + i > 0xFFFFFFFF) break; /* xxx */ debug_print(INFO, "Marking 0x%x", (uint32_t)(mmap->base_addr + i)); paging_mark_system((mmap->base_addr + i) & 0xFFFFF000); } } mmap = (mboot_memmap_t *) ((uintptr_t)mmap + mmap->size + sizeof(uintptr_t)); } } paging_finalize(); { char cmdline_[1024]; size_t len = strlen((char *)mboot_ptr->cmdline); memmove(cmdline_, (char *)mboot_ptr->cmdline, len + 1); /* Relocate the command line */ cmdline = (char *)kmalloc(len + 1); memcpy(cmdline, cmdline_, len + 1); } /* Memory management */ heap_install(); /* Kernel heap */ if (cmdline) { args_parse(cmdline); } vfs_install(); tasking_install(); /* Multi-tasking */ timer_install(); /* PIC driver */ fpu_install(); /* FPU/SSE magic */ syscalls_install(); /* Install the system calls */ shm_install(); /* Install shared memory */ modules_install(); /* Modules! */ DISABLE_EARLY_BOOT_LOG(); /* Load modules from bootloader */ debug_print(NOTICE, "%d modules to load", mboot_mods_count); for (unsigned int i = 0; i < mboot_ptr->mods_count; ++i ) { mboot_mod_t * mod = &mboot_mods[i]; uint32_t module_start = mod->mod_start; uint32_t module_end = mod->mod_end; size_t module_size = module_end - module_start; if (!module_quickcheck((void *)module_start)) { debug_print(NOTICE, "Loading ramdisk: 0x%x:0x%x", module_start, module_end); ramdisk_mount(module_start, module_size); } else { debug_print(NOTICE, "Loading a module: 0x%x:0x%x", module_start, module_end); module_data_t * mod_info = (module_data_t *)module_load_direct((void *)(module_start), module_size); if (mod_info) { debug_print(NOTICE, "Loaded: %s", mod_info->mod_info->name); } } } /* Map /dev to a device mapper */ map_vfs_directory("/dev"); if (args_present("root")) { vfs_mount_type("ext2", args_value("root"), "/"); } if (args_present("start")) { char * c = args_value("start"); if (!c) { debug_print(WARNING, "Expected an argument to kernel option `start`. Ignoring."); } else { debug_print(NOTICE, "Got start argument: %s", c); boot_arg = strdup(c); } } if (!fs_root) { debug_print(CRITICAL, "No root filesystem is mounted. Skipping init."); map_vfs_directory("/"); switch_task(0); } /* Prepare to run /bin/init */ char * argv[] = { "/bin/init", boot_arg, NULL }; int argc = 0; while (argv[argc]) { argc++; } system(argv[0], argc, argv); /* Run init */ return 0; }
k_main() // like main { k_clear_screen(); k_puts("Welcome to MoOS version 0.1 (" BUILDTAG ")\n"); k_puts("\n"); if (pci_is_available()) { k_puts(" Detected a PCI bus\n"); } else { k_puts(" No PCI bus detected\n"); } // Try to find PCI devices unsigned int i, j, k; for (i=0; i<256; i++) { for (j=0; j<32; j++) { for (k=0; k<8; k++) { unsigned int temp = pci_read_dword(i, j, k, 0); if ((temp & 0xffff) != 0xffff) { printk("PCI device on bus: %u, slot: %u, function: %u VendorId/DeviceId: %x\n", i, j, k, temp); } } } } // NE2000 code #define NS_DATAPORT 0x10 /* NatSemi-defined port window offset. */ #define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */ #define NS_RESET 0x1f /* Issue a read to reset, a write to clear. */ #define E8390_CMD 0x00 /* The command register (for all pages) */ #define E8390_STOP 0x01 /* Stop and reset the chip */ #define E8390_START 0x02 /* Start the chip, clear reset */ #define E8390_RREAD 0x08 /* Remote read */ #define E8390_NODMA 0x20 /* Remote DMA */ #define E8390_PAGE0 0x00 /* Select page chip registers */ #define E8390_PAGE1 0x40 /* using the two high-order bits */ #define E8390_PAGE2 0x80 #define E8390_PAGE3 0xC0 /* Page 3 is invalid on the real 8390. */ #define E8390_RXOFF 0x20 /* EN0_RXCR: Accept no packets */ #define E8390_TXOFF 0x02 /* EN0_TXCR: Transmitter off */ /* Page 0 register offsets. */ #define EN0_CLDALO 0x01 /* Low byte of current local dma addr RD */ #define EN0_STARTPG 0x01 /* Starting page of ring bfr WR */ #define EN0_CLDAHI 0x02 /* High byte of current local dma addr RD */ #define EN0_STOPPG 0x02 /* Ending page +1 of ring bfr WR */ #define EN0_BOUNDARY 0x03 /* Boundary page of ring bfr RD WR */ #define EN0_TSR 0x04 /* Transmit status reg RD */ #define EN0_TPSR 0x04 /* Transmit starting page WR */ #define EN0_NCR 0x05 /* Number of collision reg RD */ #define EN0_TCNTLO 0x05 /* Low byte of tx byte count WR */ #define EN0_FIFO 0x06 /* FIFO RD */ #define EN0_TCNTHI 0x06 /* High byte of tx byte count WR */ #define EN0_ISR 0x07 /* Interrupt status reg RD WR */ #define EN0_CRDALO 0x08 /* low byte of current remote dma address RD */ #define EN0_RSARLO 0x08 /* Remote start address reg 0 */ #define EN0_CRDAHI 0x09 /* high byte, current remote dma address RD */ #define EN0_RSARHI 0x09 /* Remote start address reg 1 */ #define EN0_RCNTLO 0x0a /* Remote byte count reg WR */ #define EN0_RCNTHI 0x0b /* Remote byte count reg WR */ #define EN0_RSR 0x0c /* rx status reg RD */ #define EN0_RXCR 0x0c /* RX configuration reg WR */ #define EN0_TXCR 0x0d /* TX configuration reg WR */ #define EN0_COUNTER0 0x0d /* Rcv alignment error counter RD */ #define EN0_DCFG 0x0e /* Data configuration reg WR */ #define EN0_COUNTER1 0x0e /* Rcv CRC error counter RD */ #define EN0_IMR 0x0f /* Interrupt mask reg WR */ #define EN0_COUNTER2 0x0f /* Rcv missed frame error counter RD */ unsigned char SA_prom[32]; struct {char value, offset; } program_seq[] = { {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/ {0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */ {0x00, EN0_RCNTLO}, /* Clear the count regs. */ {0x00, EN0_RCNTHI}, {0x00, EN0_IMR}, /* Mask completion irq. */ {0xFF, EN0_ISR}, {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */ {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */ {32, EN0_RCNTLO}, {0x00, EN0_RCNTHI}, {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */ {0x00, EN0_RSARHI}, {E8390_RREAD+E8390_START, E8390_CMD}, }; int wordlength = 2; /* Read the 16 bytes of station address prom, returning 1 for an eight-bit interface and 2 for a 16-bit interface. We must first initialize registers, similar to NS8390_init(eifdev, 0). We can't reliably read the SAPROM address without this. (I learned the hard way!). */ for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++) outportb(0x300 + program_seq[i].offset, program_seq[i].value); for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) { SA_prom[i] = inportb(0x300 + NE_DATAPORT); SA_prom[i+1] = inportb(0x300 + NE_DATAPORT); if (SA_prom[i] != SA_prom[i+1]) wordlength = 1; } printk("Station Address PROM 0:"); for(i = 0; i < sizeof(SA_prom)/2; i++) printk(" %2.2x", SA_prom[i]); printk("\nStation Address PROM %#2x:", i); for(; i < sizeof(SA_prom); i++) printk(" %2.2x", SA_prom[i]); printk("\n"); printk("NE200 wordlength = %u\n", wordlength); if (wordlength == 2) { /* We must set the 8390 for word mode, AND RESET IT. */ int tmp; outportb(0x300 + EN0_DCFG, 0x49); tmp = inportb(0x300 + NS_RESET); outportb(0x300 + NS_RESET, tmp); /* Un-double the SA_prom values. */ for (i = 0; i < 16; i++) SA_prom[i] = SA_prom[i+i]; } // Check for NE2000 on I/O address 0x300 printk("MAC of NE2000 @0x300: "); outportb(0x300 + E8390_CMD, E8390_NODMA + E8390_PAGE1); for (i = 1; i < 6; i++) printk("%2X:", inportb(0x300 + i)); printk("%2X\n"); // End of NE2000 code init_pics(0x20, 0x28); idt_install(); isrs_install(); irq_install(); keyboard_install(); asm volatile ("sti"); for(;;); }
void kmain(struct multiboot *mbp, u32 magic) { u32 initrd_location = *((u32*)mbp->mods_addr); //get the adress of initrd module u32 initrd_end = *(u32*)(mbp->mods_addr+4); placement_address = initrd_end; init_video_term(); puts("Welcome to chiffOS"); printk("\n"); videoram[1] = 2; videoram[3] = 4; videoram[5] = 6; videoram[7] = 8; videoram[9] = 10; videoram[11] = 12; videoram[13] = 14; videoram[15] = 12; videoram[17] = 10; videoram[19] = 8; videoram[21] = 6; videoram[23] = 4; videoram[25] = 2; videoram[27] = 6; videoram[29] = 10; videoram[31] = 14; printk("Initializing GDTs... "); gdt_install(); printk("[ok]\n"); printk("Initializing IDTs... "); idt_install(); printk("[ok]\n"); printk("Initializing ISRs and enabling interrupts... "); isrs_install(); irq_install(); printk("[ok]\n"); printk("\n"); printk("Initializing the PIT... "); timer_install(100); printk("[ok]\n"); printk("Initializing paging and the heap... "); _vmmngr_initialize(mbp); //get memory amount from grub printk("[ok]\n"); printk("Setting up the keyboard handler... "); _kbd_initialize(); printk("[ok]\n"); printk("Initializing initrd... "); fs_root = install_initrd(initrd_location); printk("[ok]\n"); printk("Initializing tasking... "); _task_initialize(); printk("[ok]\n"); _install_syscall_handler(); scan_pci_bus(0); ata_init_and_detect_drives(); mount_fat32(); fpu_install(); FAT_shell_newlib(); for(;;); }