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.

311 lines
6.7 KiB

  1. ;++
  2. ;
  3. ;Copyright (c) 1995 Microsoft Corporation
  4. ;
  5. ;Module Name:
  6. ;
  7. ; bootfix.asm
  8. ;
  9. ;Abstract:
  10. ;
  11. ; The code in this "image" is responsible for checking if is appropriate
  12. ; for us to boot from CD. We want to boot from CD whenever we don't have
  13. ; a valid active partition or when the user pressed CTRL key during the
  14. ; boot process.
  15. ;
  16. ;Author:
  17. ;
  18. ; Calin Negreanu (calinn) 25-May-1998
  19. ;
  20. ;Environment:
  21. ;
  22. ; Image has been loaded at 2000:0000 by ETFS boot code.
  23. ; Real mode
  24. ; ISO 9660 El Torito no-emulation CD-ROM Boot support
  25. ; DL = El Torito drive number we booted from
  26. ;
  27. ;Revision History:
  28. ;
  29. ; Calin Negreanu (calinn) 18-Feb-1999
  30. ;
  31. ;--
  32. page ,132
  33. title bootfix
  34. name bootfix
  35. .8086
  36. CODE SEGMENT
  37. ASSUME CS:CODE,DS:CODE,SS:NOTHING,ES:NOTHING
  38. ORG 0000H
  39. _BootFix label byte
  40. MaxCodeSize EQU 1024
  41. Part_Active EQU 0
  42. Part_Type EQU 4
  43. Data_PartType EQU 0 ;address of partition type inside BootData structure
  44. LoadSeg EQU 3000H ;we load MBR here
  45. SectSize EQU 512
  46. EntriesOnMbr EQU 4
  47. MbrDataOff EQU 01BEH
  48. VolbootOrg EQU 7c00h
  49. JMPFAR MACRO DestOfs,DestSeg
  50. db 0eah
  51. dw OFFSET DestOfs
  52. dw DestSeg
  53. endm
  54. START:
  55. ;
  56. ; we already have a valid stack set by the original ETFS boot sector
  57. ; we only need to set ds and es
  58. ;
  59. push ds
  60. push es
  61. mov ax,cs
  62. mov ds,ax
  63. mov es,ax
  64. ;
  65. ; read partition table from hdd 80h at LoadSeg:0000
  66. ;
  67. push es
  68. mov ax,LoadSeg
  69. mov es,ax
  70. mov bx,0000h
  71. mov ax,0201h ;read function, one sector
  72. mov cx,0001h
  73. mov dx,0080h
  74. int 13h
  75. jnc MbrOk
  76. ;
  77. ; there was an error, boot from CD
  78. ;
  79. pop es
  80. jmp CdBoot
  81. MbrOk:
  82. pop es
  83. ;
  84. ; now it's the time to loop and find the active partition table
  85. ;
  86. push es
  87. mov ax,LoadSeg
  88. mov es,ax
  89. mov cx,EntriesOnMbr ;number of partitions in partition table
  90. mov bp,MbrDataOff ;01beh
  91. LoopActive:
  92. ;
  93. ; 00 - inactive, 80h active, others-invalid
  94. ;
  95. cmp BYTE PTR es:[bp].Part_Active,00H
  96. jl CheckInactive
  97. jne BadMbr
  98. add bp,16
  99. loop LoopActive
  100. ;
  101. ; no active partition found. boot from CD
  102. ;
  103. pop es
  104. jmp CdBoot
  105. CheckInactive:
  106. push bp
  107. InactiveLoop:
  108. add bp,16
  109. dec cx
  110. jz ActiveFound
  111. cmp BYTE PTR es:[bp].Part_Active,00H
  112. je InactiveLoop
  113. pop bp
  114. BadMbr:
  115. ;
  116. ; bad mbr was found. boot from CD
  117. ;
  118. pop es
  119. jmp CdBoot
  120. ActiveFound:
  121. pop bp
  122. pop es
  123. ;
  124. ; let's see if we can display UI (that is if MsgPressKey is not empty
  125. ;
  126. mov si, OFFSET MsgPressKey
  127. lodsb
  128. mov UIAllowed, al
  129. push si
  130. mov si,OFFSET MsgPressKey
  131. call PrintMsg
  132. pop si
  133. ;
  134. ; read all available keys from the queue (prevents us from booting from CD when there
  135. ; is some garbage there
  136. ;
  137. mov cx, 80h
  138. FlushQueue:
  139. mov ah, 01h
  140. int 16h
  141. jz QueueEmpty
  142. mov ah, 00h
  143. int 16h
  144. loop FlushQueue
  145. QueueEmpty:
  146. ;
  147. ; hook int08
  148. ;
  149. cli
  150. push es
  151. xor ax,ax
  152. mov es,ax
  153. mov bx,08h * 4
  154. mov ax,es:[bx]
  155. mov WORD PTR [OldInt08 ], ax
  156. mov ax,es:[bx+2]
  157. mov WORD PTR [OldInt08+2], ax
  158. mov WORD PTR es:[bx],OFFSET NewInt08
  159. mov WORD PTR es:[bx+2],cs
  160. pop es
  161. sti
  162. ;
  163. ; loop until the delay ticks is 0. Check for a key pressed (if UI), or for CTRL pressed (if no UI)
  164. ;
  165. CheckKey:
  166. cmp UIAllowed, 0
  167. je CheckCTRL
  168. mov ah, 01h
  169. int 16h
  170. jnz KeyPressed
  171. CheckCTRL:
  172. mov ah,02h
  173. int 16h
  174. and al,00000100b
  175. jnz KeyPressed
  176. NotPressed:
  177. cmp DotTicks, 0
  178. jg AddDot
  179. push si
  180. mov si,OFFSET MsgDot
  181. call PrintMsg
  182. pop si
  183. mov DotTicks, 18
  184. AddDot:
  185. cmp DelayTicks, 0
  186. jne CheckKey
  187. call UnhookInt08
  188. jmp BootFromHD
  189. UnhookInt08:
  190. cli
  191. push es
  192. xor ax,ax
  193. mov es,ax
  194. mov bx,08h * 4
  195. mov ax,WORD PTR [OldInt08]
  196. mov es:[bx],ax
  197. mov ax,WORD PTR [OldInt08+2]
  198. mov es:[bx+2],ax
  199. pop es
  200. sti
  201. ret
  202. KeyPressed:
  203. call UnhookInt08
  204. jmp CdBoot
  205. BootFromHD:
  206. ;
  207. ; let's move the mbr code to 0000:7c00 and jump there
  208. ;
  209. mov ax,LoadSeg
  210. mov ds,ax
  211. xor ax,ax
  212. mov es,ax
  213. xor si,si
  214. mov di,VolBootOrg
  215. mov cx,SectSize
  216. cld
  217. rep movsb
  218. mov dl,80h
  219. JMPFAR VolbootOrg,0000H
  220. CdBoot:
  221. ;
  222. ; return to caller code
  223. ;
  224. pop es
  225. pop ds
  226. retf
  227. NewInt08:
  228. pushf
  229. cli
  230. cmp WORD PTR cs:[DelayTicks], 0
  231. je default08
  232. dec WORD PTR cs:[DotTicks]
  233. dec WORD PTR cs:[DelayTicks]
  234. default08:
  235. popf
  236. push WORD PTR cs:[OldInt08+2]
  237. push WORD PTR cs:[OldInt08]
  238. retf
  239. ;
  240. ;EXPECTS DS:SI - MESSAGE ADDR
  241. ;
  242. PrintMsg proc near
  243. push ax
  244. push bx
  245. cmp UIAllowed, 0
  246. je PrintMsgEnd
  247. PrintMsgLoop:
  248. lodsb
  249. cmp al,0
  250. je PrintMsgEnd
  251. mov ah,0eh
  252. mov bx,0007h
  253. int 10h
  254. jmp PrintMsgLoop
  255. PrintMsgEnd:
  256. pop bx
  257. pop ax
  258. ret
  259. PrintMsg endp
  260. include bootfix.inc ; message text
  261. UIAllowed db 0
  262. MsgDot db "."
  263. db 0
  264. OldInt08 dd ?
  265. DelayTicks dw 4*18+1 ; 4 seconds
  266. DotTicks dw 18
  267. .errnz ($-_BootFix) GT (MaxCodeSize - 2) ;FATAL: bootfix code is too large
  268. org MaxCodeSize - 2
  269. db 55h,0aah
  270. CODE ENDS
  271. END START