]>
Commit | Line | Data |
---|---|---|
18b144ea | 1 | /** @file\r |
2 | Debug Agent library implementition.\r | |
3 | \r | |
93c0bdec | 4 | Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r |
18b144ea | 5 | This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php.\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "SmmDebugAgentLib.h"\r | |
16 | \r | |
17 | DEBUG_AGENT_MAILBOX *mMailboxPointer = NULL;\r | |
b6ee5898 | 18 | DEBUG_AGENT_MAILBOX mLocalMailbox;\r |
19 | UINTN mSavedDebugRegisters[6];\r | |
20 | CONST BOOLEAN MultiProcessorDebugSupport = FALSE;\r | |
18b144ea | 21 | \r |
93c0bdec | 22 | /**\r |
23 | Read the Attach/Break-in symbols from the debug port.\r | |
24 | \r | |
25 | @param[in] Handle Pointer to Debug Port handle.\r | |
26 | @param[out] BreakSymbol Returned break symbol.\r | |
27 | \r | |
28 | @retval EFI_SUCCESS Read the symbol in BreakSymbol.\r | |
29 | @retval EFI_NOT_FOUND No read the break symbol.\r | |
30 | \r | |
31 | **/\r | |
32 | EFI_STATUS\r | |
33 | DebugReadBreakSymbol (\r | |
34 | IN DEBUG_PORT_HANDLE Handle,\r | |
35 | OUT UINT8 *BreakSymbol\r | |
36 | )\r | |
37 | {\r | |
38 | //\r | |
39 | // Smm instance has no debug timer to poll break symbol.\r | |
40 | //\r | |
41 | return EFI_NOT_FOUND;\r | |
42 | }\r | |
18b144ea | 43 | \r |
44 | /**\r | |
45 | Get Debug Agent Mailbox pointer.\r | |
46 | \r | |
47 | @return Mailbox pointer.\r | |
48 | \r | |
49 | **/\r | |
50 | DEBUG_AGENT_MAILBOX *\r | |
51 | GetMailboxPointer (\r | |
52 | VOID\r | |
53 | )\r | |
54 | {\r | |
55 | return mMailboxPointer;\r | |
56 | }\r | |
57 | \r | |
58 | /**\r | |
59 | Get debug port handle.\r | |
60 | \r | |
61 | @return Debug port handle.\r | |
62 | \r | |
63 | **/\r | |
64 | DEBUG_PORT_HANDLE\r | |
65 | GetDebugPortHandle (\r | |
66 | VOID\r | |
67 | )\r | |
68 | {\r | |
69 | return (DEBUG_PORT_HANDLE) (UINTN)(mMailboxPointer->DebugPortHandle);\r | |
70 | }\r | |
71 | \r | |
72 | /**\r | |
73 | Store debug register when SMI exit.\r | |
74 | \r | |
75 | **/\r | |
76 | VOID\r | |
77 | SaveDebugRegister (\r | |
78 | VOID\r | |
79 | )\r | |
80 | {\r | |
81 | mSavedDebugRegisters[0] = AsmReadDr0 ();\r | |
82 | mSavedDebugRegisters[1] = AsmReadDr1 ();\r | |
83 | mSavedDebugRegisters[2] = AsmReadDr2 ();\r | |
84 | mSavedDebugRegisters[3] = AsmReadDr3 ();\r | |
85 | mSavedDebugRegisters[4] = AsmReadDr6 ();\r | |
86 | mSavedDebugRegisters[5] = AsmReadDr7 ();\r | |
87 | }\r | |
88 | \r | |
89 | /**\r | |
90 | Restore debug register when SMI exit.\r | |
91 | \r | |
92 | **/\r | |
93 | VOID\r | |
94 | RestoreDebugRegister (\r | |
95 | VOID\r | |
96 | )\r | |
97 | {\r | |
98 | AsmWriteDr7 (0);\r | |
99 | AsmWriteDr0 (mSavedDebugRegisters[0]);\r | |
100 | AsmWriteDr1 (mSavedDebugRegisters[1]);\r | |
101 | AsmWriteDr2 (mSavedDebugRegisters[2]);\r | |
102 | AsmWriteDr3 (mSavedDebugRegisters[3]);\r | |
103 | AsmWriteDr6 (mSavedDebugRegisters[4]);\r | |
104 | AsmWriteDr7 (mSavedDebugRegisters[5]);\r | |
105 | }\r | |
106 | \r | |
107 | /**\r | |
108 | Initialize debug agent.\r | |
109 | \r | |
110 | This function is used to set up debug enviroment for source level debug\r | |
111 | in SMM code.\r | |
112 | \r | |
113 | If InitFlag is DEBUG_AGENT_INIT_SMM, it will overirde IDT table entries\r | |
114 | and initialize debug port. It will get debug agent Mailbox from GUIDed HOB,\r | |
115 | it it exists, debug agent wiil copied it into the local Mailbox in SMM space.\r | |
116 | it will overirde IDT table entries and initialize debug port. Context will be\r | |
117 | NULL.\r | |
118 | If InitFlag is DEBUG_AGENT_INIT_ENTER_SMI, debug agent will save Debug\r | |
119 | Registers and get local Mailbox in SMM space. Context will be NULL.\r | |
120 | If InitFlag is DEBUG_AGENT_INIT_EXIT_SMI, debug agent will restore Debug\r | |
121 | Registers. Context will be NULL.\r | |
122 | \r | |
123 | @param[in] InitFlag Init flag is used to decide initialize process.\r | |
124 | @param[in] Context Context needed according to InitFlag.\r | |
125 | @param[in] Function Continue function called by debug agent library; it was\r | |
126 | optional.\r | |
127 | \r | |
128 | **/\r | |
129 | VOID\r | |
130 | EFIAPI\r | |
131 | InitializeDebugAgent (\r | |
132 | IN UINT32 InitFlag,\r | |
133 | IN VOID *Context, OPTIONAL\r | |
134 | IN DEBUG_AGENT_CONTINUE Function OPTIONAL\r | |
135 | )\r | |
136 | {\r | |
137 | EFI_STATUS Status;\r | |
138 | UINT64 DebugPortHandle;\r | |
139 | \r | |
140 | switch (InitFlag) {\r | |
141 | case DEBUG_AGENT_INIT_SMM:\r | |
142 | Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **) &mMailboxPointer);\r | |
143 | if (EFI_ERROR (Status) || mMailboxPointer == NULL) {\r | |
144 | ZeroMem (&mLocalMailbox, sizeof (DEBUG_AGENT_MAILBOX));\r | |
145 | mMailboxPointer = &mLocalMailbox;\r | |
146 | }\r | |
147 | \r | |
148 | break;\r | |
149 | \r | |
150 | case DEBUG_AGENT_INIT_ENTER_SMI:\r | |
151 | SaveDebugRegister ();\r | |
152 | InitializeDebugIdt ();\r | |
153 | \r | |
154 | if (mMailboxPointer != NULL) {\r | |
155 | //\r | |
156 | // Initialize debug communication port\r | |
157 | //\r | |
158 | DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((DEBUG_PORT_HANDLE) (UINTN)mMailboxPointer->DebugPortHandle, NULL);\r | |
159 | mMailboxPointer->DebugPortHandle = DebugPortHandle;\r | |
160 | \r | |
93c0bdec | 161 | if (mMailboxPointer->DebugFlag.BreakOnNextSmi == 1) {\r |
18b144ea | 162 | //\r |
163 | // If SMM entry break is set, SMM code will be break at here.\r | |
164 | //\r | |
165 | CpuBreakpoint ();\r | |
166 | }\r | |
167 | }\r | |
168 | break;\r | |
169 | \r | |
170 | case DEBUG_AGENT_INIT_EXIT_SMI:\r | |
171 | RestoreDebugRegister ();\r | |
172 | break;\r | |
173 | }\r | |
174 | }\r | |
175 | \r |