VbeShim.asm 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. ;------------------------------------------------------------------------------
  2. ; @file
  3. ; A minimal Int10h stub that allows the Windows 2008 R2 SP1 UEFI guest's buggy,
  4. ; default VGA driver to switch to 1024x768x32.
  5. ;
  6. ; Copyright (C) 2020, Rebecca Cran <rebecca@bsdio.com>
  7. ; Copyright (C) 2015, Nahanni Systems, Inc.
  8. ; Copyright (C) 2014, Red Hat, Inc.
  9. ; Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
  10. ;
  11. ; SPDX-License-Identifier: BSD-2-Clause-Patent
  12. ;
  13. ;------------------------------------------------------------------------------
  14. ; enable this macro for debug messages
  15. %define DEBUG
  16. %macro DebugLog 1
  17. %ifdef DEBUG
  18. push si
  19. mov si, %1
  20. call PrintStringSi
  21. pop si
  22. %endif
  23. %endmacro
  24. BITS 16
  25. ORG 0
  26. VbeInfo:
  27. TIMES 256 nop
  28. VbeModeInfo:
  29. VbeMode1:
  30. TIMES 50 nop
  31. VbeMode2:
  32. TIMES 50 nop
  33. VbeMode3:
  34. TIMES 50 nop
  35. VbeMode4:
  36. TIMES 50 nop
  37. TIMES 56 nop ; filler for 256 bytes
  38. Handler:
  39. cmp ax, 0x4f00
  40. je GetInfo
  41. cmp ax, 0x4f01
  42. je GetModeInfo
  43. cmp ax, 0x4f02
  44. je SetMode
  45. cmp ax, 0x4f03
  46. je GetMode
  47. cmp ax, 0x4f10
  48. je GetPmCapabilities
  49. cmp ax, 0x4f15
  50. je ReadEdid
  51. cmp ah, 0x00
  52. je SetModeLegacy
  53. DebugLog StrUnkownFunction
  54. Hang:
  55. jmp Hang
  56. GetInfo:
  57. push es
  58. push di
  59. push ds
  60. push si
  61. push cx
  62. DebugLog StrEnterGetInfo
  63. ; target (es:di) set on input
  64. push cs
  65. pop ds
  66. mov si, VbeInfo
  67. ; source (ds:si) set now
  68. mov cx, 256
  69. cld
  70. rep movsb
  71. pop cx
  72. pop si
  73. pop ds
  74. pop di
  75. pop es
  76. jmp Success
  77. GetModeInfo:
  78. push es
  79. push di
  80. push ds
  81. push si
  82. push cx
  83. DebugLog StrEnterGetModeInfo
  84. and cx, ~0x4000 ; clear potentially set LFB bit in mode number
  85. cmp cx, 0x013f
  86. je gKnownMode1
  87. cmp cx, 0x0140
  88. je gKnownMode2
  89. cmp cx, 0x0141
  90. je gKnownMode3
  91. DebugLog StrUnkownMode
  92. jmp Hang
  93. gKnownMode1:
  94. DebugLog StrMode1
  95. mov si, VbeMode1
  96. jmp CopyModeInfo
  97. gKnownMode2:
  98. DebugLog StrMode2
  99. mov si, VbeMode2
  100. jmp CopyModeInfo
  101. gKnownMode3:
  102. DebugLog StrMode3
  103. mov si, VbeMode3
  104. jmp CopyModeInfo
  105. gKnownMode4:
  106. DebugLog StrMode4
  107. mov si, VbeMode4
  108. jmp CopyModeInfo
  109. CopyModeInfo:
  110. ; target (es:di) set on input
  111. push cs
  112. pop ds
  113. ;mov si, VbeModeInfo
  114. ; source (ds:si) set now
  115. ;mov cx, 256
  116. mov cx, 50
  117. cld
  118. rep movsb
  119. pop cx
  120. pop si
  121. pop ds
  122. pop di
  123. pop es
  124. jmp Success
  125. SetMode:
  126. push dx
  127. push ax
  128. DebugLog StrEnterSetMode
  129. and bx, ~0x4000 ; clear potentially set LFB bit in mode number
  130. cmp bx, 0x013f
  131. je KnownMode1
  132. cmp bx, 0x0140
  133. je KnownMode2
  134. cmp bx, 0x0141
  135. je KnownMode3
  136. DebugLog StrUnkownMode
  137. jmp Hang
  138. KnownMode1:
  139. DebugLog StrMode1
  140. jmp SetModeDone
  141. KnownMode2:
  142. DebugLog StrMode2
  143. jmp SetModeDone
  144. KnownMode3:
  145. DebugLog StrMode3
  146. jmp SetModeDone
  147. KnownMode4:
  148. DebugLog StrMode4
  149. SetModeDone:
  150. mov [CurMode], bl
  151. mov [CurMode+1], bh
  152. pop ax
  153. pop dx
  154. jmp Success
  155. GetMode:
  156. DebugLog StrEnterGetMode
  157. mov bl, [CurMode]
  158. mov bh, [CurMode+1]
  159. jmp Success
  160. GetPmCapabilities:
  161. DebugLog StrGetPmCapabilities
  162. mov bx, 0x0080
  163. jmp Success
  164. ReadEdid:
  165. push es
  166. push di
  167. push ds
  168. push si
  169. push cx
  170. DebugLog StrReadEdid
  171. ; target (es:di) set on input
  172. push cs
  173. pop ds
  174. mov si, Edid
  175. ; source (ds:si) set now
  176. mov cx, 128
  177. cld
  178. rep movsb
  179. pop cx
  180. pop si
  181. pop ds
  182. pop di
  183. pop es
  184. jmp Success
  185. SetModeLegacy:
  186. DebugLog StrEnterSetModeLegacy
  187. cmp al, 0x03
  188. je sKnownMode3
  189. cmp al, 0x12
  190. je sKnownMode4
  191. DebugLog StrUnkownMode
  192. jmp Hang
  193. sKnownMode3:
  194. DebugLog StrLegacyMode3
  195. mov al, 0 ; 0x30
  196. jmp SetModeLegacyDone
  197. sKnownMode4:
  198. mov al, 0 ;0x20
  199. SetModeLegacyDone:
  200. DebugLog StrExitSuccess
  201. iret
  202. Success:
  203. DebugLog StrExitSuccess
  204. mov ax, 0x004f
  205. iret
  206. Unsupported:
  207. DebugLog StrExitUnsupported
  208. mov ax, 0x024f
  209. iret
  210. %ifdef DEBUG
  211. PrintStringSi:
  212. pusha
  213. push ds ; save original
  214. push cs
  215. pop ds
  216. mov dx, 0x220 ; bhyve debug cons port
  217. mov ax, 0
  218. PrintStringSiLoop:
  219. lodsb
  220. cmp al, 0
  221. je PrintStringSiDone
  222. out dx, al
  223. jmp PrintStringSiLoop
  224. PrintStringSiDone:
  225. pop ds ; restore original
  226. popa
  227. ret
  228. StrExitSuccess:
  229. db 'vOk', 0x0d, 0x0a, 0
  230. StrExitUnsupported:
  231. db 'vUnsupported', 0x0d, 0x0a, 0
  232. StrUnkownFunction:
  233. db 'vUnknown Function', 0x0d, 0x0a, 0
  234. StrEnterGetInfo:
  235. db 'vGetInfo', 0x0d, 0x0a, 0
  236. StrEnterGetModeInfo:
  237. db 'vGetModeInfo', 0x0d, 0x0a, 0
  238. StrEnterGetMode:
  239. db 'vGetMode', 0x0d, 0x0a, 0
  240. StrEnterSetMode:
  241. db 'vSetMode', 0x0d, 0x0a, 0
  242. StrEnterSetModeLegacy:
  243. db 'vSetModeLegacy', 0x0d, 0x0a, 0
  244. StrUnkownMode:
  245. db 'vUnkown Mode', 0x0d, 0x0a, 0
  246. StrGetPmCapabilities:
  247. db 'vGetPmCapabilities', 0x0d, 0x0a, 0
  248. StrReadEdid:
  249. db 'vReadEdid', 0x0d, 0x0a, 0
  250. StrLegacyMode3:
  251. db 'vLegacyMode3', 0x0d, 0x0a, 0
  252. StrMode1:
  253. db 'mode_640x480x32', 0x0d, 0x0a, 0
  254. StrMode2:
  255. db 'mode_800x600x32', 0x0d, 0x0a, 0
  256. StrMode3:
  257. db 'mode_1024x768x32', 0x0d, 0x0a, 0
  258. StrMode4:
  259. db 'mode_unused', 0x0d, 0x0a, 0
  260. %endif
  261. CurMode:
  262. db 0x00, 0x00
  263. ;
  264. ; EDID stores monitor information. For now, just send back an null item.
  265. ;
  266. Edid:
  267. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  268. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  269. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  270. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  271. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  272. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  273. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  274. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  275. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  276. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  277. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  278. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  279. db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00