#include "kernel.h" #include "log.h" #include "serial.h" #include "asm_pic.h" #include "multiboot.h" #include "acpi.h" #include "gdt.h" #include "interrupts.h" #include "mem.h" #include "vmem.h" //-- clean below headers --// #include "asm_start.h" #include "compositor.h" #include "sysfs.h" #include "pci.h" #include "e1000.h" #include "pipe.h" #include "testing/testing.h" #include "ext2.h" #include "apic.h" #include "kernel/scheduler.h" #include "driver/timer.h" #include "driver/keyboard.h" #include "driver/mouse.h" #include "syscalls.h" #include "fifo.h" #include "asm_smp.h" #include "asm_x86.h" #include "ringbuffer.h" #include "driver/screen.h" #include "smp.h" #include "fs/elf.h" #include "kmalloc.h" #include "driver/vesa.h" #include "asm_pit.h" /** F00L 0S Entry point (called directly from asm/multiboot.asm) * * After this procedure completes we are in a well defined state. * * * All Processors are up and running in 32bit protected mode. * * Interrupts are installed and enabled: * * - APIC Timer (Frequency defined in kernel.h) ALL CPUS * - PIT Timer (20Hz hardcoded in timer.c) CPU-0 * * - PS/2 Keyboard CPU-0 * - PS/2 Mouse CPU-0 * - E1000 CPU-0 * * * Software Interrupts: * * - Syscalls * - IPI * * * Framebuffer is in a known state. * * Paging is enabled. * * Each CPU runs on its own stack at VMEM_CPU_STACK * * Each CPU has its own private page at VMEM_CPU_PRIVATE * * We are ready to start scheduling on the next interrupt. * */ void kernel_main(uint32_t eax,uint32_t ebx) { // -- COM1 -- // serial_init(); klog("Communication Port (COM1) initialized."); // -- PR & VERSION BANNER -- // klog("======================================"); klog("F00L- 0S / The Fool's Operating System"); klog("(C) 2018 / Michal Idziorek (m.i@gmx.at)"); klog("Compiled on: %s at %s",__DATE__,__TIME__); klog("Version: git-commit: %s",GIT_REVISION); klog("======================================"); uint32_t *top_kernel_vmem=VMEM_KERNEL+VMEM_KERNEL_PAGES*4096; klog("The Kernel was loaded at: 0x%08X - 0x%08X",get_kernel_start(),get_kernel_end()); klog("0x00000000 - 0x%08X will get identity mapped", VMEM_KERNEL_PAGES*4096); if(kernel_end>=top_kernel_vmem)kpanic("kernel to big. increase VMEM_KERNEL_PAGES"); fixme("still fear overrun of stack"); // -- DISABLE LEGACY PIC -- // klog("Remapping & Disabling Programmable Interrupt Controller (PIC) ..."); fixme("io_wait & spurious interrupts"); asm_pic_setup(); // -- GET CONFIGS -- // klog("Read Multiboot Structures ..."); multiboot_information *cfg_multiboot; cfg_multiboot=multiboot_read(eax, ebx,false); // true for silent // elf_multiboot_read(cfg_multiboot); // just show kernel section headers klog("Read Advanced Power Configuration Interface (ACPI) Structures ..."); acpi_information cfg_acpi; bool acpi_found=acpi_fill(&cfg_acpi); fixme("Try to read (legacy) multiprocessor mp strucutres as well (see: xxx/mp.c)"); if(!acpi_found) kpanic("We Currently rely on ACPI Structures Sorry!"); // -- GDT -- // klog("Global Descriptor Table (GDT) init ..."); gdt_init(); // -- IVT -- // klog("Interrupt Vector Table (IVT) init ..."); interrupts_init(0x08); interrupts_install(); // -- PCI SCAN --/ klog("PCI init ..."); uint32_t e1000_addr=pci_init(); klog("E1000 addr=0x%08X",e1000_addr); // -- MEMORY MANAGEMENT -- // klog("Memory init ... "); mem_init(cfg_multiboot); klog("Vritual Memory / Paging init ... "); fixme("do not disable anymore on context switching!"); fixme("write convenneint management funcs as: mapCPU, mapKErnel, map USerspace.."); fixme("move stack and guard with empty pages!"); vmem_init(cfg_multiboot,&cfg_acpi,e1000_addr); struct pdirectory_struct *dir=vmem_kernel_dir(); x86_set_page_directory(dir); x86_paging_enable(); // -- MOUNTS -- // klog("Mounting ... "); ext2_dump_info(VMEM_EXT2_RAMIMAGE); ext2_mount("/"); sysfs_mount("/sys/"); // -- APIC -- // klog("Advanced Programmable Interrupt Controller (APIC) config ..."); apic_init(&cfg_acpi); ioapic_config(); // -- COMPOSITOR (TODO: text-mode fallback) -- // klog("Compositor init ..."); compositor_init(cfg_multiboot->framebuffer_width,cfg_multiboot->framebuffer_height,cfg_multiboot->framebuffer_pitch); compositor_set_background("/home/miguel/bg.ppm"); // -- KB DRIVER -- // klog("Keyboard init ..."); keyboard_init(); // -- MOUSE DRIVER -- // klog("Mouse init ..."); mouse_init(); // -- E1000 DRIVER --/ #ifndef DISABLE_E1000 if(e1000_addr) { klog("E1000 init ..."); e1000_init(e1000_addr); } #endif // we wait until the end since the time will only start ticking once // we enable interrupts. klog("Programmable Interval Timer (PIT) init ..."); klog("Reading CMOS Clock ..."); uint64_t unixtime=timer_init(); klog("Unix Time = %u seconds",unixtime); klog("Symmetric Multi Processing (SMP) start ... "); for(int i=1;i