Source code of Windows XP (NT5)
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.

373 lines
11 KiB

  1. title "MP primitives for Compaq SystemPro"
  2. ;++
  3. ;
  4. ;Copyright (c) 1991 Microsoft Corporation
  5. ;
  6. ;Module Name:
  7. ;
  8. ; spsproca.asm
  9. ;
  10. ;Abstract:
  11. ;
  12. ; SystemPro Start Next Processor assemble code
  13. ;
  14. ; This module along with mpspro.c implement the code to start
  15. ; off the second processor on the Compaq SystemPro.
  16. ;
  17. ;Author:
  18. ;
  19. ; Ken Reneris (kenr) 12-Jan-1992
  20. ;
  21. ;Revision History:
  22. ;
  23. ;--
  24. .386p
  25. .xlist
  26. include hal386.inc
  27. include callconv.inc ; calling convention macros
  28. include i386\kimacro.inc
  29. include mac386.inc
  30. include i386\spmp.inc
  31. .list
  32. EXTRNP _HalpBuildTiledCR3,1
  33. EXTRNP _HalpFreeTiledCR3,0
  34. extrn _MppIDT:DWORD
  35. extrn _MpLowStub:DWORD
  36. extrn _MpLowStubPhysicalAddress:DWORD
  37. extrn _MpCount:DWORD
  38. extrn _SpProcessorControlPort:WORD
  39. extrn _SpType:BYTE
  40. ;
  41. ; Internal defines and structures
  42. ;
  43. PxParamBlock struc
  44. SPx_flag dd ?
  45. SPx_TiledCR3 dd ?
  46. SPx_P0EBP dd ?
  47. SPx_ControlPort dd ?
  48. SPx_PB db processorstatelength dup (?)
  49. PxParamBlock ends
  50. _TEXT SEGMENT PARA PUBLIC 'CODE' ; Start 32 bit code
  51. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  52. ;++
  53. ;
  54. ; BOOLEAN
  55. ; HalStartNextProcessor (
  56. ; IN PLOADER_BLOCK pLoaderBlock,
  57. ; IN PKPROCESSOR_STATE pProcessorState
  58. ; )
  59. ;
  60. ; Routine Description:
  61. ;
  62. ; This routine is called by the kernel durning kernel initialization
  63. ; to obtain more processors. It is called until no more processors
  64. ; are available.
  65. ;
  66. ; If another processor exists this function is to initialize it to
  67. ; the passed in processorstate structure, and return TRUE.
  68. ;
  69. ; If another processor does not exists, then a FALSE is returned.
  70. ;
  71. ; Also note that the loader block has been setup for the next processor.
  72. ; The new processor logical thread number can be obtained from it, if
  73. ; required.
  74. ;
  75. ; Arguments:
  76. ; pLoaderBlock, - Loader block which has been intialized for the
  77. ; next processor.
  78. ;
  79. ; pProcessorState - The processor state which is to be loaded into
  80. ; the next processor.
  81. ;
  82. ;
  83. ; Return Value:
  84. ;
  85. ; TRUE - ProcessorNumber was dispatched.
  86. ; FALSE - A processor was not dispatched. no other processors exists.
  87. ;
  88. ;--
  89. pLoaderBlock equ dword ptr [ebp+8] ; zero based
  90. pProcessorState equ dword ptr [ebp+12]
  91. ;
  92. ; Local variables
  93. ;
  94. PxFrame equ [ebp - size PxParamBlock]
  95. cPublicProc _HalStartNextProcessor ,2
  96. push ebp ; save ebp
  97. mov ebp, esp ;
  98. sub esp, size PxParamBlock ; Make room for local vars
  99. push esi
  100. push edi
  101. push ebx
  102. xor eax, eax
  103. mov PxFrame.SPx_flag, eax
  104. cmp _MpCount, eax
  105. jbe snp_exit ; exit FALSE
  106. mov esi, OFFSET FLAT:StartPx_RMStub
  107. mov ecx, StartPx_RMStub_Len
  108. mov edi, _MpLowStub ; Copy RMStub to low memory
  109. add edi, size PxParamBlock
  110. rep movsb
  111. lea edi, PxFrame.SPx_PB
  112. mov esi, pProcessorState
  113. mov ecx, processorstatelength ; Copy processorstate
  114. rep movsb ; to PxFrame
  115. stdCall _HalpBuildTiledCR3, <pProcessorState>
  116. mov PxFrame.SPx_TiledCR3, eax
  117. mov PxFrame.SPx_P0EBP, ebp
  118. mov eax, pLoaderBlock ; lookup processor # we are
  119. mov eax, [eax].LpbPrcb ; starting
  120. movzx eax, byte ptr [eax].PbNumber
  121. movzx edx, _SpProcessorControlPort[eax*2] ; Get processor's control port
  122. mov PxFrame.SPx_ControlPort, edx ; Pass it along
  123. mov ecx, size PxParamBlock ; copy param block
  124. lea esi, PxFrame ; to low memory stub
  125. mov edi, _MpLowStub
  126. mov eax, edi
  127. rep movsb
  128. add eax, size PxParamBlock
  129. mov ebx, OFFSET FLAT:StartPx_RMStub
  130. sub eax, ebx ; (eax) = adjusted pointer
  131. mov bx, word ptr [PxFrame.SPx_PB.PsContextFrame.CsSegCs]
  132. mov [eax.SPrxFlatCS], bx ; patch realmode stub with
  133. mov [eax.SPrxPMStub], offset _StartPx_PMStub ; valid long jump
  134. mov ebx, _MppIDT
  135. add ebx, WarmResetVector
  136. cli
  137. push dword ptr [ebx] ; Save current vector
  138. mov eax, _MpLowStubPhysicalAddress
  139. shl eax, 12 ; seg:0
  140. add eax, size PxParamBlock
  141. mov dword ptr [ebx], eax ; start Px here
  142. cmp _SpType, SMP_SYSPRO2 ; Belize?
  143. jne short snp10 ; no, reset normal
  144. mov dx, SMP_INDEX_PORT
  145. mov eax, pLoaderBlock ; lookup processor # we are
  146. mov eax, [eax].LpbPrcb ; starting
  147. movzx eax, byte ptr [eax].PbNumber
  148. or eax, (SMP_RESET_CPU shl 24) + (SMP_CSR_PORT shl 8)
  149. out dx, eax ; issue Belize reset to processor
  150. jmp short snp20 ; go wait
  151. snp10:
  152. mov edx, PxFrame.SPx_ControlPort ; Control port of target
  153. in al, dx ; processor
  154. or al, RESET ; assert RESET
  155. and al, NOT SLEEP ; wakeup P1
  156. out dx, al ; reset P1
  157. snp20: cmp PxFrame.SPx_flag, 0 ; wait for Px to get it's
  158. jz snp20 ; info
  159. pop dword ptr [ebx] ; restore WarmResetVector
  160. sti
  161. stdCall _HalpFreeTiledCR3 ; free memory used for tiled
  162. ; CR3
  163. dec _MpCount ; one less
  164. mov eax, 1 ; return TRUE
  165. snp_exit:
  166. pop ebx
  167. pop edi
  168. pop esi
  169. mov esp, ebp
  170. pop ebp
  171. stdRET _HalStartNextProcessor
  172. stdENDP _HalStartNextProcessor
  173. _TEXT ends ; end 32 bit code
  174. _TEXT16 SEGMENT DWORD PUBLIC USE16 'CODE' ; start 16 bit code
  175. ;++
  176. ;
  177. ; VOID
  178. ; StartPx_RMStub
  179. ;
  180. ; Routine Description:
  181. ;
  182. ; When a new processor is started, it starts in real-mode and is
  183. ; sent to a copy of this function which has been copied into low memory.
  184. ; (below 1m and accessable from real-mode).
  185. ;
  186. ; Once CR0 has been set, this function jmp's to a StartPx_PMStub
  187. ;
  188. ; Arguments:
  189. ; none
  190. ;
  191. ; Return Value:
  192. ; does not return, jumps to StartPx_PMStub
  193. ;
  194. ;--
  195. cPublicProc StartPx_RMStub ,0
  196. cli
  197. db 066h ; load the GDT
  198. lgdt fword ptr cs:[SPx_PB.PsSpecialRegisters.SrGdtr]
  199. db 066h ; load the IDT
  200. lidt fword ptr cs:[SPx_PB.PsSpecialRegisters.SrIdtr]
  201. mov eax, cs:[SPx_TiledCR3]
  202. mov cr3, eax
  203. mov ebp, dword ptr cs:[SPx_P0EBP]
  204. mov ecx, dword ptr cs:[SPx_PB.PsContextFrame.CsSegDs]
  205. mov ebx, dword ptr cs:[SPx_PB.PsSpecialRegisters.SrCr3]
  206. mov eax, dword ptr cs:[SPx_PB.PsSpecialRegisters.SrCr0]
  207. mov cr0, eax ; into prot mode
  208. db 066h
  209. db 0eah ; reload cs:eip
  210. SPrxPMStub dd 0
  211. SPrxFlatCS dw 0
  212. StartPx_RMStub_Len equ $ - StartPx_RMStub
  213. stdENDP StartPx_RMStub
  214. _TEXT16 ends ; End 16 bit code
  215. _TEXT SEGMENT ; Start 32 bit code
  216. ;++
  217. ;
  218. ; VOID
  219. ; StartPx_PMStub
  220. ;
  221. ; Routine Description:
  222. ;
  223. ; This function completes the processor's state loading, and signals
  224. ; the requesting processor that the state has been loaded.
  225. ;
  226. ; Arguments:
  227. ; ebx - requested CR3 for this processors_state
  228. ; cx - requested ds for this processors_state
  229. ; ebp - EBP of P0
  230. ;
  231. ; Return Value:
  232. ; does not return - completes the loading of the processors_state
  233. ;
  234. ;--
  235. align 16 ; to make sure we don't cross a page boundry
  236. ; before reloading CR3
  237. cPublicProc _StartPx_PMStub ,0
  238. ; process is now in the load image copy of this function.
  239. ; (ie, it's not the low memory copy)
  240. mov cr3, ebx ; get real CR3
  241. mov ds, cx ; set real ds
  242. lea esi, PxFrame.SPx_PB.PsSpecialRegisters
  243. lldt word ptr ds:[esi].SrLdtr ; load ldtr
  244. ltr word ptr ds:[esi].SrTr ; load tss
  245. lea edi, PxFrame.SPx_PB.PsContextFrame
  246. mov es, word ptr ds:[edi].CsSegEs ; Set other selectors
  247. mov fs, word ptr ds:[edi].CsSegFs
  248. mov gs, word ptr ds:[edi].CsSegGs
  249. mov ss, word ptr ds:[edi].CsSegSs
  250. add esi, SrKernelDr0
  251. .errnz (SrKernelDr1 - SrKernelDr0 - 1 * 4)
  252. .errnz (SrKernelDr2 - SrKernelDr0 - 2 * 4)
  253. .errnz (SrKernelDr3 - SrKernelDr0 - 3 * 4)
  254. .errnz (SrKernelDr6 - SrKernelDr0 - 4 * 4)
  255. .errnz (SrKernelDr7 - SrKernelDr0 - 5 * 4)
  256. lodsd
  257. mov dr0, eax ; load dr0-dr7
  258. lodsd
  259. mov dr1, eax
  260. lodsd
  261. mov dr2, eax
  262. lodsd
  263. mov dr3, eax
  264. lodsd
  265. mov dr6, eax
  266. lodsd
  267. mov dr7, eax
  268. mov esp, dword ptr ds:[edi].CsEsp
  269. mov esi, dword ptr ds:[edi].CsEsi
  270. mov ecx, dword ptr ds:[edi].CsEcx
  271. push dword ptr ds:[edi].CsEflags
  272. popfd ; load eflags
  273. push dword ptr ds:[edi].CsEip ; make a copy of remaining
  274. push dword ptr ds:[edi].CsEax ; registers which need
  275. push dword ptr ds:[edi].CsEbx ; loaded
  276. push dword ptr ds:[edi].CsEdx
  277. push dword ptr ds:[edi].CsEdi
  278. push dword ptr ds:[edi].CsEbp
  279. cmp _SpType, SMP_SYSPRO2 ; Don't send old SP
  280. je short spxpm01 ; style Cache on enable
  281. ; eax, ebx, edx are still free
  282. mov edx, [PxFrame.SPx_ControlPort] ; our control port
  283. in al, dx ; Get register
  284. and al, NOT INTDIS ; allow PINTs on this proc
  285. or al, CACHEON ; turn cache on
  286. out dx, al
  287. spxpm01:
  288. inc [PxFrame.SPx_flag] ; Signal p0 that we are
  289. ; done with it's data
  290. ; Set remaining registers
  291. pop ebp
  292. pop edi
  293. pop edx
  294. pop ebx
  295. pop eax
  296. stdRET _StartPx_PMStub ; Set eip
  297. stdENDP _StartPx_PMStub
  298. _TEXT ends ; end 32 bit code
  299. end