summaryrefslogtreecommitdiff
path: root/kernel/src/scheduler
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksav013@gmail.com>2023-01-29 16:56:16 +0100
committerAleksa Vuckovic <aleksav013@gmail.com>2023-01-29 16:56:16 +0100
commit03fa5edfa5562f2fd3a8895d85da2cdcdbb92377 (patch)
tree5d3d8d7480bce9f6a5bdea609c66710b1e137c30 /kernel/src/scheduler
parentb44da1cc8773578610db2225b21c0882ad37f5a2 (diff)
SMP WORKING
Diffstat (limited to 'kernel/src/scheduler')
-rw-r--r--kernel/src/scheduler/ap_init.S71
-rw-r--r--kernel/src/scheduler/ap_startup.c5
2 files changed, 76 insertions, 0 deletions
diff --git a/kernel/src/scheduler/ap_init.S b/kernel/src/scheduler/ap_init.S
new file mode 100644
index 0000000..8cb4314
--- /dev/null
+++ b/kernel/src/scheduler/ap_init.S
@@ -0,0 +1,71 @@
+.section .apinit, "a"
+
+
+.SET stack_top, 0x3008000
+.SET stack_off, 0x8000
+.SET bspdone, 0x3000100
+.SET aprunning, 0x3000200
+
+# this code will be relocated to 0x8000, sets up environment for calling a C function
+.code16
+ap_trampoline:
+ cli
+ cld
+ ljmp $0, $0x8040
+.align 16
+_L8010_GDT_table:
+ .long 0, 0
+ .long 0x0000FFFF, 0x00CF9A00 # flat code
+ .long 0x0000FFFF, 0x008F9200 # flat data
+ .long 0x00000068, 0x00CF8900 # tss
+_L8030_GDT_value:
+ .word _L8030_GDT_value - _L8010_GDT_table - 1
+ .long 0x8010
+ .long 0, 0
+ .align 64
+_L8040:
+ xorw %ax, %ax
+ movw %ax, %ds
+ lgdtl 0x8030
+ movl %cr0, %eax
+ orl $1, %eax
+ movl %eax, %cr0
+ ljmp $8, $0x8060
+ .align 32
+ .code32
+_L8060:
+ movw $16, %ax
+ movw %ax, %ds
+ movw %ax, %ss
+ # get our Local APIC ID
+ mov $1, %eax
+ cpuid
+ shrl $24, %ebx
+ movl %ebx, %edi
+
+
+ # set up 32k stack, one for each core. It is important that all core must have its own stack
+ movl $stack_top, %esp
+ mov %edi, %ecx
+2:
+ addl $stack_off, %esp
+ decl %ecx
+ cmp $0, %ecx
+ jne 2b
+
+ shll $15, %ebx
+ subl %ebx, %esp
+ pushl %edi
+ # spinlock, wait for the BSP to finish
+1:
+ pause
+ cmpb $0, bspdone
+ jz 1b
+ lock incb aprunning
+
+3:
+ hlt
+ jmp 3b
+
+ # jump into C code (should never return)
+ # ljmp $8, $ap_startup
diff --git a/kernel/src/scheduler/ap_startup.c b/kernel/src/scheduler/ap_startup.c
new file mode 100644
index 0000000..43b1a51
--- /dev/null
+++ b/kernel/src/scheduler/ap_startup.c
@@ -0,0 +1,5 @@
+// this C code can be anywhere you want it, no relocation needed
+void ap_startup(int apicid) {
+ // do what you want to do on the AP
+ while(1);
+}