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.

283 lines
5.8 KiB

  1. PAGE ,132
  2. TITLE ROM - Kernel ROM specific code
  3. .xlist
  4. include kernel.inc
  5. include protect.inc
  6. include pdb.inc
  7. .list
  8. if ROM ;----------------------------------------------------------------
  9. ;------------------------------------------------------------------------
  10. ; Local Macros & Equates
  11. ;------------------------------------------------------------------------
  12. DPMICALL MACRO callno
  13. ifnb <callno>
  14. mov ax,callno
  15. endif
  16. int 31h
  17. ENDM
  18. GA_ALIGN_BYTES = (((GA_ALIGN+1) SHL 4) - 1)
  19. GA_MASK_BYTES = NOT GA_ALIGN_BYTES
  20. ;------------------------------------------------------------------------
  21. ; External Routines
  22. ;------------------------------------------------------------------------
  23. externFP LZDecode
  24. ;------------------------------------------------------------------------
  25. ; Data Segment Variables
  26. ;------------------------------------------------------------------------
  27. DataBegin
  28. if PMODE32
  29. externW gdtdsc
  30. externB MS_DOS_Name_String
  31. endif
  32. externW MyDSSeg
  33. externW WinFlags
  34. externD linHiROM
  35. externD lmaHiROM
  36. DataEnd
  37. ;------------------------------------------------------------------------
  38. ; INITDATA Variables
  39. ;------------------------------------------------------------------------
  40. DataBegin INIT
  41. DataEnd INIT
  42. ;------------------------------------------------------------------------
  43. sBegin INITCODE
  44. assumes cs,CODE
  45. ;-----------------------------------------------------------------------;
  46. ; ROMInit ;
  47. ; ;
  48. ; Performs ROM specific initialization. ;
  49. ; ;
  50. ; Arguments: ;
  51. ; DS = ES = SS = selector to conventional RAM mem block & PSP ;
  52. ; for kernel use. ;
  53. ; SP = offset in conventional RAM block ;
  54. ; SS:SP = [near ret to ldboot] [far ret to invoker] ;
  55. ; CX:DX = linear address of hi rom (as opposed to physical) ;
  56. ; set by DOSX or the fake KRNL386 which enh exec's ;
  57. ; ;
  58. ; Returns: ;
  59. ; BX = 0 ;
  60. ; DS:0 = Kernel's RAM Data segment ;
  61. ; ES:0 = Kernel's PSP ;
  62. ; ;
  63. ; Regs Used: ;
  64. ; AX, CX, DX, DI ;
  65. ; ;
  66. ; ;
  67. ;-----------------------------------------------------------------------;
  68. assumes ds,nothing
  69. assumes es,nothing
  70. assumes ss,nothing
  71. cProc ROMInit,<PUBLIC,NEAR>,<es>
  72. localW selNewDS
  73. localW selBaseMem
  74. localD lpProc
  75. if PMODE32
  76. localD romhilinear
  77. localD linDOSBlock
  78. localD cbDOSBlock
  79. endif
  80. cBegin
  81. if PMODE32
  82. mov word ptr romhilinear[0], dx
  83. mov word ptr romhilinear[2], cx
  84. endif
  85. ; On entry we do not have a RAM copy of our data segment, set up a
  86. ; selector for on in the conventional memory block. This will become
  87. ; the first block in the global heap...
  88. mov cx,1 ;allocate 1 selector to use for DS
  89. DPMICall 0000h
  90. ;;; jc RIFailed ; worry about this?
  91. mov selNewDS,ax ;save new selector
  92. DPMICall 0000h ;and another for base memory ptr
  93. ;;; jc RIFailed ; worry about this?
  94. mov selBaseMem,ax
  95. mov bx,ds ;get base of conventional memory blk
  96. DPMICall 0006h ; and PSP
  97. if PMODE32
  98. mov word ptr linDOSBlock[0], dx
  99. mov word ptr linDOSBlock[2], cx
  100. endif
  101. add dx,100h+GA_ALIGN_BYTES ;point selBaseMem past PSP and
  102. adc cx,0 ; align for initial heap sentinal
  103. and dl,GA_MASK_BYTES
  104. mov bx,selBaseMem
  105. DPMICall 0007h
  106. ife PMODE32
  107. add dx,10h+GA_ALIGN_BYTES ;align DS selector and leave room
  108. adc cx,0 ; for heap sentinel & arena
  109. and dl,GA_MASK_BYTES ; (where DS arena goes)
  110. add dx,10h
  111. adc cx,0 ; (where DS goes)
  112. endif
  113. push cx ;save RAM DS base on stack
  114. push dx
  115. mov bx,selNewDS ;set base of new DS selector
  116. DPMICall 0007h
  117. xor cx,cx ;set limit of new DS selector
  118. xor dx,dx ; to 64k for now
  119. dec dx
  120. DPMICall 0008h
  121. xor ax,ax
  122. mov si,seg _DATA
  123. mov dx,0E000h ;ASSUMES kernel ds < E000 & uncompress
  124. ; buffer < 2000 bytes
  125. push es
  126. cCall LZDecode,<bx,si,bx,dx> ; uncompress our DS
  127. pop es
  128. mov dx,ax ;ax = # expanded bytes, make this
  129. dec dx ; the new limit for selNewDS
  130. xor cx,cx
  131. mov bx,selNewDS
  132. DPMICall 0008h
  133. mov ds,bx
  134. ReSetKernelDS
  135. ; Update the original data selector to point to the RAM copy
  136. mov bx,seg _DATA ;orig DS selector
  137. pop dx ;base of RAM data seg
  138. pop cx
  139. DPMICall 0007h
  140. push cx
  141. push dx
  142. mov cx,ds
  143. lsl dx,cx ;increase limit of DS selector
  144. add dx,ROMEXTRASTACKSZ ; to include extra stack space
  145. xor cx,cx
  146. DPMICall 0008h
  147. mov cl,DSC_PRESENT OR DSC_DATA ; and make sure it's writable
  148. DPMICall 0009h
  149. pop dx
  150. pop cx
  151. mov ds,bx ;use orig DS selector and free temp
  152. ReSetKernelDS
  153. mov bx,selNewDS
  154. DPMICall 0001h
  155. mov bx,cx ;convert RAM DS base to segment & save
  156. mov cx,4
  157. @@: shr bx,1
  158. rcr dx,1
  159. loop @b
  160. mov MyDSSeg,dx
  161. if PMODE32
  162. .386p
  163. ; now that we're looking at our ds, set the linear address of the
  164. ; high ROM
  165. mov eax, romhilinear
  166. or eax, eax
  167. jnz @F
  168. mov eax, lmaHiROM
  169. @@: mov linHiROM, eax
  170. endif
  171. ; Set WinFlags to have the CPU type
  172. DPMICall 0400h ;returns CPU type in CL
  173. mov ax,WF_CPU286
  174. cmp cl,2
  175. jbe @f
  176. mov al,WF_CPU386
  177. cmp cl,3
  178. je @f
  179. mov al,WF_CPU486
  180. @@:
  181. mov WinFlags,ax
  182. if PMODE32
  183. push es
  184. mov ax, 168Ah ; See if we have MS-DOS extensions
  185. mov si, dataoffset MS_DOS_Name_String
  186. int 2Fh ; DS:SI -> MS-DOS string
  187. cmp al, 8Ah ; Have extensions?
  188. je short NoLDTParty ; no extensions, screwed
  189. mov word ptr [lpProc][0], di ; Save CallBack address
  190. mov word ptr [lpProc][2], es
  191. mov ax, 0100h ; Get base of LDT
  192. call [lpProc]
  193. jc short NoLDTParty
  194. verw ax ; Writeable?
  195. jnz short NoLDTParty ; nope, don't bother with it yet
  196. mov gdtdsc, ax
  197. NoLDTParty:
  198. pop es
  199. ;; now page-unlock the DOS block
  200. ;;
  201. mov bx, es:[PDB_Block_Len]
  202. DPMICALL 0006h
  203. mov si, cx
  204. mov di, dx
  205. mov cx, word ptr linDOSBlock[0]
  206. mov bx, word ptr linDOSBlock[2]
  207. sub di, cx
  208. sbb si, bx
  209. DPMICALL 0602h
  210. endif
  211. xor bx,bx ;return 0 in BX (for LDT_Init)
  212. mov si,selBaseMem ;return selector to memory base in SI
  213. cEnd
  214. sEnd INITCODE
  215. endif ;ROM ---------------------------------------------------------
  216. end