]>
Commit | Line | Data |
---|---|---|
18b144ea | 1 | /** @file\r |
2 | Debug Agent library implementition.\r | |
3 | \r | |
4 | Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r | |
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 |
22 | \r | |
23 | /**\r | |
24 | Get Debug Agent Mailbox pointer.\r | |
25 | \r | |
26 | @return Mailbox pointer.\r | |
27 | \r | |
28 | **/\r | |
29 | DEBUG_AGENT_MAILBOX *\r | |
30 | GetMailboxPointer (\r | |
31 | VOID\r | |
32 | )\r | |
33 | {\r | |
34 | return mMailboxPointer;\r | |
35 | }\r | |
36 | \r | |
37 | /**\r | |
38 | Get debug port handle.\r | |
39 | \r | |
40 | @return Debug port handle.\r | |
41 | \r | |
42 | **/\r | |
43 | DEBUG_PORT_HANDLE\r | |
44 | GetDebugPortHandle (\r | |
45 | VOID\r | |
46 | )\r | |
47 | {\r | |
48 | return (DEBUG_PORT_HANDLE) (UINTN)(mMailboxPointer->DebugPortHandle);\r | |
49 | }\r | |
50 | \r | |
51 | /**\r | |
52 | Store debug register when SMI exit.\r | |
53 | \r | |
54 | **/\r | |
55 | VOID\r | |
56 | SaveDebugRegister (\r | |
57 | VOID\r | |
58 | )\r | |
59 | {\r | |
60 | mSavedDebugRegisters[0] = AsmReadDr0 ();\r | |
61 | mSavedDebugRegisters[1] = AsmReadDr1 ();\r | |
62 | mSavedDebugRegisters[2] = AsmReadDr2 ();\r | |
63 | mSavedDebugRegisters[3] = AsmReadDr3 ();\r | |
64 | mSavedDebugRegisters[4] = AsmReadDr6 ();\r | |
65 | mSavedDebugRegisters[5] = AsmReadDr7 ();\r | |
66 | }\r | |
67 | \r | |
68 | /**\r | |
69 | Restore debug register when SMI exit.\r | |
70 | \r | |
71 | **/\r | |
72 | VOID\r | |
73 | RestoreDebugRegister (\r | |
74 | VOID\r | |
75 | )\r | |
76 | {\r | |
77 | AsmWriteDr7 (0);\r | |
78 | AsmWriteDr0 (mSavedDebugRegisters[0]);\r | |
79 | AsmWriteDr1 (mSavedDebugRegisters[1]);\r | |
80 | AsmWriteDr2 (mSavedDebugRegisters[2]);\r | |
81 | AsmWriteDr3 (mSavedDebugRegisters[3]);\r | |
82 | AsmWriteDr6 (mSavedDebugRegisters[4]);\r | |
83 | AsmWriteDr7 (mSavedDebugRegisters[5]);\r | |
84 | }\r | |
85 | \r | |
86 | /**\r | |
87 | Initialize debug agent.\r | |
88 | \r | |
89 | This function is used to set up debug enviroment for source level debug\r | |
90 | in SMM code.\r | |
91 | \r | |
92 | If InitFlag is DEBUG_AGENT_INIT_SMM, it will overirde IDT table entries\r | |
93 | and initialize debug port. It will get debug agent Mailbox from GUIDed HOB,\r | |
94 | it it exists, debug agent wiil copied it into the local Mailbox in SMM space.\r | |
95 | it will overirde IDT table entries and initialize debug port. Context will be\r | |
96 | NULL.\r | |
97 | If InitFlag is DEBUG_AGENT_INIT_ENTER_SMI, debug agent will save Debug\r | |
98 | Registers and get local Mailbox in SMM space. Context will be NULL.\r | |
99 | If InitFlag is DEBUG_AGENT_INIT_EXIT_SMI, debug agent will restore Debug\r | |
100 | Registers. Context will be NULL.\r | |
101 | \r | |
102 | @param[in] InitFlag Init flag is used to decide initialize process.\r | |
103 | @param[in] Context Context needed according to InitFlag.\r | |
104 | @param[in] Function Continue function called by debug agent library; it was\r | |
105 | optional.\r | |
106 | \r | |
107 | **/\r | |
108 | VOID\r | |
109 | EFIAPI\r | |
110 | InitializeDebugAgent (\r | |
111 | IN UINT32 InitFlag,\r | |
112 | IN VOID *Context, OPTIONAL\r | |
113 | IN DEBUG_AGENT_CONTINUE Function OPTIONAL\r | |
114 | )\r | |
115 | {\r | |
116 | EFI_STATUS Status;\r | |
117 | UINT64 DebugPortHandle;\r | |
118 | \r | |
119 | switch (InitFlag) {\r | |
120 | case DEBUG_AGENT_INIT_SMM:\r | |
121 | Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **) &mMailboxPointer);\r | |
122 | if (EFI_ERROR (Status) || mMailboxPointer == NULL) {\r | |
123 | ZeroMem (&mLocalMailbox, sizeof (DEBUG_AGENT_MAILBOX));\r | |
124 | mMailboxPointer = &mLocalMailbox;\r | |
125 | }\r | |
126 | \r | |
127 | break;\r | |
128 | \r | |
129 | case DEBUG_AGENT_INIT_ENTER_SMI:\r | |
130 | SaveDebugRegister ();\r | |
131 | InitializeDebugIdt ();\r | |
132 | \r | |
133 | if (mMailboxPointer != NULL) {\r | |
134 | //\r | |
135 | // Initialize debug communication port\r | |
136 | //\r | |
137 | DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((DEBUG_PORT_HANDLE) (UINTN)mMailboxPointer->DebugPortHandle, NULL);\r | |
138 | mMailboxPointer->DebugPortHandle = DebugPortHandle;\r | |
139 | \r | |
140 | if (mMailboxPointer->DebugFlag.Bits.BreakOnNextSmi == 1) {\r | |
141 | //\r | |
142 | // If SMM entry break is set, SMM code will be break at here.\r | |
143 | //\r | |
144 | CpuBreakpoint ();\r | |
145 | }\r | |
146 | }\r | |
147 | break;\r | |
148 | \r | |
149 | case DEBUG_AGENT_INIT_EXIT_SMI:\r | |
150 | RestoreDebugRegister ();\r | |
151 | break;\r | |
152 | }\r | |
153 | }\r | |
154 | \r |