ReactOS 0.4.17-dev-1196-gb6224c3
bootvid.c File Reference
#include "precomp.h"
Include dependency graph for bootvid.c:

Go to the source code of this file.

Functions

static BOOLEAN VgaInterpretCmdStream (_In_ const USHORT *CmdStream)
 
static BOOLEAN VgaIsPresent (VOID)
 
BOOLEAN NTAPI VidInitialize (_In_ BOOLEAN SetMode)
 
VOID ResetDisplay (_In_ BOOLEAN SetMode)
 

Function Documentation

◆ ResetDisplay()

VOID ResetDisplay ( _In_ BOOLEAN  SetMode)

Definition at line 478 of file bootvid.c.

480{
481 /* Reset the video mode with HAL if requested */
482 if (SetMode && !HalResetDisplay())
483 {
484 /* The HAL didn't handle the display, fully re-initialize the VGA */
486 }
487
488 /* Always re-initialize the AC registers */
490
491 /* Re-initialize the palette and fill the screen black */
494}
VOID NTAPI VidSolidColorFill(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Right, _In_ ULONG Bottom, _In_ UCHAR Color)
Definition: bootvid.c:298
const USHORT VGA_640x480[]
Definition: bootdata.c:47
const USHORT AT_Initialization[]
Definition: bootdata.c:16
#define InitializePalette()
Definition: precomp.h:94
static BOOLEAN VgaInterpretCmdStream(_In_ const USHORT *CmdStream)
Definition: bootvid.c:14
#define HalResetDisplay
Definition: halfuncs.h:45
#define SCREEN_WIDTH
Definition: pc98video.c:24
#define SCREEN_HEIGHT
Definition: pc98video.c:25
#define BV_COLOR_BLACK
Definition: display.h:15

◆ VgaInterpretCmdStream()

static BOOLEAN VgaInterpretCmdStream ( _In_ const USHORT *  CmdStream)
static

Definition at line 14 of file bootvid.c.

16{
17 USHORT Cmd;
18 UCHAR Major, Minor;
23 USHORT ShortValue;
24
25 /* First make sure that we have a Command Stream */
26 if (!CmdStream)
27 return TRUE;
28
29 /* Loop as long as we have commands */
30 while (*CmdStream != EOD)
31 {
32 /* Get the next command and its Major and Minor functions */
33 Cmd = *CmdStream++;
34 Major = Cmd & 0xF0;
35 Minor = Cmd & 0x0F;
36
37 /* Check which major function this is */
38 if (Major == INOUT)
39 {
40 /* Check the minor function */
41 if (Minor & IO /* CMD_STREAM_READ */)
42 {
43 /* Check the sub-type */
44 if (Minor & BW /* CMD_STREAM_USHORT */)
45 {
46 /* Get the port and read an USHORT from it */
47 Port = *CmdStream++;
48 ShortValue = __inpw(Port);
49 }
50 else // if (Minor & CMD_STREAM_WRITE)
51 {
52 /* Get the port and read an UCHAR from it */
53 Port = *CmdStream++;
54 Value = __inpb(Port);
55 }
56 }
57 else if (Minor & MULTI /* CMD_STREAM_WRITE_ARRAY */)
58 {
59 /* Check the sub-type */
60 if (Minor & BW /* CMD_STREAM_USHORT */)
61 {
62 /* Get the port and the count of elements */
63 Port = *CmdStream++;
64 Count = *CmdStream++;
65
66 /* Write the USHORT to the port; the buffer is what's in the command stream */
68
69 /* Move past the buffer in the command stream */
70 CmdStream += Count;
71 }
72 else // if (Minor & CMD_STREAM_WRITE)
73 {
74 /* Get the port and the count of elements */
75 Port = *CmdStream++;
76 Count = *CmdStream++;
77
78 /* Loop the command array */
79 for (; Count; --Count, ++CmdStream)
80 {
81 /* Get the UCHAR and write it to the port */
82 Value = (UCHAR)*CmdStream;
84 }
85 }
86 }
87 else if (Minor & BW /* CMD_STREAM_USHORT */)
88 {
89 /* Get the port */
90 Port = *CmdStream++;
91
92 /* Get the USHORT and write it to the port */
93 ShortValue = *CmdStream++;
94 __outpw(Port, ShortValue);
95 }
96 else // if (Minor & CMD_STREAM_WRITE)
97 {
98 /* Get the port */
99 Port = *CmdStream++;
100
101 /* Get the UCHAR and write it to the port */
102 Value = (UCHAR)*CmdStream++;
104 }
105 }
106 else if (Major == METAOUT)
107 {
108 /* Check the minor function. Note these are not flags. */
109 switch (Minor)
110 {
111 case INDXOUT:
112 {
113 /* Get the port, the count of elements and the start index */
114 Port = *CmdStream++;
115 Count = *CmdStream++;
116 Index = (UCHAR)*CmdStream++;
117
118 /* Loop the command array */
119 for (; Count; --Count, ++Index, ++CmdStream)
120 {
121 /* Get the USHORT and write it to the port */
122 ShortValue = (USHORT)Index + ((*CmdStream) << 8);
123 __outpw(Port, ShortValue);
124 }
125 break;
126 }
127
128 case ATCOUT:
129 {
130 /* Get the port, the count of elements and the start index */
131 Port = *CmdStream++;
132 Count = *CmdStream++;
133 Index = (UCHAR)*CmdStream++;
134
135 /* Loop the command array */
136 for (; Count; --Count, ++Index, ++CmdStream)
137 {
138 /* Write the index */
140
141 /* Get the UCHAR and write it to the port */
142 Value = (UCHAR)*CmdStream;
144 }
145 break;
146 }
147
148 case MASKOUT:
149 {
150 /* Get the port */
151 Port = *CmdStream++;
152
153 /* Read the current value and add the stream data */
154 Value = __inpb(Port);
155 Value &= *CmdStream++;
156 Value ^= *CmdStream++;
157
158 /* Write the value */
160 break;
161 }
162
163 default:
164 /* Unknown command, fail */
165 return FALSE;
166 }
167 }
168 else if (Major != NCMD)
169 {
170 /* Unknown major function, fail */
171 return FALSE;
172 }
173 }
174
175 /* If we got here, return success */
176 return TRUE;
177}
#define WRITE_PORT_BUFFER_USHORT(port, buffer, count)
Definition: hardware.h:34
ULONG Minor
Definition: classlib.cpp:99
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ATCOUT
Definition: cmdcnst.h:76
#define NCMD
Definition: cmdcnst.h:63
#define INOUT
Definition: cmdcnst.h:61
#define INDXOUT
Definition: cmdcnst.h:75
#define BW
Definition: cmdcnst.h:70
#define MASKOUT
Definition: cmdcnst.h:77
#define EOD
Definition: cmdcnst.h:60
#define METAOUT
Definition: cmdcnst.h:62
#define MULTI
Definition: cmdcnst.h:69
#define IO
Definition: cmdcnst.h:71
CPPORT Port[4]
Definition: headless.c:38
int Count
Definition: noreturn.cpp:7
ULONG_PTR VgaRegisterBase
Definition: vga.c:68
#define __inpb(Port)
Definition: pc.h:18
#define __outpw(Port, Value)
Definition: pc.h:27
#define __outpb(Port, Value)
Definition: pc.h:24
#define __inpw(Port)
Definition: pc.h:21
unsigned short USHORT
Definition: pedump.c:61
@ Cmd
Definition: sacdrv.h:278
unsigned char UCHAR
Definition: typedefs.h:53
uint16_t * PUSHORT
Definition: typedefs.h:56
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by ResetDisplay(), and VidInitialize().

◆ VgaIsPresent()

static BOOLEAN VgaIsPresent ( VOID  )
static

Definition at line 180 of file bootvid.c.

181{
182 UCHAR OrgGCAddr, OrgReadMap, OrgBitMask;
183 UCHAR OrgSCAddr, OrgMemMode;
184 UCHAR i;
185
186#if (NTDDI_VERSION >= NTDDI_WIN7)
187 /* Check whether the current platform supports IO port access
188 * and fail if not, since we won't be able to use VGA IO ports */
189 if ((HALPRIVATEDISPATCH->Version >= 13) &&
191 {
192 return FALSE;
193 }
194#endif
195
196 /* Remember the original state of the Graphics Controller Address register */
198
199 /*
200 * Write the Read Map register with a known state so we can verify
201 * that it isn't changed after we fool with the Bit Mask. This ensures
202 * that we're dealing with indexed registers, since both the Read Map and
203 * the Bit Mask are addressed at GRAPH_DATA_PORT.
204 */
206
207 /*
208 * If we can't read back the Graphics Address register setting we just
209 * performed, it's not readable and this isn't a VGA.
210 */
212 return FALSE;
213
214 /*
215 * Set the Read Map register to a known state.
216 */
219
220 /* Read it back... it should be the same */
222 {
223 /*
224 * The Read Map setting we just performed can't be read back; not a
225 * VGA. Restore the default Read Map state and fail.
226 */
228 return FALSE;
229 }
230
231 /* Remember the original setting of the Bit Mask register */
233
234 /* Read it back... it should be the same */
236 {
237 /*
238 * The Graphics Address register setting we just made can't be read
239 * back; not a VGA. Restore the default Read Map state and fail.
240 */
243 return FALSE;
244 }
245
246 /* Read the VGA Data Register */
248
249 /*
250 * Set up the initial test mask we'll write to and read from the Bit Mask,
251 * and loop on the bitmasks.
252 */
253 for (i = 0xBB; i; i >>= 1)
254 {
255 /* Write the test mask to the Bit Mask */
257
258 /* Read it back... it should be the same */
260 {
261 /*
262 * The Bit Mask is not properly writable and readable; not a VGA.
263 * Restore the Bit Mask and Read Map to their default states and fail.
264 */
268 return FALSE;
269 }
270 }
271
272 /*
273 * There's something readable at GRAPH_DATA_PORT; now switch back and
274 * make sure that the Read Map register hasn't changed, to verify that
275 * we're dealing with indexed registers.
276 */
278
279 /* Read it back */
281 {
282 /*
283 * The Read Map is not properly writable and readable; not a VGA.
284 * Restore the Bit Mask and Read Map to their default states, in case
285 * this is an EGA, so subsequent writes to the screen aren't garbled.
286 * Then fail.
287 */
291 return FALSE;
292 }
293
294 /*
295 * We've pretty surely verified the existence of the Bit Mask register.
296 * Put the Graphics Controller back to the original state.
297 */
302
303 /*
304 * Now, check for the existence of the Chain4 bit.
305 */
306
307 /*
308 * Remember the original states of the Sequencer Address and Memory Mode
309 * registers.
310 */
313
314 /* Read it back... it should be the same */
316 {
317 /*
318 * Couldn't read back the Sequencer Address register setting
319 * we just performed, fail.
320 */
321 return FALSE;
322 }
323
324 /* Read sequencer Data */
325 OrgMemMode = __inpb(VGA_BASE_IO_PORT + SEQ_DATA_PORT);
326
327 /*
328 * Toggle the Chain4 bit and read back the result. This must be done during
329 * sync reset, since we're changing the chaining state.
330 */
331
332 /* Begin sync reset */
334
335 /* Toggle the Chain4 bit */
338
339 /* Read it back... it should be the same */
340 if (__inpb(VGA_BASE_IO_PORT + SEQ_DATA_PORT) != (OrgMemMode ^ CHAIN4_MASK))
341 {
342 /*
343 * Chain4 bit is not there, not a VGA.
344 * Set text mode default for Memory Mode register.
345 */
347
348 /* End sync reset */
350
351 /* Fail */
352 return FALSE;
353 }
354
355 /*
356 * It's a VGA.
357 */
358
359 /* Restore the original Memory Mode setting */
361
362 /* End sync reset */
364
365 /* Restore the original Sequencer Address setting */
367
368 /* VGA is present! */
369 return TRUE;
370}
#define START_SYNC_RESET_VALUE
Definition: vga.h:123
#define SEQ_ADDRESS_PORT
Definition: vga.h:69
#define SEQ_ADDR_MASK
Definition: vga.h:145
#define GRAPH_ADDRESS_PORT
Definition: vga.h:81
#define GRAPH_DATA_PORT
Definition: vga.h:82
#define BIT_MASK_DEFAULT
Definition: vga.h:167
#define GRAPH_ADDR_MASK
Definition: vga.h:144
#define CHAIN4_MASK
Definition: vga.h:151
#define IND_BIT_MASK
Definition: vga.h:114
#define READ_MAP_DEFAULT
Definition: vga.h:168
#define IND_READ_MAP
Definition: vga.h:111
#define IND_SYNC_RESET
Definition: vga.h:115
#define READ_MAP_TEST_SETTING
Definition: vga.h:159
#define IND_MEMORY_MODE
Definition: vga.h:117
#define VGA_BASE_IO_PORT
Definition: vga.h:38
#define SEQ_DATA_PORT
Definition: vga.h:70
#define END_SYNC_RESET_VALUE
Definition: vga.h:125
#define MEMORY_MODE_TEXT_DEFAULT
Definition: vga.h:166
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define HalQueryIoPortAccessSupported
Definition: halfuncs.h:92
#define HALPRIVATEDISPATCH
Definition: haltypes.h:2101

Referenced by VidInitialize().

◆ VidInitialize()

BOOLEAN NTAPI VidInitialize ( _In_ BOOLEAN  SetMode)

Definition at line 376 of file bootvid.c.

378{
379 ULONG_PTR Context = 0;
381 PHYSICAL_ADDRESS NullAddress = {{0, 0}}, VgaAddress;
385
386 /* Make sure that we have a bus translation function */
388
389 /* Loop trying to find possible VGA base addresses */
390 while (TRUE)
391 {
392 /* Get the VGA Register address */
393 AddressSpace = 1;
397 &Context,
398 TRUE);
399 if (!Result) return FALSE;
400
401 /* See if this is I/O Space, which we need to map */
402 if (!AddressSpace)
403 {
404 /* Map it */
406 }
407 else
408 {
409 /* The base is the translated address, no need to map I/O space */
411 }
412
413 /* Try to see if this is VGA */
415 if (VgaIsPresent())
416 {
417 /* Translate the VGA Memory Address */
418 VgaAddress.LowPart = MEM_VGA;
419 VgaAddress.HighPart = 0;
420 AddressSpace = 0;
424 &Context,
425 FALSE);
426 if (Result) break;
427 }
428 else
429 {
430 /* It's not, so unmap the I/O space if we mapped it */
432 }
433
434 /* Continue trying to see if there's any other address */
435 }
436
437 /* Success! See if this is I/O Space, which we need to map */
438 if (!AddressSpace)
439 {
440 /* Map it */
444 }
445 else
446 {
447 /* The base is the translated address, no need to map I/O space */
449 }
450
451 /* Set the VGA Memory Base */
452 VgaBase = Base;
453
454 /* Check whether we have to set the video mode */
455 if (SetMode)
456 {
457 /* Clear the current position */
458 VidpCurrentX = 0;
459 VidpCurrentY = 0;
460
461 /* Reset the display and initialize it */
462 if (HalResetDisplay())
463 {
464 /* The HAL handled the display, re-initialize only the AC registers */
466 }
467 else
468 {
469 /* The HAL didn't handle the display, fully re-initialize the VGA */
471 }
472 }
473
474 return TRUE;
475}
unsigned char BOOLEAN
Definition: actypes.h:127
ULONG VidpCurrentY
Definition: console.c:16
ULONG VidpCurrentX
Definition: console.c:15
#define MEM_VGA_SIZE
Definition: vga.h:22
#define MEM_VGA
Definition: vga.h:21
#define ULONG_PTR
Definition: config.h:101
static BOOLEAN VgaIsPresent(VOID)
Definition: bootvid.c:180
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:192
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
_In_ PIRP _In_ PIO_COMPLETION_ROUTINE _In_ PVOID Context
Definition: kse.h:81
#define HalFindBusAddressTranslation
Definition: halfuncs.h:44
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2486
ULONG_PTR VgaBase
Definition: vga.c:69
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
ULONG LowPart
Definition: typedefs.h:106
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2275
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2274
@ MmNonCached
Definition: mmtypes.h:129