Check comments, format and fix some typo.
[mirror_edk2.git] / MdeModulePkg / Universal / DebugSupportDxe / DebugSupport.c
CommitLineData
fb0b259e 1/** @file\r
2 Top level C file for debug support driver. Contains initialization function.\r
c1f23d63 3\r
fb0b259e 4Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
c1f23d63 9\r
fb0b259e 10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
c1f23d63 12\r
fb0b259e 13**/\r
c1f23d63 14\r
e9f9d09a 15#include "PlDebugSupport.h"\r
c1f23d63 16\r
c84507ab 17EFI_DEBUG_SUPPORT_PROTOCOL mDebugSupportProtocolInterface = {\r
c1f23d63 18 EFI_ISA,\r
19 GetMaximumProcessorIndex,\r
20 RegisterPeriodicCallback,\r
21 RegisterExceptionCallback,\r
22 InvalidateInstructionCache\r
23};\r
24\r
9e604fe4 25\r
26/**\r
c84507ab 27 Debug Support Driver entry point. \r
9e604fe4 28\r
c84507ab 29 Checks to see if there's not already a Debug Support protocol installed for \r
30 the selected processor before installing it.\r
9e604fe4 31\r
32 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
33 @param[in] SystemTable A pointer to the EFI System Table.\r
34 \r
35 @retval EFI_SUCCESS The entry point is executed successfully.\r
7601dbe7 36 @retval EFI_ALREADY_STARTED Debug Support protocol is installed already.\r
9e604fe4 37 @retval other Some error occurs when executing this entry point.\r
38\r
39**/\r
c1f23d63 40EFI_STATUS\r
41InitializeDebugSupportDriver (\r
42 IN EFI_HANDLE ImageHandle,\r
43 IN EFI_SYSTEM_TABLE *SystemTable\r
44 )\r
c1f23d63 45{\r
46 EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProtocolPtr;\r
47 EFI_STATUS Status;\r
48 EFI_HANDLE Handle;\r
49 EFI_HANDLE *HandlePtr;\r
50 UINTN NumHandles;\r
51 EFI_DEBUG_SUPPORT_PROTOCOL *DebugSupportProtocolPtr;\r
52\r
c1f23d63 53 //\r
54 // First check to see that the debug support protocol for this processor\r
55 // type is not already installed\r
56 //\r
57 Status = gBS->LocateHandleBuffer (\r
58 ByProtocol,\r
59 &gEfiDebugSupportProtocolGuid,\r
60 NULL,\r
61 &NumHandles,\r
62 &HandlePtr\r
63 );\r
64\r
65 if (Status != EFI_NOT_FOUND) {\r
66 do {\r
67 NumHandles--;\r
68 Status = gBS->OpenProtocol (\r
69 HandlePtr[NumHandles],\r
70 &gEfiDebugSupportProtocolGuid,\r
71 (VOID **) &DebugSupportProtocolPtr,\r
72 ImageHandle,\r
73 NULL,\r
74 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
75 );\r
c84507ab 76 if ((Status == EFI_SUCCESS) && (DebugSupportProtocolPtr->Isa == EFI_ISA)) {\r
77 //\r
78 // a Debug Support protocol has been installed for this processor\r
79 //\r
c1f23d63 80 FreePool (HandlePtr);\r
81 Status = EFI_ALREADY_STARTED;\r
82 goto ErrExit;\r
83 }\r
84 } while (NumHandles > 0);\r
85 FreePool (HandlePtr);\r
86 }\r
87\r
88 //\r
89 // Get our image information and install platform specific unload handler\r
90 //\r
91 Status = gBS->OpenProtocol (\r
92 ImageHandle,\r
93 &gEfiLoadedImageProtocolGuid,\r
94 (VOID **) &LoadedImageProtocolPtr,\r
95 ImageHandle,\r
96 NULL,\r
97 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
98 );\r
99 ASSERT (!EFI_ERROR (Status));\r
100 if (Status != EFI_SUCCESS) {\r
101 goto ErrExit;\r
102 }\r
103\r
9e604fe4 104 LoadedImageProtocolPtr->Unload = PlUnloadDebugSupportDriver;\r
c1f23d63 105\r
106 //\r
c84507ab 107 // Call hook for processor specific initialization \r
c1f23d63 108 //\r
9e604fe4 109 Status = PlInitializeDebugSupportDriver ();\r
c1f23d63 110 ASSERT (!EFI_ERROR (Status));\r
111 if (Status != EFI_SUCCESS) {\r
112 goto ErrExit;\r
113 }\r
114\r
115 //\r
c84507ab 116 // Install Debug Support protocol to new handle\r
c1f23d63 117 //\r
118 Handle = NULL;\r
119 Status = gBS->InstallProtocolInterface (\r
120 &Handle,\r
121 &gEfiDebugSupportProtocolGuid,\r
122 EFI_NATIVE_INTERFACE,\r
c84507ab 123 &mDebugSupportProtocolInterface\r
c1f23d63 124 );\r
125 ASSERT (!EFI_ERROR (Status));\r
126 if (Status != EFI_SUCCESS) {\r
127 goto ErrExit;\r
128 }\r
129\r
130ErrExit:\r
131 return Status;\r
132}\r