]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/WinNtConsoleDxe/ConsoleOut.c
Add WinNtSimpleFileSystemDxe driver into Nt32Pkg.
[mirror_edk2.git] / Nt32Pkg / WinNtConsoleDxe / ConsoleOut.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 ConsoleOut.c
15
16 Abstract:
17
18 Console based on Win32 APIs.
19
20 This file creates an Win32 window and attaches a SimpleTextOut protocol.
21
22 --*/
23
24 //
25 // The package level header files this module uses
26 //
27 #include <Uefi.h>
28 #include <WinNtDxe.h>
29 //
30 // The protocols, PPI and GUID defintions for this module
31 //
32 #include <Protocol/SimpleTextIn.h>
33 #include <Protocol/WinNtIo.h>
34 #include <Protocol/SimpleTextOut.h>
35 #include <Protocol/ComponentName.h>
36 #include <Protocol/DriverBinding.h>
37 //
38 // The Library classes this module consumes
39 //
40 #include <Library/DebugLib.h>
41 #include <Library/BaseLib.h>
42 #include <Library/UefiDriverEntryPoint.h>
43 #include <Library/UefiLib.h>
44 #include <Library/BaseMemoryLib.h>
45 #include <Library/UefiBootServicesTableLib.h>
46 #include <Library/MemoryAllocationLib.h>
47
48
49 #include "Console.h"
50 //
51 // Private worker functions.
52 //
53
54 STATIC
55 VOID
56 WinNtSimpleTextOutScrollScreen (
57 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Console
58 );
59
60 STATIC
61 VOID
62 WinNtSimpleTextOutPutChar (
63 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Console,
64 IN CHAR16 Char
65 );
66
67 //
68 // Modeule Global for Simple Text Out Mode.
69 //
70 #define MAX_SIMPLE_TEXT_OUT_MODE \
71 (sizeof(mWinNtSimpleTextOutSupportedModes)/sizeof(WIN_NT_SIMPLE_TEXT_OUT_MODE))
72
73 STATIC WIN_NT_SIMPLE_TEXT_OUT_MODE mWinNtSimpleTextOutSupportedModes[] = {
74 { 80, 25 },
75 { 80, 50 },
76 { 80, 43 },
77 { 100, 100 },
78 { 100, 999 }
79 };
80
81 STATIC
82 EFI_STATUS
83 EFIAPI
84 WinNtSimpleTextOutReset (
85 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
86 IN BOOLEAN ExtendedVerification
87 )
88 /*++
89
90 Routine Description:
91
92 TODO: Add function description
93
94 Arguments:
95
96 This - TODO: add argument description
97 ExtendedVerification - TODO: add argument description
98
99 Returns:
100
101 EFI_SUCCESS - TODO: Add description for return value
102
103 --*/
104 {
105 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
106
107 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
108
109 WinNtSimpleTextOutSetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));
110
111 WinNtSimpleTextOutSetMode (This, 0);
112 return EFI_SUCCESS;
113 }
114
115 STATIC
116 EFI_STATUS
117 EFIAPI
118 WinNtSimpleTextOutOutputString (
119 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
120 IN CHAR16 *String
121 )
122 /*++
123
124 Routine Description:
125
126 TODO: Add function description
127
128 Arguments:
129
130 This - TODO: add argument description
131 String - TODO: add argument description
132
133 Returns:
134
135 EFI_SUCCESS - TODO: Add description for return value
136
137 --*/
138 {
139 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
140 CHAR16 *Str;
141
142 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
143
144 for (Str = String; *Str != '\0'; Str++) {
145 switch (*Str) {
146 case '\n':
147 if (Private->Possition.Y == (Private->MaxScreenSize.Y - 1)) {
148 WinNtSimpleTextOutScrollScreen (Private);
149 }
150
151 if (Private->Possition.Y < (Private->MaxScreenSize.Y - 1)) {
152 Private->Possition.Y++;
153 This->Mode->CursorRow++;
154 }
155 break;
156
157 case '\r':
158 Private->Possition.X = 0;
159 This->Mode->CursorColumn = 0;
160 break;
161
162 case '\b':
163 if (Private->Possition.X > 0) {
164 Private->Possition.X--;
165 This->Mode->CursorColumn--;
166 }
167 break;
168
169 default:
170 WinNtSimpleTextOutPutChar (Private, *Str);
171 }
172 }
173
174 return EFI_SUCCESS;
175 }
176
177 STATIC
178 VOID
179 WinNtSimpleTextOutPutChar (
180 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Console,
181 IN CHAR16 Char
182 )
183 /*++
184
185 Routine Description:
186
187 TODO: Add function description
188
189 Arguments:
190
191 Console - TODO: add argument description
192 Char - TODO: add argument description
193
194 Returns:
195
196 TODO: add return values
197
198 --*/
199 {
200 SMALL_RECT Region;
201 COORD StrCoordinate;
202 COORD StrSize;
203 CHAR_INFO CharInfo;
204 BOOL Flag;
205
206 CharInfo.Char.UnicodeChar = Char;
207 CharInfo.Attributes = Console->Attribute;
208
209 StrSize.X = 1;
210 StrSize.Y = 1;
211 StrCoordinate.X = 0;
212 StrCoordinate.Y = 0;
213
214 Region.Left = (INT16) Console->Possition.X;
215 Region.Top = (INT16) Console->Possition.Y;
216 Region.Right = (INT16) (Console->Possition.X + 1);
217 Region.Bottom = (INT16) Console->Possition.Y;
218
219 Console->WinNtThunk->WriteConsoleOutput (
220 Console->NtOutHandle,
221 &CharInfo,
222 StrSize,
223 StrCoordinate,
224 &Region
225 );
226
227 if (Console->Possition.X >= (Console->MaxScreenSize.X - 1)) {
228 //
229 // If you print off the end wrap around
230 //
231 Console->SimpleTextOut.OutputString (&Console->SimpleTextOut, L"\n\r");
232 } else {
233 Console->Possition.X++;
234 Console->SimpleTextOut.Mode->CursorColumn++;
235 }
236
237 Flag = Console->WinNtThunk->SetConsoleCursorPosition (Console->NtOutHandle, Console->Possition);
238 }
239
240 STATIC
241 VOID
242 WinNtSimpleTextOutScrollScreen (
243 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Console
244 )
245 /*++
246
247 Routine Description:
248
249 TODO: Add function description
250
251 Arguments:
252
253 Console - TODO: add argument description
254
255 Returns:
256
257 TODO: add return values
258
259 --*/
260 {
261 SMALL_RECT Scroll;
262 CHAR_INFO CharInfo;
263 COORD Origin;
264
265 CharInfo.Char.UnicodeChar = ' ';
266 CharInfo.Attributes = Console->Attribute;
267
268 Origin.X = 0;
269 Origin.Y = 0;
270
271 Scroll.Top = 1;
272 Scroll.Left = 0;
273 Scroll.Right = (INT16) Console->MaxScreenSize.X;
274 Scroll.Bottom = (INT16) Console->MaxScreenSize.Y;
275
276 Console->WinNtThunk->ScrollConsoleScreenBuffer (
277 Console->NtOutHandle,
278 &Scroll,
279 NULL,
280 Origin,
281 &CharInfo
282 );
283 }
284
285 STATIC
286 EFI_STATUS
287 EFIAPI
288 WinNtSimpleTextOutTestString (
289 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
290 IN CHAR16 *String
291 )
292 /*++
293
294 Routine Description:
295
296 TODO: Add function description
297
298 Arguments:
299
300 This - TODO: add argument description
301 String - TODO: add argument description
302
303 Returns:
304
305 EFI_SUCCESS - TODO: Add description for return value
306
307 --*/
308 {
309 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
310
311 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
312
313 //
314 // BugBug: The correct answer would be a function of what code pages
315 // are currently loaded? For now we will just return success.
316 //
317 return EFI_SUCCESS;
318 }
319
320 STATIC
321 EFI_STATUS
322 EFIAPI
323 WinNtSimpleTextOutQueryMode (
324 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
325 IN UINTN ModeNumber,
326 OUT UINTN *Columns,
327 OUT UINTN *Rows
328 )
329 /*++
330
331 Routine Description:
332
333 TODO: Add function description
334
335 Arguments:
336
337 This - TODO: add argument description
338 ModeNumber - TODO: add argument description
339 Columns - TODO: add argument description
340 Rows - TODO: add argument description
341
342 Returns:
343
344 EFI_INVALID_PARAMETER - TODO: Add description for return value
345 EFI_SUCCESS - TODO: Add description for return value
346
347 --*/
348 {
349 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
350
351 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
352
353 if (ModeNumber > MAX_SIMPLE_TEXT_OUT_MODE) {
354 return EFI_INVALID_PARAMETER;
355 }
356
357 *Columns = mWinNtSimpleTextOutSupportedModes[ModeNumber].ColumnsX;
358 *Rows = mWinNtSimpleTextOutSupportedModes[ModeNumber].RowsY;
359
360 return EFI_SUCCESS;
361 }
362
363 STATIC
364 EFI_STATUS
365 EFIAPI
366 WinNtSimpleTextOutSetMode (
367 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
368 IN UINTN ModeNumber
369 )
370 /*++
371
372 Routine Description:
373
374 TODO: Add function description
375
376 Arguments:
377
378 This - TODO: add argument description
379 ModeNumber - TODO: add argument description
380
381 Returns:
382
383 EFI_INVALID_PARAMETER - TODO: Add description for return value
384 EFI_SUCCESS - TODO: Add description for return value
385
386 --*/
387 {
388 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
389
390 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
391
392 if (ModeNumber > MAX_SIMPLE_TEXT_OUT_MODE) {
393 return EFI_INVALID_PARAMETER;
394 }
395
396 Private->MaxScreenSize.X = (WORD) mWinNtSimpleTextOutSupportedModes[ModeNumber].ColumnsX;
397 Private->MaxScreenSize.Y = (WORD) mWinNtSimpleTextOutSupportedModes[ModeNumber].RowsY;
398
399 Private->WinNtThunk->SetConsoleScreenBufferSize (Private->NtOutHandle, Private->MaxScreenSize);
400 Private->WinNtThunk->SetConsoleActiveScreenBuffer (Private->NtOutHandle);
401
402 This->Mode->Mode = (INT32) ModeNumber;
403
404 This->EnableCursor (This, TRUE);
405 This->ClearScreen (This);
406 return EFI_SUCCESS;
407 }
408
409 STATIC
410 EFI_STATUS
411 EFIAPI
412 WinNtSimpleTextOutSetAttribute (
413 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
414 IN UINTN Attribute
415 )
416 /*++
417
418 Routine Description:
419
420 TODO: Add function description
421
422 Arguments:
423
424 This - TODO: add argument description
425 Attribute - TODO: add argument description
426
427 Returns:
428
429 EFI_SUCCESS - TODO: Add description for return value
430
431 --*/
432 {
433 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
434
435 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
436
437 Private->Attribute = (WORD) Attribute;
438 This->Mode->Attribute = (INT32) Attribute;
439
440 return EFI_SUCCESS;
441 }
442
443 STATIC
444 EFI_STATUS
445 EFIAPI
446 WinNtSimpleTextOutClearScreen (
447 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
448 )
449 /*++
450
451 Routine Description:
452
453 TODO: Add function description
454
455 Arguments:
456
457 This - TODO: add argument description
458
459 Returns:
460
461 EFI_SUCCESS - TODO: Add description for return value
462
463 --*/
464 {
465 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
466 DWORD ConsoleWindow;
467
468 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
469
470 This->SetCursorPosition (This, 0, 0);
471
472 Private->WinNtThunk->FillConsoleOutputCharacter (
473 Private->NtOutHandle,
474 ' ',
475 Private->MaxScreenSize.X * Private->MaxScreenSize.Y,
476 Private->Possition,
477 &ConsoleWindow
478 );
479 Private->WinNtThunk->FillConsoleOutputAttribute (
480 Private->NtOutHandle,
481 Private->Attribute,
482 Private->MaxScreenSize.X * Private->MaxScreenSize.Y,
483 Private->Possition,
484 &ConsoleWindow
485 );
486
487 return EFI_SUCCESS;
488 }
489
490 STATIC
491 EFI_STATUS
492 EFIAPI
493 WinNtSimpleTextOutSetCursorPosition (
494 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
495 IN UINTN Column,
496 IN UINTN Row
497 )
498 /*++
499
500 Routine Description:
501
502 TODO: Add function description
503
504 Arguments:
505
506 This - TODO: add argument description
507 Column - TODO: add argument description
508 Row - TODO: add argument description
509
510 Returns:
511
512 EFI_SUCCESS - TODO: Add description for return value
513
514 --*/
515 {
516 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
517
518 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
519
520 Private->Possition.X = (WORD) Column;
521 This->Mode->CursorColumn = (INT32) Column;
522
523 Private->Possition.Y = (WORD) Row;
524 This->Mode->CursorRow = (INT32) Row;
525 Private->WinNtThunk->SetConsoleCursorPosition (Private->NtOutHandle, Private->Possition);
526
527 return EFI_SUCCESS;
528 }
529
530 STATIC
531 EFI_STATUS
532 EFIAPI
533 WinNtSimpleTextOutEnableCursor (
534 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
535 IN BOOLEAN Enable
536 )
537 /*++
538
539 Routine Description:
540
541 TODO: Add function description
542
543 Arguments:
544
545 This - TODO: add argument description
546 Enable - TODO: add argument description
547
548 Returns:
549
550 EFI_SUCCESS - TODO: Add description for return value
551
552 --*/
553 {
554 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private;
555 CONSOLE_CURSOR_INFO Info;
556
557 Private = WIN_NT_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
558 Private->CursorEnable = Enable;
559 This->Mode->CursorVisible = Enable;
560
561 Private->WinNtThunk->GetConsoleCursorInfo (Private->NtOutHandle, &Info);
562 Info.bVisible = Enable;
563 Private->WinNtThunk->SetConsoleCursorInfo (Private->NtOutHandle, &Info);
564
565 return EFI_SUCCESS;
566 }
567
568 EFI_STATUS
569 WinNtSimpleTextOutOpenWindow (
570 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Private
571 )
572 /*++
573
574 Routine Description:
575
576 TODO: Add function description
577
578 Arguments:
579
580 Private - TODO: add argument description
581
582 Returns:
583
584 TODO: add return values
585
586 --*/
587 {
588 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
589 CHAR16 *WindowName;
590
591 WindowName = Private->WinNtIo->EnvString;
592 Private->Attribute = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
593 if (*WindowName == '?') {
594 Private->Attribute = BACKGROUND_RED | FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;
595 WindowName = L"EFI Emulator Error Console";
596 }
597
598 AddUnicodeString (
599 "eng",
600 gWinNtConsoleComponentName.SupportedLanguages,
601 &Private->ControllerNameTable,
602 WindowName
603 );
604
605 //
606 // Fill in protocol member functions
607 //
608 SimpleTextOut = &Private->SimpleTextOut;
609 SimpleTextOut->Reset = WinNtSimpleTextOutReset;
610 SimpleTextOut->OutputString = WinNtSimpleTextOutOutputString;
611 SimpleTextOut->TestString = WinNtSimpleTextOutTestString;
612 SimpleTextOut->QueryMode = WinNtSimpleTextOutQueryMode;
613 SimpleTextOut->SetMode = WinNtSimpleTextOutSetMode;
614 SimpleTextOut->SetAttribute = WinNtSimpleTextOutSetAttribute;
615 SimpleTextOut->ClearScreen = WinNtSimpleTextOutClearScreen;
616 SimpleTextOut->SetCursorPosition = WinNtSimpleTextOutSetCursorPosition;
617 SimpleTextOut->EnableCursor = WinNtSimpleTextOutEnableCursor;
618
619 //
620 // Initialize SimpleTextOut protocol mode structure
621 //
622 SimpleTextOut->Mode = &Private->SimpleTextOutMode;
623 SimpleTextOut->Mode->MaxMode = MAX_SIMPLE_TEXT_OUT_MODE;
624 SimpleTextOut->Mode->Attribute = (INT32) Private->Attribute;
625
626 //
627 // Open the window an initialize it!
628 //
629 Private->NtOutHandle = Private->WinNtThunk->CreateConsoleScreenBuffer (
630 GENERIC_WRITE | GENERIC_READ,
631 FILE_SHARE_WRITE | FILE_SHARE_READ,
632 NULL,
633 CONSOLE_TEXTMODE_BUFFER,
634 NULL
635 );
636 Private->WinNtThunk->SetConsoleTitle (WindowName);
637
638 return SimpleTextOut->SetMode (SimpleTextOut, 0);
639 }
640
641 EFI_STATUS
642 WinNtSimpleTextOutCloseWindow (
643 IN OUT WIN_NT_SIMPLE_TEXT_PRIVATE_DATA *Console
644 )
645 /*++
646
647 Routine Description:
648
649 TODO: Add function description
650
651 Arguments:
652
653 Console - TODO: add argument description
654
655 Returns:
656
657 EFI_SUCCESS - TODO: Add description for return value
658
659 --*/
660 {
661 Console->WinNtThunk->CloseHandle (Console->NtOutHandle);
662 return EFI_SUCCESS;
663 }