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