BarryServer : Git

All the code for all my projects
// BarryServer : Git / Orion / commit / d41a53cbc7d055b1c00cf0a339dbed6925f4f02c / proc / trampoline.S

// Related

Orion

Barry Importing existing Orion kernel d41a53c (2 years, 4 months ago)
diff --git a/proc/trampoline.S b/proc/trampoline.S
new file mode 100644
index 0000000..8a8656f
--- /dev/null
+++ b/proc/trampoline.S
@@ -0,0 +1,52 @@
+; This file contains the AP trampoline code to bounce it back into protected
+; mode and run the Kernel on them.  The location of the stack is set by the
+; calling code.  This code runs initially in real (16-bit) mode, at 0x0000 in
+; physical memory.  Modifying this code should be done with care, since it makes
+; use of fixed offsets in memory to jump around.
+
+[bits 16]
+
+[extern ap_startup]
+
+; This is the code run by the APs on startup.  They need to initialise
+; themselves, which includes setting up a GDT and switching to protected mode.
+; When they're in protected mode they can just run their main C function.
+[global ap_trampoline]
+ap_trampoline:
+	cli
+	cld
+	jmp 0x0000:0x2040 ; continue
+
+align 16
+.gdt_start:
+	dd 0, 0
+	dd 0x0000FFFF, 0x00CF9A00 ; Flat Code
+	dd 0x0000FFFF, 0x00CF9200 ; Flat Data
+	dd 0x00000068, 0x00CF8900 ; TSS
+.gdt_desc:
+	dw .gdt_desc - .gdt_start - 1
+	dd 0x2010 ; gdt_start
+	dd 0, 0
+
+align 64
+.continue:
+	xor ax, ax
+	mov ds, ax
+	lgdt [0x2030] ; gdt_desc
+	mov eax, cr0
+	or eax, 0x01
+	mov cr0, eax
+	jmp 0x08:0x2060 ; pm
+
+align 32
+[bits 32]
+.pm:
+	mov ax, 0x10
+	mov ds, ax
+	mov ss, ax
+	; Load passed stack
+	mov eax, [0x2FF0]
+	mov esp, eax
+	mov ebp, esp
+	sti
+	jmp 0x08:ap_startup