3 Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
13 Check whether current IP is EBC BREAK3 instruction.
15 @param Address EBC IP address.
17 @retval TRUE Current IP is EBC BREAK3 instruction
18 @retval FALSE Current IP is not EBC BREAK3 instruction
26 if (GET_OPCODE (Address
) != OPCODE_BREAK
) {
30 if (GET_OPERANDS (Address
) != 3) {
39 Check whether the Address is already set in breakpoint.
41 @param DebuggerPrivate EBC Debugger private data structure
42 @param Address Breakpoint Address
44 @retval TRUE breakpoint is found
45 @retval FALSE breakpoint is not found
49 DebuggerBreakpointIsDuplicated (
50 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
57 // Go through each breakpoint context
59 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
60 if (DebuggerPrivate
->DebuggerBreakpointContext
[Index
].BreakpointAddress
== Address
) {
78 @param DebuggerPrivate EBC Debugger private data structure
79 @param Address Breakpoint Address
81 @retval EFI_SUCCESS breakpoint added successfully
82 @retval EFI_ALREADY_STARTED breakpoint is already added
83 @retval EFI_OUT_OF_RESOURCES all the breakpoint entries are used
87 DebuggerBreakpointAdd (
88 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
93 // Check duplicated breakpoint
95 if (DebuggerBreakpointIsDuplicated (DebuggerPrivate
, Address
)) {
96 EDBPrint (L
"Breakpoint duplicated!\n");
97 return EFI_ALREADY_STARTED
;
101 // Check whether the address is a breakpoint 3 instruction
103 if (IsEBCBREAK3 (Address
)) {
104 EDBPrint (L
"Breakpoint can not be set on BREAK 3 instruction!\n");
105 return EFI_ALREADY_STARTED
;
108 if (DebuggerPrivate
->DebuggerBreakpointCount
>= EFI_DEBUGGER_BREAKPOINT_MAX
) {
109 EDBPrint (L
"Breakpoint out of resource!\n");
110 return EFI_OUT_OF_RESOURCES
;
114 // Set the breakpoint
116 DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].BreakpointAddress
= Address
;
117 DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].State
= TRUE
;
118 DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].OldInstruction
= 0;
120 &DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].OldInstruction
,
125 DebuggerPrivate
->DebuggerBreakpointCount
++;
135 Delete this breakpoint.
137 @param DebuggerPrivate EBC Debugger private data structure
138 @param Index Breakpoint Index
140 @retval EFI_SUCCESS breakpoint deleted successfully
141 @retval EFI_NOT_FOUND breakpoint not found
145 DebuggerBreakpointDel (
146 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
152 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
153 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
))
155 return EFI_NOT_FOUND
;
159 // Delete this breakpoint
161 for (BpIndex
= Index
; BpIndex
< DebuggerPrivate
->DebuggerBreakpointCount
- 1; BpIndex
++) {
163 &DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
],
164 &DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
+ 1],
165 sizeof (DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
])
170 &DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
],
171 sizeof (DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
])
174 DebuggerPrivate
->DebuggerBreakpointCount
--;
184 Disable this breakpoint.
186 @param DebuggerPrivate EBC Debugger private data structure
187 @param Index Breakpoint Index
189 @retval EFI_SUCCESS breakpoint disabled successfully
190 @retval EFI_NOT_FOUND breakpoint not found
194 DebuggerBreakpointDis (
195 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
199 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
200 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
))
202 return EFI_NOT_FOUND
;
206 // Disable this breakpoint
208 DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
= FALSE
;
215 Enable this breakpoint.
217 @param DebuggerPrivate - EBC Debugger private data structure
218 @param Index - Breakpoint Index
220 @retval EFI_SUCCESS - breakpoint enabled successfully
221 @retval EFI_NOT_FOUND - breakpoint not found
225 DebuggerBreakpointEn (
226 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
230 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
231 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
))
233 return EFI_NOT_FOUND
;
237 // Enable this breakpoint
239 DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
= TRUE
;
246 DebuggerCommand - BreakpointList.
248 @param CommandArg - The argument for this command
249 @param DebuggerPrivate - EBC Debugger private data structure
250 @param ExceptionType - Exception type.
251 @param SystemContext - EBC system context.
253 @retval EFI_DEBUG_CONTINUE - formal return value
257 DebuggerBreakpointList (
258 IN CHAR16
*CommandArg
,
259 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
260 IN EFI_EXCEPTION_TYPE ExceptionType
,
261 IN OUT EFI_SYSTEM_CONTEXT SystemContext
267 // Check breakpoint cound
269 if (DebuggerPrivate
->DebuggerBreakpointCount
== 0) {
270 EDBPrint (L
"No Breakpoint\n");
271 return EFI_DEBUG_CONTINUE
;
272 } else if (DebuggerPrivate
->DebuggerBreakpointCount
> EFI_DEBUGGER_BREAKPOINT_MAX
) {
273 EDBPrint (L
"Breakpoint too many!\n");
274 DebuggerPrivate
->DebuggerBreakpointCount
= 0;
275 return EFI_DEBUG_CONTINUE
;
279 // Go through each breakpoint
281 EDBPrint (L
"Breakpoint :\n");
282 EDBPrint (L
" Index Address Status\n");
283 EDBPrint (L
"======= ================== ========\n");
284 // EDBPrint (L" 1 0xFFFFFFFF00000000 *\n");
285 // EDBPrint (L" 12 0x00000000FFFFFFFF\n");
286 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
288 // Print the breakpoint
290 EDBPrint (L
" %2d 0x%016lx", Index
, DebuggerPrivate
->DebuggerBreakpointContext
[Index
].BreakpointAddress
);
291 if (DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
) {
301 return EFI_DEBUG_CONTINUE
;
306 DebuggerCommand - BreakpointSet.
308 @param CommandArg The argument for this command
309 @param DebuggerPrivate EBC Debugger private data structure
310 @param ExceptionType Exception type.
311 @param SystemContext EBC system context.
313 @retval EFI_DEBUG_CONTINUE - formal return value
317 DebuggerBreakpointSet (
318 IN CHAR16
*CommandArg
,
319 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
320 IN EFI_EXCEPTION_TYPE ExceptionType
,
321 IN OUT EFI_SYSTEM_CONTEXT SystemContext
327 if (CommandArg
== NULL
) {
328 EDBPrint (L
"BreakpointSet Argument error!\n");
329 return EFI_DEBUG_CONTINUE
;
333 // Get breakpoint address
335 Status
= Symboltoi (CommandArg
, &Address
);
336 if (EFI_ERROR (Status
)) {
337 if (Status
== EFI_NOT_FOUND
) {
338 Address
= Xtoi (CommandArg
);
341 // Something wrong, let Symboltoi print error info.
343 EDBPrint (L
"Command Argument error!\n");
344 return EFI_DEBUG_CONTINUE
;
351 Status
= DebuggerBreakpointAdd (DebuggerPrivate
, Address
);
352 if (EFI_ERROR (Status
)) {
353 EDBPrint (L
"BreakpointSet error!\n");
359 return EFI_DEBUG_CONTINUE
;
364 DebuggerCommand - BreakpointClear
366 @param CommandArg The argument for this command
367 @param DebuggerPrivate EBC Debugger private data structure
368 @param ExceptionType Exception type.
369 @param SystemContext EBC system context.
371 @retval EFI_DEBUG_CONTINUE formal return value
375 DebuggerBreakpointClear (
376 IN CHAR16
*CommandArg
,
377 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
378 IN EFI_EXCEPTION_TYPE ExceptionType
,
379 IN OUT EFI_SYSTEM_CONTEXT SystemContext
385 if (CommandArg
== NULL
) {
386 EDBPrint (L
"BreakpointClear Argument error!\n");
387 return EFI_DEBUG_CONTINUE
;
390 if (StriCmp (CommandArg
, L
"*") == 0) {
392 // delete all breakpoint
394 DebuggerPrivate
->DebuggerBreakpointCount
= 0;
395 ZeroMem (DebuggerPrivate
->DebuggerBreakpointContext
, sizeof (DebuggerPrivate
->DebuggerBreakpointContext
));
396 EDBPrint (L
"All the Breakpoint is cleared\n");
397 return EFI_DEBUG_CONTINUE
;
401 // Get breakpoint index
403 Index
= Atoi (CommandArg
);
404 if (Index
== (UINTN
)-1) {
405 EDBPrint (L
"BreakpointClear Argument error!\n");
406 return EFI_DEBUG_CONTINUE
;
409 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
410 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
))
412 EDBPrint (L
"BreakpointClear error!\n");
413 return EFI_DEBUG_CONTINUE
;
419 Status
= DebuggerBreakpointDel (DebuggerPrivate
, Index
);
420 if (EFI_ERROR (Status
)) {
421 EDBPrint (L
"BreakpointClear error!\n");
427 return EFI_DEBUG_CONTINUE
;
432 DebuggerCommand - BreakpointDisable
434 @param CommandArg The argument for this command
435 @param DebuggerPrivate EBC Debugger private data structure
436 @param ExceptionType Exception type.
437 @param SystemContext EBC system context.
439 @retval EFI_DEBUG_CONTINUE formal return value
443 DebuggerBreakpointDisable (
444 IN CHAR16
*CommandArg
,
445 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
446 IN EFI_EXCEPTION_TYPE ExceptionType
,
447 IN OUT EFI_SYSTEM_CONTEXT SystemContext
453 if (CommandArg
== NULL
) {
454 EDBPrint (L
"BreakpointDisable Argument error!\n");
455 return EFI_DEBUG_CONTINUE
;
458 if (StriCmp (CommandArg
, L
"*") == 0) {
460 // disable all breakpoint
462 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
463 Status
= DebuggerBreakpointDis (DebuggerPrivate
, Index
);
466 EDBPrint (L
"All the Breakpoint is disabled\n");
467 return EFI_DEBUG_CONTINUE
;
471 // Get breakpoint index
473 Index
= Atoi (CommandArg
);
474 if (Index
== (UINTN
)-1) {
475 EDBPrint (L
"BreakpointDisable Argument error!\n");
476 return EFI_DEBUG_CONTINUE
;
480 // Disable breakpoint
482 Status
= DebuggerBreakpointDis (DebuggerPrivate
, Index
);
483 if (EFI_ERROR (Status
)) {
484 EDBPrint (L
"BreakpointDisable error!\n");
490 return EFI_DEBUG_CONTINUE
;
494 DebuggerCommand - BreakpointEnable.
496 @param CommandArg The argument for this command
497 @param DebuggerPrivate EBC Debugger private data structure
498 @param ExceptionType Exception type.
499 @param SystemContext EBC system context.
501 @retval EFI_DEBUG_CONTINUE formal return value
505 DebuggerBreakpointEnable (
506 IN CHAR16
*CommandArg
,
507 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
508 IN EFI_EXCEPTION_TYPE ExceptionType
,
509 IN OUT EFI_SYSTEM_CONTEXT SystemContext
515 if (CommandArg
== NULL
) {
516 EDBPrint (L
"BreakpointEnable Argument error!\n");
517 return EFI_DEBUG_CONTINUE
;
520 if (StriCmp (CommandArg
, L
"*") == 0) {
522 // enable all breakpoint
524 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
525 Status
= DebuggerBreakpointEn (DebuggerPrivate
, Index
);
528 EDBPrint (L
"All the Breakpoint is enabled\n");
529 return EFI_DEBUG_CONTINUE
;
533 // Get breakpoint index
535 Index
= Atoi (CommandArg
);
536 if (Index
== (UINTN
)-1) {
537 EDBPrint (L
"BreakpointEnable Argument error!\n");
538 return EFI_DEBUG_CONTINUE
;
544 Status
= DebuggerBreakpointEn (DebuggerPrivate
, Index
);
545 if (EFI_ERROR (Status
)) {
546 EDBPrint (L
"BreakpointEnable error!\n");
552 return EFI_DEBUG_CONTINUE
;