c1f23d63 |
1 | /*++\r |
2 | \r |
3 | Copyright (c) 2006, Intel Corporation \r |
4 | All rights reserved. This program and the accompanying materials \r |
5 | are licensed and made available under the terms and conditions of the BSD License \r |
6 | which accompanies this distribution. The full text of the license may be found at \r |
7 | http://opensource.org/licenses/bsd-license.php \r |
8 | \r |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r |
11 | \r |
12 | Module Name:\r |
13 | \r |
14 | DebugSupport.c\r |
15 | \r |
16 | Abstract:\r |
17 | \r |
18 | Top level C file for debug support driver. Contains initialization function.\r |
19 | \r |
20 | Revision History\r |
21 | \r |
22 | --*/\r |
23 | \r |
24 | //\r |
25 | // private header files\r |
26 | //\r |
27 | #include "plDebugSupport.h"\r |
28 | \r |
29 | //\r |
30 | // This is a global that is the actual interface\r |
31 | //\r |
32 | EFI_DEBUG_SUPPORT_PROTOCOL gDebugSupportProtocolInterface = {\r |
33 | EFI_ISA,\r |
34 | GetMaximumProcessorIndex,\r |
35 | RegisterPeriodicCallback,\r |
36 | RegisterExceptionCallback,\r |
37 | InvalidateInstructionCache\r |
38 | };\r |
39 | \r |
40 | //\r |
41 | // Driver Entry Point\r |
42 | //\r |
43 | EFI_STATUS\r |
44 | InitializeDebugSupportDriver (\r |
45 | IN EFI_HANDLE ImageHandle,\r |
46 | IN EFI_SYSTEM_TABLE *SystemTable\r |
47 | )\r |
48 | /*++\r |
49 | \r |
50 | Routine Description:\r |
51 | Driver entry point. Checks to see there's not already a DebugSupport protocol\r |
52 | installed for the selected processor before installing protocol.\r |
53 | \r |
54 | Arguments:\r |
55 | IN EFI_HANDLE ImageHandle,\r |
56 | IN EFI_SYSTEM_TABLE *SystemTable\r |
57 | \r |
58 | Returns:\r |
59 | \r |
60 | EFI_STATUS\r |
61 | \r |
62 | --*/\r |
63 | // TODO: ImageHandle - add argument and description to function comment\r |
64 | // TODO: SystemTable - add argument and description to function comment\r |
65 | {\r |
66 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProtocolPtr;\r |
67 | EFI_STATUS Status;\r |
68 | EFI_HANDLE Handle;\r |
69 | EFI_HANDLE *HandlePtr;\r |
70 | UINTN NumHandles;\r |
71 | EFI_DEBUG_SUPPORT_PROTOCOL *DebugSupportProtocolPtr;\r |
72 | \r |
73 | //\r |
74 | // Install Protocol Interface...\r |
75 | //\r |
76 | // First check to see that the debug support protocol for this processor\r |
77 | // type is not already installed\r |
78 | //\r |
79 | Status = gBS->LocateHandleBuffer (\r |
80 | ByProtocol,\r |
81 | &gEfiDebugSupportProtocolGuid,\r |
82 | NULL,\r |
83 | &NumHandles,\r |
84 | &HandlePtr\r |
85 | );\r |
86 | \r |
87 | if (Status != EFI_NOT_FOUND) {\r |
88 | do {\r |
89 | NumHandles--;\r |
90 | Status = gBS->OpenProtocol (\r |
91 | HandlePtr[NumHandles],\r |
92 | &gEfiDebugSupportProtocolGuid,\r |
93 | (VOID **) &DebugSupportProtocolPtr,\r |
94 | ImageHandle,\r |
95 | NULL,\r |
96 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r |
97 | );\r |
98 | if (Status == EFI_SUCCESS && DebugSupportProtocolPtr->Isa == EFI_ISA) {\r |
99 | FreePool (HandlePtr);\r |
100 | Status = EFI_ALREADY_STARTED;\r |
101 | goto ErrExit;\r |
102 | }\r |
103 | } while (NumHandles > 0);\r |
104 | FreePool (HandlePtr);\r |
105 | }\r |
106 | \r |
107 | //\r |
108 | // Get our image information and install platform specific unload handler\r |
109 | //\r |
110 | Status = gBS->OpenProtocol (\r |
111 | ImageHandle,\r |
112 | &gEfiLoadedImageProtocolGuid,\r |
113 | (VOID **) &LoadedImageProtocolPtr,\r |
114 | ImageHandle,\r |
115 | NULL,\r |
116 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r |
117 | );\r |
118 | ASSERT (!EFI_ERROR (Status));\r |
119 | if (Status != EFI_SUCCESS) {\r |
120 | goto ErrExit;\r |
121 | }\r |
122 | \r |
123 | LoadedImageProtocolPtr->Unload = plUnloadDebugSupportDriver;\r |
124 | \r |
125 | //\r |
126 | // Call hook for platform specific initialization\r |
127 | //\r |
128 | Status = plInitializeDebugSupportDriver ();\r |
129 | ASSERT (!EFI_ERROR (Status));\r |
130 | if (Status != EFI_SUCCESS) {\r |
131 | goto ErrExit;\r |
132 | }\r |
133 | \r |
134 | //\r |
135 | // Install DebugSupport protocol to new handle\r |
136 | //\r |
137 | Handle = NULL;\r |
138 | Status = gBS->InstallProtocolInterface (\r |
139 | &Handle,\r |
140 | &gEfiDebugSupportProtocolGuid,\r |
141 | EFI_NATIVE_INTERFACE,\r |
142 | &gDebugSupportProtocolInterface\r |
143 | );\r |
144 | ASSERT (!EFI_ERROR (Status));\r |
145 | if (Status != EFI_SUCCESS) {\r |
146 | goto ErrExit;\r |
147 | }\r |
148 | \r |
149 | ErrExit:\r |
150 | return Status;\r |
151 | }\r |