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