summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-16 20:42:37 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-16 20:42:37 +0200
commit3bac6dd02d640923646b8ad988f509f47adab57f (patch)
tree42d91a578fba55f6e0e6e473644aa7941ae1863c /kernel
parentec6d07e29d1d55afe9d2c6f7f25e9fed20819af6 (diff)
working on smp support, strange things happening!?
Diffstat (limited to 'kernel')
-rw-r--r--kernel/config.h2
-rw-r--r--kernel/interrupts.c5
-rw-r--r--kernel/kernel.c49
-rw-r--r--kernel/smp.c51
-rw-r--r--kernel/syscalls.c2
-rw-r--r--kernel/task.c4
-rw-r--r--kernel/usermode.c14
7 files changed, 68 insertions, 59 deletions
diff --git a/kernel/config.h b/kernel/config.h
index 8329457..74304d8 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -8,7 +8,7 @@
#define FOOLOS_CONFIG_H
#define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line
-//#define FOOLOS_LOG_OFF // do not log anything
+#define FOOLOS_LOG_OFF // do not log anything
#define FOOLOS_CONSOLE // otherwise VESA will be used!
#define FOOLSOS_SHOW_VESAMODES
#define MEM_PRINT_MEMORYMAP
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index a7e021c..088c94e 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -173,10 +173,10 @@ void int_init(uint16_t sel)
int_install_ir(0x80, 0b11101110, 0x08,&int_syscall_handler);
- int_install();
+ int_install();
// now we can enable interrupts back again
- x86_int_enable();
+ x86_int_enable();
}
@@ -191,3 +191,4 @@ void int_install()
__asm__("lidt %0"::"m" (idtd));
}
+
diff --git a/kernel/kernel.c b/kernel/kernel.c
index e5369f4..df3a573 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -37,7 +37,6 @@ void kernel_main(uint32_t eax,uint32_t ebx)
//
console_init();
-
//
// PR
//
@@ -55,6 +54,11 @@ void kernel_main(uint32_t eax,uint32_t ebx)
//
gdt_setup();
+ //
+ // Setup Interrupts (code segment: 0x08)
+ //
+ int_init(0x08);
+
//
// Process Multiboot Header
@@ -63,6 +67,16 @@ void kernel_main(uint32_t eax,uint32_t 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
@@ -71,35 +85,22 @@ void kernel_main(uint32_t eax,uint32_t ebx)
uint32_t kernel_blocks=mem_init(info);
//
- // Gather Info about other processors. (APs = application processors)
- // ACPI or MP
- //
- smp_processors procdata;
+ // Mount Root EXT2 ramimage (needs to be done before other processors started, because of /boot/mp.bin)
+ //
+ fs_mount(info);
- if(!acpi_find(&procdata))
- if(!mp_find(&procdata))
- panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!");
//
- // Start the other Processors (before paging)
+ // Start the other Processors (before paging because apic addr etc..?)
//
- smp_log_procdata(&procdata);
+ // smp_log_procdata(&procdata);
//TODO: !!! Check commented out sleep ()!!!
- //smp_start_aps(&procdata,0x80000); // starts at 0x80000
- // but it will be copied over mbr
- while(1);
+ smp_start_aps(&procdata,"/boot/mp.bin"); //will be copied over mbr
//
// Activate Virtual Memory (paging)
//
pdirectory *dir=vmem_init(kernel_blocks);
-
- //
- // Setup Interrupts (code segment: 0x08)
- //
- int_init(0x08);
-
-
//
// Scan the PCI Bus
//
@@ -107,13 +108,6 @@ void kernel_main(uint32_t eax,uint32_t ebx)
// Its driver will be hopefully implemented one day ;) TODO
//
//pci_init();
-
-
-
- //
- // Mount Root EXT2 ramimage
- //
- fs_mount(info);
//
@@ -122,6 +116,7 @@ void kernel_main(uint32_t eax,uint32_t ebx)
task_init(dir);
+
//
// Abvoe should never returon
//
diff --git a/kernel/smp.c b/kernel/smp.c
index 8d122ee..f776c72 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -16,19 +16,22 @@ uint32_t c1,c2,c3;
volatile uint8_t proc;
uint32_t cpu_counter[SMP_MAX_PROC];
+extern
+
void smp_main()
{
- /// 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");
- }
+ // int_install();
+ // x86_int_enable();
+ switch_to_user_mode();
+
+ while(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;
@@ -58,22 +61,20 @@ void smp_log_procdata(smp_processors *procdata)
}
+
// this will start all our application processors!
-void smp_start_aps(smp_processors *pros,uint8_t *start_sel)
-{
+void smp_start_aps(smp_processors *pros,char *path)
+{
+ //lets copy the binary into mbr
+ fs_content(path,0x7000,0x100); // copy 0x100 bytes to 0x7000
- //lets copy the code to the bootsector !
-
- uint8_t *dest=0x7000;
- for(int i=0;i<0x100;i++)
- {
- dest[i]=start_sel[i];
+ // tell them where to enter (agreed adress at 0x8010)
+ uint32_t *entry=0x8010;
+ *entry=smp_main;
- }
-
//bsp (boot processor) enables its local apic
uint32_t *reg=pros->local_apic_address+FOOLOS_APIC_SPUR_INT;
- *reg=0xffffffff; // all bits 1 and interrupt 255
+// *reg=0xffffffff; // all bits 1 and interrupt 255
for(int i=0;i<pros->processors;i++)
{
@@ -90,12 +91,20 @@ void smp_start_aps(smp_processors *pros,uint8_t *start_sel)
*reg=(5<<8)|(1<<14); // 101 INIT
// do we really neet this?
+ // TODO!!
// todo: use some real sleep (not implemented yet :( )
//sleep(30);
// start proc 0x7 = 0x7000; etc..
*reg=(6<<8)|(1<<14)|0x7; // 110 SIPI
+
+ //bsp (boot processor) enables its local apic
+ uint32_t *reg=pros->local_apic_address+FOOLOS_APIC_SPUR_INT;
+ // *reg=0xffffffff; // all bits 1 and interrupt 255
+
+
}
}
+
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 9671469..e9ef9d5 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -31,6 +31,7 @@ int syscall_lseek(int file,int ptr,int dir)
// TODO: /dev/console or /dev/tty1 - /dev/ttyN
int syscall_write(int file, char *buf, int len)
{
+ lock_spin(2);
//x86_int_disable();
#ifdef LOG_SYSCALLS
@@ -44,6 +45,7 @@ int syscall_write(int file, char *buf, int len)
{
console_put_char_green(buf[i]);
}
+ lock_release(2);
//x86_int_enable();
return len;
}
diff --git a/kernel/task.c b/kernel/task.c
index 000dc74..54381fa 100644
--- a/kernel/task.c
+++ b/kernel/task.c
@@ -82,8 +82,8 @@ volatile uint32_t my_scheduler(uint32_t oldesp)
// this gets called by our clock interrupt regularly!
volatile uint32_t task_switch_next(uint32_t oldesp)
{
- asm volatile("sti");
+ //syscall_write(1,"\n\n*tick*\n\n",10);
timer_tick();
@@ -161,7 +161,7 @@ volatile void task_init(pdirectory *dir)
task_list[0].esp = 0; // will be set by next task_switch_next() call.
current_task=0;
-
+ while(1);
switch_to_user_mode();
//syscall_execve("/bin/foolshell",argv_init,env_init);
diff --git a/kernel/usermode.c b/kernel/usermode.c
index 76128d1..ff16156 100644
--- a/kernel/usermode.c
+++ b/kernel/usermode.c
@@ -55,9 +55,11 @@ void install_tss(int cpu_no){
void switch_to_user_mode()
{
- char text[]="internal";
- write(1,text,10);
- asm_usermode();
+ char text[]="[internal] ";
+
+ //asm_usermode();
+ write(1,text,11);
+
while(1); // will not be reached?
}
@@ -75,11 +77,11 @@ void userfunc()
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"we are usermode!");
}
-
- while(1)
- {
char text[]="syscalling!";
write(1,text,10);
+
+ while(1)
+ {
}
}