[FREELDR] i386vid.c: Downgrade/Improve 3 false ERR() to WARN(). CORE-13496
[reactos.git] / boot / freeldr / freeldr / arch / i386 / i386vid.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <freeldr.h>
21
22 #define NDEBUG
23 #include <debug.h>
24
25 DBG_DEFAULT_CHANNEL(HWDETECT);
26
27 #include <pshpack2.h>
28 typedef struct
29 {
30 UCHAR Signature[4]; // (ret) signature ("VESA")
31 // (call) VESA 2.0 request signature ("VBE2"), required to receive
32 // version 2.0 info
33 USHORT VesaVersion; // VESA version number (one-digit minor version -- 0102h = v1.2)
34 ULONG OemNamePtr; // pointer to OEM name
35 // "761295520" for ATI
36 ULONG Capabilities; // capabilities flags (see #00078)
37 ULONG SupportedModeListPtr; // pointer to list of supported VESA and OEM video modes
38 // (list of words terminated with FFFFh)
39 USHORT TotalVideoMemory; // total amount of video memory in 64K blocks
40
41 // ---VBE v1.x ---
42 //UCHAR Reserved[236];
43
44 // ---VBE v2.0 ---
45 USHORT OemSoftwareVersion; // OEM software version (BCD, high byte = major, low byte = minor)
46 ULONG VendorNamePtr; // pointer to vendor name
47 ULONG ProductNamePtr; // pointer to product name
48 ULONG ProductRevisionStringPtr; // pointer to product revision string
49 USHORT VBE_AF_Version; // (if capabilities bit 3 set) VBE/AF version (BCD)
50 // 0100h for v1.0P
51 ULONG AcceleratedModeListPtr; // (if capabilities bit 3 set) pointer to list of supported
52 // accelerated video modes (list of words terminated with FFFFh)
53 UCHAR Reserved[216]; // reserved for VBE implementation
54 UCHAR ScratchPad[256]; // OEM scratchpad (for OEM strings, etc.)
55 } VESA_SVGA_INFO, *PVESA_SVGA_INFO;
56 #include <poppack.h>
57
58 // Bitfields for VESA capabilities:
59 //
60 // Bit(s) Description (Table 00078)
61 // 0 DAC can be switched into 8-bit mode
62 // 1 non-VGA controller
63 // 2 programmed DAC with blank bit (i.e. only during blanking interval)
64 // 3 (VBE v3.0) controller supports hardware stereoscopic signalling
65 // 3 controller supports VBE/AF v1.0P extensions
66 // 4 (VBE v3.0) if bit 3 set:
67 // =0 stereo signalling via external VESA stereo connector
68 // =1 stereo signalling via VESA EVC connector
69 // 4 (VBE/AF v1.0P) must call EnableDirectAccess to access framebuffer
70 // 5 (VBE/AF v1.0P) controller supports hardware mouse cursor
71 // 6 (VBE/AF v1.0P) controller supports hardware clipping
72 // 7 (VBE/AF v1.0P) controller supports transparent BitBLT
73 // 8-31 reserved (0)
74
75 // Notes: The list of supported video modes is stored in the reserved
76 // portion of the SuperVGA information record by some implementations,
77 // and it may thus be necessary to either copy the mode list or use a
78 // different buffer for all subsequent VESA calls. Not all of the video
79 // modes in the list of mode numbers may be supported, e.g. if they require
80 // more memory than currently installed or are not supported by the
81 // attached monitor. Check any mode you intend to use through AX=4F01h first..
82 // The 1.1 VESA document specifies 242 reserved bytes at the end, so the
83 // buffer should be 262 bytes to ensure that it is not overrun; for v2.0,
84 // the buffer should be 512 bytes. The S3 specific video modes will most
85 // likely follow the FFFFh terminator at the end of the standard modes.
86 // A search must then be made to find them, FFFFh will also terminate this
87 // second list. In some cases, only a "stub" VBE may be present, supporting
88 // only AX=4F00h; this case may be assumed if the list of supported video modes
89 // is empty (consisting of a single word of FFFFh)
90 #if 0
91 static VOID BiosSetVideoFont8x16(VOID)
92 {
93 REGS Regs;
94
95 // Int 10h AX=1114h
96 // VIDEO - TEXT-MODE CHARGEN - LOAD ROM 8x16 CHARACTER SET (VGA)
97 //
98 // AX = 1114h
99 // BL = block to load
100 // Return:
101 // Nothing
102 Regs.w.ax = 0x1114;
103 Regs.b.bl = 0;
104 Int386(0x10, &Regs, &Regs);
105 }
106
107 static VOID VideoSetTextCursorPosition(ULONG X, ULONG Y)
108 {
109 }
110
111 static ULONG VideoGetTextCursorPositionX(VOID)
112 {
113 REGS Regs;
114
115 // Int 10h AH=03h
116 // VIDEO - GET CURSOR POSITION AND SIZE
117 //
118 // AH = 03h
119 // BH = page number
120 // 0-3 in modes 2&3
121 // 0-7 in modes 0&1
122 // 0 in graphics modes
123 // Return:
124 // AX = 0000h (Phoenix BIOS)
125 // CH = start scan line
126 // CL = end scan line
127 // DH = row (00h is top)
128 // DL = column (00h is left)
129 Regs.b.ah = 0x03;
130 Regs.b.bh = 0x00;
131 Int386(0x10, &Regs, &Regs);
132
133 return Regs.b.dl;
134 }
135
136 static ULONG VideoGetTextCursorPositionY(VOID)
137 {
138 REGS Regs;
139
140 // Int 10h AH=03h
141 // VIDEO - GET CURSOR POSITION AND SIZE
142 //
143 // AH = 03h
144 // BH = page number
145 // 0-3 in modes 2&3
146 // 0-7 in modes 0&1
147 // 0 in graphics modes
148 // Return:
149 // AX = 0000h (Phoenix BIOS)
150 // CH = start scan line
151 // CL = end scan line
152 // DH = row (00h is top)
153 // DL = column (00h is left)
154 Regs.b.ah = 0x03;
155 Regs.b.bh = 0x00;
156 Int386(0x10, &Regs, &Regs);
157
158 return Regs.b.dh;
159 }
160 #endif
161
162 USHORT BiosIsVesaSupported(VOID)
163 {
164 REGS Regs;
165 PVESA_SVGA_INFO SvgaInfo = (PVESA_SVGA_INFO)BIOSCALLBUFFER;
166 //USHORT* VideoModes;
167 //USHORT Index;
168
169 TRACE("BiosIsVesaSupported()\n");
170
171 RtlZeroMemory(SvgaInfo, sizeof(VESA_SVGA_INFO));
172
173 // Make sure we receive version 2.0 info
174 SvgaInfo->Signature[0] = 'V';
175 SvgaInfo->Signature[1] = 'B';
176 SvgaInfo->Signature[2] = 'E';
177 SvgaInfo->Signature[3] = '2';
178
179 // Int 10h AX=4F00h
180 // VESA SuperVGA BIOS (VBE) - GET SuperVGA INFORMATION
181 //
182 // AX = 4F00h
183 // ES:DI -> buffer for SuperVGA information (see #00077)
184 // Return:
185 // AL = 4Fh if function supported
186 // AH = status
187 // 00h successful
188 // ES:DI buffer filled
189 // 01h failed
190 // ---VBE v2.0---
191 // 02h function not supported by current hardware configuration
192 // 03h function invalid in current video mode
193 //
194 // Determine whether VESA BIOS extensions are present and the
195 // capabilities supported by the display adapter
196 //
197 // Installation check;VESA SuperVGA
198 Regs.w.ax = 0x4F00;
199 Regs.w.es = BIOSCALLBUFSEGMENT;
200 Regs.w.di = BIOSCALLBUFOFFSET;
201 Int386(0x10, &Regs, &Regs);
202
203 TRACE("AL = 0x%x\n", Regs.b.al);
204 TRACE("AH = 0x%x\n", Regs.b.ah);
205
206 if (Regs.w.ax != 0x004F)
207 {
208 WARN("VBE Get SuperVGA information function not supported (AL=0x%x) or failed (AH=0x%x)\n",
209 Regs.b.al, Regs.b.ah);
210 return 0x0000;
211 }
212
213 TRACE("Supported.\n");
214 TRACE("SvgaInfo->Signature[4] = %c%c%c%c\n", SvgaInfo->Signature[0], SvgaInfo->Signature[1], SvgaInfo->Signature[2], SvgaInfo->Signature[3]);
215 TRACE("SvgaInfo->VesaVersion = v%d.%d\n", ((SvgaInfo->VesaVersion >> 8) & 0xFF), (SvgaInfo->VesaVersion & 0xFF));
216 TRACE("SvgaInfo->OemNamePtr = 0x%x\n", SvgaInfo->OemNamePtr);
217 TRACE("SvgaInfo->Capabilities = 0x%x\n", SvgaInfo->Capabilities);
218 TRACE("SvgaInfo->VideoMemory = %dK\n", SvgaInfo->TotalVideoMemory * 64);
219 TRACE("---VBE v2.0 ---\n");
220 TRACE("SvgaInfo->OemSoftwareVersion = v%d.%d\n", ((SvgaInfo->OemSoftwareVersion >> 8) & 0x0F) + (((SvgaInfo->OemSoftwareVersion >> 12) & 0x0F) * 10), (SvgaInfo->OemSoftwareVersion & 0x0F) + (((SvgaInfo->OemSoftwareVersion >> 4) & 0x0F) * 10));
221 TRACE("SvgaInfo->VendorNamePtr = 0x%x\n", SvgaInfo->VendorNamePtr);
222 TRACE("SvgaInfo->ProductNamePtr = 0x%x\n", SvgaInfo->ProductNamePtr);
223 TRACE("SvgaInfo->ProductRevisionStringPtr = 0x%x\n", SvgaInfo->ProductRevisionStringPtr);
224 TRACE("SvgaInfo->VBE/AF Version = 0x%x (BCD WORD)\n", SvgaInfo->VBE_AF_Version);
225
226 if (SvgaInfo->Signature[0] != 'V' ||
227 SvgaInfo->Signature[1] != 'E' ||
228 SvgaInfo->Signature[2] != 'S' ||
229 SvgaInfo->Signature[3] != 'A')
230 {
231 ERR("Bad signature in VESA information (%c%c%c%c)\n",
232 SvgaInfo->Signature[0],
233 SvgaInfo->Signature[1],
234 SvgaInfo->Signature[2],
235 SvgaInfo->Signature[3]);
236 return 0x0000;
237 }
238
239 return SvgaInfo->VesaVersion;
240 }
241
242
243 BOOLEAN
244 BiosIsVesaDdcSupported(VOID)
245 {
246 REGS Regs;
247
248 TRACE("BiosIsVesaDdcSupported()\n");
249
250 Regs.w.ax = 0x4F15;
251 Regs.b.bl = 0;
252 Regs.w.cx = 0;
253 Regs.w.es = 0;
254 Regs.w.di = 0;
255 Int386(0x10, &Regs, &Regs);
256
257 TRACE("AL = 0x%x\n", Regs.b.al);
258 TRACE("AH = 0x%x\n", Regs.b.ah);
259
260 TRACE("BL = 0x%x\n", Regs.b.bl);
261
262 if (Regs.w.ax != 0x004F)
263 {
264 WARN("VBE/DDC Installation check function not supported (AL=0x%x) or failed (AH=0x%x)\n",
265 Regs.b.al, Regs.b.ah);
266 return FALSE;
267 }
268
269 return (Regs.b.ah == 0);
270 }
271
272
273 BOOLEAN
274 BiosVesaReadEdid(VOID)
275 {
276 REGS Regs;
277
278 TRACE("BiosVesaReadEdid()\n");
279
280 RtlZeroMemory((PVOID)BIOSCALLBUFFER, 128);
281
282 Regs.w.ax = 0x4F15;
283 Regs.b.bl = 1;
284 Regs.w.cx = 0;
285 Regs.w.dx = 0;
286 Regs.w.es = BIOSCALLBUFSEGMENT;
287 Regs.w.di = BIOSCALLBUFOFFSET;
288 Int386(0x10, &Regs, &Regs);
289
290 TRACE("AL = 0x%x\n", Regs.b.al);
291 TRACE("AH = 0x%x\n", Regs.b.ah);
292
293 if (Regs.w.ax != 0x004F)
294 {
295 WARN("VBE/DDC Read EDID function not supported (AL=0x%x) or failed (AH=0x%x)\n",
296 Regs.b.al, Regs.b.ah);
297 return FALSE;
298 }
299
300 return (Regs.b.ah == 0);
301 }
302
303 /* EOF */