diff options
| author | Miguel <m.i@gmx.at> | 2018-09-11 19:49:17 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-11 19:49:17 +0200 |
| commit | c9351caacd49c8442cc586f9e53a2dcc49a004aa (patch) | |
| tree | 7032ebdc1a6ff27043a3d2e81d897c2bf78731af /kernel/smp.c | |
| parent | bd2c3fcfa2b562724667d7b83089b5ff1e2d33dc (diff) | |
cleaning up vmem etc..
Diffstat (limited to 'kernel/smp.c')
| -rw-r--r-- | kernel/smp.c | 69 |
1 files changed, 45 insertions, 24 deletions
diff --git a/kernel/smp.c b/kernel/smp.c index b385681..d22fff0 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -13,50 +13,70 @@ #include "asm_smp.h" #include "apic.h" #include "vesa.h" +#include "syscalls.h" +#include "test/selftest.h" +// set cpu private value +void smp_set(uint32_t offset, uint32_t value) +{ + uint32_t *cpu_mem=VMEM_CPU_PRIVATE; + cpu_mem[offset]=value; +} -void smp_main() +// get cpu private value +uint32_t smp_get(uint32_t offset) { + uint32_t *cpu_mem=VMEM_CPU_PRIVATE; + return cpu_mem[offset]; +} + +void smp_main_generic(bool bsp) +{ + if(!bsp) // for the bsp this was already done beforehand + { + klog("Install Interrupt Vector Table (IVT) on CPU with lapic_id=0x%x ...",apic_id()); + interrupts_install(); + + klog("Install Global Descriptor Table (GDT) on CPU with lapic_id=0x%x ...",apic_id()); + gdt_init(); + + klog("Setup Paging on CPU with lapic_id=0x%x ...",apic_id()); + struct pdirectory_struct *dir=vmem_kernel_dir(); + x86_set_page_directory(dir); + x86_paging_enable(); + } + // setup stack and jump to kernel_ap(); - uint32_t ebp=kballoc(1); + uint32_t ebp=VMEM_CPU_STACK_TOP; asm volatile("mov %0, %%ebp"::"r"(ebp)); asm volatile("mov %ebp, %esp"); - asm volatile("jmp kernel_ap"); + asm volatile("jmp run_smp"); } -void kernel_ap() +void smp_main() { + smp_main_generic(false); +} - klog("Install Interrupt Vector Table (IVT) on CPU with lapic_id=0x%x ...",apic_id()); - interrupts_install(); - - klog("Install Global Descriptor Table (GDT) on CPU with lapic_id=0x%x ...",apic_id()); - gdt_init(); - - klog("Setup Paging on CPU with lapic_id=0x%x ...",apic_id()); - struct pdirectory_struct *dir=vmem_kernel_dir(); - x86_set_page_directory(dir); - x86_paging_enable(); - +static void run_smp() +{ apic_enable(); - - //1024 pages from here on are mapped per cpu for testing! TODO: dynamic. - uint32_t *cpu_mem=VMEM_CPU_PRIVATE; - cpu_mem[0]=apic_id(); klog("Setup the LAPIC Timer on CPU with lapic_id=0x%x ...",apic_id()); apic_init_timer(1);// freq 1HZ klog("Enable Interrupts on CPU with lapic_id=0x%x ...",apic_id()); - x86_sti(); asm_smp_unlock(); - cpu_mem[1]=0; + smp_set(0,apic_id()); + smp_set(1,'a'+apic_id()); + + x86_sti(); while(1){ - PutString("cpu cnt: %d",10,10+apic_id()*20,0xff0000,cpu_mem[1]++); - asm("hlt"); + syscall_write(1, VMEM_CPU_PRIVATE+4,1); // stdout + asm("hlt"); // wait for scheduler to kick in } } @@ -71,5 +91,6 @@ void smp_start_aps(acpi_information *pros) klog("starting cpu %d (destination apic id: 0x%x) ",i,dest); apic_sipi(dest,0x7); // start on 0x7000 } + + smp_main_generic(true); } - |
