summaryrefslogtreecommitdiff
path: root/kernel/kernel.c
blob: df3a5738338da7b0c6d583cc00b2c5c5c7261807 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#define FOOLOS_MODULE_NAME "kernel"

#ifdef __linux__
#error "Watchout! this is not Linux but FoolOS. Use a cross-compiler"
#endif

#include "kernel.h"

#include <stdint.h>
#include "config.h"
#include "types.h"
#include "lib/logger/log.h"

#include "timer.h"
#include "mem.h"
#include "vmem.h"
#include "mp.h"
#include "interrupts.h"
#include "multiboot.h"

#include "console.h"

#include <stddef.h> 

// for built-in shell
#include "lib/buffer/ringbuffer.h"
#include "task.h"
#include "video/vesa.h"
#include "multiboot.h"


void kernel_main(uint32_t eax,uint32_t ebx)
{

    //
    // Init Console
    // 
    console_init();

    //
    // 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..?)
    //
    // smp_log_procdata(&procdata);
    //TODO: !!! Check commented out sleep ()!!!
    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();
    

    //
    // Initialize Multitasking
    //
    task_init(dir); 



    //
    // Abvoe should never returon
    //
    panic(FOOLOS_MODULE_NAME,"reached end of kernel.c !!");
 
}