summaryrefslogtreecommitdiff
path: root/kernel/kernel.c
blob: 5a17567ae1cdefb6b73fd3f356575a02b9d6560c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <stdint.h>
#include "kernel/kernel.h"

#include "kernel/mem.h"
#include "kernel/vmem.h"
#include "kernel/gdt.h"
#include "kernel/scheduler.h"
#include "kernel/multiboot.h"

#include "driver/serial.h"
#include "driver/timer.h"
#include "driver/keyboard.h"
#include "driver/mouse.h"

#include "syscalls.h"
#include "fifo.h"
#include "mp.h"
#include "asm_mp.h"
#include "asm_x86.h"
#include "interrupts.h"
#include "ringbuffer.h"
#include "driver/screen.h"
#include "asm_pic.h"

#include "fs/fs.h"
#include "kmalloc.h"
#include "driver/vesa.h"

/* F00L 0S Entry point (called directly from asm/multiboot.asm */
void kernel_main(uint32_t eax,uint32_t ebx)
{
    serial_init();
    klog("FOOL-OS ver-%s (%s)",GIT_REVISION,__DATE__);

    klog("Global Descriptor Table (GDT) init ...");
    gdt_init();

    klog("Interrupt Vector Table (IVT) init ...");
    interrupts_init(0x08);

    klog("Remapping & Disabling PIC ...");
    asm_pic_setup();

    klog("Keyboard init ...");
    keyboard_init(0); 

    klog("Mouse init ...");
    mouse_init();

    // gather some info (before we start paging)
    klog("Search / Read Multiboot Structures ... ");
    multiboot_information *info;
    info=get_multiboot(eax, ebx);
    
    klog("Search / Read ACPI Structures... ");
    smp_processors procdata;    
    bool acpi_found=acpi_find(&procdata);

    klog("Search / Read MP Structures... ");
    smp_processors procdata2;    
    bool mp_found=mp_find(&procdata2);
    //

    // memory management
    klog("Memory init ... ");
    uint32_t kernel_blocks=mem_init(info);
    
    klog("Vritual Memory / Paging init ... ");
    pdirectory *dir=vmem_init(kernel_blocks,(uint32_t)info->framebuffer_addr,procdata.local_apic_address,procdata.io_apic_address);
    //
    
    klog("Ram Filesystem init ... ");
    fs_mount(info);

    klog("Video Electronics Standards Association (VESA) init ... "); // TODO check if text or fb?
    uint32_t addr=kballoc(1);
    fs_content("/binfont.bin",addr,0x100); // copy font (0x100 bytes) to memory.
    vesa_init(info->vbe_control_info,info->vbe_mode_info,addr);

    klog("stdin/stdout init ...");
    uint32_t sstdin  = syscall_open("stdin",0,0);   // stdin  0
    uint32_t sstdout = syscall_open("term",0,0);    // stdout 1
    uint32_t sstderr = syscall_open("stderr",0,0);  // stderr 2

    klog("Scheduler init ...");
    scheduler_init(dir); 

    klog("Symmetric Multi Processing (SMP) start ... ");
    smp_start_aps(&procdata);

    klog("Programmable Interval Timer (PIT) init ...");
    uint64_t unixtime=timer_init();
    klog("Unix Time = %u seconds)",unixtime);

    klog("Unlock application processors ... ");
    asm_smp_unlock();

    klog("Enable Interrupts ... ");
    x86_sti(); // this will start processing hardware interrupts

    // now just wait until our scheduler kicks in.
    while(1)asm("hlt");
}