#define FOOLOS_MODULE_NAME "kernel" #include "x86.h" #include "../lib/logger/log.h" // logger facilities // TODO: WHHYY can i compile it without the includes!??? /////// // interrupt handler prototypes // todo: move somewhere else!? void int_clock_handler(); void int_kb_handler(); void int_floppy_handler(); uint32_t read_eip(); // // KERNEL MAIN // // this is the very heart of our operating system! // void kernel_main(uint32_t initial_stack, int mp) { volatile static uint32_t cpu1_counter=0; // catch the APs (Application Processors) /* if(mp==1) { //while(1) { static uint16_t c=0; PutString("cpu2: %03d", 200,560,0b1111100000000000, (c++)/100); } while(1) { static uint16_t c=0; PutString("cpu1counter: %d", 200,560,0b1111100000000000, (cpu1_counter)); } } */ // // We want to get output to the screen as fast as possible! // // Our Fool-Boot-Loader did set up VESA already for us. // The desired VESA mode is hardcoded in [boot/mbr.asm]. // // The [vesa_init(...)] function requires: // // * the addresses of the vbeinfo struct // * the address of the vbemodeinfo struct (for selected mode). // * the address of our Fool-Font binary data. // // The first two paramters are hardcoded in [boot/mbr.asm], // while the last one is set in the Makefile. The font binary // is integrated in the kernel image. // // this function returns the physical base address of // our video memory // uint32_t vesa_physbase=vesa_init(0x8300,0x8400,0x7200); // // Print initial address of the esp stack pointer // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial esp: 0x%08X",initial_stack); // // Initialize other processors // // This currently uses the MP Floating Pointer Struct. // Should support APCI in future too. // if(!init_mp()) panic(FOOLOS_MODULE_NAME,"Can not Find _MP_"); // // Memory Init // // we know that here, the bootloader placed the mamory map! mem_init(0x7c00+0x400,*((uint16_t *)(0x7c00+0x600))); // paging (pass the vesa physbase address for identity mapping) vmem_init(vesa_physbase); while(1) { PutString("cpu1counter: %d", 10,560,0b1111100000000000, (cpu1_counter)); cpu1_counter++; } // // Setup PIC // // Do we nee this when using APIC? // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setting up PIC."); pic_setup(); //while(1); // // Configuring the PIT timer. // timer_init(); // // Interrupts // // init and interrupt decriptor table int_init(0x08); // set default interrupts int_install(); // setup some custom interrupts // remember that we shifted all interrupts with the pic by 32 // install PIT interrupt handler (irq 0 => 32) int_install_ir(32, 0b10001110, 0x08,&int_clock_handler); // install keyboard interrupt handler (irq 1 => 33) int_install_ir(33, 0b10001110, 0x08,&int_kb_handler); // install floppy interrupt handler (irq 6 => 38) int_install_ir(38, 0b10001110, 0x08,&int_floppy_handler); // now we can enable interrupts back again // int_enable(); while(1) { cpu1_counter++; /* static uint16_t c=0; PutString("cpu1: A",20,560,0xffffff,0); for(int c2=0;c2<0xffff;c2++); PutString("cpu1: B",20,560,0xffffff,0); for(int c2=0;c2<0xffff;c2++); //PutString("cpu1: %03d", 20,560,0b1111100000000000, (c++)/100); */ } // // Scan the PCI Bus // // We are interested in the E1000 Network Adapter in particular // Its driver will be hopefully implemented one day ;) // pci_init(); // // Initialize Floppy Disk // // floppy_init(); // // "Shell" // // Will process input from the keyboard but will be completely // redesigned soon. // shell_init(); // // Initialize Multitasking // // For now this starts two tasks which are scheduled // round robin style. // task_init(); // // Just hang here. // while(1); }