#define FOOLOS_MODULE_NAME "kernel" #ifdef __linux__ #error "Watchout! this is not Linux but FoolOS. Use a cross-compiler" #endif #include #include "config.h" #include "asm/asm.h" // TODO: ?!?! #include "lib/logger/log.h" #include "lib/buffer/ringbuffer.h" #include "timer.h" #include "spinlock.h" #include "syscalls.h" #include "mem.h" #include "vmem.h" #include "interrupts.h" #include "keyboard.h" #include "console.h" #include "fs/fs.h" #include "fs/ext2.h" #include "task.h" #include #include // CODE FOR Stack Smashing Protector, TODO: MOVE / and do not duplicate // with sys.c // http://wiki.osdev.org/Stack_Smashing_Protector #if UINT32_MAX == UINTPTR_MAX #define STACK_CHK_GUARD 0xe2dee396 #else #define STACK_CHK_GUARD 0x595e9fbd94fda766 #endif uintptr_t __stack_chk_guard = STACK_CHK_GUARD; __attribute__((noreturn)) void __stack_chk_fail(void) { panic(FOOLOS_MODULE_NAME,"Stack smashing detected"); } // mp informs us if this if this is the main processor void kernel_main(uint32_t initial_stack, int mp) { // // Memory Init // // after this is set up we will be able to allocate and deallocate // blocks of physical memory :) // // we know that here, the bootloader placed the memory map and // the number of entries. // mem_init(0xa001,*((uint16_t *)(0xa000))); // // Configuring the PIT timer. // timer_init(); // // Activate Virtual Memory (paging) // vmem_init(); // // init output to screen // console_init(); // log buffered messages to console log_log(); // // Setup PIC (interrupts) // pic_setup(); // mouse and kb driver init (before interrupts) // mouse_init(); keyboard_init(); // // Setup Interrupts (code segment: 0x08) // int_init(0x08); // // Gather Info about other processors. (APs) // 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!"); */ // init spinlocks init_spinlocks(); // ringbuffer for stdin! ringbuffer_init(); // load and run foolshell // we will come back into the kernel only on interrupts... asm("mov $0x05bff,%esp"); // set stack pointer syscall_execve("/bin/foolshell",0,0); // // Start the other Processors (also before paging for some reason!) // //smp_log_procdata(&procdata); //smp_start_aps(&procdata,0x80000); // starts at 0x80000 // but it will be copied over mbr // // 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(); // // Initialize Multitasking // // For now this starts three "tasks" which are scheduled // round robin style. // //task_init(); // Just hang around here, if its reached. // we do our tasks anyway. on the next clock tick. // while(1); }