More SMP Work, also changed the physical allocator to allocate downwards
[tpg/acess2.git] / Kernel / arch / x86 / start.asm
index 4135160..4dd7603 100644 (file)
@@ -52,6 +52,52 @@ start:
        hlt\r
        jmp .hlt\r
 \r
+; \r
+; Multiprocessing AP Startup Code (Must be within 0x10FFF0)\r
+;\r
+%if USE_MP\r
+[extern gGDTptr]\r
+[extern gpMP_LocalAPIC]\r
+[extern gaAPIC_to_CPU]\r
+[extern gaCPUs]\r
+[global APStartup]\r
+\r
+[bits 16]\r
+APStartup:\r
+       xchg bx, bx     ; MAGIC BREAK!\r
+       mov ax, 0xFFFF\r
+       mov ds, ax\r
+       lgdt [DWORD ds:gGDTptr-0xFFFF0]\r
+       mov eax, cr0\r
+       or      al, 1\r
+       mov     cr0, eax\r
+       jmp 08h:DWORD .ProtectedMode\r
+[bits 32]\r
+.ProtectedMode:\r
+       ; Start Paging\r
+       mov eax, gaInitPageDir - KERNEL_BASE\r
+       mov cr3, eax\r
+       mov eax, cr0\r
+       or      eax, 0x80010000 ; PG and WP\r
+       mov cr0, eax\r
+       ; Jump to higher half\r
+       lea eax, [.higherHalf]\r
+       jmp eax\r
+.higherHalf:\r
+       mov eax, [gpMP_LocalAPIC]\r
+       mov DWORD [eax], 0\r
+       xor ecx, ecx\r
+       mov cl, BYTE [eax+0x10]\r
+       ; CL is now local APIC ID\r
+       mov cl, BYTE [gaAPIC_to_CPU+ecx]\r
+       ; CL is now the CPU ID\r
+       mov BYTE [gaCPUs+ecx*8+1], 1\r
+       ; CPU is now marked as initialised\r
+.hlt:\r
+       hlt\r
+       jmp .hlt\r
+%endif\r
+\r
 [global GetEIP]\r
 GetEIP:\r
        mov eax, [esp]\r

UCC git Repository :: git.ucc.asn.au