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