VbeShim.asm 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. ; @file
  2. ; A minimal Int10h stub that allows the Windows 2008 R2 SP1 UEFI guest's buggy,
  3. ; default VGA driver to switch to 1024x768x32, on the stdvga and QXL video
  4. ; cards of QEMU.
  5. ;
  6. ; Copyright (C) 2014, Red Hat, Inc.
  7. ; Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>
  8. ;
  9. ; SPDX-License-Identifier: BSD-2-Clause-Patent
  10. ;
  11. ; enable this macro for debug messages
  12. ;%define DEBUG
  13. %macro DebugLog 1
  14. %ifdef DEBUG
  15. push si
  16. mov si, %1
  17. call PrintStringSi
  18. pop si
  19. %endif
  20. %endmacro
  21. BITS 16
  22. ORG 0
  23. VbeInfo:
  24. TIMES 256 nop
  25. VbeModeInfo:
  26. TIMES 256 nop
  27. Handler:
  28. cmp ax, 0x4f00
  29. je GetInfo
  30. cmp ax, 0x4f01
  31. je GetModeInfo
  32. cmp ax, 0x4f02
  33. je SetMode
  34. cmp ax, 0x4f03
  35. je GetMode
  36. cmp ax, 0x4f10
  37. je GetPmCapabilities
  38. cmp ax, 0x4f15
  39. je ReadEdid
  40. cmp ah, 0x00
  41. je SetModeLegacy
  42. DebugLog StrUnkownFunction
  43. Hang:
  44. jmp Hang
  45. GetInfo:
  46. push es
  47. push di
  48. push ds
  49. push si
  50. push cx
  51. DebugLog StrEnterGetInfo
  52. ; target (es:di) set on input
  53. push cs
  54. pop ds
  55. mov si, VbeInfo
  56. ; source (ds:si) set now
  57. mov cx, 256
  58. cld
  59. rep movsb
  60. pop cx
  61. pop si
  62. pop ds
  63. pop di
  64. pop es
  65. jmp Success
  66. GetModeInfo:
  67. push es
  68. push di
  69. push ds
  70. push si
  71. push cx
  72. DebugLog StrEnterGetModeInfo
  73. and cx, ~0x4000 ; clear potentially set LFB bit in mode number
  74. cmp cx, 0x00f1
  75. je KnownMode1
  76. DebugLog StrUnkownMode
  77. jmp Hang
  78. KnownMode1:
  79. ; target (es:di) set on input
  80. push cs
  81. pop ds
  82. mov si, VbeModeInfo
  83. ; source (ds:si) set now
  84. mov cx, 256
  85. cld
  86. rep movsb
  87. pop cx
  88. pop si
  89. pop ds
  90. pop di
  91. pop es
  92. jmp Success
  93. %define ATT_ADDRESS_REGISTER 0x03c0
  94. %define VBE_DISPI_IOPORT_INDEX 0x01ce
  95. %define VBE_DISPI_IOPORT_DATA 0x01d0
  96. %define VBE_DISPI_INDEX_XRES 0x1
  97. %define VBE_DISPI_INDEX_YRES 0x2
  98. %define VBE_DISPI_INDEX_BPP 0x3
  99. %define VBE_DISPI_INDEX_ENABLE 0x4
  100. %define VBE_DISPI_INDEX_BANK 0x5
  101. %define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
  102. %define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
  103. %define VBE_DISPI_INDEX_X_OFFSET 0x8
  104. %define VBE_DISPI_INDEX_Y_OFFSET 0x9
  105. %define VBE_DISPI_ENABLED 0x01
  106. %define VBE_DISPI_LFB_ENABLED 0x40
  107. %macro BochsWrite 2
  108. push dx
  109. push ax
  110. mov dx, VBE_DISPI_IOPORT_INDEX
  111. mov ax, %1
  112. out dx, ax
  113. mov dx, VBE_DISPI_IOPORT_DATA
  114. mov ax, %2
  115. out dx, ax
  116. pop ax
  117. pop dx
  118. %endmacro
  119. SetMode:
  120. push dx
  121. push ax
  122. DebugLog StrEnterSetMode
  123. cmp bx, 0x40f1
  124. je KnownMode2
  125. DebugLog StrUnkownMode
  126. jmp Hang
  127. KnownMode2:
  128. ; unblank
  129. mov dx, ATT_ADDRESS_REGISTER
  130. mov al, 0x20
  131. out dx, al
  132. BochsWrite VBE_DISPI_INDEX_ENABLE, 0
  133. BochsWrite VBE_DISPI_INDEX_BANK, 0
  134. BochsWrite VBE_DISPI_INDEX_X_OFFSET, 0
  135. BochsWrite VBE_DISPI_INDEX_Y_OFFSET, 0
  136. BochsWrite VBE_DISPI_INDEX_BPP, 32
  137. BochsWrite VBE_DISPI_INDEX_XRES, 1024
  138. BochsWrite VBE_DISPI_INDEX_VIRT_WIDTH, 1024
  139. BochsWrite VBE_DISPI_INDEX_YRES, 768
  140. BochsWrite VBE_DISPI_INDEX_VIRT_HEIGHT, 768
  141. BochsWrite VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED
  142. pop ax
  143. pop dx
  144. jmp Success
  145. GetMode:
  146. DebugLog StrEnterGetMode
  147. mov bx, 0x40f1
  148. jmp Success
  149. GetPmCapabilities:
  150. DebugLog StrGetPmCapabilities
  151. jmp Unsupported
  152. ReadEdid:
  153. DebugLog StrReadEdid
  154. jmp Unsupported
  155. SetModeLegacy:
  156. DebugLog StrEnterSetModeLegacy
  157. cmp al, 0x03
  158. je KnownMode3
  159. cmp al, 0x12
  160. je KnownMode4
  161. DebugLog StrUnkownMode
  162. jmp Hang
  163. KnownMode3:
  164. mov al, 0x30
  165. jmp SetModeLegacyDone
  166. KnownMode4:
  167. mov al, 0x20
  168. SetModeLegacyDone:
  169. DebugLog StrExitSuccess
  170. iret
  171. Success:
  172. DebugLog StrExitSuccess
  173. mov ax, 0x004f
  174. iret
  175. Unsupported:
  176. DebugLog StrExitUnsupported
  177. mov ax, 0x014f
  178. iret
  179. %ifdef DEBUG
  180. PrintStringSi:
  181. pusha
  182. push ds ; save original
  183. push cs
  184. pop ds
  185. mov dx, 0x0402
  186. PrintStringSiLoop:
  187. lodsb
  188. cmp al, 0
  189. je PrintStringSiDone
  190. out dx, al
  191. jmp PrintStringSiLoop
  192. PrintStringSiDone:
  193. pop ds ; restore original
  194. popa
  195. ret
  196. StrExitSuccess:
  197. db 'Exit', 0x0a, 0
  198. StrExitUnsupported:
  199. db 'Unsupported', 0x0a, 0
  200. StrUnkownFunction:
  201. db 'Unknown Function', 0x0a, 0
  202. StrEnterGetInfo:
  203. db 'GetInfo', 0x0a, 0
  204. StrEnterGetModeInfo:
  205. db 'GetModeInfo', 0x0a, 0
  206. StrEnterGetMode:
  207. db 'GetMode', 0x0a, 0
  208. StrEnterSetMode:
  209. db 'SetMode', 0x0a, 0
  210. StrEnterSetModeLegacy:
  211. db 'SetModeLegacy', 0x0a, 0
  212. StrUnkownMode:
  213. db 'Unkown Mode', 0x0a, 0
  214. StrGetPmCapabilities:
  215. db 'GetPmCapabilities', 0x0a, 0
  216. StrReadEdid:
  217. db 'ReadEdid', 0x0a, 0
  218. %endif