]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
IntelFsp2WrapperPkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcDebugger / EdbCmdBreakpoint.c
CommitLineData
e8a5ac7c 1/** @file\r
748edcd5 2\r
e8a5ac7c 3Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
9d510e61 4SPDX-License-Identifier: BSD-2-Clause-Patent\r
748edcd5 5\r
748edcd5 6\r
e8a5ac7c 7**/\r
748edcd5 8\r
e8a5ac7c 9#include "Edb.h"\r
748edcd5 10\r
e8a5ac7c 11/**\r
748edcd5 12\r
e8a5ac7c 13 Check whether current IP is EBC BREAK3 instruction.\r
748edcd5 14\r
e8a5ac7c 15 @param Address EBC IP address.\r
748edcd5 16\r
e8a5ac7c
DB
17 @retval TRUE Current IP is EBC BREAK3 instruction\r
18 @retval FALSE Current IP is not EBC BREAK3 instruction\r
19\r
20**/\r
748edcd5
PB
21BOOLEAN\r
22IsEBCBREAK3 (\r
23 IN UINTN Address\r
24 )\r
748edcd5
PB
25{\r
26 if (GET_OPCODE(Address) != OPCODE_BREAK) {\r
27 return FALSE;\r
28 }\r
29\r
30 if (GET_OPERANDS (Address) != 3) {\r
31 return FALSE;\r
32 } else {\r
33 return TRUE;\r
34 }\r
35}\r
36\r
e8a5ac7c
DB
37/**\r
38\r
39 Check whether the Address is already set in breakpoint.\r
40\r
41 @param DebuggerPrivate EBC Debugger private data structure\r
42 @param Address Breakpoint Address\r
43\r
44 @retval TRUE breakpoint is found\r
45 @retval FALSE breakpoint is not found\r
46\r
47**/\r
748edcd5
PB
48BOOLEAN\r
49DebuggerBreakpointIsDuplicated (\r
50 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
51 IN UINTN Address\r
52 )\r
748edcd5
PB
53{\r
54 UINTN Index;\r
55\r
56 //\r
57 // Go through each breakpoint context\r
58 //\r
59 for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {\r
60 if (DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress == Address) {\r
61 //\r
62 // Found it\r
63 //\r
64 return TRUE;\r
65 }\r
66 }\r
67\r
68 //\r
69 // Not found\r
70 //\r
71 return FALSE;\r
72}\r
73\r
e8a5ac7c
DB
74/**\r
75\r
76 Add this breakpoint.\r
77\r
78 @param DebuggerPrivate EBC Debugger private data structure\r
79 @param Address Breakpoint Address\r
80\r
81 @retval EFI_SUCCESS breakpoint added successfully\r
82 @retval EFI_ALREADY_STARTED breakpoint is already added\r
83 @retval EFI_OUT_OF_RESOURCES all the breakpoint entries are used\r
84\r
85**/\r
748edcd5
PB
86EFI_STATUS\r
87DebuggerBreakpointAdd (\r
88 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
89 IN UINTN Address\r
90 )\r
748edcd5
PB
91{\r
92 //\r
93 // Check duplicated breakpoint\r
94 //\r
95 if (DebuggerBreakpointIsDuplicated (DebuggerPrivate, Address)) {\r
96 EDBPrint (L"Breakpoint duplicated!\n");\r
97 return EFI_ALREADY_STARTED;\r
98 }\r
99\r
100 //\r
101 // Check whether the address is a breakpoint 3 instruction\r
102 //\r
103 if (IsEBCBREAK3 (Address)) {\r
104 EDBPrint (L"Breakpoint can not be set on BREAK 3 instruction!\n");\r
105 return EFI_ALREADY_STARTED;\r
106 }\r
107\r
108 if (DebuggerPrivate->DebuggerBreakpointCount >= EFI_DEBUGGER_BREAKPOINT_MAX) {\r
109 EDBPrint (L"Breakpoint out of resource!\n");\r
110 return EFI_OUT_OF_RESOURCES;\r
111 }\r
112\r
113 //\r
114 // Set the breakpoint\r
115 //\r
116 DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].BreakpointAddress = Address;\r
117 DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].State = TRUE;\r
118 DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].OldInstruction = 0;\r
119 CopyMem (\r
120 &DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].OldInstruction,\r
121 (VOID *)Address,\r
122 sizeof(UINT16)\r
123 );\r
124\r
125 DebuggerPrivate->DebuggerBreakpointCount ++;\r
126\r
127 //\r
128 // Done\r
129 //\r
130 return EFI_SUCCESS;\r
131}\r
132\r
e8a5ac7c
DB
133/**\r
134\r
135 Delete this breakpoint.\r
136\r
137 @param DebuggerPrivate EBC Debugger private data structure\r
138 @param Index Breakpoint Index\r
139\r
140 @retval EFI_SUCCESS breakpoint deleted successfully\r
141 @retval EFI_NOT_FOUND breakpoint not found\r
142\r
143**/\r
748edcd5
PB
144EFI_STATUS\r
145DebuggerBreakpointDel (\r
146 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
147 IN UINTN Index\r
148 )\r
748edcd5
PB
149{\r
150 UINTN BpIndex;\r
151\r
152 if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||\r
153 (Index >= DebuggerPrivate->DebuggerBreakpointCount)) {\r
154 return EFI_NOT_FOUND;\r
155 }\r
156\r
157 //\r
158 // Delete this breakpoint\r
159 //\r
160 for (BpIndex = Index; BpIndex < DebuggerPrivate->DebuggerBreakpointCount - 1; BpIndex++) {\r
b04453d3
M
161 CopyMem (\r
162 &DebuggerPrivate->DebuggerBreakpointContext[BpIndex],\r
163 &DebuggerPrivate->DebuggerBreakpointContext[BpIndex + 1],\r
164 sizeof (DebuggerPrivate->DebuggerBreakpointContext[BpIndex])\r
165 );\r
748edcd5
PB
166 }\r
167 ZeroMem (\r
168 &DebuggerPrivate->DebuggerBreakpointContext[BpIndex],\r
169 sizeof(DebuggerPrivate->DebuggerBreakpointContext[BpIndex])\r
170 );\r
171\r
172 DebuggerPrivate->DebuggerBreakpointCount --;\r
173\r
174 //\r
175 // Done\r
176 //\r
177 return EFI_SUCCESS;\r
178}\r
179\r
e8a5ac7c
DB
180/**\r
181\r
182 Disable this breakpoint.\r
183\r
184 @param DebuggerPrivate EBC Debugger private data structure\r
185 @param Index Breakpoint Index\r
186\r
187 @retval EFI_SUCCESS breakpoint disabled successfully\r
188 @retval EFI_NOT_FOUND breakpoint not found\r
189\r
190**/\r
748edcd5
PB
191EFI_STATUS\r
192DebuggerBreakpointDis (\r
193 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
194 IN UINTN Index\r
195 )\r
748edcd5
PB
196{\r
197 if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||\r
198 (Index >= DebuggerPrivate->DebuggerBreakpointCount)) {\r
199 return EFI_NOT_FOUND;\r
200 }\r
201\r
202 //\r
203 // Disable this breakpoint\r
204 //\r
205 DebuggerPrivate->DebuggerBreakpointContext[Index].State = FALSE;\r
206\r
207 return EFI_SUCCESS;\r
208}\r
209\r
e8a5ac7c
DB
210/**\r
211\r
212 Enable this breakpoint.\r
213\r
214 @param DebuggerPrivate - EBC Debugger private data structure\r
215 @param Index - Breakpoint Index\r
216\r
217 @retval EFI_SUCCESS - breakpoint enabled successfully\r
218 @retval EFI_NOT_FOUND - breakpoint not found\r
219\r
220**/\r
748edcd5
PB
221EFI_STATUS\r
222DebuggerBreakpointEn (\r
223 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
224 IN UINTN Index\r
225 )\r
748edcd5
PB
226{\r
227 if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||\r
228 (Index >= DebuggerPrivate->DebuggerBreakpointCount)) {\r
229 return EFI_NOT_FOUND;\r
230 }\r
231\r
232 //\r
233 // Enable this breakpoint\r
234 //\r
235 DebuggerPrivate->DebuggerBreakpointContext[Index].State = TRUE;\r
236\r
237 return EFI_SUCCESS;\r
238}\r
239\r
e8a5ac7c
DB
240/**\r
241\r
242 DebuggerCommand - BreakpointList.\r
243\r
244 @param CommandArg - The argument for this command\r
245 @param DebuggerPrivate - EBC Debugger private data structure\r
246 @param ExceptionType - Exception type.\r
247 @param SystemContext - EBC system context.\r
248\r
249 @retval EFI_DEBUG_CONTINUE - formal return value\r
250\r
251**/\r
748edcd5
PB
252EFI_DEBUG_STATUS\r
253DebuggerBreakpointList (\r
254 IN CHAR16 *CommandArg,\r
255 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
256 IN EFI_EXCEPTION_TYPE ExceptionType,\r
257 IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
258 )\r
748edcd5
PB
259{\r
260 UINTN Index;\r
261\r
262 //\r
263 // Check breakpoint cound\r
264 //\r
265 if (DebuggerPrivate->DebuggerBreakpointCount == 0) {\r
266 EDBPrint (L"No Breakpoint\n");\r
267 return EFI_DEBUG_CONTINUE;\r
268 } else if (DebuggerPrivate->DebuggerBreakpointCount > EFI_DEBUGGER_BREAKPOINT_MAX) {\r
269 EDBPrint (L"Breakpoint too many!\n");\r
270 DebuggerPrivate->DebuggerBreakpointCount = 0;\r
271 return EFI_DEBUG_CONTINUE;\r
272 }\r
273\r
274 //\r
275 // Go through each breakpoint\r
276 //\r
277 EDBPrint (L"Breakpoint :\n");\r
278 EDBPrint (L" Index Address Status\n");\r
279 EDBPrint (L"======= ================== ========\n");\r
280//EDBPrint (L" 1 0xFFFFFFFF00000000 *\n");\r
281//EDBPrint (L" 12 0x00000000FFFFFFFF\n");\r
282 for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {\r
283 //\r
284 // Print the breakpoint\r
285 //\r
286 EDBPrint (L" %2d 0x%016lx", Index, DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress);\r
287 if (DebuggerPrivate->DebuggerBreakpointContext[Index].State) {\r
288 EDBPrint (L" *\n");\r
289 } else {\r
290 EDBPrint (L"\n");\r
291 }\r
292 }\r
293\r
294 //\r
295 // Done\r
296 //\r
297 return EFI_DEBUG_CONTINUE;\r
298}\r
299\r
e8a5ac7c
DB
300/**\r
301\r
302 DebuggerCommand - BreakpointSet.\r
303\r
304 @param CommandArg The argument for this command\r
305 @param DebuggerPrivate EBC Debugger private data structure\r
306 @param ExceptionType Exception type.\r
307 @param SystemContext EBC system context.\r
308\r
309 @retval EFI_DEBUG_CONTINUE - formal return value\r
310\r
311**/\r
748edcd5
PB
312EFI_DEBUG_STATUS\r
313DebuggerBreakpointSet (\r
314 IN CHAR16 *CommandArg,\r
315 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
316 IN EFI_EXCEPTION_TYPE ExceptionType,\r
317 IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
318 )\r
748edcd5
PB
319{\r
320 UINTN Address;\r
321 EFI_STATUS Status;\r
322\r
323 if (CommandArg == NULL) {\r
324 EDBPrint (L"BreakpointSet Argument error!\n");\r
325 return EFI_DEBUG_CONTINUE;\r
326 }\r
327\r
328 //\r
329 // Get breakpoint address\r
330 //\r
331 Status = Symboltoi (CommandArg, &Address);\r
332 if (EFI_ERROR (Status)) {\r
333 if (Status == EFI_NOT_FOUND) {\r
334 Address = Xtoi(CommandArg);\r
335 } else {\r
336 //\r
337 // Something wrong, let Symboltoi print error info.\r
338 //\r
339 EDBPrint (L"Command Argument error!\n");\r
340 return EFI_DEBUG_CONTINUE;\r
341 }\r
342 }\r
343\r
344 //\r
345 // Add breakpoint\r
346 //\r
347 Status = DebuggerBreakpointAdd (DebuggerPrivate, Address);\r
348 if (EFI_ERROR(Status)) {\r
349 EDBPrint (L"BreakpointSet error!\n");\r
350 }\r
351\r
352 //\r
353 // Done\r
354 //\r
355 return EFI_DEBUG_CONTINUE;\r
356}\r
357\r
e8a5ac7c
DB
358/**\r
359\r
360 DebuggerCommand - BreakpointClear\r
361\r
362 @param CommandArg The argument for this command\r
363 @param DebuggerPrivate EBC Debugger private data structure\r
364 @param ExceptionType Exception type.\r
365 @param SystemContext EBC system context.\r
366\r
367 @retval EFI_DEBUG_CONTINUE formal return value\r
368\r
369**/\r
748edcd5
PB
370EFI_DEBUG_STATUS\r
371DebuggerBreakpointClear (\r
372 IN CHAR16 *CommandArg,\r
373 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
374 IN EFI_EXCEPTION_TYPE ExceptionType,\r
375 IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
376 )\r
748edcd5
PB
377{\r
378 UINTN Index;\r
379 EFI_STATUS Status;\r
748edcd5
PB
380\r
381 if (CommandArg == NULL) {\r
382 EDBPrint (L"BreakpointClear Argument error!\n");\r
383 return EFI_DEBUG_CONTINUE;\r
384 }\r
385\r
386 if (StriCmp (CommandArg, L"*") == 0) {\r
387 //\r
388 // delete all breakpoint\r
389 //\r
390 DebuggerPrivate->DebuggerBreakpointCount = 0;\r
391 ZeroMem (DebuggerPrivate->DebuggerBreakpointContext, sizeof(DebuggerPrivate->DebuggerBreakpointContext));\r
392 EDBPrint (L"All the Breakpoint is cleared\n");\r
393 return EFI_DEBUG_CONTINUE;\r
394 }\r
395\r
396 //\r
397 // Get breakpoint index\r
398 //\r
399 Index = Atoi(CommandArg);\r
12f49354
HW
400 if (Index == (UINTN) -1) {\r
401 EDBPrint (L"BreakpointClear Argument error!\n");\r
402 return EFI_DEBUG_CONTINUE;\r
403 }\r
748edcd5
PB
404\r
405 if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||\r
406 (Index >= DebuggerPrivate->DebuggerBreakpointCount)) {\r
407 EDBPrint (L"BreakpointClear error!\n");\r
408 return EFI_DEBUG_CONTINUE;\r
748edcd5
PB
409 }\r
410\r
411 //\r
412 // Delete breakpoint\r
413 //\r
414 Status = DebuggerBreakpointDel (DebuggerPrivate, Index);\r
415 if (EFI_ERROR(Status)) {\r
416 EDBPrint (L"BreakpointClear error!\n");\r
417 }\r
418\r
419 //\r
420 // Done\r
421 //\r
422 return EFI_DEBUG_CONTINUE;\r
423}\r
424\r
e8a5ac7c
DB
425/**\r
426\r
427 DebuggerCommand - BreakpointDisable\r
428\r
429 @param CommandArg The argument for this command\r
430 @param DebuggerPrivate EBC Debugger private data structure\r
431 @param ExceptionType Exception type.\r
432 @param SystemContext EBC system context.\r
433\r
434 @retval EFI_DEBUG_CONTINUE formal return value\r
435\r
436**/\r
748edcd5
PB
437EFI_DEBUG_STATUS\r
438DebuggerBreakpointDisable (\r
439 IN CHAR16 *CommandArg,\r
440 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
441 IN EFI_EXCEPTION_TYPE ExceptionType,\r
442 IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
443 )\r
748edcd5
PB
444{\r
445 UINTN Index;\r
446 EFI_STATUS Status;\r
447\r
448 if (CommandArg == NULL) {\r
449 EDBPrint (L"BreakpointDisable Argument error!\n");\r
450 return EFI_DEBUG_CONTINUE;\r
451 }\r
452\r
453 if (StriCmp (CommandArg, L"*") == 0) {\r
454 //\r
455 // disable all breakpoint\r
456 //\r
457 for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {\r
458 Status = DebuggerBreakpointDis (DebuggerPrivate, Index);\r
459 }\r
460 EDBPrint (L"All the Breakpoint is disabled\n");\r
461 return EFI_DEBUG_CONTINUE;\r
462 }\r
463\r
464 //\r
465 // Get breakpoint index\r
466 //\r
467 Index = Atoi(CommandArg);\r
12f49354
HW
468 if (Index == (UINTN) -1) {\r
469 EDBPrint (L"BreakpointDisable Argument error!\n");\r
470 return EFI_DEBUG_CONTINUE;\r
471 }\r
748edcd5
PB
472\r
473 //\r
474 // Disable breakpoint\r
475 //\r
476 Status = DebuggerBreakpointDis (DebuggerPrivate, Index);\r
477 if (EFI_ERROR(Status)) {\r
478 EDBPrint (L"BreakpointDisable error!\n");\r
479 }\r
480\r
481 //\r
482 // Done\r
483 //\r
484 return EFI_DEBUG_CONTINUE;\r
485}\r
486\r
e8a5ac7c
DB
487/**\r
488 DebuggerCommand - BreakpointEnable.\r
489\r
490 @param CommandArg The argument for this command\r
491 @param DebuggerPrivate EBC Debugger private data structure\r
492 @param ExceptionType Exception type.\r
493 @param SystemContext EBC system context.\r
494\r
495 @retval EFI_DEBUG_CONTINUE formal return value\r
496\r
497**/\r
748edcd5
PB
498EFI_DEBUG_STATUS\r
499DebuggerBreakpointEnable (\r
500 IN CHAR16 *CommandArg,\r
501 IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
502 IN EFI_EXCEPTION_TYPE ExceptionType,\r
503 IN OUT EFI_SYSTEM_CONTEXT SystemContext\r
504 )\r
748edcd5
PB
505{\r
506 UINTN Index;\r
507 EFI_STATUS Status;\r
508\r
509 if (CommandArg == NULL) {\r
510 EDBPrint (L"BreakpointEnable Argument error!\n");\r
511 return EFI_DEBUG_CONTINUE;\r
512 }\r
513\r
514 if (StriCmp (CommandArg, L"*") == 0) {\r
515 //\r
516 // enable all breakpoint\r
517 //\r
518 for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {\r
519 Status = DebuggerBreakpointEn (DebuggerPrivate, Index);\r
520 }\r
521 EDBPrint (L"All the Breakpoint is enabled\n");\r
522 return EFI_DEBUG_CONTINUE;\r
523 }\r
524\r
525 //\r
526 // Get breakpoint index\r
527 //\r
528 Index = Atoi(CommandArg);\r
12f49354
HW
529 if (Index == (UINTN) -1) {\r
530 EDBPrint (L"BreakpointEnable Argument error!\n");\r
531 return EFI_DEBUG_CONTINUE;\r
532 }\r
748edcd5
PB
533\r
534 //\r
535 // Enable breakpoint\r
536 //\r
537 Status = DebuggerBreakpointEn (DebuggerPrivate, Index);\r
538 if (EFI_ERROR(Status)) {\r
539 EDBPrint (L"BreakpointEnable error!\n");\r
540 }\r
541\r
542 //\r
543 // Done\r
544 //\r
545 return EFI_DEBUG_CONTINUE;\r
546}\r