]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/QemuVideoDxe/VbeShim.asm
OvmfPkg/QemuVideoDxe/VbeShim: handle PAM1 register on Q35 correctly
[mirror_edk2.git] / OvmfPkg / QemuVideoDxe / VbeShim.asm
CommitLineData
90803342
LE
1;------------------------------------------------------------------------------\r
2; @file\r
3; A minimal Int10h stub that allows the Windows 2008 R2 SP1 UEFI guest's buggy,\r
4; default VGA driver to switch to 1024x768x32, on the stdvga and QXL video\r
5; cards of QEMU.\r
6;\r
7; Copyright (C) 2014, Red Hat, Inc.\r
8; Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
9;\r
10; This program and the accompanying materials are licensed and made available\r
11; under the terms and conditions of the BSD License which accompanies this\r
12; distribution. The full text of the license may be found at\r
13; http://opensource.org/licenses/bsd-license.php\r
14;\r
15; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
16; WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17;\r
18;------------------------------------------------------------------------------\r
19\r
20; enable this macro for debug messages\r
21;%define DEBUG\r
22\r
23%macro DebugLog 1\r
24%ifdef DEBUG\r
25 push si\r
26 mov si, %1\r
27 call PrintStringSi\r
28 pop si\r
29%endif\r
30%endmacro\r
31\r
32\r
33BITS 16\r
34ORG 0\r
35\r
36VbeInfo:\r
37TIMES 256 nop\r
38\r
39VbeModeInfo:\r
40TIMES 256 nop\r
41\r
42\r
43Handler:\r
44 cmp ax, 0x4f00\r
45 je GetInfo\r
46 cmp ax, 0x4f01\r
47 je GetModeInfo\r
48 cmp ax, 0x4f02\r
49 je SetMode\r
50 cmp ax, 0x4f03\r
51 je GetMode\r
52 cmp ax, 0x4f10\r
53 je GetPmCapabilities\r
54 cmp ax, 0x4f15\r
55 je ReadEdid\r
56 cmp ah, 0x00\r
57 je SetModeLegacy\r
58 DebugLog StrUnkownFunction\r
59Hang:\r
60 jmp Hang\r
61\r
62\r
63GetInfo:\r
64 push es\r
65 push di\r
66 push ds\r
67 push si\r
68 push cx\r
69\r
70 DebugLog StrEnterGetInfo\r
71\r
72 ; target (es:di) set on input\r
73 push cs\r
74 pop ds\r
75 mov si, VbeInfo\r
76 ; source (ds:si) set now\r
77\r
78 mov cx, 256\r
79 cld\r
80 rep movsb\r
81\r
82 pop cx\r
83 pop si\r
84 pop ds\r
85 pop di\r
86 pop es\r
87 jmp Success\r
88\r
89\r
90GetModeInfo:\r
91 push es\r
92 push di\r
93 push ds\r
94 push si\r
95 push cx\r
96\r
97 DebugLog StrEnterGetModeInfo\r
98\r
99 and cx, ~0x4000 ; clear potentially set LFB bit in mode number\r
100 cmp cx, 0x00f1\r
101 je KnownMode1\r
102 DebugLog StrUnkownMode\r
103 jmp Hang\r
104KnownMode1:\r
105 ; target (es:di) set on input\r
106 push cs\r
107 pop ds\r
108 mov si, VbeModeInfo\r
109 ; source (ds:si) set now\r
110\r
111 mov cx, 256\r
112 cld\r
113 rep movsb\r
114\r
115 pop cx\r
116 pop si\r
117 pop ds\r
118 pop di\r
119 pop es\r
120 jmp Success\r
121\r
122\r
123%define ATT_ADDRESS_REGISTER 0x03c0\r
124%define VBE_DISPI_IOPORT_INDEX 0x01ce\r
125%define VBE_DISPI_IOPORT_DATA 0x01d0\r
126\r
127%define VBE_DISPI_INDEX_XRES 0x1\r
128%define VBE_DISPI_INDEX_YRES 0x2\r
129%define VBE_DISPI_INDEX_BPP 0x3\r
130%define VBE_DISPI_INDEX_ENABLE 0x4\r
131%define VBE_DISPI_INDEX_BANK 0x5\r
132%define VBE_DISPI_INDEX_VIRT_WIDTH 0x6\r
133%define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7\r
134%define VBE_DISPI_INDEX_X_OFFSET 0x8\r
135%define VBE_DISPI_INDEX_Y_OFFSET 0x9\r
136\r
137%define VBE_DISPI_ENABLED 0x01\r
138%define VBE_DISPI_LFB_ENABLED 0x40\r
139\r
140%macro BochsWrite 2\r
141 push dx\r
142 push ax\r
143\r
144 mov dx, VBE_DISPI_IOPORT_INDEX\r
145 mov ax, %1\r
146 out dx, ax\r
147\r
148 mov dx, VBE_DISPI_IOPORT_DATA\r
149 mov ax, %2\r
150 out dx, ax\r
151\r
152 pop ax\r
153 pop dx\r
154%endmacro\r
155\r
156SetMode:\r
157 push dx\r
158 push ax\r
159\r
160 DebugLog StrEnterSetMode\r
161\r
162 cmp bx, 0x40f1\r
163 je KnownMode2\r
164 DebugLog StrUnkownMode\r
165 jmp Hang\r
166KnownMode2:\r
167\r
168 ; unblank\r
169 mov dx, ATT_ADDRESS_REGISTER\r
170 mov al, 0x20\r
171 out dx, al\r
172\r
173 BochsWrite VBE_DISPI_INDEX_ENABLE, 0\r
174 BochsWrite VBE_DISPI_INDEX_BANK, 0\r
175 BochsWrite VBE_DISPI_INDEX_X_OFFSET, 0\r
176 BochsWrite VBE_DISPI_INDEX_Y_OFFSET, 0\r
177 BochsWrite VBE_DISPI_INDEX_BPP, 32\r
178 BochsWrite VBE_DISPI_INDEX_XRES, 1024\r
179 BochsWrite VBE_DISPI_INDEX_VIRT_WIDTH, 1024\r
180 BochsWrite VBE_DISPI_INDEX_YRES, 768\r
181 BochsWrite VBE_DISPI_INDEX_VIRT_HEIGHT, 768\r
182 BochsWrite VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | VBE_DISPI_LFB_ENABLED\r
183\r
184 pop ax\r
185 pop dx\r
186 jmp Success\r
187\r
188\r
189GetMode:\r
190 DebugLog StrEnterGetMode\r
191 mov bx, 0x40f1\r
192 jmp Success\r
193\r
194\r
195GetPmCapabilities:\r
196 DebugLog StrGetPmCapabilities\r
197 jmp Unsupported\r
198\r
199\r
200ReadEdid:\r
201 DebugLog StrReadEdid\r
202 jmp Unsupported\r
203\r
204\r
205SetModeLegacy:\r
206 DebugLog StrEnterSetModeLegacy\r
207\r
208 cmp al, 0x03\r
209 je KnownMode3\r
210 cmp al, 0x12\r
211 je KnownMode4\r
212 DebugLog StrUnkownMode\r
213 jmp Hang\r
214KnownMode3:\r
215 mov al, 0x30\r
216 jmp SetModeLegacyDone\r
217KnownMode4:\r
218 mov al, 0x20\r
219SetModeLegacyDone:\r
220 DebugLog StrExitSuccess\r
221 iret\r
222\r
223\r
224Success:\r
225 DebugLog StrExitSuccess\r
226 mov ax, 0x004f\r
227 iret\r
228\r
229\r
230Unsupported:\r
231 DebugLog StrExitUnsupported\r
232 mov ax, 0x014f\r
233 iret\r
234\r
235\r
236%ifdef DEBUG\r
237PrintStringSi:\r
238 pusha\r
239 push ds ; save original\r
240 push cs\r
241 pop ds\r
242 mov dx, 0x0402\r
243PrintStringSiLoop:\r
244 lodsb\r
245 cmp al, 0\r
246 je PrintStringSiDone\r
247 out dx, al\r
248 jmp PrintStringSiLoop\r
249PrintStringSiDone:\r
250 pop ds ; restore original\r
251 popa\r
252 ret\r
253\r
254\r
255StrExitSuccess:\r
256 db 'Exit', 0x0a, 0\r
257\r
258StrExitUnsupported:\r
259 db 'Unsupported', 0x0a, 0\r
260\r
261StrUnkownFunction:\r
262 db 'Unknown Function', 0x0a, 0\r
263\r
264StrEnterGetInfo:\r
265 db 'GetInfo', 0x0a, 0\r
266\r
267StrEnterGetModeInfo:\r
268 db 'GetModeInfo', 0x0a, 0\r
269\r
270StrEnterGetMode:\r
271 db 'GetMode', 0x0a, 0\r
272\r
273StrEnterSetMode:\r
274 db 'SetMode', 0x0a, 0\r
275\r
276StrEnterSetModeLegacy:\r
277 db 'SetModeLegacy', 0x0a, 0\r
278\r
279StrUnkownMode:\r
280 db 'Unkown Mode', 0x0a, 0\r
281\r
282StrGetPmCapabilities:\r
283 db 'GetPmCapabilities', 0x0a, 0\r
284\r
285StrReadEdid:\r
286 db 'ReadEdid', 0x0a, 0\r
287%endif\r