summaryrefslogtreecommitdiff
path: root/src/kernel/smp_trampoline.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/smp_trampoline.asm')
-rw-r--r--src/kernel/smp_trampoline.asm42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/kernel/smp_trampoline.asm b/src/kernel/smp_trampoline.asm
index f723aa6..15b85e2 100644
--- a/src/kernel/smp_trampoline.asm
+++ b/src/kernel/smp_trampoline.asm
@@ -1,10 +1,12 @@
-global smp_bootstrap_corecount;
+global smp_bootstrap_stackarray
+global smp_bootstrap_bsp
+global smp_bootstrap_corecount
+
+extern multicore_main
[bits 16]
smp_trampoline:
cli
-hlt
-hlt
xor ax, ax
mov ds, ax
@@ -50,7 +52,7 @@ SMP_PROTECTED_DATA_SEGMENT equ .gdt_data_p - .gdt_start_p
;________________________________________________________________________________________
-.smp_protected
+.smp_protected:
[bits 32]
mov ax, SMP_PROTECTED_DATA_SEGMENT
@@ -60,6 +62,9 @@ mov es, ax
mov fs, ax
mov gs, ax
+lgdt [.gdt_descriptor_l]
+
+
mov eax, 0x10000 ;TODO clarify _why_ this is a thing
mov cr3, eax
@@ -82,12 +87,14 @@ or eax, 1 << 8 | 1 << 11
or eax, edx
wrmsr
+
;enable paging
mov eax, cr0
or eax, 1 << 31 | 1 << 0;
and ax, ~(1 << 2)
mov cr0, eax
+
jmp SMP_LONG_CODE_SEGMENT:.counter
;________________________________________________________________________________________
@@ -123,7 +130,7 @@ db 0
.gdt_end_l: ; later calculates offset in defs below
-.descriptor_l:
+.gdt_descriptor_l:
dw .gdt_end_l - .gdt_start_l - 1
dq .gdt_start_l
@@ -131,10 +138,27 @@ SMP_LONG_CODE_SEGMENT equ .gdt_code_l - .gdt_start_l
SMP_LONG_DATA_SEGMENT equ .gdt_data_l - .gdt_start_l
.counter:
+mov eax, 1
+cpuid
+shr ebx, 24
+cmp bl, BYTE [smp_bootstrap_bsp]
+jl .apic_below_bsp
+sub bl, 1
+
+.apic_below_bsp:
+
+mov rax, QWORD [smp_bootstrap_stackarray]
+debug:
+mov rsp, QWORD [rax + rbx * 8]
+
mov rax, [smp_bootstrap_corecount]
-inc QWORD [rax]
-cli
-hlt
-;TODO set up stack; enter kernel
+inc BYTE [rax]
+
+mov rax, multicore_main
+jmp rax
+align 8
+smp_bootstrap_stackarray: dq 0
+smp_bootstrap_bsp: db 0
smp_bootstrap_corecount: db 0
+times 512 - ($ - $$) db 0