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
|
#define FOOLOS_MODULE_NAME "kernel"
#include "kernel.h"
#include <stdint.h>
#include <stddef.h>
#include "syscalls.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"
/* F00L 0S Entry point (called directly from asm/multiboot.asm */
void kernel_main(uint32_t eax,uint32_t ebx)
{
serial_init();
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"COM 1 - initialized");
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%s - BUILD: git-%s (%s %s)",
KERNEL_NAME,GIT_REVISION,__DATE__,__TIME__);
// PIT TIMER
timer_init();
// STREAMS
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
// KEYBOARD DRIVER
keyboard_init(sstdin);
// MOUSE DRIVER
mouse_init();
// GDT
gdt_setup();
// INTERRUPTS (code segment: 0x08)
int_init(0x08);
// 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 (allows allocating and deaclloating 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 ()!!!
// https://wiki.osdev.org/Symmetric_Multiprocessing
// smp_log_procdata(&procdata);
// smp_start_aps(&procdata,"/boot/mp.bin"); //will be copied over mbr
// VIRTUAL MEMORY (paging)
pdirectory *dir=vmem_init(kernel_blocks,(uint32_t)info->framebuffer_addr);
// PCI Bus
pci_init();
// INIT VESA
uint32_t addr=kballoc(1);
fs_content("/binfont.bin",addr,0x100); // copy 0x100 bytes to 0x7000
vesa_init(info->vbe_control_info,info->vbe_mode_info,addr);
PutString("WELCOME TO THE Fool Operating System",100,100,0xffff00);
// INIT MULTITASKING (and switch to usermode)
task_init(dir);
// we should never reach this
panic(FOOLOS_MODULE_NAME,"reached end of kernel.c !!");
}
|