#define FOOLOS_MODULE_NAME "kernel" #include "kernel.h" #include #include #include "config.h" #include "types.h" #include "lib/logger/log.h" #include "fifo.h" #include "timer.h" #include "mem.h" #include "vmem.h" #include "mp.h" #include "interrupts.h" #include "multiboot.h" #include "ringbuffer.h" #include "task.h" #include "multiboot.h" #include "terminal/terminal.h" #include "driver/screen.h" // The Foolish structure of Fool OS! // static fool_os foolos; fool_os *get_fool() { return &foolos; } // // stdio init : TODO: move away! static terminal_tty tty1; static term_out screen; static term_in input; static ringbuffer stdin_buf; static void put_kb(uint8_t c) { terminal_kb(&tty1,c); } static void stdin_put_char(uint8_t c) { ringbuffer_put(&stdin_buf,c); } static void init_stdio() { // // Setup terminal output / input // screen.put_char=console_put_char; screen.update_cursor=update_cursor; input.put_char=stdin_put_char; tty1=terminal_init(&screen,&input); get_fool()->tty=&tty1; // get_fool()->std_out.data=&tty1; get_fool()->std_out.put=terminal_put; stdin_buf=ringbuffer_init(1); get_fool()->std_in.data=&stdin_buf; get_fool()->std_in.put=ringbuffer_put; get_fool()->std_in.get=ringbuffer_get; get_fool()->std_in.has=ringbuffer_has; keyboard_init(put_kb); } /* F00L 0S Entry point (called directly from asm/multiboot.asm */ void kernel_main(uint32_t eax,uint32_t ebx) { // // STDIN and STDOUT // init_stdio(); // // PR // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%s - compiled on %s at %s",KERNEL_VERSION,__DATE__,__TIME__); // // Configuring the PIT timer. // timer_init(); // // GDT // gdt_setup(); // // Setup Interrupts (code segment: 0x08) // int_init(0x08); // // Process Multiboot Header // multiboot_information *info=get_multiboot(eax, ebx); // // Gather Info about other processors. (APs = application processors) // ACPI or MP // smp_processors procdata; if(!acpi_find(&procdata)) if(!mp_find(&procdata)) panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!"); // // Memory Init // // after this is set up we will be able to allocate and deallocate // blocks of physical memory :) // uint32_t kernel_blocks=mem_init(info); // // Mount Root EXT2 ramimage (needs to be done before other processors started, because of /boot/mp.bin) // fs_mount(info); // // Start the other Processors (before paging because apic addr etc..?) // //TODO: !!! Check commented out sleep ()!!! smp_log_procdata(&procdata); smp_start_aps(&procdata,"/boot/mp.bin"); //will be copied over mbr // // Activate Virtual Memory (paging) // pdirectory *dir=vmem_init(kernel_blocks); // // Scan the PCI Bus // // We are interested in the E1000 Network Adapter in particular // Its driver will be hopefully implemented one day ;) TODO // //pci_init(); // //empty stdin! while(fifo_has(&get_fool()->std_in)) fifo_get(&get_fool()->std_in); // // Initialize Multitasking // task_init(dir); // // Abvoe should never returon // panic(FOOLOS_MODULE_NAME,"reached end of kernel.c !!"); }