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.asm76
1 files changed, 47 insertions, 29 deletions
diff --git a/src/kernel/smp_trampoline.asm b/src/kernel/smp_trampoline.asm
index 15b85e2..78303a3 100644
--- a/src/kernel/smp_trampoline.asm
+++ b/src/kernel/smp_trampoline.asm
@@ -1,13 +1,19 @@
global smp_bootstrap_stackarray
global smp_bootstrap_bsp
global smp_bootstrap_corecount
+global final_gdt_descriptor
-extern multicore_main
+extern smp_kinit
+extern _pmem_vaddr
[bits 16]
smp_trampoline:
cli
+in al, 0x92
+or al, 2
+out 0x92, al
+
xor ax, ax
mov ds, ax
lgdt [.gdt_descriptor_p]
@@ -15,12 +21,11 @@ mov eax, cr0
or eax, 0x1
mov cr0, eax ; now in long mode
-jmp 0x8:.smp_protected
+jmp 0x8:smp_protected
;________________________________________________________________________________________
-;TODO find how to use old gdt
.gdt_start_p: ; we need to start with a null gdt
dd 0
dd 0
@@ -52,9 +57,9 @@ SMP_PROTECTED_DATA_SEGMENT equ .gdt_data_p - .gdt_start_p
;________________________________________________________________________________________
-.smp_protected:
+smp_protected:
-[bits 32]
+bits 32
mov ax, SMP_PROTECTED_DATA_SEGMENT
mov ds, ax
mov ss, ax
@@ -62,10 +67,8 @@ mov es, ax
mov fs, ax
mov gs, ax
-lgdt [.gdt_descriptor_l]
-
-mov eax, 0x10000 ;TODO clarify _why_ this is a thing
+mov eax, 0x10000
mov cr3, eax
;setting up misc features
@@ -78,13 +81,15 @@ mov cr4, eax
;set NX and LME
mov eax, 0x80000001
cpuid
-and edx, 1 << 20
-shr edx, 9
+mov ebx, edx
+and ebx, 1 << 20
+shr ebx, 9
mov ecx, 0xc0000080
rdmsr
-or eax, 1 << 8 | 1 << 11
-or eax, edx
+or eax, 1 << 8
+fuckyou:
+or eax, ebx
wrmsr
@@ -94,14 +99,16 @@ or eax, 1 << 31 | 1 << 0;
and ax, ~(1 << 2)
mov cr0, eax
+lgdt [final_gdt_descriptor]
+
-jmp SMP_LONG_CODE_SEGMENT:.counter
+jmp SMP_LONG_CODE_SEGMENT:smp_longsetup
;________________________________________________________________________________________
-[bits 64]
-;TODO do we really need all this?
-.gdt_start_l:
+bits 64
+final_gdt:
+.start:
;and now we set up a temporary GDT creating a 1:1 mapping
dw 0xffff
dw 0
@@ -111,7 +118,7 @@ db 1
db 0
;now for the code GDT:
-.gdt_code_l:
+.code:
dw 0 ; segment limit 15:00 (I don't think this matters in 64 bit mode!)
dw 0 ; base address 15:00
db 0 ; base address 23:16
@@ -119,7 +126,7 @@ db 10011010b
db 00100000b
db 0
-.gdt_data_l:
+.data:
dw 0
dw 0
db 0
@@ -127,17 +134,18 @@ db 10010010b
db 00100000b
db 0
-.gdt_end_l: ; later calculates offset in defs below
+.end: ; later calculates offset in defs below
-.gdt_descriptor_l:
- dw .gdt_end_l - .gdt_start_l - 1
-dq .gdt_start_l
+final_gdt_descriptor:
+ dw final_gdt.end - final_gdt.start - 1
+.offset:
+dq final_gdt.start
-SMP_LONG_CODE_SEGMENT equ .gdt_code_l - .gdt_start_l
-SMP_LONG_DATA_SEGMENT equ .gdt_data_l - .gdt_start_l
+SMP_LONG_CODE_SEGMENT equ final_gdt.code - final_gdt.start
+SMP_LONG_DATA_SEGMENT equ final_gdt.data - final_gdt.start
-.counter:
+smp_longsetup:
mov eax, 1
cpuid
shr ebx, 24
@@ -146,19 +154,29 @@ 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, 0xffff800000000000
+;or QWORD [final_gdt_descriptor.offset], rax
+;lgdt [final_gdt_descriptor]
+
+.inc_corecounter:
+
+
mov rax, [smp_bootstrap_corecount]
-inc BYTE [rax]
+lock inc BYTE [rax]
+
-mov rax, multicore_main
+
+smp_enter_kernel:
+mov rax, smp_kinit
jmp rax
align 8
smp_bootstrap_stackarray: dq 0
+smp_lock: dq 0
smp_bootstrap_bsp: db 0
smp_bootstrap_corecount: db 0
+
times 512 - ($ - $$) db 0