VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c@ 58464

最後變更 在這個檔案從58464是 58464,由 vboxsync 提交於 9 年 前

EFI/Firmware: Export new files and directories.

  • 屬性 svn:eol-style 設為 native
檔案大小: 6.8 KB
 
1/** @file
2 CPU exception handler library implemenation for SEC/PEIM modules.
3
4Copyright (c) 2012 - 2013, Intel Corporation. All rights reserved.<BR>
5This program and the accompanying materials are licensed and made available under
6the terms and conditions of the BSD License that accompanies this distribution.
7The full text of the license may be found at
8http://opensource.org/licenses/bsd-license.php.
9
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13**/
14
15#include <PiPei.h>
16#include "CpuExceptionCommon.h"
17
18//
19// Image Aglinment size for SEC/PEI phase
20//
21CONST UINTN mImageAlignSize = 4;
22CONST UINTN mDoFarReturnFlag = 0;
23
24/**
25 Common exception handler.
26
27 @param ExceptionType Exception type.
28 @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
29**/
30VOID
31EFIAPI
32CommonExceptionHandler (
33 IN EFI_EXCEPTION_TYPE ExceptionType,
34 IN EFI_SYSTEM_CONTEXT SystemContext
35 )
36{
37 //
38 // Display ExceptionType, CPU information and Image information
39 //
40 DumpCpuContent (ExceptionType, SystemContext);
41
42 //
43 // Enter a dead loop.
44 //
45 CpuDeadLoop ();
46}
47
48/**
49 Initializes all CPU exceptions entries and provides the default exception handlers.
50
51 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
52 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
53 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
54 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
55 Note: Before invoking this API, caller must allocate memory for IDT table and load
56 IDTR by AsmWriteIdtr().
57
58 @param[in] VectorInfo Pointer to reserved vector list.
59
60 @retval EFI_SUCCESS CPU Exception Entries have been successfully initialized
61 with default exception handlers.
62 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
63 @retval EFI_UNSUPPORTED This function is not supported.
64
65**/
66EFI_STATUS
67EFIAPI
68InitializeCpuExceptionHandlers (
69 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
70 )
71{
72 EFI_STATUS Status;
73 RESERVED_VECTORS_DATA ReservedVectorData[CPU_EXCEPTION_NUM];
74 IA32_DESCRIPTOR IdtDescriptor;
75 UINTN IdtEntryCount;
76 UINT16 CodeSegment;
77 EXCEPTION_HANDLER_TEMPLATE_MAP TemplateMap;
78 IA32_IDT_GATE_DESCRIPTOR *IdtTable;
79 UINTN Index;
80 UINTN InterruptHandler;
81
82 if (VectorInfo != NULL) {
83 SetMem ((VOID *) ReservedVectorData, sizeof (RESERVED_VECTORS_DATA) * CPU_EXCEPTION_NUM, 0xff);
84 Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectorData, CPU_EXCEPTION_NUM);
85 if (EFI_ERROR (Status)) {
86 return EFI_INVALID_PARAMETER;
87 }
88 }
89 //
90 // Read IDT descriptor and calculate IDT size
91 //
92 AsmReadIdtr (&IdtDescriptor);
93 IdtEntryCount = (IdtDescriptor.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR);
94 if (IdtEntryCount > CPU_EXCEPTION_NUM) {
95 //
96 // CPU exeption library only setup CPU_EXCEPTION_NUM exception handler at most
97 //
98 IdtEntryCount = CPU_EXCEPTION_NUM;
99 }
100 //
101 // Use current CS as the segment selector of interrupt gate in IDT
102 //
103 CodeSegment = AsmReadCs ();
104
105 AsmGetTemplateAddressMap (&TemplateMap);
106 IdtTable = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
107 for (Index = 0; Index < IdtEntryCount; Index ++) {
108 IdtTable[Index].Bits.Selector = CodeSegment;
109 //
110 // Check reserved vectors attributes if has, only EFI_VECTOR_HANDOFF_DO_NOT_HOOK
111 // supported in this instance
112 //
113 if (VectorInfo != NULL) {
114 if (ReservedVectorData[Index].Attribute == EFI_VECTOR_HANDOFF_DO_NOT_HOOK) {
115 continue;
116 }
117 }
118 //
119 // Update IDT entry
120 //
121 InterruptHandler = TemplateMap.ExceptionStart + Index * TemplateMap.ExceptionStubHeaderSize;
122 ArchUpdateIdtEntry (&IdtTable[Index], InterruptHandler);
123 }
124 return EFI_SUCCESS;
125}
126
127/**
128 Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.
129
130 Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
131 persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
132 If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL.
133 If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.
134
135 @param[in] VectorInfo Pointer to reserved vector list.
136
137 @retval EFI_SUCCESS All CPU interrupt/exception entries have been successfully initialized
138 with default interrupt/exception handlers.
139 @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
140 @retval EFI_UNSUPPORTED This function is not supported.
141
142**/
143EFI_STATUS
144EFIAPI
145InitializeCpuInterruptHandlers (
146 IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL
147 )
148{
149 return EFI_UNSUPPORTED;
150}
151
152/**
153 Registers a function to be called from the processor interrupt handler.
154
155 This function registers and enables the handler specified by InterruptHandler for a processor
156 interrupt or exception type specified by InterruptType. If InterruptHandler is NULL, then the
157 handler for the processor interrupt or exception type specified by InterruptType is uninstalled.
158 The installed handler is called once for each processor interrupt or exception.
159 NOTE: This function should be invoked after InitializeCpuExceptionHandlers() or
160 InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED returned.
161
162 @param[in] InterruptType Defines which interrupt or exception to hook.
163 @param[in] InterruptHandler A pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called
164 when a processor interrupt occurs. If this parameter is NULL, then the handler
165 will be uninstalled.
166
167 @retval EFI_SUCCESS The handler for the processor interrupt was successfully installed or uninstalled.
168 @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a handler for InterruptType was
169 previously installed.
170 @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler for InterruptType was not
171 previously installed.
172 @retval EFI_UNSUPPORTED The interrupt specified by InterruptType is not supported,
173 or this function is not supported.
174**/
175EFI_STATUS
176EFIAPI
177RegisterCpuInterruptHandler (
178 IN EFI_EXCEPTION_TYPE InterruptType,
179 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
180 )
181{
182 return EFI_UNSUPPORTED;
183}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette