X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Fstart.asm;h=f1d1ea7467ab15ad1b8c75101a3bc0b5ee197b82;hb=ca05044548d5c1de87c030d625a305731a6cc665;hp=0c2508b9f71c82e641b713b51c2a1120af48f258;hpb=b7beadbbf953f23b9d88db5ede3720003fac69d4;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86/start.asm b/Kernel/arch/x86/start.asm index 0c2508b9..f1d1ea74 100644 --- a/Kernel/arch/x86/start.asm +++ b/Kernel/arch/x86/start.asm @@ -21,14 +21,14 @@ mboot: dd mboot - KERNEL_BASE ;Location of Multiboot Header [section .text] -[extern _kmain] +[extern kmain] [global start] start: ; Set up stack - mov esp, _Kernel_Stack_Top + mov esp, Kernel_Stack_Top ; Start Paging - mov ecx, _gaInitPageDir - KERNEL_BASE + mov ecx, gaInitPageDir - KERNEL_BASE mov cr3, ecx mov ecx, cr0 @@ -39,12 +39,10 @@ start: jmp ecx .higherHalf: - mov DWORD [_gaInitPageDir], 0 - ; Call the kernel push ebx ; Multiboot Info push eax ; Multiboot Magic Value - call _kmain + call kmain ; Halt the Machine cli @@ -52,20 +50,79 @@ start: hlt jmp .hlt -[global _GetEIP] -_GetEIP: +; +; Multiprocessing AP Startup Code (Must be within 0x10FFF0) +; +%if USE_MP +[extern gGDT] +[extern gGDTPtr] +[extern gIDTPtr] +[extern gpMP_LocalAPIC] +[extern gaAPIC_to_CPU] +[extern gaCPUs] +[extern giNumInitingCPUs] +lGDTPtr: ; Local GDT Pointer + dw 2*8-1 + dd gGDT-KERNEL_BASE + +[bits 16] +[global APStartup] +APStartup: + xchg bx, bx ; MAGIC BREAK! + mov ax, 0xFFFF + mov ds, ax + lgdt [DWORD ds:lGDTPtr-KERNEL_BASE-0xFFFF0] + mov eax, cr0 + or al, 1 + mov cr0, eax + jmp 08h:DWORD .ProtectedMode-KERNEL_BASE +[bits 32] +.ProtectedMode: + ; Start Paging + mov eax, gaInitPageDir - KERNEL_BASE + mov cr3, eax + mov eax, cr0 + or eax, 0x80010000 ; PG and WP + mov cr0, eax + ; Jump to higher half + lea eax, [.higherHalf] + jmp eax +.higherHalf: + ; Load True GDT & IDT + lgdt [gGDTPtr] + lidt [gIDTPtr] + + mov eax, [gpMP_LocalAPIC] + mov DWORD [eax], 0 + xor ecx, ecx + mov cl, BYTE [eax+0x10] + ; CL is now local APIC ID + mov cl, BYTE [gaAPIC_to_CPU+ecx] + ; CL is now the CPU ID + mov BYTE [gaCPUs+ecx*8+1], 1 + ; Decrement the remaining CPU count + dec DWORD [giNumInitingCPUs] + ; CPU is now marked as initialised + sti +.hlt: + hlt + jmp .hlt +%endif + +[global GetEIP] +GetEIP: mov eax, [esp] ret -[extern _Proc_Clone] -[extern _Threads_Exit] -[global _SpawnTask] -_SpawnTask: +[extern Proc_Clone] +[extern Threads_Exit] +[global SpawnTask] +SpawnTask: ; Call Proc_Clone with Flags=0 xor eax, eax push eax push eax - call _Proc_Clone + call Proc_Clone add esp, 8 ; Remove arguments from stack test eax, eax @@ -77,29 +134,29 @@ _SpawnTask: ; Child push edx ; Argument call ebx ; Function - call _Threads_Exit ; Kill Thread + call Threads_Exit ; Kill Thread .parent: ret [section .initpd] -[global _gaInitPageDir] -[global _gaInitPageTable] +[global gaInitPageDir] +[global gaInitPageTable] align 0x1000 -_gaInitPageDir: - dd _gaInitPageTable-KERNEL_BASE+3 ; 0x00 +gaInitPageDir: + dd gaInitPageTable-KERNEL_BASE+3 ; 0x00 times 1024-256-1 dd 0 - dd _gaInitPageTable-KERNEL_BASE+3 ; 0xC0 + dd gaInitPageTable-KERNEL_BASE+3 ; 0xC0 times 256-1 dd 0 align 0x1000 -_gaInitPageTable: +gaInitPageTable: %assign i 0 %rep 1024 dd i*0x1000+3 %assign i i+1 %endrep -[global _Kernel_Stack_Top] +[global Kernel_Stack_Top] ALIGN 0x1000 times 1024 dd 0 -_Kernel_Stack_Top: +Kernel_Stack_Top: