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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
#define FOOLOS_MODULE_NAME "kernel"
#include "config.h"
#include "asm/asm.h"
#include "lib/logger/log.h"
#include "lib/int/stdint.h"
#include "lib/bool/bool.h"
#include "lib/buffer/ringbuffer.h"
#include "smp.h"
#include "timer.h"
#include "spinlock.h"
#include "syscalls.h"
#include "mem.h"
#include "interrupts.h"
#include "acpi.h"
#include "mp.h"
#include "keyboard.h"
#include "console.h"
#include "fs/fs.h"
#include "fs/ext2.h"
#include "task.h"
#ifdef FOOLOS_COMPILE_FLOPPY
#include "floppy.h"
#endif
// some multiprocessor shit that should move away TODO
uint32_t c1,c2,c3;
volatile uint8_t proc;
uint32_t cpu_counter[SMP_MAX_PROC];
void kernel_ap()
{
proc++;
uint8_t p=proc;
while(1)
{
cpu_counter[p]++;
lock_spin(0);
if(cpu_counter[p]%1000000==0)log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"cpu[%d] %d",p,cpu_counter[p]);
lock_release(0);
}
}
// mouse coords testing, move away
volatile int16_t mouse_x;
volatile int16_t mouse_y;
//
// KERNEL MAIN
// this is the very heart of our operating system!
//
void kernel_main(uint32_t initial_stack, int mp)
{
/// TODO
/////// SYMMETRIC MULTIPROCESSING, APS get caought here, move it away ///
// catch the APs (Application Processors)
if(mp==1)
{
uint32_t ebp=pmmngr_alloc_block()+4095;
asm volatile("mov %0, %%ebp"::"r"(ebp));
asm volatile("mov %ebp, %esp");
asm volatile("jmp kernel_ap");
}
proc=c1=c2=c3=0;
for(int i=0;i<SMP_MAX_PROC;i++)cpu_counter[i]=0;
/////////////////// BULLSHIT ABOVE THIS LINE: TODO: CLEANUP
//
// Print initial address of the esp stack pointer
//
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial esp: 0x%08X",initial_stack);
//
// Configuring the PIT timer.
//
timer_init();
//
// 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(0x7c00+1,*((uint16_t *)(0x7c00)));
//
// init output to screen
//
console_init();
// log buffered messages to console
log_log();
//
// Setup PIC
//
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setting up PIC.");
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();
//
// 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
//
// Activate Virtual Memory (paging)
//
// paging (pass the vesa physbase address for identity mapping)
// TODO: we will work on this later (not needed so urgently yet)
//
//vmem_init(vesa_physbase);
//
// 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 Floppy Disk if activated in config.h
// Sadly we won't use it anyway so its uncommented anyway.
//
//#ifdef FOOLOS_COMPILE_FLOPPY
//floppy_init();
//#endif
//
// Initialize Multitasking
//
// For now this starts three "tasks" which are scheduled
// round robin style.
//
task_init();
//
//vesa_init_doublebuff();
// Just hang around here, if its reached.
// we do our tasks anyway. on the next clock tick.
while(1);
}
|