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
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.
25 BOOLEAN mInterruptState
= FALSE
;
26 extern UINT32 mExceptionCodeSize
;
27 UINTN mTimerVector
= 0;
28 volatile EFI_CPU_INTERRUPT_HANDLER mTimerHandler
= NULL
;
29 EFI_LEGACY_8259_PROTOCOL
*gLegacy8259
= NULL
;
32 // The Cpu Architectural Protocol that this Driver produces
34 EFI_HANDLE mHandle
= NULL
;
35 EFI_CPU_ARCH_PROTOCOL mCpu
= {
41 CpuRegisterInterruptHandler
,
43 CpuSetMemoryAttributes
,
45 4, // DmaBufferAlignment
50 CpuFlushCpuDataCache (
51 IN EFI_CPU_ARCH_PROTOCOL
*This
,
52 IN EFI_PHYSICAL_ADDRESS Start
,
54 IN EFI_CPU_FLUSH_TYPE FlushType
59 Flush CPU data cache. If the instruction cache is fully coherent
60 with all DMA operations then function can just return EFI_SUCCESS.
63 This - Protocol instance structure
64 Start - Physical address to start flushing from.
65 Length - Number of bytes to flush. Round up to chipset
67 FlushType - Specifies the type of flush operation to perform.
71 EFI_SUCCESS - If cache was flushed
72 EFI_UNSUPPORTED - If flush type is not supported.
73 EFI_DEVICE_ERROR - If requested range could not be flushed.
77 if (FlushType
== EfiCpuFlushTypeWriteBackInvalidate
) {
80 } else if (FlushType
== EfiCpuFlushTypeInvalidate
) {
84 return EFI_UNSUPPORTED
;
92 IN EFI_CPU_ARCH_PROTOCOL
*This
97 Enables CPU interrupts.
100 This - Protocol instance structure
103 EFI_SUCCESS - If interrupts were enabled in the CPU
104 EFI_DEVICE_ERROR - If interrupts could not be enabled on the CPU.
110 mInterruptState
= TRUE
;
117 CpuDisableInterrupt (
118 IN EFI_CPU_ARCH_PROTOCOL
*This
123 Disables CPU interrupts.
126 This - Protocol instance structure
129 EFI_SUCCESS - If interrupts were disabled in the CPU.
130 EFI_DEVICE_ERROR - If interrupts could not be disabled on the CPU.
134 DisableInterrupts ();
136 mInterruptState
= FALSE
;
143 CpuGetInterruptState (
144 IN EFI_CPU_ARCH_PROTOCOL
*This
,
150 Return the state of interrupts.
153 This - Protocol instance structure
154 State - Pointer to the CPU's current interrupt state
157 EFI_SUCCESS - If interrupts were disabled in the CPU.
158 EFI_INVALID_PARAMETER - State is NULL.
163 return EFI_INVALID_PARAMETER
;
166 *State
= mInterruptState
;
174 IN EFI_CPU_ARCH_PROTOCOL
*This
,
175 IN EFI_CPU_INIT_TYPE InitType
181 Generates an INIT to the CPU
184 This - Protocol instance structure
185 InitType - Type of CPU INIT to perform
188 EFI_SUCCESS - If CPU INIT occurred. This value should never be
190 EFI_DEVICE_ERROR - If CPU INIT failed.
191 EFI_NOT_SUPPORTED - Requested type of CPU INIT not supported.
195 return EFI_UNSUPPORTED
;
201 CpuRegisterInterruptHandler (
202 IN EFI_CPU_ARCH_PROTOCOL
*This
,
203 IN EFI_EXCEPTION_TYPE InterruptType
,
204 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
209 Registers a function to be called from the CPU interrupt handler.
212 This - Protocol instance structure
213 InterruptType - Defines which interrupt to hook. IA-32 valid range
215 InterruptHandler - A pointer to a function of type
216 EFI_CPU_INTERRUPT_HANDLER that is called when a
217 processor interrupt occurs. A null pointer
218 is an error condition.
221 EFI_SUCCESS - If handler installed or uninstalled.
222 EFI_ALREADY_STARTED - InterruptHandler is not NULL, and a handler for
223 InterruptType was previously installed
224 EFI_INVALID_PARAMETER - InterruptHandler is NULL, and a handler for
225 InterruptType was not previously installed.
226 EFI_UNSUPPORTED - The interrupt specified by InterruptType is not
231 if ((InterruptType
< 0) || (InterruptType
>= INTERRUPT_VECTOR_NUMBER
)) {
232 return EFI_UNSUPPORTED
;
234 if ((UINTN
)(UINT32
)InterruptType
!= mTimerVector
) {
235 return EFI_UNSUPPORTED
;
237 if ((mTimerHandler
== NULL
) && (InterruptHandler
== NULL
)) {
238 return EFI_INVALID_PARAMETER
;
239 } else if ((mTimerHandler
!= NULL
) && (InterruptHandler
!= NULL
)) {
240 return EFI_ALREADY_STARTED
;
242 mTimerHandler
= InterruptHandler
;
249 IN EFI_CPU_ARCH_PROTOCOL
*This
,
250 IN UINT32 TimerIndex
,
251 OUT UINT64
*TimerValue
,
252 OUT UINT64
*TimerPeriod OPTIONAL
257 Returns a timer value from one of the CPU's internal timers. There is no
258 inherent time interval between ticks but is a function of the CPU
262 This - Protocol instance structure
263 TimerIndex - Specifies which CPU timer ie requested
264 TimerValue - Pointer to the returned timer value
268 EFI_SUCCESS - If the CPU timer count was returned.
269 EFI_UNSUPPORTED - If the CPU does not have any readable timers
270 EFI_DEVICE_ERROR - If an error occurred reading the timer.
271 EFI_INVALID_PARAMETER - TimerIndex is not valid
275 if (TimerValue
== NULL
) {
276 return EFI_INVALID_PARAMETER
;
279 if (TimerIndex
== 0) {
280 *TimerValue
= AsmReadTsc ();
281 if (TimerPeriod
!= NULL
) {
283 // BugBug: Hard coded. Don't know how to do this generically
285 *TimerPeriod
= 1000000000;
289 return EFI_INVALID_PARAMETER
;
294 CpuSetMemoryAttributes (
295 IN EFI_CPU_ARCH_PROTOCOL
*This
,
296 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
303 Set memory cacheability attributes for given range of memeory
306 This - Protocol instance structure
307 BaseAddress - Specifies the start address of the memory range
308 Length - Specifies the length of the memory range
309 Attributes - The memory cacheability for the memory range
312 EFI_SUCCESS - If the cacheability of that memory range is set successfully
313 EFI_UNSUPPORTED - If the desired operation cannot be done
314 EFI_INVALID_PARAMETER - The input parameter is not correct, such as Length = 0
318 return EFI_UNSUPPORTED
;
321 #if CPU_EXCEPTION_DEBUG_OUTPUT
324 DumpExceptionDataDebugOut (
325 IN EFI_EXCEPTION_TYPE InterruptType
,
326 IN EFI_SYSTEM_CONTEXT SystemContext
329 UINT32 ErrorCodeFlag
;
331 ErrorCodeFlag
= 0x00027d00;
336 "!!!! IA32 Exception Type - %08x !!!!\n",
341 "EIP - %08x, CS - %08x, EFLAGS - %08x\n",
342 SystemContext
.SystemContextIa32
->Eip
,
343 SystemContext
.SystemContextIa32
->Cs
,
344 SystemContext
.SystemContextIa32
->Eflags
346 if (ErrorCodeFlag
& (1 << InterruptType
)) {
349 "ExceptionData - %08x\n",
350 SystemContext
.SystemContextIa32
->ExceptionData
355 "EAX - %08x, ECX - %08x, EDX - %08x, EBX - %08x\n",
356 SystemContext
.SystemContextIa32
->Eax
,
357 SystemContext
.SystemContextIa32
->Ecx
,
358 SystemContext
.SystemContextIa32
->Edx
,
359 SystemContext
.SystemContextIa32
->Ebx
363 "ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x\n",
364 SystemContext
.SystemContextIa32
->Esp
,
365 SystemContext
.SystemContextIa32
->Ebp
,
366 SystemContext
.SystemContextIa32
->Esi
,
367 SystemContext
.SystemContextIa32
->Edi
371 "DS - %08x, ES - %08x, FS - %08x, GS - %08x, SS - %08x\n",
372 SystemContext
.SystemContextIa32
->Ds
,
373 SystemContext
.SystemContextIa32
->Es
,
374 SystemContext
.SystemContextIa32
->Fs
,
375 SystemContext
.SystemContextIa32
->Gs
,
376 SystemContext
.SystemContextIa32
->Ss
380 "GDTR - %08x %08x, IDTR - %08x %08x\n",
381 SystemContext
.SystemContextIa32
->Gdtr
[0],
382 SystemContext
.SystemContextIa32
->Gdtr
[1],
383 SystemContext
.SystemContextIa32
->Idtr
[0],
384 SystemContext
.SystemContextIa32
->Idtr
[1]
388 "LDTR - %08x, TR - %08x\n",
389 SystemContext
.SystemContextIa32
->Ldtr
,
390 SystemContext
.SystemContextIa32
->Tr
394 "CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x\n",
395 SystemContext
.SystemContextIa32
->Cr0
,
396 SystemContext
.SystemContextIa32
->Cr2
,
397 SystemContext
.SystemContextIa32
->Cr3
,
398 SystemContext
.SystemContextIa32
->Cr4
402 "DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x\n",
403 SystemContext
.SystemContextIa32
->Dr0
,
404 SystemContext
.SystemContextIa32
->Dr1
,
405 SystemContext
.SystemContextIa32
->Dr2
,
406 SystemContext
.SystemContextIa32
->Dr3
410 "DR6 - %08x, DR7 - %08x\n",
411 SystemContext
.SystemContextIa32
->Dr6
,
412 SystemContext
.SystemContextIa32
->Dr7
417 "!!!! X64 Exception Type - %016lx !!!!\n",
418 (UINT64
)InterruptType
422 "RIP - %016lx, CS - %016lx, RFLAGS - %016lx\n",
423 SystemContext
.SystemContextX64
->Rip
,
424 SystemContext
.SystemContextX64
->Cs
,
425 SystemContext
.SystemContextX64
->Rflags
427 if (ErrorCodeFlag
& (1 << InterruptType
)) {
430 "ExceptionData - %016lx\n",
431 SystemContext
.SystemContextX64
->ExceptionData
436 "RAX - %016lx, RCX - %016lx, RDX - %016lx\n",
437 SystemContext
.SystemContextX64
->Rax
,
438 SystemContext
.SystemContextX64
->Rcx
,
439 SystemContext
.SystemContextX64
->Rdx
443 "RBX - %016lx, RSP - %016lx, RBP - %016lx\n",
444 SystemContext
.SystemContextX64
->Rbx
,
445 SystemContext
.SystemContextX64
->Rsp
,
446 SystemContext
.SystemContextX64
->Rbp
450 "RSI - %016lx, RDI - %016lx\n",
451 SystemContext
.SystemContextX64
->Rsi
,
452 SystemContext
.SystemContextX64
->Rdi
456 "R8 - %016lx, R9 - %016lx, R10 - %016lx\n",
457 SystemContext
.SystemContextX64
->R8
,
458 SystemContext
.SystemContextX64
->R9
,
459 SystemContext
.SystemContextX64
->R10
463 "R11 - %016lx, R12 - %016lx, R13 - %016lx\n",
464 SystemContext
.SystemContextX64
->R11
,
465 SystemContext
.SystemContextX64
->R12
,
466 SystemContext
.SystemContextX64
->R13
470 "R14 - %016lx, R15 - %016lx\n",
471 SystemContext
.SystemContextX64
->R14
,
472 SystemContext
.SystemContextX64
->R15
476 "DS - %016lx, ES - %016lx, FS - %016lx\n",
477 SystemContext
.SystemContextX64
->Ds
,
478 SystemContext
.SystemContextX64
->Es
,
479 SystemContext
.SystemContextX64
->Fs
483 "GS - %016lx, SS - %016lx\n",
484 SystemContext
.SystemContextX64
->Gs
,
485 SystemContext
.SystemContextX64
->Ss
489 "GDTR - %016lx %016lx, LDTR - %016lx\n",
490 SystemContext
.SystemContextX64
->Gdtr
[0],
491 SystemContext
.SystemContextX64
->Gdtr
[1],
492 SystemContext
.SystemContextX64
->Ldtr
496 "IDTR - %016lx %016lx, TR - %016lx\n",
497 SystemContext
.SystemContextX64
->Idtr
[0],
498 SystemContext
.SystemContextX64
->Idtr
[1],
499 SystemContext
.SystemContextX64
->Tr
503 "CR0 - %016lx, CR2 - %016lx, CR3 - %016lx\n",
504 SystemContext
.SystemContextX64
->Cr0
,
505 SystemContext
.SystemContextX64
->Cr2
,
506 SystemContext
.SystemContextX64
->Cr3
510 "CR4 - %016lx, CR8 - %016lx\n",
511 SystemContext
.SystemContextX64
->Cr4
,
512 SystemContext
.SystemContextX64
->Cr8
516 "DR0 - %016lx, DR1 - %016lx, DR2 - %016lx\n",
517 SystemContext
.SystemContextX64
->Dr0
,
518 SystemContext
.SystemContextX64
->Dr1
,
519 SystemContext
.SystemContextX64
->Dr2
523 "DR3 - %016lx, DR6 - %016lx, DR7 - %016lx\n",
524 SystemContext
.SystemContextX64
->Dr3
,
525 SystemContext
.SystemContextX64
->Dr6
,
526 SystemContext
.SystemContextX64
->Dr7
536 IN OUT CHAR16
*Buffer
,
537 IN CONST CHAR16
*Format
,
547 VA_START (Marker
, Format
);
550 // Process the format string. Stop if Buffer is over run.
553 for (Index
= 0; *Format
!= 0; Format
++) {
554 if (*Format
!= L
'%') {
555 Buffer
[Index
++] = *Format
;
559 // Now it's time to parse what follows after %
560 // Support: % [ 0 width ] [ l ] x
561 // width - fill 0, to ensure the width of x will be "width"
562 // l - UINT64 instead of UINT32
568 if (*Format
== L
'0') {
569 Flags
|= PREFIX_ZERO
;
571 Width
+= Width
* 10 + (*Format
- L
'0');
573 } while (*Format
>= L
'1' && *Format
<= L
'9');
576 if (*Format
== L
'l') {
584 Flags
|= PREFIX_ZERO
;
585 Width
= sizeof (UINT64
) * 2;
587 // break skiped on purpose
590 if ((Flags
& LONG_TYPE
) == LONG_TYPE
) {
591 Value
= VA_ARG (Marker
, UINT64
);
593 Value
= VA_ARG (Marker
, UINTN
);
596 UnicodeValueToString (Buffer
+Index
, Flags
, Value
, Width
);
598 for ( ; Buffer
[Index
] != L
'\0'; Index
++) {
605 // if the type is unknown print it to the screen
607 Buffer
[Index
++] = *Format
;
611 Buffer
[Index
++] = '\0';
619 DumpExceptionDataVgaOut (
620 IN EFI_EXCEPTION_TYPE InterruptType
,
621 IN EFI_SYSTEM_CONTEXT SystemContext
626 UINT32 ErrorCodeFlag
;
627 CHAR16
*VideoBufferBase
;
633 ErrorCodeFlag
= 0x00027d00;
634 VideoBufferBase
= (CHAR16
*) (UINTN
) 0xb8000;
635 VideoBuffer
= (CHAR16
*) (UINTN
) 0xb8000;
640 L
"!!!! IA32 Exception Type - %08x !!!!",
643 VideoBuffer
+= COLUMN_MAX
;
646 L
"EIP - %08x, CS - %08x, EFLAGS - %08x",
647 SystemContext
.SystemContextIa32
->Eip
,
648 SystemContext
.SystemContextIa32
->Cs
,
649 SystemContext
.SystemContextIa32
->Eflags
651 VideoBuffer
+= COLUMN_MAX
;
652 if (ErrorCodeFlag
& (1 << InterruptType
)) {
655 L
"ExceptionData - %08x",
656 SystemContext
.SystemContextIa32
->ExceptionData
658 VideoBuffer
+= COLUMN_MAX
;
662 L
"EAX - %08x, ECX - %08x, EDX - %08x, EBX - %08x",
663 SystemContext
.SystemContextIa32
->Eax
,
664 SystemContext
.SystemContextIa32
->Ecx
,
665 SystemContext
.SystemContextIa32
->Edx
,
666 SystemContext
.SystemContextIa32
->Ebx
668 VideoBuffer
+= COLUMN_MAX
;
672 L
"ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x",
673 SystemContext
.SystemContextIa32
->Esp
,
674 SystemContext
.SystemContextIa32
->Ebp
,
675 SystemContext
.SystemContextIa32
->Esi
,
676 SystemContext
.SystemContextIa32
->Edi
678 VideoBuffer
+= COLUMN_MAX
;
682 L
"DS - %08x, ES - %08x, FS - %08x, GS - %08x, SS - %08x",
683 SystemContext
.SystemContextIa32
->Ds
,
684 SystemContext
.SystemContextIa32
->Es
,
685 SystemContext
.SystemContextIa32
->Fs
,
686 SystemContext
.SystemContextIa32
->Gs
,
687 SystemContext
.SystemContextIa32
->Ss
689 VideoBuffer
+= COLUMN_MAX
;
693 L
"GDTR - %08x %08x, IDTR - %08x %08x",
694 SystemContext
.SystemContextIa32
->Gdtr
[0],
695 SystemContext
.SystemContextIa32
->Gdtr
[1],
696 SystemContext
.SystemContextIa32
->Idtr
[0],
697 SystemContext
.SystemContextIa32
->Idtr
[1]
699 VideoBuffer
+= COLUMN_MAX
;
703 L
"LDTR - %08x, TR - %08x",
704 SystemContext
.SystemContextIa32
->Ldtr
,
705 SystemContext
.SystemContextIa32
->Tr
707 VideoBuffer
+= COLUMN_MAX
;
711 L
"CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x",
712 SystemContext
.SystemContextIa32
->Cr0
,
713 SystemContext
.SystemContextIa32
->Cr2
,
714 SystemContext
.SystemContextIa32
->Cr3
,
715 SystemContext
.SystemContextIa32
->Cr4
717 VideoBuffer
+= COLUMN_MAX
;
721 L
"DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x",
722 SystemContext
.SystemContextIa32
->Dr0
,
723 SystemContext
.SystemContextIa32
->Dr1
,
724 SystemContext
.SystemContextIa32
->Dr2
,
725 SystemContext
.SystemContextIa32
->Dr3
727 VideoBuffer
+= COLUMN_MAX
;
731 L
"DR6 - %08x, DR7 - %08x",
732 SystemContext
.SystemContextIa32
->Dr6
,
733 SystemContext
.SystemContextIa32
->Dr7
735 VideoBuffer
+= COLUMN_MAX
;
739 L
"!!!! X64 Exception Type - %016lx !!!!",
740 (UINT64
)InterruptType
742 VideoBuffer
+= COLUMN_MAX
;
746 L
"RIP - %016lx, CS - %016lx, RFLAGS - %016lx",
747 SystemContext
.SystemContextX64
->Rip
,
748 SystemContext
.SystemContextX64
->Cs
,
749 SystemContext
.SystemContextX64
->Rflags
751 VideoBuffer
+= COLUMN_MAX
;
753 if (ErrorCodeFlag
& (1 << InterruptType
)) {
756 L
"ExceptionData - %016lx",
757 SystemContext
.SystemContextX64
->ExceptionData
759 VideoBuffer
+= COLUMN_MAX
;
764 L
"RAX - %016lx, RCX - %016lx, RDX - %016lx",
765 SystemContext
.SystemContextX64
->Rax
,
766 SystemContext
.SystemContextX64
->Rcx
,
767 SystemContext
.SystemContextX64
->Rdx
769 VideoBuffer
+= COLUMN_MAX
;
773 L
"RBX - %016lx, RSP - %016lx, RBP - %016lx",
774 SystemContext
.SystemContextX64
->Rbx
,
775 SystemContext
.SystemContextX64
->Rsp
,
776 SystemContext
.SystemContextX64
->Rbp
778 VideoBuffer
+= COLUMN_MAX
;
782 L
"RSI - %016lx, RDI - %016lx",
783 SystemContext
.SystemContextX64
->Rsi
,
784 SystemContext
.SystemContextX64
->Rdi
786 VideoBuffer
+= COLUMN_MAX
;
790 L
"R8 - %016lx, R9 - %016lx, R10 - %016lx",
791 SystemContext
.SystemContextX64
->R8
,
792 SystemContext
.SystemContextX64
->R9
,
793 SystemContext
.SystemContextX64
->R10
795 VideoBuffer
+= COLUMN_MAX
;
799 L
"R11 - %016lx, R12 - %016lx, R13 - %016lx",
800 SystemContext
.SystemContextX64
->R11
,
801 SystemContext
.SystemContextX64
->R12
,
802 SystemContext
.SystemContextX64
->R13
804 VideoBuffer
+= COLUMN_MAX
;
808 L
"R14 - %016lx, R15 - %016lx",
809 SystemContext
.SystemContextX64
->R14
,
810 SystemContext
.SystemContextX64
->R15
812 VideoBuffer
+= COLUMN_MAX
;
816 L
"DS - %016lx, ES - %016lx, FS - %016lx",
817 SystemContext
.SystemContextX64
->Ds
,
818 SystemContext
.SystemContextX64
->Es
,
819 SystemContext
.SystemContextX64
->Fs
821 VideoBuffer
+= COLUMN_MAX
;
825 L
"GS - %016lx, SS - %016lx",
826 SystemContext
.SystemContextX64
->Gs
,
827 SystemContext
.SystemContextX64
->Ss
829 VideoBuffer
+= COLUMN_MAX
;
833 L
"GDTR - %016lx %016lx, LDTR - %016lx",
834 SystemContext
.SystemContextX64
->Gdtr
[0],
835 SystemContext
.SystemContextX64
->Gdtr
[1],
836 SystemContext
.SystemContextX64
->Ldtr
838 VideoBuffer
+= COLUMN_MAX
;
842 L
"IDTR - %016lx %016lx, TR - %016lx",
843 SystemContext
.SystemContextX64
->Idtr
[0],
844 SystemContext
.SystemContextX64
->Idtr
[1],
845 SystemContext
.SystemContextX64
->Tr
847 VideoBuffer
+= COLUMN_MAX
;
851 L
"CR0 - %016lx, CR2 - %016lx, CR3 - %016lx",
852 SystemContext
.SystemContextX64
->Cr0
,
853 SystemContext
.SystemContextX64
->Cr2
,
854 SystemContext
.SystemContextX64
->Cr3
856 VideoBuffer
+= COLUMN_MAX
;
860 L
"CR4 - %016lx, CR8 - %016lx",
861 SystemContext
.SystemContextX64
->Cr4
,
862 SystemContext
.SystemContextX64
->Cr8
864 VideoBuffer
+= COLUMN_MAX
;
868 L
"DR0 - %016lx, DR1 - %016lx, DR2 - %016lx",
869 SystemContext
.SystemContextX64
->Dr0
,
870 SystemContext
.SystemContextX64
->Dr1
,
871 SystemContext
.SystemContextX64
->Dr2
873 VideoBuffer
+= COLUMN_MAX
;
877 L
"DR3 - %016lx, DR6 - %016lx, DR7 - %016lx",
878 SystemContext
.SystemContextX64
->Dr3
,
879 SystemContext
.SystemContextX64
->Dr6
,
880 SystemContext
.SystemContextX64
->Dr7
882 VideoBuffer
+= COLUMN_MAX
;
885 for (Index
= 0; Index
< COLUMN_MAX
* ROW_MAX
; Index
++) {
886 if (Index
> (UINTN
)(VideoBuffer
- VideoBufferBase
)) {
887 VideoBufferBase
[Index
] = 0x0c20;
889 VideoBufferBase
[Index
] |= 0x0c00;
896 #if CPU_EXCEPTION_VGA_SWITCH
904 Switch Video Mode from current mode to new mode, and return the old mode.
908 NewVideoMode - new video mode want to set
911 UINT16 - (UINT16) -1 indicates failure
912 Other value indicates the old mode, which can be used for restore later
917 EFI_LEGACY_BIOS_THUNK_PROTOCOL
*LegacyBios
;
918 EFI_IA32_REGISTER_SET Regs
;
919 UINT16 OriginalVideoMode
= (UINT16
) -1;
922 // See if the Legacy BIOS Protocol is available
924 Status
= gBS
->LocateProtocol (&gEfiLegacyBiosThunkProtocolGuid
, NULL
, (VOID
**) &LegacyBios
);
925 if (EFI_ERROR (Status
)) {
926 return OriginalVideoMode
;
930 // VESA SuperVGA BIOS - GET CURRENT VIDEO MODE
932 // Return:AL = 4Fh if function supported
933 // AH = status 00h successful
934 // BX = video mode (see #0082,#0083)
936 gBS
->SetMem (&Regs
, sizeof (Regs
), 0);
938 LegacyBios
->Int86 (LegacyBios
, 0x10, &Regs
);
939 if (Regs
.X
.AX
== 0x004F) {
940 OriginalVideoMode
= Regs
.X
.BX
;
943 // VIDEO - GET CURRENT VIDEO MODE
945 // Return:AH = number of character columns
946 // AL = display mode (see #0009 at AH=00h)
947 // BH = active page (see AH=05h)
949 gBS
->SetMem (&Regs
, sizeof (Regs
), 0);
951 LegacyBios
->Int86 (LegacyBios
, 0x10, &Regs
);
952 OriginalVideoMode
= Regs
.H
.AL
;
956 // Set new video mode
958 if (NewVideoMode
< 0x100) {
960 // Set the 80x25 Text VGA Mode: Assume successful always
962 // VIDEO - SET VIDEO MODE
964 // AL = desired video mode (see #0009)
965 // Return:AL = video mode flag (Phoenix, AMI BIOS)
967 // 30h modes 0-5 and 7
969 // AL = CRT controller mode byte (Phoenix 386 BIOS v1.10)
971 gBS
->SetMem (&Regs
, sizeof (Regs
), 0);
973 Regs
.H
.AL
= (UINT8
) NewVideoMode
;
974 LegacyBios
->Int86 (LegacyBios
, 0x10, &Regs
);
977 // VIDEO - TEXT-MODE CHARGEN - LOAD ROM 8x16 CHARACTER SET (VGA)
979 // BL = block to load
982 gBS
->SetMem (&Regs
, sizeof (Regs
), 0);
986 LegacyBios
->Int86 (LegacyBios
, 0x10, &Regs
);
989 // VESA SuperVGA BIOS - SET SuperVGA VIDEO MODE
991 // BX = mode (see #0082,#0083)
992 // bit 15 set means don't clear video memory
993 // bit 14 set means enable linear framebuffer mode (VBE v2.0+)
994 // Return:AL = 4Fh if function supported
999 gBS
->SetMem (&Regs
, sizeof (Regs
), 0);
1001 Regs
.X
.BX
= NewVideoMode
;
1002 LegacyBios
->Int86 (LegacyBios
, 0x10, &Regs
);
1003 if (Regs
.X
.AX
!= 0x004F) {
1004 DEBUG ((EFI_D_ERROR
, "SORRY: Cannot set to video mode: 0x%04X!\n", NewVideoMode
));
1009 return OriginalVideoMode
;
1015 IN EFI_EXCEPTION_TYPE InterruptType
,
1016 IN EFI_SYSTEM_CONTEXT SystemContext
1019 #if CPU_EXCEPTION_VGA_SWITCH
1023 #if CPU_EXCEPTION_DEBUG_OUTPUT
1024 DumpExceptionDataDebugOut (InterruptType
, SystemContext
);
1027 #if CPU_EXCEPTION_VGA_SWITCH
1029 // Switch to text mode for RED-SCREEN output
1031 VideoMode
= SwitchVideoMode (0x83);
1032 if (VideoMode
== (UINT16
) -1) {
1033 DEBUG ((EFI_D_ERROR
, "Video Mode Unknown!\n"));
1037 DumpExceptionDataVgaOut (InterruptType
, SystemContext
);
1040 // Use this macro to hang so that the compiler does not optimize out
1041 // the following RET instructions. This allows us to return if we
1042 // have a debugger attached.
1046 #if CPU_EXCEPTION_VGA_SWITCH
1048 // Switch back to the old video mode
1050 if (VideoMode
!= (UINT16
)-1) {
1051 SwitchVideoMode (VideoMode
);
1060 IN EFI_EXCEPTION_TYPE InterruptType
,
1061 IN EFI_SYSTEM_CONTEXT SystemContext
1064 if (mTimerHandler
!= NULL
) {
1065 mTimerHandler (InterruptType
, SystemContext
);
1072 IN EFI_HANDLE ImageHandle
,
1073 IN EFI_SYSTEM_TABLE
*SystemTable
1077 Routine Description:
1078 Initialize the state information for the CPU Architectural Protocol
1081 ImageHandle of the loaded driver
1082 Pointer to the System Table
1085 EFI_SUCCESS - thread can be successfully created
1086 EFI_OUT_OF_RESOURCES - cannot allocate protocol data structure
1087 EFI_DEVICE_ERROR - cannot create the thread
1093 UINT32 InterruptVector
;
1096 // Find the Legacy8259 protocol.
1098 Status
= gBS
->LocateProtocol (&gEfiLegacy8259ProtocolGuid
, NULL
, (VOID
**) &gLegacy8259
);
1099 ASSERT_EFI_ERROR (Status
);
1102 // Get the interrupt vector number corresponding to IRQ0 from the 8259 driver
1104 Status
= gLegacy8259
->GetVector (gLegacy8259
, Efi8259Irq0
, (UINT8
*) &mTimerVector
);
1105 ASSERT_EFI_ERROR (Status
);
1113 // Install Exception Handler (0x00 ~ 0x1F)
1115 for (InterruptVector
= 0; InterruptVector
< 0x20; InterruptVector
++) {
1116 InstallInterruptHandler (
1118 (VOID (*)(VOID
))(UINTN
)((UINTN
)SystemExceptionHandler
+ mExceptionCodeSize
* InterruptVector
)
1123 // Install Timer Handler
1125 InstallInterruptHandler (mTimerVector
, SystemTimerHandler
);
1128 // BUGBUG: We add all other interrupt vector
1130 for (Irq
= Efi8259Irq1
; Irq
<= Efi8259Irq15
; Irq
++) {
1131 InterruptVector
= 0;
1132 Status
= gLegacy8259
->GetVector (gLegacy8259
, Irq
, (UINT8
*) &InterruptVector
);
1133 ASSERT_EFI_ERROR (Status
);
1134 InstallInterruptHandler (InterruptVector
, SystemTimerHandler
);
1138 // Install CPU Architectural Protocol and the thunk protocol
1141 Status
= gBS
->InstallMultipleProtocolInterfaces (
1143 &gEfiCpuArchProtocolGuid
,
1147 ASSERT_EFI_ERROR (Status
);