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