summaryrefslogblamecommitdiffstats
path: root/private/ntos/nthals/halx86/i386/xxdisp.c
blob: 5806751fc8dc1b328a1398b52f23ce4f7a06b606 (plain) (tree)
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476



























































































































































































































































































































































































































































































                                                                             
/*++

Copyright (c) 1991  Microsoft Corporation

Module Name:

    xxdisp.c

Abstract:

    This module implements the HAL display initialization and output routines
    for a x86 system.

Author:

    David N. Cutler (davec) 27-Apr-1991

Environment:

    Kernel mode

Revision History:

--*/

#include "halp.h"

//
// Private function prototypes
//
VOID
HalpClearDisplay(
    VOID
    );

VOID
HalpNextLine(
    VOID
    );

VOID
HalpScrollDisplay(
    VOID
    );

VOID
HalpPutCharacter(
    IN UCHAR Character
    );

#define REVERSE_ATTRIBUTE 0x17
#define ROWS 50
#define COLS 80

ULONG HalpCursorX=0;
ULONG HalpCursorY=0;

KSPIN_LOCK HalpDisplayLock;


PUSHORT VideoBuffer;

//
// If someone calls HalDisplayString before HalInitSystem, we need to be
// able to put something up on screen anyway.
//
BOOLEAN HalpDisplayInitialized=FALSE;

//
// This is how we tell if GDI has taken over the display.  If so, we are
// in graphics mode and we need to reset the display to text mode before
// displaying anything.  (Panic stop)
//
BOOLEAN HalpOwnsDisplay=TRUE;
PHAL_RESET_DISPLAY_PARAMETERS HalpResetDisplayParameters;

BOOLEAN HalpDoingCrashDump = FALSE;


VOID
HalAcquireDisplayOwnership (
    IN PHAL_RESET_DISPLAY_PARAMETERS  ResetDisplayParameters
    )

/*++

Routine Description:

    This routine switches ownership of the display away from the HAL to
    the system display driver. It is called when the system has reached
    a point during bootstrap where it is self supporting and can output
    its own messages. Once ownership has passed to the system display
    driver any attempts to output messages using HalDisplayString must
    result in ownership of the display reverting to the HAL and the
    display hardware reinitialized for use by the HAL.

Arguments:

    ResetDisplayParameters - if non-NULL the address of a function
    the hal can call to reset the video card.  The function returns
    TRUE if the display was reset.

Return Value:

    None.

--*/

{
    HalpResetDisplayParameters=ResetDisplayParameters;
    HalpOwnsDisplay=FALSE;
    return;
}

VOID
HalpVideoReboot()
{
    if (HalpResetDisplayParameters && !HalpOwnsDisplay) {
        //
        // Video work-around.  The video driver has a reset function,
        // call it before resetting the system in case the bios doesn't
        // know how to reset the displays video mode.
        //

        if (HalpResetDisplayParameters(COLS, ROWS)) {
            // display was reset, make sure it's blank
            HalpClearDisplay();
        }
    }
}



VOID
HalpInitializeDisplay(
    VOID
    )

/*++

Routine Description:

    Initializes the VGA display.  This uses HalpMapPhysicalMemory to map
    the video buffer at 0xb8000 - 0xba000 into high virtual memory.

Arguments:

    None.

Return Value:

    None.

--*/

{

    if (HalpDisplayInitialized == FALSE) {

        HalpDisplayInitialized = TRUE;

        KeInitializeSpinLock(&HalpDisplayLock);

        //
        // If somebody called HalDisplayString before Phase 0 initialization,
        // the video buffer has already been mapped and cleared, and a
        // message has already been displayed.  So we don't want to clear
        // the screen again, or map the screen again.
        //

        //
        // Map two pages of memory starting at physical address 0xb8000.
        //

        VideoBuffer = (PUSHORT)HalpMapPhysicalMemory((PVOID)0xb8000,2);

        HalpClearDisplay();
    }
}

VOID
HalDisplayString (
    PUCHAR String
    )

/*++

Routine Description:

    This routine displays a character string on the display screen.

Arguments:

    String - Supplies a pointer to the characters that are to be displayed.

Return Value:

    None.

--*/

{
    if (!HalpDisplayInitialized && HalpOwnsDisplay) {

        //
        // If somebody has called HalDisplayString before Phase 0
        // initialization, we need to make sure we get our message out
        // anyway.  So we initialize the display before HalInitSystem does.
        // HalpInitializeDisplay is smart enough to only map the video
        // buffer and clear the screen the first time it is called.
        //

        HalpInitializeDisplay();
    }

    //
    // Synchronize access to the display so that MP systems won't
    // get garbage output due to simultaneous calls.  It also prevents
    // two processors from attempting to call BIOS and reset the display
    // simultaneously.
    //

    KiAcquireSpinLock(&HalpDisplayLock);

    if (HalpOwnsDisplay == FALSE) {

        //
        // The display has been put in graphics mode, and we need to
        // reset it to text mode before we can display any text on it.
        //

        if (HalpResetDisplayParameters) {
            HalpOwnsDisplay = HalpResetDisplayParameters(COLS, ROWS);
        }

        if (HalpOwnsDisplay == FALSE) {
            HalpBiosDisplayReset();
        }

        HalpOwnsDisplay = TRUE;
        HalpDoingCrashDump = TRUE;
        HalpClearDisplay();
    }

    while (*String) {

        switch (*String) {
            case '\n':
                HalpNextLine();
                break;
            case '\r':
                HalpCursorX = 0;
                break;
            default:
                HalpPutCharacter(*String);
                if (++HalpCursorX == COLS) {
                    HalpNextLine();
                }
        }
        ++String;
    }

    KiReleaseSpinLock(&HalpDisplayLock);
    return;
}

VOID
HalpDisplayDebugStatus (
    PUCHAR str,
    ULONG  len
    )
{
    PUSHORT p;

    if (!HalpDisplayInitialized || !HalpOwnsDisplay) {
        return;
    }

    for (p = &VideoBuffer [COLS - len]; len; str++, p++, len--) {
        *p = (USHORT)((REVERSE_ATTRIBUTE << 8) | *str);
    }
}

VOID
HalQueryDisplayParameters (
    OUT PULONG WidthInCharacters,
    OUT PULONG HeightInLines,
    OUT PULONG CursorColumn,
    OUT PULONG CursorRow
    )
/*++

Routine Description:

    This routine return information about the display area and current
    cursor position.

Arguments:

    WidthInCharacter - Supplies a pointer to a varible that receives
        the width of the display area in characters.

    HeightInLines - Supplies a pointer to a variable that receives the
        height of the display area in lines.

    CursorColumn - Supplies a pointer to a variable that receives the
        current display column position.

    CursorRow - Supplies a pointer to a variable that receives the
        current display row position.

Return Value:

    None.

--*/
{
    *WidthInCharacters = COLS;
    *HeightInLines = ROWS;
    *CursorColumn = HalpCursorX;
    *CursorRow = HalpCursorX;

}

VOID
HalSetDisplayParameters (
    IN ULONG CursorColumn,
    IN ULONG CursorRow
    )
/*++

Routine Description:

    This routine set the current cursor position on the display area.

Arguments:

    CursorColumn - Supplies the new display column position.

    CursorRow - Supplies a the new display row position.

Return Value:

    None.

--*/
{
    HalpCursorX = CursorColumn >= COLS ? COLS-1 : CursorColumn;
    HalpCursorY = CursorRow >= ROWS ? ROWS-1 : CursorRow;
}

VOID
HalpNextLine(
    VOID
    )

/*++

Routine Description:

    Moves the cursor to the start of the next line, scrolling if necessary.

Arguments:

    None.

Return Value:

    None.

--*/

{
    if (HalpCursorY==ROWS-1) {
        HalpScrollDisplay();
    } else {
        ++HalpCursorY;
    }
    HalpCursorX = 0;
}

VOID
HalpScrollDisplay(
    VOID
    )

/*++

Routine Description:

    Scrolls the text on the display up one line.

Arguments:

    None

Return Value:

    None.

--*/

{
    PUSHORT NewStart;
    ULONG i;


    NewStart = VideoBuffer+COLS;
    RtlMoveMemory(VideoBuffer, NewStart, (ROWS-1)*COLS*sizeof(USHORT));

    for (i=(ROWS-1)*COLS; i<ROWS*COLS; i++) {
        VideoBuffer[i] = (REVERSE_ATTRIBUTE << 8) | ' ';
    }
}

VOID
HalpPutCharacter(
    IN UCHAR Character
    )

/*++

Routine Description:

    Places a character on the console screen.  It uses the variables
    HalpCursorX and HalpCursorY to determine the character's location.

Arguments:

    Character - Supplies the character to be displayed

Return Value:

    None.

--*/

{
    VideoBuffer[HalpCursorY*COLS + HalpCursorX] =
            (USHORT)((REVERSE_ATTRIBUTE << 8) | Character);
}

VOID
HalpClearDisplay(
    VOID
    )

/*++

Routine Description:

    Clears the video display and sets the current cursor position to the
    upper left-hand corner.

Arguments:

    None

Return Value:

    None.

--*/

{
    USHORT Attribute;
    ULONG i;

    Attribute = (REVERSE_ATTRIBUTE << 8) | ' ';
    for (i=0; i < ROWS*COLS; i++) {
       VideoBuffer[i] = Attribute;
    }
    HalpCursorX=0;
    HalpCursorY=0;

}