1 ;------------------------------------------------------------------------------ 2 ; IA32 assembly file for AP startup vector. 3 ; 4 ; Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR> 5 ; This program and the accompanying materials 6 ; are licensed and made available under the terms and conditions of the BSD License 7 ; which accompanies this distribution. The full text of the license may be found at 8 ; http://opensource.org/licenses/bsd-license.php 9 ; 10 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 ; 13 ;------------------------------------------------------------------------------ 14 15 .686p 16 .model flat 17 .code 18 19 include AsmInclude.inc 20 ;------------------------------------------------------------------------------------- 21 FJMP32 MACRO Selector, Offset 22 DB 066h 23 DB 067h 24 DB 0EAh ; far jump 25 DD Offset ; 32-bit offset 26 DW Selector ; 16-bit selector 27 ENDM 28 29 ;------------------------------------------------------------------------------------- 30 ;RendezvousFunnelProc procedure follows. All APs execute their procedure. This 31 ;procedure serializes all the AP processors through an Init sequence. It must be 32 ;noted that APs arrive here very raw...ie: real mode, no stack. 33 ;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC 34 ;IS IN MACHINE CODE. 35 ;------------------------------------------------------------------------------------- 36 ;RendezvousFunnelProc (&WakeUpBuffer,MemAddress); 37 38 RendezvousFunnelProc PROC near C PUBLIC 39 RendezvousFunnelProcStart:: 40 41 42 ; At this point CS = 0x(vv00) and ip= 0x0. 43 44 db 8ch, 0c8h ; mov ax, cs 45 db 8eh, 0d8h ; mov ds, ax 46 db 8eh, 0c0h ; mov es, ax 47 db 8eh, 0d0h ; mov ss, ax 48 db 33h, 0c0h ; xor ax, ax 49 db 8eh, 0e0h ; mov fs, ax 50 db 8eh, 0e8h ; mov gs, ax 51 52 ; Switch to flat mode. 53 54 db 0BEh 55 dw BufferStart ; mov si, BufferStart 56 db 66h, 8Bh, 0Ch ; mov ecx,dword ptr [si] ; ECX is keeping the start address of wakeup buffer 57 58 db 0FAh ; cli 59 db 0BEh 60 dw GdtrProfile ; mov si, GdtrProfile 61 db 66h ; db 66h 62 db 2Eh,0Fh, 01h, 14h ; lgdt fword ptr cs:[si] 63 64 db 0BEh 65 dw IdtrProfile ; mov si, IdtrProfile 66 db 66h ; db 66h 67 db 2Eh,0Fh, 01h, 1Ch ; lidt fword ptr cs:[si] 68 69 db 33h, 0C0h ; xor ax, ax 70 db 8Eh, 0D8h ; mov ds, ax 71 db 0Fh, 20h, 0C0h ; mov eax, cr0 ; Get control register 0 72 db 66h, 83h, 0C8h, 01h ; or eax, 000000001h ; Set PE bit (bit #0) 73 db 0Fh, 22h, 0C0h ; mov cr0, eax 74 75 76 FLAT32_JUMP:: 77 FJMP32 010h,0h ; Far jmp using code segment descriptor 78 79 ProtectedModeStart:: ; protected mode entry point 80 81 mov ax, 8h 82 mov ds, ax 83 mov es, ax 84 mov fs, ax 85 mov gs, ax 86 mov ss, ax ; Flat mode setup. 87 88 ; 89 ; ProgramStack 90 ; 91 mov ecx, 1bh ; Read IA32_APIC_BASE MSR 92 rdmsr 93 94 bt eax, 10 ; Check for x2apic mode 95 jnc LegacyApicMode 96 mov ecx, 802h ; Read APIC_ID 97 rdmsr 98 mov ebx, eax ; ebx == apicid 99 jmp GetCpuNumber 100 101 LegacyApicMode:: 102 103 and eax, 0fffff000h 104 add eax, 20h 105 mov ebx, dword ptr [eax] 106 shr ebx, 24 ; ebx == apicid 107 108 GetCpuNumber:: 109 110 xor ecx, ecx 111 mov edi, esi 112 add edi, ProcessorNumber 113 mov ecx, dword ptr [edi + 4 * ebx] ; ECX = CpuNumber 114 115 mov edi, esi 116 add edi, StackSize 117 mov eax, dword ptr [edi] 118 inc ecx 119 mul ecx ; EAX = StackSize * (CpuNumber + 1) 120 121 mov edi, esi 122 add edi, StackStart 123 mov ebx, dword ptr [edi] 124 add eax, ebx ; EAX = StackStart + StackSize * (CpuNumber + 1) 125 126 mov esp, eax 127 128 ; 129 ; Call C Function 130 ; 131 mov edi, esi 132 add edi, RendezvousProc 133 mov ebx, dword ptr [edi] 134 135 test ebx, ebx 136 jz GoToSleep 137 call ebx ; Call C function 138 139 GoToSleep:: 140 141 cli 142 hlt 143 jmp $-2 144 145 RendezvousFunnelProc ENDP 146 RendezvousFunnelProcEnd:: 147 ;------------------------------------------------------------------------------------- 148 ; AsmGetAddressMap (&AddressMap); 149 ;------------------------------------------------------------------------------------- 150 AsmGetAddressMap PROC near C PUBLIC 151 152 pushad 153 mov ebp,esp 154 155 mov ebx, dword ptr [ebp+24h] 156 mov dword ptr [ebx], RendezvousFunnelProcStart 157 mov dword ptr [ebx+4h], ProtectedModeStart - RendezvousFunnelProcStart 158 mov dword ptr [ebx+8h], FLAT32_JUMP - RendezvousFunnelProcStart 159 mov dword ptr [ebx+0ch], 0 160 mov dword ptr [ebx+10h], 0 161 mov dword ptr [ebx+14h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart 162 163 popad 164 ret 165 AsmGetAddressMap ENDP 166 167 END 168