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.

238 lines
5.7 KiB

  1. ;++
  2. ;
  3. ; File Name:
  4. ;
  5. ; macro.inc
  6. ;
  7. ; Author:
  8. ;
  9. ; Thomas Parslow [tomp]
  10. ;
  11. ; Created:
  12. ;
  13. ; 27-Feb-91
  14. ;
  15. ; Abstract:
  16. ;
  17. ; The macros used for creating the exported entry points the
  18. ; OS loader will use for basic h/w dependent services. These
  19. ; services are:
  20. ;
  21. ; o Disk I/O
  22. ; o Character I/O
  23. ;
  24. ;
  25. ;--
  26. ;++
  27. ;
  28. ; EXPORT_ENTRY_MACRO
  29. ; We arrive here from the OS loader with a 32bit CS. That is, we're
  30. ; executing the code with cs:eip where cs contains a selector for a
  31. ; 32bit flat segment. We want to get to a 16bit cs. That is, cs:ip.
  32. ; The entry points are exported as 32bit near pointers to the OS loader.
  33. ; All code in the SU module is identity mapped so the flat 32bit offset
  34. ; is equal to the physical address.
  35. ;
  36. ; Therefore, we export the 32bit physical address as the
  37. ; entry point and the code may be executed with either the 32bit
  38. ; flat cs or the SU module's 16bit based cs. Before we can switch
  39. ; modes we must load all of the segment registers with selectors for
  40. ; 16bit segments. We start by pushing a far pointer to a label in
  41. ; the macro and then doing a retf. This allows us to fall through
  42. ; to the next instruction, but we're now executing through cs:ip
  43. ; with a 16bit CS.
  44. ;
  45. ; Output:
  46. ;
  47. ; (ebx) = pointer to stack frame (and top of 32bit stack).
  48. ;
  49. EXPORT_ENTRY_MACRO macro entryname
  50. LOCAL exp1
  51. _TEXT32 segment para use32 public 'CODE'
  52. ASSUME CS:_TEXT32
  53. ALIGN 4
  54. Public EntryName
  55. EntryName LABEL near
  56. ;
  57. ; We've go a 32bit CS:EIP - go to a 16bit CS:IP
  58. push dword ptr SuCodeSelector
  59. push dword ptr (offset exp1)
  60. retf
  61. _TEXT32 ends
  62. ASSUME CS:_TEXT
  63. ALIGN 4
  64. exp1:
  65. ;
  66. ; Save caller's EBP register and stack pointer (ESP)
  67. ;
  68. push ebp
  69. push ebx
  70. push esi
  71. push edi
  72. mov ebx,esp
  73. ;
  74. ; Load all the segment registers with 16bit segment selectors
  75. ;
  76. mov ax,SuDataSelector
  77. mov ds,ax
  78. mov ss,ax
  79. ;
  80. ; Set the stack to the top of the segment. We can do this now since
  81. ; all of the OS loader's code has already be relocated. Also, we need
  82. ; plenty of stack since we'll be calling BIOS routines.
  83. ;
  84. mov sp,EXPORT_STACK
  85. push ebx ; save the caller's esp
  86. endm
  87. ;
  88. ; EXPORT_ENTRY_MACRO end
  89. ;
  90. ;++
  91. ;
  92. ; Name:
  93. ;
  94. ; ExportExit
  95. ;
  96. ; Arguments:
  97. ;
  98. ;
  99. ; Notes:
  100. ;
  101. ; EAX = return code and MUST be preserved by this macro.
  102. ;
  103. ;--
  104. EXPORT_EXIT_MACRO macro
  105. ;
  106. ; Next get caller's esp that we saved upon entry on the 16bit stack
  107. ;
  108. pop ebx ; get caller's esp
  109. ;
  110. ; Restore flat selectors in segment registers.
  111. ;
  112. mov dx,KeDataSelector
  113. mov ds,dx
  114. mov ss,dx
  115. mov es,dx
  116. mov esp,ebx
  117. ;
  118. ; Restore callers' ebp that we saved on the 32bit stack
  119. ;
  120. pop edi
  121. pop esi
  122. pop ebx
  123. pop ebp ; (ebp) = caller's ebp
  124. ;
  125. ; Pull callers flat return address off stack and push the
  126. ; flat code selector followed by the return offset, then
  127. ; execute a far return and we'll be back in the OS loaders code space.
  128. ;
  129. pop edx ; (edx) = caller's return address
  130. push dword ptr KeCodeSelector
  131. push edx
  132. db OVERRIDE
  133. retf
  134. endm
  135. ;++
  136. ;
  137. ;
  138. ;
  139. ;--
  140. RE_ENABLE_PAGING_MACRO macro
  141. extrn _EnableProtectPaging:near
  142. push RE_ENABLING
  143. call _EnableProtectPaging
  144. add sp,2
  145. endm
  146. ENTER_REALMODE_MACRO macro
  147. extrn _RealMode:near
  148. call _RealMode
  149. endm
  150. WAIT_FOREVER_MACRO macro
  151. LOCAL wf1
  152. wf1: jmp wf1
  153. endm
  154. ;++
  155. ;
  156. ; MAKE_STACK_FRAME_MACRO
  157. ;
  158. ; Arguments:
  159. ;
  160. ; _FrameName_ - is the name of the structure defining the
  161. ; stack frame layout.
  162. ;
  163. ; _PointerRegister_ - is the register containing the linear pointer to
  164. ; the top of the stack frame.
  165. ; ProtectMode ONLY
  166. ;
  167. ;--
  168. MAKE_STACK_FRAME_MACRO macro _FrameName_ , _PointerRegister_
  169. Local msf1
  170. mov ecx, (size _FrameName_)/2
  171. mov esi,_PointerRegister_ ; (esi) = offset of argument frame
  172. add esi,20 ; account for ebp, ebx, esi, edi and
  173. ; return address
  174. push KeDataSelector ; (ax) = Flat 32bit segment selector
  175. pop ds ; (ds:esi) points to argument frame
  176. push ss ;
  177. pop es ; (es) = 16bit stack selector
  178. sub sp, size _FrameName_ ; make room for the arguments
  179. xor edi,edi ; clear out upper 16bits of edi
  180. mov di,sp ; (es:edi) points to top of stack
  181. msf1:
  182. mov ax,[esi]
  183. mov es:[edi],ax
  184. add esi,2
  185. add edi,2
  186. loop msf1
  187. push es ;
  188. pop ds ; put 16bit selector back into ds
  189. endm
  190. REMOVE_STACK_FRAME_MACRO macro _FrameName_
  191. add sp, size _FrameName_
  192. endm
  193. ;BuildDescriptor macro Base,Limit,Access,Dpl,Stype
  194. ; dw (Limit AND 0ffffh)
  195. ; dw (Base AND 0ffffh)
  196. ; db ((Base SHR 16) AND 0ffh)
  197. ; db (Gran + Dpl + Stype)
  198. ; db ((Limit SHR 16) AND 0ffh)
  199. ; db ((Base SHR 24) AND 0ffh)
  200. ; endm
  201. ;
  202. ;
  203. ;
  204. RETURNCODE_IN_EAX_MACRO macro
  205. shl edx,16
  206. mov dx,ax
  207. mov eax,edx
  208. endm
  209.