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 |
|
---|
15 | ; enable this macro for debug messages
|
---|
16 | %define DEBUG
|
---|
17 |
|
---|
18 | %macro DebugLog 1
|
---|
19 | %ifdef DEBUG
|
---|
20 | push si
|
---|
21 | mov si, %1
|
---|
22 | call PrintStringSi
|
---|
23 | pop si
|
---|
24 | %endif
|
---|
25 | %endmacro
|
---|
26 |
|
---|
27 |
|
---|
28 | BITS 16
|
---|
29 | ORG 0
|
---|
30 |
|
---|
31 | VbeInfo:
|
---|
32 | TIMES 256 nop
|
---|
33 |
|
---|
34 | VbeModeInfo:
|
---|
35 | VbeMode1:
|
---|
36 | TIMES 50 nop
|
---|
37 | VbeMode2:
|
---|
38 | TIMES 50 nop
|
---|
39 | VbeMode3:
|
---|
40 | TIMES 50 nop
|
---|
41 | VbeMode4:
|
---|
42 | TIMES 50 nop
|
---|
43 | TIMES 56 nop ; filler for 256 bytes
|
---|
44 |
|
---|
45 | Handler:
|
---|
46 | cmp ax, 0x4f00
|
---|
47 | je GetInfo
|
---|
48 | cmp ax, 0x4f01
|
---|
49 | je GetModeInfo
|
---|
50 | cmp ax, 0x4f02
|
---|
51 | je SetMode
|
---|
52 | cmp ax, 0x4f03
|
---|
53 | je GetMode
|
---|
54 | cmp ax, 0x4f10
|
---|
55 | je GetPmCapabilities
|
---|
56 | cmp ax, 0x4f15
|
---|
57 | je ReadEdid
|
---|
58 | cmp ah, 0x00
|
---|
59 | je SetModeLegacy
|
---|
60 | DebugLog StrUnkownFunction
|
---|
61 | Hang:
|
---|
62 | jmp Hang
|
---|
63 |
|
---|
64 |
|
---|
65 | GetInfo:
|
---|
66 | push es
|
---|
67 | push di
|
---|
68 | push ds
|
---|
69 | push si
|
---|
70 | push cx
|
---|
71 |
|
---|
72 | DebugLog StrEnterGetInfo
|
---|
73 |
|
---|
74 | ; target (es:di) set on input
|
---|
75 | push cs
|
---|
76 | pop ds
|
---|
77 | mov si, VbeInfo
|
---|
78 | ; source (ds:si) set now
|
---|
79 |
|
---|
80 | mov cx, 256
|
---|
81 | cld
|
---|
82 | rep movsb
|
---|
83 |
|
---|
84 | pop cx
|
---|
85 | pop si
|
---|
86 | pop ds
|
---|
87 | pop di
|
---|
88 | pop es
|
---|
89 | jmp Success
|
---|
90 |
|
---|
91 |
|
---|
92 | GetModeInfo:
|
---|
93 | push es
|
---|
94 | push di
|
---|
95 | push ds
|
---|
96 | push si
|
---|
97 | push cx
|
---|
98 |
|
---|
99 | DebugLog StrEnterGetModeInfo
|
---|
100 |
|
---|
101 | and cx, ~0x4000 ; clear potentially set LFB bit in mode number
|
---|
102 |
|
---|
103 | cmp cx, 0x013f
|
---|
104 | je gKnownMode1
|
---|
105 | cmp cx, 0x0140
|
---|
106 | je gKnownMode2
|
---|
107 | cmp cx, 0x0141
|
---|
108 | je gKnownMode3
|
---|
109 |
|
---|
110 | DebugLog StrUnkownMode
|
---|
111 | jmp Hang
|
---|
112 | gKnownMode1:
|
---|
113 | DebugLog StrMode1
|
---|
114 | mov si, VbeMode1
|
---|
115 | jmp CopyModeInfo
|
---|
116 | gKnownMode2:
|
---|
117 | DebugLog StrMode2
|
---|
118 | mov si, VbeMode2
|
---|
119 | jmp CopyModeInfo
|
---|
120 | gKnownMode3:
|
---|
121 | DebugLog StrMode3
|
---|
122 | mov si, VbeMode3
|
---|
123 | jmp CopyModeInfo
|
---|
124 | gKnownMode4:
|
---|
125 | DebugLog StrMode4
|
---|
126 | mov si, VbeMode4
|
---|
127 | jmp CopyModeInfo
|
---|
128 |
|
---|
129 | CopyModeInfo:
|
---|
130 | ; target (es:di) set on input
|
---|
131 | push cs
|
---|
132 | pop ds
|
---|
133 | ;mov si, VbeModeInfo
|
---|
134 | ; source (ds:si) set now
|
---|
135 |
|
---|
136 | ;mov cx, 256
|
---|
137 | mov cx, 50
|
---|
138 | cld
|
---|
139 | rep movsb
|
---|
140 |
|
---|
141 | pop cx
|
---|
142 | pop si
|
---|
143 | pop ds
|
---|
144 | pop di
|
---|
145 | pop es
|
---|
146 | jmp Success
|
---|
147 |
|
---|
148 |
|
---|
149 | SetMode:
|
---|
150 | push dx
|
---|
151 | push ax
|
---|
152 |
|
---|
153 | DebugLog StrEnterSetMode
|
---|
154 |
|
---|
155 | and bx, ~0x4000 ; clear potentially set LFB bit in mode number
|
---|
156 | cmp bx, 0x013f
|
---|
157 | je KnownMode1
|
---|
158 | cmp bx, 0x0140
|
---|
159 | je KnownMode2
|
---|
160 | cmp bx, 0x0141
|
---|
161 | je KnownMode3
|
---|
162 | DebugLog StrUnkownMode
|
---|
163 | jmp Hang
|
---|
164 | KnownMode1:
|
---|
165 | DebugLog StrMode1
|
---|
166 | jmp SetModeDone
|
---|
167 | KnownMode2:
|
---|
168 | DebugLog StrMode2
|
---|
169 | jmp SetModeDone
|
---|
170 | KnownMode3:
|
---|
171 | DebugLog StrMode3
|
---|
172 | jmp SetModeDone
|
---|
173 | KnownMode4:
|
---|
174 | DebugLog StrMode4
|
---|
175 |
|
---|
176 | SetModeDone:
|
---|
177 | mov [CurMode], bl
|
---|
178 | mov [CurMode+1], bh
|
---|
179 | pop ax
|
---|
180 | pop dx
|
---|
181 | jmp Success
|
---|
182 |
|
---|
183 |
|
---|
184 | GetMode:
|
---|
185 | DebugLog StrEnterGetMode
|
---|
186 | mov bl, [CurMode]
|
---|
187 | mov bh, [CurMode+1]
|
---|
188 | jmp Success
|
---|
189 |
|
---|
190 |
|
---|
191 | GetPmCapabilities:
|
---|
192 | DebugLog StrGetPmCapabilities
|
---|
193 | mov bx, 0x0080
|
---|
194 | jmp Success
|
---|
195 |
|
---|
196 |
|
---|
197 | ReadEdid:
|
---|
198 | push es
|
---|
199 | push di
|
---|
200 | push ds
|
---|
201 | push si
|
---|
202 | push cx
|
---|
203 |
|
---|
204 | DebugLog StrReadEdid
|
---|
205 |
|
---|
206 | ; target (es:di) set on input
|
---|
207 | push cs
|
---|
208 | pop ds
|
---|
209 | mov si, Edid
|
---|
210 | ; source (ds:si) set now
|
---|
211 |
|
---|
212 | mov cx, 128
|
---|
213 | cld
|
---|
214 | rep movsb
|
---|
215 |
|
---|
216 | pop cx
|
---|
217 | pop si
|
---|
218 | pop ds
|
---|
219 | pop di
|
---|
220 | pop es
|
---|
221 | jmp Success
|
---|
222 |
|
---|
223 |
|
---|
224 | SetModeLegacy:
|
---|
225 | DebugLog StrEnterSetModeLegacy
|
---|
226 |
|
---|
227 | cmp al, 0x03
|
---|
228 | je sKnownMode3
|
---|
229 | cmp al, 0x12
|
---|
230 | je sKnownMode4
|
---|
231 | DebugLog StrUnkownMode
|
---|
232 | jmp Hang
|
---|
233 | sKnownMode3:
|
---|
234 | DebugLog StrLegacyMode3
|
---|
235 | mov al, 0 ; 0x30
|
---|
236 | jmp SetModeLegacyDone
|
---|
237 | sKnownMode4:
|
---|
238 | mov al, 0 ;0x20
|
---|
239 | SetModeLegacyDone:
|
---|
240 | DebugLog StrExitSuccess
|
---|
241 | iret
|
---|
242 |
|
---|
243 |
|
---|
244 | Success:
|
---|
245 | DebugLog StrExitSuccess
|
---|
246 | mov ax, 0x004f
|
---|
247 | iret
|
---|
248 |
|
---|
249 |
|
---|
250 | Unsupported:
|
---|
251 | DebugLog StrExitUnsupported
|
---|
252 | mov ax, 0x024f
|
---|
253 | iret
|
---|
254 |
|
---|
255 |
|
---|
256 | %ifdef DEBUG
|
---|
257 | PrintStringSi:
|
---|
258 | pusha
|
---|
259 | push ds ; save original
|
---|
260 | push cs
|
---|
261 | pop ds
|
---|
262 | mov dx, 0x220 ; bhyve debug cons port
|
---|
263 | mov ax, 0
|
---|
264 | PrintStringSiLoop:
|
---|
265 | lodsb
|
---|
266 | cmp al, 0
|
---|
267 | je PrintStringSiDone
|
---|
268 | out dx, al
|
---|
269 | jmp PrintStringSiLoop
|
---|
270 | PrintStringSiDone:
|
---|
271 | pop ds ; restore original
|
---|
272 | popa
|
---|
273 | ret
|
---|
274 |
|
---|
275 |
|
---|
276 | StrExitSuccess:
|
---|
277 | db 'vOk', 0x0d, 0x0a, 0
|
---|
278 |
|
---|
279 | StrExitUnsupported:
|
---|
280 | db 'vUnsupported', 0x0d, 0x0a, 0
|
---|
281 |
|
---|
282 | StrUnkownFunction:
|
---|
283 | db 'vUnknown Function', 0x0d, 0x0a, 0
|
---|
284 |
|
---|
285 | StrEnterGetInfo:
|
---|
286 | db 'vGetInfo', 0x0d, 0x0a, 0
|
---|
287 |
|
---|
288 | StrEnterGetModeInfo:
|
---|
289 | db 'vGetModeInfo', 0x0d, 0x0a, 0
|
---|
290 |
|
---|
291 | StrEnterGetMode:
|
---|
292 | db 'vGetMode', 0x0d, 0x0a, 0
|
---|
293 |
|
---|
294 | StrEnterSetMode:
|
---|
295 | db 'vSetMode', 0x0d, 0x0a, 0
|
---|
296 |
|
---|
297 | StrEnterSetModeLegacy:
|
---|
298 | db 'vSetModeLegacy', 0x0d, 0x0a, 0
|
---|
299 |
|
---|
300 | StrUnkownMode:
|
---|
301 | db 'vUnkown Mode', 0x0d, 0x0a, 0
|
---|
302 |
|
---|
303 | StrGetPmCapabilities:
|
---|
304 | db 'vGetPmCapabilities', 0x0d, 0x0a, 0
|
---|
305 |
|
---|
306 | StrReadEdid:
|
---|
307 | db 'vReadEdid', 0x0d, 0x0a, 0
|
---|
308 |
|
---|
309 | StrLegacyMode3:
|
---|
310 | db 'vLegacyMode3', 0x0d, 0x0a, 0
|
---|
311 |
|
---|
312 |
|
---|
313 | StrMode1:
|
---|
314 | db 'mode_640x480x32', 0x0d, 0x0a, 0
|
---|
315 | StrMode2:
|
---|
316 | db 'mode_800x600x32', 0x0d, 0x0a, 0
|
---|
317 | StrMode3:
|
---|
318 | db 'mode_1024x768x32', 0x0d, 0x0a, 0
|
---|
319 | StrMode4:
|
---|
320 | db 'mode_unused', 0x0d, 0x0a, 0
|
---|
321 | %endif
|
---|
322 |
|
---|
323 | CurMode:
|
---|
324 | db 0x00, 0x00
|
---|
325 |
|
---|
326 | ;
|
---|
327 | ; EDID stores monitor information. For now, just send back an null item.
|
---|
328 | ;
|
---|
329 | Edid:
|
---|
330 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
331 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
332 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
333 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
334 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
335 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
336 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
337 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
338 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
339 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
340 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
341 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|
342 | db 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
---|