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
323 DumpExceptionDataDebugOut (
324 IN EFI_EXCEPTION_TYPE InterruptType
,
325 IN EFI_SYSTEM_CONTEXT SystemContext
328 UINT32 ErrorCodeFlag
;
330 ErrorCodeFlag
= 0x00027d00;
335 "!!!! IA32 Exception Type - %08x !!!!\n",
340 "EIP - %08x, CS - %08x, EFLAGS - %08x\n",
341 SystemContext
.SystemContextIa32
->Eip
,
342 SystemContext
.SystemContextIa32
->Cs
,
343 SystemContext
.SystemContextIa32
->Eflags
345 if (ErrorCodeFlag
& (1 << InterruptType
)) {
348 "ExceptionData - %08x\n",
349 SystemContext
.SystemContextIa32
->ExceptionData
354 "EAX - %08x, ECX - %08x, EDX - %08x, EBX - %08x\n",
355 SystemContext
.SystemContextIa32
->Eax
,
356 SystemContext
.SystemContextIa32
->Ecx
,
357 SystemContext
.SystemContextIa32
->Edx
,
358 SystemContext
.SystemContextIa32
->Ebx
362 "ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x\n",
363 SystemContext
.SystemContextIa32
->Esp
,
364 SystemContext
.SystemContextIa32
->Ebp
,
365 SystemContext
.SystemContextIa32
->Esi
,
366 SystemContext
.SystemContextIa32
->Edi
370 "DS - %08x, ES - %08x, FS - %08x, GS - %08x, SS - %08x\n",
371 SystemContext
.SystemContextIa32
->Ds
,
372 SystemContext
.SystemContextIa32
->Es
,
373 SystemContext
.SystemContextIa32
->Fs
,
374 SystemContext
.SystemContextIa32
->Gs
,
375 SystemContext
.SystemContextIa32
->Ss
379 "GDTR - %08x %08x, IDTR - %08x %08x\n",
380 SystemContext
.SystemContextIa32
->Gdtr
[0],
381 SystemContext
.SystemContextIa32
->Gdtr
[1],
382 SystemContext
.SystemContextIa32
->Idtr
[0],
383 SystemContext
.SystemContextIa32
->Idtr
[1]
387 "LDTR - %08x, TR - %08x\n",
388 SystemContext
.SystemContextIa32
->Ldtr
,
389 SystemContext
.SystemContextIa32
->Tr
393 "CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x\n",
394 SystemContext
.SystemContextIa32
->Cr0
,
395 SystemContext
.SystemContextIa32
->Cr2
,
396 SystemContext
.SystemContextIa32
->Cr3
,
397 SystemContext
.SystemContextIa32
->Cr4
401 "DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x\n",
402 SystemContext
.SystemContextIa32
->Dr0
,
403 SystemContext
.SystemContextIa32
->Dr1
,
404 SystemContext
.SystemContextIa32
->Dr2
,
405 SystemContext
.SystemContextIa32
->Dr3
409 "DR6 - %08x, DR7 - %08x\n",
410 SystemContext
.SystemContextIa32
->Dr6
,
411 SystemContext
.SystemContextIa32
->Dr7
416 "!!!! X64 Exception Type - %016lx !!!!\n",
417 (UINT64
)InterruptType
421 "RIP - %016lx, CS - %016lx, RFLAGS - %016lx\n",
422 SystemContext
.SystemContextX64
->Rip
,
423 SystemContext
.SystemContextX64
->Cs
,
424 SystemContext
.SystemContextX64
->Rflags
426 if (ErrorCodeFlag
& (1 << InterruptType
)) {
429 "ExceptionData - %016lx\n",
430 SystemContext
.SystemContextX64
->ExceptionData
435 "RAX - %016lx, RCX - %016lx, RDX - %016lx\n",
436 SystemContext
.SystemContextX64
->Rax
,
437 SystemContext
.SystemContextX64
->Rcx
,
438 SystemContext
.SystemContextX64
->Rdx
442 "RBX - %016lx, RSP - %016lx, RBP - %016lx\n",
443 SystemContext
.SystemContextX64
->Rbx
,
444 SystemContext
.SystemContextX64
->Rsp
,
445 SystemContext
.SystemContextX64
->Rbp
449 "RSI - %016lx, RDI - %016lx\n",
450 SystemContext
.SystemContextX64
->Rsi
,
451 SystemContext
.SystemContextX64
->Rdi
455 "R8 - %016lx, R9 - %016lx, R10 - %016lx\n",
456 SystemContext
.SystemContextX64
->R8
,
457 SystemContext
.SystemContextX64
->R9
,
458 SystemContext
.SystemContextX64
->R10
462 "R11 - %016lx, R12 - %016lx, R13 - %016lx\n",
463 SystemContext
.SystemContextX64
->R11
,
464 SystemContext
.SystemContextX64
->R12
,
465 SystemContext
.SystemContextX64
->R13
469 "R14 - %016lx, R15 - %016lx\n",
470 SystemContext
.SystemContextX64
->R14
,
471 SystemContext
.SystemContextX64
->R15
475 "DS - %016lx, ES - %016lx, FS - %016lx\n",
476 SystemContext
.SystemContextX64
->Ds
,
477 SystemContext
.SystemContextX64
->Es
,
478 SystemContext
.SystemContextX64
->Fs
482 "GS - %016lx, SS - %016lx\n",
483 SystemContext
.SystemContextX64
->Gs
,
484 SystemContext
.SystemContextX64
->Ss
488 "GDTR - %016lx %016lx, LDTR - %016lx\n",
489 SystemContext
.SystemContextX64
->Gdtr
[0],
490 SystemContext
.SystemContextX64
->Gdtr
[1],
491 SystemContext
.SystemContextX64
->Ldtr
495 "IDTR - %016lx %016lx, TR - %016lx\n",
496 SystemContext
.SystemContextX64
->Idtr
[0],
497 SystemContext
.SystemContextX64
->Idtr
[1],
498 SystemContext
.SystemContextX64
->Tr
502 "CR0 - %016lx, CR2 - %016lx, CR3 - %016lx\n",
503 SystemContext
.SystemContextX64
->Cr0
,
504 SystemContext
.SystemContextX64
->Cr2
,
505 SystemContext
.SystemContextX64
->Cr3
509 "CR4 - %016lx, CR8 - %016lx\n",
510 SystemContext
.SystemContextX64
->Cr4
,
511 SystemContext
.SystemContextX64
->Cr8
515 "DR0 - %016lx, DR1 - %016lx, DR2 - %016lx\n",
516 SystemContext
.SystemContextX64
->Dr0
,
517 SystemContext
.SystemContextX64
->Dr1
,
518 SystemContext
.SystemContextX64
->Dr2
522 "DR3 - %016lx, DR6 - %016lx, DR7 - %016lx\n",
523 SystemContext
.SystemContextX64
->Dr3
,
524 SystemContext
.SystemContextX64
->Dr6
,
525 SystemContext
.SystemContextX64
->Dr7
534 IN OUT CHAR16
*Buffer
,
535 IN CONST CHAR16
*Format
,
545 VA_START (Marker
, Format
);
548 // Process the format string. Stop if Buffer is over run.
551 for (Index
= 0; *Format
!= 0; Format
++) {
552 if (*Format
!= L
'%') {
553 Buffer
[Index
++] = *Format
;
557 // Now it's time to parse what follows after %
558 // Support: % [ 0 width ] [ l ] x
559 // width - fill 0, to ensure the width of x will be "width"
560 // l - UINT64 instead of UINT32
566 if (*Format
== L
'0') {
567 Flags
|= PREFIX_ZERO
;
569 Width
+= Width
* 10 + (*Format
- L
'0');
571 } while (*Format
>= L
'1' && *Format
<= L
'9');
574 if (*Format
== L
'l') {
582 Flags
|= PREFIX_ZERO
;
583 Width
= sizeof (UINT64
) * 2;
585 // break skiped on purpose
588 if ((Flags
& LONG_TYPE
) == LONG_TYPE
) {
589 Value
= VA_ARG (Marker
, UINT64
);
591 Value
= VA_ARG (Marker
, UINTN
);
594 UnicodeValueToString (Buffer
+Index
, Flags
, Value
, Width
);
596 for ( ; Buffer
[Index
] != L
'\0'; Index
++) {
603 // if the type is unknown print it to the screen
605 Buffer
[Index
++] = *Format
;
609 Buffer
[Index
++] = '\0';
616 DumpExceptionDataVgaOut (
617 IN EFI_EXCEPTION_TYPE InterruptType
,
618 IN EFI_SYSTEM_CONTEXT SystemContext
623 UINT32 ErrorCodeFlag
;
624 CHAR16
*VideoBufferBase
;
630 ErrorCodeFlag
= 0x00027d00;
631 VideoBufferBase
= (CHAR16
*) (UINTN
) 0xb8000;
632 VideoBuffer
= (CHAR16
*) (UINTN
) 0xb8000;
637 L
"!!!! IA32 Exception Type - %08x !!!!",
640 VideoBuffer
+= COLUMN_MAX
;
643 L
"EIP - %08x, CS - %08x, EFLAGS - %08x",
644 SystemContext
.SystemContextIa32
->Eip
,
645 SystemContext
.SystemContextIa32
->Cs
,
646 SystemContext
.SystemContextIa32
->Eflags
648 VideoBuffer
+= COLUMN_MAX
;
649 if (ErrorCodeFlag
& (1 << InterruptType
)) {
652 L
"ExceptionData - %08x",
653 SystemContext
.SystemContextIa32
->ExceptionData
655 VideoBuffer
+= COLUMN_MAX
;
659 L
"EAX - %08x, ECX - %08x, EDX - %08x, EBX - %08x",
660 SystemContext
.SystemContextIa32
->Eax
,
661 SystemContext
.SystemContextIa32
->Ecx
,
662 SystemContext
.SystemContextIa32
->Edx
,
663 SystemContext
.SystemContextIa32
->Ebx
665 VideoBuffer
+= COLUMN_MAX
;
669 L
"ESP - %08x, EBP - %08x, ESI - %08x, EDI - %08x",
670 SystemContext
.SystemContextIa32
->Esp
,
671 SystemContext
.SystemContextIa32
->Ebp
,
672 SystemContext
.SystemContextIa32
->Esi
,
673 SystemContext
.SystemContextIa32
->Edi
675 VideoBuffer
+= COLUMN_MAX
;
679 L
"DS - %08x, ES - %08x, FS - %08x, GS - %08x, SS - %08x",
680 SystemContext
.SystemContextIa32
->Ds
,
681 SystemContext
.SystemContextIa32
->Es
,
682 SystemContext
.SystemContextIa32
->Fs
,
683 SystemContext
.SystemContextIa32
->Gs
,
684 SystemContext
.SystemContextIa32
->Ss
686 VideoBuffer
+= COLUMN_MAX
;
690 L
"GDTR - %08x %08x, IDTR - %08x %08x",
691 SystemContext
.SystemContextIa32
->Gdtr
[0],
692 SystemContext
.SystemContextIa32
->Gdtr
[1],
693 SystemContext
.SystemContextIa32
->Idtr
[0],
694 SystemContext
.SystemContextIa32
->Idtr
[1]
696 VideoBuffer
+= COLUMN_MAX
;
700 L
"LDTR - %08x, TR - %08x",
701 SystemContext
.SystemContextIa32
->Ldtr
,
702 SystemContext
.SystemContextIa32
->Tr
704 VideoBuffer
+= COLUMN_MAX
;
708 L
"CR0 - %08x, CR2 - %08x, CR3 - %08x, CR4 - %08x",
709 SystemContext
.SystemContextIa32
->Cr0
,
710 SystemContext
.SystemContextIa32
->Cr2
,
711 SystemContext
.SystemContextIa32
->Cr3
,
712 SystemContext
.SystemContextIa32
->Cr4
714 VideoBuffer
+= COLUMN_MAX
;
718 L
"DR0 - %08x, DR1 - %08x, DR2 - %08x, DR3 - %08x",
719 SystemContext
.SystemContextIa32
->Dr0
,
720 SystemContext
.SystemContextIa32
->Dr1
,
721 SystemContext
.SystemContextIa32
->Dr2
,
722 SystemContext
.SystemContextIa32
->Dr3
724 VideoBuffer
+= COLUMN_MAX
;
728 L
"DR6 - %08x, DR7 - %08x",
729 SystemContext
.SystemContextIa32
->Dr6
,
730 SystemContext
.SystemContextIa32
->Dr7
732 VideoBuffer
+= COLUMN_MAX
;
736 L
"!!!! X64 Exception Type - %016lx !!!!",
737 (UINT64
)InterruptType
739 VideoBuffer
+= COLUMN_MAX
;
743 L
"RIP - %016lx, CS - %016lx, RFLAGS - %016lx",
744 SystemContext
.SystemContextX64
->Rip
,
745 SystemContext
.SystemContextX64
->Cs
,
746 SystemContext
.SystemContextX64
->Rflags
748 VideoBuffer
+= COLUMN_MAX
;
750 if (ErrorCodeFlag
& (1 << InterruptType
)) {
753 L
"ExceptionData - %016lx",
754 SystemContext
.SystemContextX64
->ExceptionData
756 VideoBuffer
+= COLUMN_MAX
;
761 L
"RAX - %016lx, RCX - %016lx, RDX - %016lx",
762 SystemContext
.SystemContextX64
->Rax
,
763 SystemContext
.SystemContextX64
->Rcx
,
764 SystemContext
.SystemContextX64
->Rdx
766 VideoBuffer
+= COLUMN_MAX
;
770 L
"RBX - %016lx, RSP - %016lx, RBP - %016lx",
771 SystemContext
.SystemContextX64
->Rbx
,
772 SystemContext
.SystemContextX64
->Rsp
,
773 SystemContext
.SystemContextX64
->Rbp
775 VideoBuffer
+= COLUMN_MAX
;
779 L
"RSI - %016lx, RDI - %016lx",
780 SystemContext
.SystemContextX64
->Rsi
,
781 SystemContext
.SystemContextX64
->Rdi
783 VideoBuffer
+= COLUMN_MAX
;
787 L
"R8 - %016lx, R9 - %016lx, R10 - %016lx",
788 SystemContext
.SystemContextX64
->R8
,
789 SystemContext
.SystemContextX64
->R9
,
790 SystemContext
.SystemContextX64
->R10
792 VideoBuffer
+= COLUMN_MAX
;
796 L
"R11 - %016lx, R12 - %016lx, R13 - %016lx",
797 SystemContext
.SystemContextX64
->R11
,
798 SystemContext
.SystemContextX64
->R12
,
799 SystemContext
.SystemContextX64
->R13
801 VideoBuffer
+= COLUMN_MAX
;
805 L
"R14 - %016lx, R15 - %016lx",
806 SystemContext
.SystemContextX64
->R14
,
807 SystemContext
.SystemContextX64
->R15
809 VideoBuffer
+= COLUMN_MAX
;
813 L
"DS - %016lx, ES - %016lx, FS - %016lx",
814 SystemContext
.SystemContextX64
->Ds
,
815 SystemContext
.SystemContextX64
->Es
,
816 SystemContext
.SystemContextX64
->Fs
818 VideoBuffer
+= COLUMN_MAX
;
822 L
"GS - %016lx, SS - %016lx",
823 SystemContext
.SystemContextX64
->Gs
,
824 SystemContext
.SystemContextX64
->Ss
826 VideoBuffer
+= COLUMN_MAX
;
830 L
"GDTR - %016lx %016lx, LDTR - %016lx",
831 SystemContext
.SystemContextX64
->Gdtr
[0],
832 SystemContext
.SystemContextX64
->Gdtr
[1],
833 SystemContext
.SystemContextX64
->Ldtr
835 VideoBuffer
+= COLUMN_MAX
;
839 L
"IDTR - %016lx %016lx, TR - %016lx",
840 SystemContext
.SystemContextX64
->Idtr
[0],
841 SystemContext
.SystemContextX64
->Idtr
[1],
842 SystemContext
.SystemContextX64
->Tr
844 VideoBuffer
+= COLUMN_MAX
;
848 L
"CR0 - %016lx, CR2 - %016lx, CR3 - %016lx",
849 SystemContext
.SystemContextX64
->Cr0
,
850 SystemContext
.SystemContextX64
->Cr2
,
851 SystemContext
.SystemContextX64
->Cr3
853 VideoBuffer
+= COLUMN_MAX
;
857 L
"CR4 - %016lx, CR8 - %016lx",
858 SystemContext
.SystemContextX64
->Cr4
,
859 SystemContext
.SystemContextX64
->Cr8
861 VideoBuffer
+= COLUMN_MAX
;
865 L
"DR0 - %016lx, DR1 - %016lx, DR2 - %016lx",
866 SystemContext
.SystemContextX64
->Dr0
,
867 SystemContext
.SystemContextX64
->Dr1
,
868 SystemContext
.SystemContextX64
->Dr2
870 VideoBuffer
+= COLUMN_MAX
;
874 L
"DR3 - %016lx, DR6 - %016lx, DR7 - %016lx",
875 SystemContext
.SystemContextX64
->Dr3
,
876 SystemContext
.SystemContextX64
->Dr6
,
877 SystemContext
.SystemContextX64
->Dr7
879 VideoBuffer
+= COLUMN_MAX
;
882 for (Index
= 0; Index
< COLUMN_MAX
* ROW_MAX
; Index
++) {
883 if (Index
> (UINTN
)(VideoBuffer
- VideoBufferBase
)) {
884 VideoBufferBase
[Index
] = 0x0c20;
886 VideoBufferBase
[Index
] |= 0x0c00;
893 #if CPU_EXCEPTION_VGA_SWITCH
900 Switch Video Mode from current mode to new mode, and return the old mode.
904 NewVideoMode - new video mode want to set
907 UINT16 - (UINT16) -1 indicates failure
908 Other value indicates the old mode, which can be used for restore later
913 EFI_LEGACY_BIOS_THUNK_PROTOCOL
*LegacyBios
;
914 EFI_IA32_REGISTER_SET Regs
;
915 UINT16 OriginalVideoMode
= (UINT16
) -1;
918 // See if the Legacy BIOS Protocol is available
920 Status
= gBS
->LocateProtocol (&gEfiLegacyBiosThunkProtocolGuid
, NULL
, (VOID
**) &LegacyBios
);
921 if (EFI_ERROR (Status
)) {
922 return OriginalVideoMode
;
926 // VESA SuperVGA BIOS - GET CURRENT VIDEO MODE
928 // Return:AL = 4Fh if function supported
929 // AH = status 00h successful
930 // BX = video mode (see #0082,#0083)
932 gBS
->SetMem (&Regs
, sizeof (Regs
), 0);
934 LegacyBios
->Int86 (LegacyBios
, 0x10, &Regs
);
935 if (Regs
.X
.AX
== 0x004F) {
936 OriginalVideoMode
= Regs
.X
.BX
;
939 // VIDEO - GET CURRENT VIDEO MODE
941 // Return:AH = number of character columns
942 // AL = display mode (see #0009 at AH=00h)
943 // BH = active page (see AH=05h)
945 gBS
->SetMem (&Regs
, sizeof (Regs
), 0);
947 LegacyBios
->Int86 (LegacyBios
, 0x10, &Regs
);
948 OriginalVideoMode
= Regs
.H
.AL
;
952 // Set new video mode
954 if (NewVideoMode
< 0x100) {
956 // Set the 80x25 Text VGA Mode: Assume successful always
958 // VIDEO - SET VIDEO MODE
960 // AL = desired video mode (see #0009)
961 // Return:AL = video mode flag (Phoenix, AMI BIOS)
963 // 30h modes 0-5 and 7
965 // AL = CRT controller mode byte (Phoenix 386 BIOS v1.10)
967 gBS
->SetMem (&Regs
, sizeof (Regs
), 0);
969 Regs
.H
.AL
= (UINT8
) NewVideoMode
;
970 LegacyBios
->Int86 (LegacyBios
, 0x10, &Regs
);
973 // VIDEO - TEXT-MODE CHARGEN - LOAD ROM 8x16 CHARACTER SET (VGA)
975 // BL = block to load
978 gBS
->SetMem (&Regs
, sizeof (Regs
), 0);
982 LegacyBios
->Int86 (LegacyBios
, 0x10, &Regs
);
985 // VESA SuperVGA BIOS - SET SuperVGA VIDEO MODE
987 // BX = mode (see #0082,#0083)
988 // bit 15 set means don't clear video memory
989 // bit 14 set means enable linear framebuffer mode (VBE v2.0+)
990 // Return:AL = 4Fh if function supported
995 gBS
->SetMem (&Regs
, sizeof (Regs
), 0);
997 Regs
.X
.BX
= NewVideoMode
;
998 LegacyBios
->Int86 (LegacyBios
, 0x10, &Regs
);
999 if (Regs
.X
.AX
!= 0x004F) {
1000 DEBUG ((EFI_D_ERROR
, "SORRY: Cannot set to video mode: 0x%04X!\n", NewVideoMode
));
1005 return OriginalVideoMode
;
1011 IN EFI_EXCEPTION_TYPE InterruptType
,
1012 IN EFI_SYSTEM_CONTEXT SystemContext
1015 #if CPU_EXCEPTION_VGA_SWITCH
1019 #if CPU_EXCEPTION_DEBUG_OUTPUT
1020 DumpExceptionDataDebugOut (InterruptType
, SystemContext
);
1023 #if CPU_EXCEPTION_VGA_SWITCH
1025 // Switch to text mode for RED-SCREEN output
1027 VideoMode
= SwitchVideoMode (0x83);
1028 if (VideoMode
== (UINT16
) -1) {
1029 DEBUG ((EFI_D_ERROR
, "Video Mode Unknown!\n"));
1033 DumpExceptionDataVgaOut (InterruptType
, SystemContext
);
1036 // Use this macro to hang so that the compiler does not optimize out
1037 // the following RET instructions. This allows us to return if we
1038 // have a debugger attached.
1042 #if CPU_EXCEPTION_VGA_SWITCH
1044 // Switch back to the old video mode
1046 if (VideoMode
!= (UINT16
)-1) {
1047 SwitchVideoMode (VideoMode
);
1056 IN EFI_EXCEPTION_TYPE InterruptType
,
1057 IN EFI_SYSTEM_CONTEXT SystemContext
1060 if (mTimerHandler
!= NULL
) {
1061 mTimerHandler (InterruptType
, SystemContext
);
1068 IN EFI_HANDLE ImageHandle
,
1069 IN EFI_SYSTEM_TABLE
*SystemTable
1073 Routine Description:
1074 Initialize the state information for the CPU Architectural Protocol
1077 ImageHandle of the loaded driver
1078 Pointer to the System Table
1081 EFI_SUCCESS - thread can be successfully created
1082 EFI_OUT_OF_RESOURCES - cannot allocate protocol data structure
1083 EFI_DEVICE_ERROR - cannot create the thread
1089 UINT32 InterruptVector
;
1092 // Find the Legacy8259 protocol.
1094 Status
= gBS
->LocateProtocol (&gEfiLegacy8259ProtocolGuid
, NULL
, (VOID
**) &gLegacy8259
);
1095 ASSERT_EFI_ERROR (Status
);
1098 // Get the interrupt vector number corresponding to IRQ0 from the 8259 driver
1100 Status
= gLegacy8259
->GetVector (gLegacy8259
, Efi8259Irq0
, (UINT8
*) &mTimerVector
);
1101 ASSERT_EFI_ERROR (Status
);
1109 // Install Exception Handler (0x00 ~ 0x1F)
1111 for (InterruptVector
= 0; InterruptVector
< 0x20; InterruptVector
++) {
1112 InstallInterruptHandler (
1114 (VOID (*)(VOID
))(UINTN
)((UINTN
)SystemExceptionHandler
+ mExceptionCodeSize
* InterruptVector
)
1119 // Install Timer Handler
1121 InstallInterruptHandler (mTimerVector
, SystemTimerHandler
);
1124 // BUGBUG: We add all other interrupt vector
1126 for (Irq
= Efi8259Irq1
; Irq
<= Efi8259Irq15
; Irq
++) {
1127 InterruptVector
= 0;
1128 Status
= gLegacy8259
->GetVector (gLegacy8259
, Irq
, (UINT8
*) &InterruptVector
);
1129 ASSERT_EFI_ERROR (Status
);
1130 InstallInterruptHandler (InterruptVector
, SystemTimerHandler
);
1134 // Install CPU Architectural Protocol and the thunk protocol
1137 Status
= gBS
->InstallMultipleProtocolInterfaces (
1139 &gEfiCpuArchProtocolGuid
,
1143 ASSERT_EFI_ERROR (Status
);