]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/StatusCode/RuntimeDxe/DebugAssert.c
Initial import.
[mirror_edk2.git] / EdkModulePkg / Universal / StatusCode / RuntimeDxe / DebugAssert.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 DebugAssert.c
15
16 Abstract:
17
18 Produce EfiDebugAssertProtocol to enable EfiUtilityLib to function.
19 The EfiUtilityLib is used by the EFI shell!
20
21 --*/
22
23 #include "StatusCode.h"
24
25 EFI_STATUS
26 EFIAPI
27 StatusCodeDebugAssert (
28 IN EFI_DEBUG_ASSERT_PROTOCOL *This,
29 IN CHAR8 *FileName,
30 IN INTN LineNumber,
31 IN CHAR8 *Description
32 );
33
34 EFI_STATUS
35 EFIAPI
36 StatusCodeDebugPrint (
37 IN EFI_DEBUG_ASSERT_PROTOCOL *This,
38 IN UINTN ErrorLevel,
39 IN CHAR8 *Format,
40 IN VA_LIST Marker
41 );
42
43 EFI_STATUS
44 EFIAPI
45 StatusCodePostCode (
46 IN EFI_DEBUG_ASSERT_PROTOCOL * This,
47 IN UINT16 PostCode,
48 IN CHAR8 *PostCodeString OPTIONAL
49 );
50
51 EFI_STATUS
52 EFIAPI
53 StatusCodeGetErrorLevel (
54 IN EFI_DEBUG_ASSERT_PROTOCOL *This,
55 IN UINTN *ErrorLevel
56 );
57
58 EFI_STATUS
59 EFIAPI
60 StatusCodeSetErrorLevel (
61 IN EFI_DEBUG_ASSERT_PROTOCOL *This,
62 IN UINTN ErrorLevel
63 );
64
65 //
66 // Protocol instance, there can be only one.
67 //
68 EFI_HANDLE mHandle = NULL;
69 EFI_DEBUG_ASSERT_PROTOCOL mDebugAssertProtocol = {
70 StatusCodeDebugAssert,
71 StatusCodeDebugPrint,
72 StatusCodePostCode,
73 StatusCodeGetErrorLevel,
74 StatusCodeSetErrorLevel
75 };
76
77 //
78 // Function implementations
79 //
80 EFI_STATUS
81 EFIAPI
82 StatusCodeDebugAssert (
83 IN EFI_DEBUG_ASSERT_PROTOCOL *This,
84 IN CHAR8 *FileName,
85 IN INTN LineNumber,
86 IN CHAR8 *Description
87 )
88 /*++
89
90 Routine Description:
91
92 Worker function for ASSERT (). If Error Logging hub is loaded log ASSERT
93 information. If Error Logging hub is not loaded CpuBreakpoint ().
94
95 Arguments:
96
97 This - Protocol instance.
98 FileName - File name of failing routine.
99 LineNumber - Line number of failing ASSERT().
100 Description - Description, usually the assertion,
101
102 Returns:
103
104 EFI_SUCCESS The function always completes successfully.
105
106 --*/
107 {
108 DebugAssert (FileName, LineNumber, Description);
109
110 return EFI_SUCCESS;
111 }
112
113 EFI_STATUS
114 EFIAPI
115 StatusCodeDebugPrint (
116 IN EFI_DEBUG_ASSERT_PROTOCOL *This,
117 IN UINTN ErrorLevel,
118 IN CHAR8 *Format,
119 IN VA_LIST Marker
120 )
121 /*++
122
123 Routine Description:
124
125 Worker function for DEBUG (). If Error Logging hub is loaded log ASSERT
126 information. If Error Logging hub is not loaded do nothing.
127
128 Arguments:
129
130 This - Protocol Instance.
131 ErrorLevel - If error level is set do the debug print.
132 Format - String to use for the print, followed by Print arguments.
133
134 Returns:
135
136 EFI_SUCCESS The function always completes successfully.
137
138 --*/
139 {
140 CHAR8 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
141
142 AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
143 DebugPrint (ErrorLevel, Buffer);
144
145 return EFI_SUCCESS;
146 }
147
148 EFI_STATUS
149 EFIAPI
150 StatusCodeGetErrorLevel (
151 IN EFI_DEBUG_ASSERT_PROTOCOL *This,
152 IN UINTN *ErrorLevel
153 )
154 {
155 *ErrorLevel = PcdGet32(PcdDebugPrintErrorLevel);
156 return EFI_SUCCESS;
157 }
158
159 EFI_STATUS
160 EFIAPI
161 StatusCodeSetErrorLevel (
162 IN EFI_DEBUG_ASSERT_PROTOCOL *This,
163 IN UINTN ErrorLevel
164 )
165 {
166 return EFI_UNSUPPORTED;
167 }
168
169 EFI_STATUS
170 EFIAPI
171 StatusCodePostCode (
172 IN EFI_DEBUG_ASSERT_PROTOCOL * This,
173 IN UINT16 PostCode,
174 IN CHAR8 *PostCodeString OPTIONAL
175 )
176 /*++
177
178 Routine Description:
179
180 Write the code to IO ports 80 and 81.
181
182 Arguments:
183
184 This - Protocol Instance.
185 PostCode - Code to write
186 PostCodeString - String, currently ignored.
187
188 Returns:
189
190 EFI_SUCCESS The function always completes successfully.
191
192 --*/
193 {
194 IoWrite8 (0x80, (UINT8) (PostCode & 0xff));
195 IoWrite8 (0x81, (UINT8) (PostCode >> 8));
196
197 return EFI_SUCCESS;
198 }
199
200 EFI_STATUS
201 InstallStatusCodeDebugAssert (
202 VOID
203 )
204 /*++
205
206 Routine Description:
207
208 Install the status code debug assert protocol
209
210 Arguments:
211
212 None
213
214 Returns:
215
216 Results of call to InstallProtocolInterface.
217
218 --*/
219 {
220
221 DEBUG_CODE (
222 gBS->InstallProtocolInterface (
223 &mHandle,
224 &gEfiDebugAssertProtocolGuid,
225 EFI_NATIVE_INTERFACE,
226 &mDebugAssertProtocol
227 );
228 );
229
230 return EFI_SUCCESS;
231 }