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.

215 lines
5.8 KiB

  1. title "Processor type and stepping detection"
  2. ;++
  3. ;
  4. ; Copyright (c) 1989 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; main.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This file implements the main entry code for x86 hardware detection
  13. ; module. This assembly file is required in order to link C modules
  14. ; into a "/TINY" (single segment) memory module.
  15. ;
  16. ; Author:
  17. ;
  18. ; Shie-Lin Tzong (shielint) 15-Feb-1992.
  19. ; The code is extracted from NTLDR su.asm.
  20. ;
  21. ; Environment:
  22. ;
  23. ; x86 Real Mode.
  24. ;
  25. ; Revision History:
  26. ;
  27. ;
  28. ; Build Notes:
  29. ; ~~~~~~~~~~~~
  30. ; The microsoft C compiler will not produce "tiny" model programs. In the
  31. ; tiny model, the entire program consists of only one segment. The small
  32. ; model produced by our compilers consists of two segments: DGROUP and _TEXT.
  33. ; If you convert a small model program into a tiny model program, DS (which
  34. ; should point to DGROUP (bss,const,data) will always be wrong. For this reason
  35. ; we need an assembly module to do a simple run-time fixup on SS and DS. To
  36. ; guarantee that DS will point to DGROUP no matter where the detection module
  37. ; is loaded, the paragraph (shifted right four bits) offset of DGROUP from
  38. ; _TEXT must be added to the value in CS to compute DS and SS.
  39. ;
  40. ; We get the linker to fixup the offset of the beginning of the dgroup segment
  41. ; relative to the beginning of the code segment and it's this value added
  42. ; to the value in CS that allows us to build a "tiny" model program in C
  43. ; without a lot of munging around in order to get the data reference offsets
  44. ; in the code correct.
  45. ;
  46. ; If the _TEXT:DGROUP fixup appears in other files (which it does), the linker
  47. ; will not compute the correct value unless the accumulated data pointer is
  48. ; zero when it gets there. Therefore, no data should be placed in the data segment
  49. ; until after all instances of _TEXT:DGROUP have been encountered by the linker.
  50. ; The linker processes files from right to left on the command line.
  51. ;
  52. ;--
  53. .386p
  54. include main.inc
  55. _DATA SEGMENT PARA USE16 PUBLIC 'DATA'
  56. ;
  57. ; Define double wrod to save caller's (ntldr's) stack pointer
  58. ;
  59. NtldrStack df 0 ; saved area for ss:esp
  60. dw 2048 dup (0)
  61. DetectionStack equ $
  62. _DATA ends
  63. _TEXT segment para use16 public 'CODE'
  64. ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP
  65. ;++
  66. ;
  67. ; VOID
  68. ; DetectionMain (
  69. ; ULONG HeapStart,
  70. ; ULONG HeapSize,
  71. ; ULONG ConfigurationTree,
  72. ; ULONG HeapUsed,
  73. ; ULONG LoadOptions,
  74. ; ULONG LoadOptionsLength
  75. ; )
  76. ;
  77. ; Routine Description:
  78. ;
  79. ; This is the entry point of the detection module.
  80. ; Memory from HeapStart to (HeapStart + HeapSize) is allocated for detection
  81. ; module to store the hardware configuration tree.
  82. ; Note that detection module loaded address will be resued by loader after
  83. ; the control is passed back to ntldr.
  84. ;
  85. ; Arguments:
  86. ;
  87. ; HeapStart - supplies a 32 bit FLAT starting addr of the heap
  88. ;
  89. ; HeapSize - Supplies the size of the useable heap
  90. ;
  91. ; ConfigurationTree - Supplies a 32 bit FLAT address of the variable to
  92. ; receive the configuration tree.
  93. ;
  94. ; HeapUsed - Supplies a 32 bit FLAT address of the variable to receive
  95. ; the size of heap we acually used.
  96. ;
  97. ; LoadOptions - Supplies a 32 bit FLAT address of the load options string.
  98. ;
  99. ; LoadOptionsLength - Supplies the length of the LoadOptions string. Note,
  100. ; this is for sanity check to make sure the LoadOptions string is valid.
  101. ; (in case use usews Nt 1.0 ntldr with the new ntdetect.com.)
  102. ;
  103. ; Return Value:
  104. ;
  105. ; None.
  106. ;
  107. ;--
  108. ;
  109. ;
  110. ; Run-time fixups for stack and data segment
  111. ;
  112. public DetectionMain
  113. DetectionMain:
  114. ;
  115. ; Save all the registers we need to preserved on NTLDR's stack
  116. ;
  117. push ebp
  118. mov ebp, esp
  119. and ebp, 0ffffh
  120. push ds
  121. push es
  122. push ebx
  123. push esi
  124. push edi
  125. ;
  126. ; Compute the paragraph needed for DS
  127. ;
  128. mov cx,offset _TEXT:DGROUP ; first calculate offset to data
  129. shr cx,4 ; must be para aligned
  130. mov ax,cs ; get base of code
  131. add ax,cx ; add paragraph offset to data
  132. ;
  133. ; Make DS point to the paragraph address of DGROUP
  134. ;
  135. mov ds,ax ; ds now points to beginning of DGROUP
  136. mov es,ax
  137. ;
  138. ; Save old stack pointer and set up our own stack.
  139. ;
  140. mov ecx, esp
  141. mov dword ptr NtldrStack, ecx
  142. mov cx, ss
  143. mov word ptr NtldrStack + 4, cx
  144. mov ebx, [bp + 8] ; [ebx] = Heap Start
  145. mov ecx, [bp + 12] ; [ecx] = Heap Size
  146. mov esi, [bp + 16] ; [esi] -> addr of ConfigurationTree
  147. mov edi, [bp + 20] ; [edi] -> Addr of HeapUsed variable
  148. mov edx, [bp + 24] ; [edx]-> Addr of LoadOptions string
  149. mov ebp, [bp + 28] ; [ebp] = length of LoadOptions
  150. mov ss,ax
  151. mov esp,offset DGROUP:DetectionStack ; (ss:esp) = top of internal stack
  152. ;
  153. ; Set up parameters and invoke real detection code to collect hardware
  154. ; information.
  155. ;
  156. push ebp
  157. push edx
  158. push edi
  159. push esi
  160. push ecx
  161. push ebx
  162. xor eax, eax
  163. xor ebx, ebx
  164. xor ecx, ecx
  165. xor edx, edx
  166. xor esi, esi
  167. xor edi, edi
  168. call _HardwareDetection
  169. ;
  170. ; The hardware detection is done. We need to switch to ntldr's stack,
  171. ; restore registers and return back to ntldr.
  172. ;
  173. lss esp, NtldrStack
  174. pop edi ; retore registers
  175. pop esi
  176. pop ebx
  177. pop es
  178. pop ds
  179. pop ebp
  180. retf
  181. _TEXT ends
  182. end DetectionMain