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