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.

168 lines
2.8 KiB

  1. title "Amd64 startup"
  2. ;++
  3. ;
  4. ; Copyright (c) 2001 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; xmstub.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements the code that starts secondary processors. This
  13. ; module is unique in that it is assembled by the i386 32-bit assembler,
  14. ; because the Amd64 assembler does not assemble 16- or 32-bit x86 code.
  15. ;
  16. ; The .obj file that is the result of assembling this module is fed
  17. ; through a tool, DMPOBJ.EXE, that stores the contents of the relevant
  18. ; section and generates a c file (startup.c) that can be included in the
  19. ; 64-bit compilation process.
  20. ;
  21. ; Author:
  22. ;
  23. ; Forrest Foltz (forrestf) March 6, 2001
  24. ;
  25. ; Environment:
  26. ;
  27. ; Kernel mode only.
  28. ;
  29. ; Revision History:
  30. ;
  31. ;--
  32. .586p
  33. include ksamd64.inc
  34. RMSTUB SEGMENT DWORD PUBLIC USE16 'CODE'
  35. ;++
  36. ;
  37. ; VOID
  38. ; StartPx_RMStub
  39. ;
  40. ; When a new processor is started, it starts in real mode and is sent to a
  41. ; copy of this function which resides in low (<1MB) memory.
  42. ;
  43. ; When this function is complete, it jumps to StartPx_PMStub.
  44. ;
  45. ; Arguments:
  46. ; None
  47. ;
  48. ; Return Value:
  49. ; Does not return, jumps to StartPx_PMStub
  50. ;--
  51. StartPx_RMStub:
  52. jmp spr10 ; skip the processor start block
  53. db (ProcessorStartBlockLength - ($ - StartPx_RMStub)) dup (0)
  54. spr10: cli
  55. mov ax, cs
  56. mov ds, ax
  57. ;
  58. ; Load the 32-bit GDT.
  59. ;
  60. db 066h
  61. lgdt fword ptr ds:[PsbGdt32]
  62. ;
  63. ; Load edi with the linear address of the processor start block.
  64. ;
  65. sub eax, eax
  66. mov ax, ds
  67. shl eax, 4
  68. mov edi, eax
  69. ;
  70. ; Enter protected mode. Note paging is still off.
  71. ;
  72. mov eax, cr0
  73. or eax, CR0_PE OR CR0_ET
  74. mov cr0, eax
  75. ;
  76. ; Load CS by performing a far jump to the protected mode target
  77. ; address
  78. ;
  79. db 066h
  80. jmp DWORD PTR ds:[PsbPmTarget]
  81. RMSTUB ENDS
  82. ;++
  83. ;
  84. ; VOID
  85. ; StartPx_PMStub
  86. ;
  87. ; When a new processor is started, it starts in real mode and is sent to a
  88. ; copy of this function which resides in low (<1MB) memory.
  89. ;
  90. ; When this function is complete, it jumps to StartPx_PMStub.
  91. ;
  92. ; Arguments:
  93. ; None
  94. ;
  95. ; Return Value:
  96. ; Does not return, jumps to StartPx_LMStub
  97. ;--
  98. PMSTUB SEGMENT PARA PUBLIC 'CODE'
  99. StartPx_PMStub:
  100. ;
  101. ; 32-bit protected-mode boot code goes here. We are still executing
  102. ; the low-memory, identity-mapped copy of this code.
  103. ;
  104. ; edi -> linear address of PROCESSOR_START_BLOCK
  105. ;
  106. ;
  107. ; Enable PAE mode (requisite for LongMode), load the tiled CR3
  108. ;
  109. mov eax, cr4
  110. or eax, CR4_PAE
  111. mov cr4, eax
  112. mov eax, DWORD PTR [edi] + PsbTiledCr3
  113. mov cr3, eax
  114. ;
  115. ; Set the long mode enable bit in the EFER msr
  116. ;
  117. mov ecx, MSR_EFER
  118. rdmsr
  119. or eax, MSR_LMA
  120. wrmsr
  121. ;
  122. ; Enable paging and activate long mode
  123. ;
  124. mov eax, cr0
  125. or eax, CR0_PG
  126. mov cr0, eax
  127. ;
  128. ; Still in 32-bit legacy mode until we branch to a long mode
  129. ; code selector
  130. ;
  131. jmp FAR PTR [edi] + PsbLmTarget
  132. PMSTUB ENDS
  133. END