Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

311 lines
8.2 KiB

  1. title "MP primitives for MP+AT Systems"
  2. ;++
  3. ;
  4. ;Copyright (c) 1991 Microsoft Corporation
  5. ;Copyright (c) 1992 Intel Corporation
  6. ;All rights reserved
  7. ;
  8. ;INTEL CORPORATION PROPRIETARY INFORMATION
  9. ;
  10. ;This software is supplied to Microsoft under the terms
  11. ;of a license agreement with Intel Corporation and may not be
  12. ;copied nor disclosed except in accordance with the terms
  13. ;of that agreement.
  14. ;
  15. ;
  16. ;Module Name:
  17. ;
  18. ; mpsproca.asm
  19. ;
  20. ;Abstract:
  21. ;
  22. ; PC+MP Start Next Processor assemble code
  23. ;
  24. ; This module along with mpspro.c implement the code to start
  25. ; processors on MP+AT Systems.
  26. ;
  27. ;Author:
  28. ;
  29. ; Ken Reneris (kenr) 12-Jan-1992
  30. ;
  31. ;Revision History:
  32. ;
  33. ; Ron Mosgrove (Intel) - Modified to support PC+MP Systems
  34. ;
  35. ;--
  36. .386p
  37. .xlist
  38. include i386\ixcmos.inc
  39. include hal386.inc
  40. include callconv.inc ; calling convention macros
  41. include i386\kimacro.inc
  42. include mac386.inc
  43. include apic.inc
  44. include ntapic.inc
  45. include i386\ixslpctx.inc
  46. .list
  47. ifndef NT_UP
  48. EXTRNP _HalpBuildTiledCR3,1
  49. EXTRNP _HalpFreeTiledCR3,0
  50. EXTRNP _HalpStartProcessor,2
  51. endif
  52. EXTRNP _HalpAcquireCmosSpinLock
  53. EXTRNP _HalpReleaseCmosSpinLock
  54. EXTRNP _HalDisplayString,1
  55. EXTRNP _StartPx_BuildRealModeStart,1
  56. EXTRNP _KeStallExecutionProcessor, 1
  57. extrn _Halp1stPhysicalPageVaddr:DWORD
  58. extrn _HalpLowStub:DWORD
  59. extrn _HalpLowStubPhysicalAddress:DWORD
  60. extrn _HalpHiberInProgress:BYTE
  61. extrn _CurTiledCr3LowPart:DWORD
  62. ;
  63. ; Internal defines and structures
  64. ;
  65. WarmResetVector equ 467h ; warm reset vector in ROM data segment
  66. PAGELK SEGMENT PARA PUBLIC 'CODE' ; Start 32 bit code
  67. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  68. ;++
  69. ;
  70. ; BOOLEAN
  71. ; HalStartNextProcessor (
  72. ; IN PLOADER_BLOCK pLoaderBlock,
  73. ; IN PKPROCESSOR_STATE pProcessorState
  74. ; )
  75. ;
  76. ; Routine Description:
  77. ;
  78. ; This routine is called by the kernel durning kernel initialization
  79. ; to obtain more processors. It is called until no more processors
  80. ; are available.
  81. ;
  82. ; If another processor exists this function is to initialize it to
  83. ; the passed in processorstate structure, and return TRUE.
  84. ;
  85. ; If another processor does not exists or if the processor fails to
  86. ; start, then a FALSE is returned.
  87. ;
  88. ; Also note that the loader block has been setup for the next processor.
  89. ; The new processor logical thread number can be obtained from it, if
  90. ; required.
  91. ;
  92. ; In order to use the Startup IPI the real mode startup code must be
  93. ; page aligned. The HalpLowStubPhysicalAddress has always been page
  94. ; aligned but because the PxParamBlock was placed first in this
  95. ; segment the real mode code has been something other than page aligned.
  96. ; This has been changed by making the first entry in the PxParamBlock
  97. ; a jump instruction to the real mode startup code.
  98. ;
  99. ; Arguments:
  100. ; pLoaderBlock, - Loader block which has been intialized for the
  101. ; next processor.
  102. ;
  103. ; pProcessorState - The processor state which is to be loaded into
  104. ; the next processor.
  105. ;
  106. ;
  107. ; Return Value:
  108. ;
  109. ; TRUE - ProcessorNumber was dispatched.
  110. ; FALSE - A processor was not dispatched. no other processors exists.
  111. ;
  112. ;--
  113. pLoaderBlock equ dword ptr [ebp+8] ; zero based
  114. pProcessorState equ dword ptr [ebp+12]
  115. ;
  116. ; Local variables
  117. ;
  118. PxFrame equ [ebp - size PxParamBlock]
  119. LWarmResetVector equ [ebp - size PxParamBlock - 4]
  120. LStatusCode equ [ebp - size PxParamBlock - 8]
  121. LCmosValue equ [ebp - size PxParamBlock - 12]
  122. Prcb equ [ebp - size PxParamBlock - 16]
  123. cPublicProc _HalStartNextProcessor ,2
  124. ifdef NT_UP
  125. xor eax, eax ; up build of hal, no processors to
  126. stdRET _HalStartNextProcessor ; start
  127. else
  128. push ebp ; save ebp
  129. mov ebp, esp ; Save Frame
  130. sub esp, size PxParamBlock + 16 ; Make room for local vars
  131. push esi ; Save required registers
  132. push edi
  133. push ebx
  134. pushfd
  135. xor eax, eax
  136. mov LStatusCode, eax
  137. mov PxFrame.SPx_flag, eax ; Initialize the flags
  138. ;
  139. ; Copy Processor state into the stack based Parameter Block
  140. ;
  141. lea edi, PxFrame.SPx_PB ; Destination on stack
  142. mov esi, pProcessorState ; Input parameter address
  143. mov ecx, ProcessorStateLength ; Structure length
  144. rep movsb
  145. ;
  146. ; Build a CR3 for the starting processor. If returning
  147. ; from hibernation, then use setup tiled CR3 else
  148. ; create a new map
  149. ;
  150. mov al, _HalpHiberInProgress
  151. or al, al
  152. jz Hpsnp_Hiber
  153. mov eax, _CurTiledCr3LowPart
  154. jmp Hpsnp_TiledCr3_done
  155. Hpsnp_Hiber:
  156. stdCall _HalpBuildTiledCR3, <pProcessorState>
  157. Hpsnp_TiledCr3_done:
  158. ;
  159. ; Save the special registers
  160. ;
  161. mov PxFrame.SPx_TiledCR3, eax ; Newly contructed CR3
  162. mov PxFrame.SPx_P0EBP, ebp ; Stack pointer
  163. lea eax, PxFrame
  164. stdCall _StartPx_BuildRealModeStart, <eax>
  165. ;
  166. ; Set the BIOS warm reset vector to our routine in Low Memory
  167. ;
  168. mov ebx, _Halp1stPhysicalPageVaddr
  169. add ebx, WarmResetVector
  170. cli
  171. mov eax, [ebx] ; Get current vector
  172. mov LWarmResetVector, eax ; Save it
  173. ;
  174. ; Actually build the vector (Seg:Offset)
  175. ;
  176. mov eax, _HalpLowStubPhysicalAddress
  177. shl eax, 12 ; seg:0
  178. mov dword ptr [ebx], eax ; start Px at Seg:0
  179. ;
  180. ; Tell BIOS to Jump Via The Vector we gave it
  181. ; By setting the Reset Code in CMOS
  182. ;
  183. stdCall _HalpAcquireCmosSpinLock
  184. mov al, 0fh
  185. CMOS_READ
  186. mov LCmosValue, eax
  187. mov eax, 0a0fh
  188. CMOS_WRITE
  189. stdCall _HalpReleaseCmosSpinLock
  190. ;
  191. ; Start the processor
  192. ;
  193. mov eax, pLoaderBlock ; lookup processor # we are
  194. mov eax, [eax].LpbPrcb ; starting
  195. mov Prcb, eax ; save this away for later
  196. movzx eax, byte ptr [eax].PbNumber
  197. stdCall _HalpStartProcessor < _HalpLowStubPhysicalAddress, eax >
  198. or eax, eax
  199. jnz short WaitTilPnOnline
  200. ;
  201. ; Zero Return Value means couldn't kick start the processor
  202. ; so there's no point in waiting for it.
  203. ;
  204. jmp NotWaitingOnProcessor
  205. WaitTilPnOnline:
  206. dec eax ; Local APIC ID
  207. mov ecx, Prcb
  208. mov [ecx].PbHalReserved.PrcbPCMPApicID, al
  209. ;
  210. ; We can't proceed until the started processor gives us the OK
  211. ;
  212. mov edi, 200
  213. mov esi, _HalpLowStub
  214. WaitAbit:
  215. test [esi].SPx_flag, SPX_FLAG_STARTED ; wait for Px to get it's
  216. jne short ProcessorStarted ; info
  217. stdCall _KeStallExecutionProcessor, <2000>
  218. dec edi
  219. cmp edi, 0
  220. jne short WaitAbit
  221. jmp short NotWaitingOnProcessor
  222. ProcessorStarted:
  223. mov LStatusCode, 1 ; Return TRUE
  224. mov ecx, Prcb ; save this away for later
  225. movzx ecx, byte ptr [ecx].PbNumber
  226. NotWaitingOnProcessor:
  227. mov al, _HalpHiberInProgress
  228. or al, al
  229. jnz short Hpsnp_ResetVector
  230. stdCall _HalpFreeTiledCR3 ; free memory used for tiled CR3
  231. Hpsnp_ResetVector:
  232. mov eax, LWarmResetVector
  233. mov [ebx], eax ; Restore reset vector
  234. stdCall _HalpAcquireCmosSpinLock
  235. mov eax, LCmosValue ; Restore the Cmos setting
  236. shl eax, 8
  237. mov al, 0fh
  238. CMOS_WRITE
  239. stdCall _HalpReleaseCmosSpinLock
  240. mov eax, LStatusCode
  241. snp_exit:
  242. popfd
  243. pop ebx
  244. pop edi
  245. pop esi
  246. mov esp, ebp
  247. pop ebp
  248. stdRET _HalStartNextProcessor
  249. endif
  250. stdENDP _HalStartNextProcessor
  251. PAGELK ends ; end 32 bit code
  252. end