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
)) {
154 return EFI_NOT_FOUND
;
158 // Delete this breakpoint
160 for (BpIndex
= Index
; BpIndex
< DebuggerPrivate
->DebuggerBreakpointCount
- 1; BpIndex
++) {
161 DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
] = DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
+ 1];
164 &DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
],
165 sizeof(DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
])
168 DebuggerPrivate
->DebuggerBreakpointCount
--;
178 Disable this breakpoint.
180 @param DebuggerPrivate EBC Debugger private data structure
181 @param Index Breakpoint Index
183 @retval EFI_SUCCESS breakpoint disabled successfully
184 @retval EFI_NOT_FOUND breakpoint not found
188 DebuggerBreakpointDis (
189 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
193 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
194 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
)) {
195 return EFI_NOT_FOUND
;
199 // Disable this breakpoint
201 DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
= FALSE
;
208 Enable this breakpoint.
210 @param DebuggerPrivate - EBC Debugger private data structure
211 @param Index - Breakpoint Index
213 @retval EFI_SUCCESS - breakpoint enabled successfully
214 @retval EFI_NOT_FOUND - breakpoint not found
218 DebuggerBreakpointEn (
219 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
223 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
224 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
)) {
225 return EFI_NOT_FOUND
;
229 // Enable this breakpoint
231 DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
= TRUE
;
238 DebuggerCommand - BreakpointList.
240 @param CommandArg - The argument for this command
241 @param DebuggerPrivate - EBC Debugger private data structure
242 @param ExceptionType - Exception type.
243 @param SystemContext - EBC system context.
245 @retval EFI_DEBUG_CONTINUE - formal return value
249 DebuggerBreakpointList (
250 IN CHAR16
*CommandArg
,
251 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
252 IN EFI_EXCEPTION_TYPE ExceptionType
,
253 IN OUT EFI_SYSTEM_CONTEXT SystemContext
259 // Check breakpoint cound
261 if (DebuggerPrivate
->DebuggerBreakpointCount
== 0) {
262 EDBPrint (L
"No Breakpoint\n");
263 return EFI_DEBUG_CONTINUE
;
264 } else if (DebuggerPrivate
->DebuggerBreakpointCount
> EFI_DEBUGGER_BREAKPOINT_MAX
) {
265 EDBPrint (L
"Breakpoint too many!\n");
266 DebuggerPrivate
->DebuggerBreakpointCount
= 0;
267 return EFI_DEBUG_CONTINUE
;
271 // Go through each breakpoint
273 EDBPrint (L
"Breakpoint :\n");
274 EDBPrint (L
" Index Address Status\n");
275 EDBPrint (L
"======= ================== ========\n");
276 //EDBPrint (L" 1 0xFFFFFFFF00000000 *\n");
277 //EDBPrint (L" 12 0x00000000FFFFFFFF\n");
278 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
280 // Print the breakpoint
282 EDBPrint (L
" %2d 0x%016lx", Index
, DebuggerPrivate
->DebuggerBreakpointContext
[Index
].BreakpointAddress
);
283 if (DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
) {
293 return EFI_DEBUG_CONTINUE
;
298 DebuggerCommand - BreakpointSet.
300 @param CommandArg The argument for this command
301 @param DebuggerPrivate EBC Debugger private data structure
302 @param ExceptionType Exception type.
303 @param SystemContext EBC system context.
305 @retval EFI_DEBUG_CONTINUE - formal return value
309 DebuggerBreakpointSet (
310 IN CHAR16
*CommandArg
,
311 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
312 IN EFI_EXCEPTION_TYPE ExceptionType
,
313 IN OUT EFI_SYSTEM_CONTEXT SystemContext
319 if (CommandArg
== NULL
) {
320 EDBPrint (L
"BreakpointSet Argument error!\n");
321 return EFI_DEBUG_CONTINUE
;
325 // Get breakpoint address
327 Status
= Symboltoi (CommandArg
, &Address
);
328 if (EFI_ERROR (Status
)) {
329 if (Status
== EFI_NOT_FOUND
) {
330 Address
= Xtoi(CommandArg
);
333 // Something wrong, let Symboltoi print error info.
335 EDBPrint (L
"Command Argument error!\n");
336 return EFI_DEBUG_CONTINUE
;
343 Status
= DebuggerBreakpointAdd (DebuggerPrivate
, Address
);
344 if (EFI_ERROR(Status
)) {
345 EDBPrint (L
"BreakpointSet error!\n");
351 return EFI_DEBUG_CONTINUE
;
356 DebuggerCommand - BreakpointClear
358 @param CommandArg The argument for this command
359 @param DebuggerPrivate EBC Debugger private data structure
360 @param ExceptionType Exception type.
361 @param SystemContext EBC system context.
363 @retval EFI_DEBUG_CONTINUE formal return value
367 DebuggerBreakpointClear (
368 IN CHAR16
*CommandArg
,
369 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
370 IN EFI_EXCEPTION_TYPE ExceptionType
,
371 IN OUT EFI_SYSTEM_CONTEXT SystemContext
377 if (CommandArg
== NULL
) {
378 EDBPrint (L
"BreakpointClear Argument error!\n");
379 return EFI_DEBUG_CONTINUE
;
382 if (StriCmp (CommandArg
, L
"*") == 0) {
384 // delete all breakpoint
386 DebuggerPrivate
->DebuggerBreakpointCount
= 0;
387 ZeroMem (DebuggerPrivate
->DebuggerBreakpointContext
, sizeof(DebuggerPrivate
->DebuggerBreakpointContext
));
388 EDBPrint (L
"All the Breakpoint is cleared\n");
389 return EFI_DEBUG_CONTINUE
;
393 // Get breakpoint index
395 Index
= Atoi(CommandArg
);
396 if (Index
== (UINTN
) -1) {
397 EDBPrint (L
"BreakpointClear Argument error!\n");
398 return EFI_DEBUG_CONTINUE
;
401 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
402 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
)) {
403 EDBPrint (L
"BreakpointClear error!\n");
404 return EFI_DEBUG_CONTINUE
;
410 Status
= DebuggerBreakpointDel (DebuggerPrivate
, Index
);
411 if (EFI_ERROR(Status
)) {
412 EDBPrint (L
"BreakpointClear error!\n");
418 return EFI_DEBUG_CONTINUE
;
423 DebuggerCommand - BreakpointDisable
425 @param CommandArg The argument for this command
426 @param DebuggerPrivate EBC Debugger private data structure
427 @param ExceptionType Exception type.
428 @param SystemContext EBC system context.
430 @retval EFI_DEBUG_CONTINUE formal return value
434 DebuggerBreakpointDisable (
435 IN CHAR16
*CommandArg
,
436 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
437 IN EFI_EXCEPTION_TYPE ExceptionType
,
438 IN OUT EFI_SYSTEM_CONTEXT SystemContext
444 if (CommandArg
== NULL
) {
445 EDBPrint (L
"BreakpointDisable Argument error!\n");
446 return EFI_DEBUG_CONTINUE
;
449 if (StriCmp (CommandArg
, L
"*") == 0) {
451 // disable all breakpoint
453 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
454 Status
= DebuggerBreakpointDis (DebuggerPrivate
, Index
);
456 EDBPrint (L
"All the Breakpoint is disabled\n");
457 return EFI_DEBUG_CONTINUE
;
461 // Get breakpoint index
463 Index
= Atoi(CommandArg
);
464 if (Index
== (UINTN
) -1) {
465 EDBPrint (L
"BreakpointDisable Argument error!\n");
466 return EFI_DEBUG_CONTINUE
;
470 // Disable breakpoint
472 Status
= DebuggerBreakpointDis (DebuggerPrivate
, Index
);
473 if (EFI_ERROR(Status
)) {
474 EDBPrint (L
"BreakpointDisable error!\n");
480 return EFI_DEBUG_CONTINUE
;
484 DebuggerCommand - BreakpointEnable.
486 @param CommandArg The argument for this command
487 @param DebuggerPrivate EBC Debugger private data structure
488 @param ExceptionType Exception type.
489 @param SystemContext EBC system context.
491 @retval EFI_DEBUG_CONTINUE formal return value
495 DebuggerBreakpointEnable (
496 IN CHAR16
*CommandArg
,
497 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
498 IN EFI_EXCEPTION_TYPE ExceptionType
,
499 IN OUT EFI_SYSTEM_CONTEXT SystemContext
505 if (CommandArg
== NULL
) {
506 EDBPrint (L
"BreakpointEnable Argument error!\n");
507 return EFI_DEBUG_CONTINUE
;
510 if (StriCmp (CommandArg
, L
"*") == 0) {
512 // enable all breakpoint
514 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
515 Status
= DebuggerBreakpointEn (DebuggerPrivate
, Index
);
517 EDBPrint (L
"All the Breakpoint is enabled\n");
518 return EFI_DEBUG_CONTINUE
;
522 // Get breakpoint index
524 Index
= Atoi(CommandArg
);
525 if (Index
== (UINTN
) -1) {
526 EDBPrint (L
"BreakpointEnable Argument error!\n");
527 return EFI_DEBUG_CONTINUE
;
533 Status
= DebuggerBreakpointEn (DebuggerPrivate
, Index
);
534 if (EFI_ERROR(Status
)) {
535 EDBPrint (L
"BreakpointEnable error!\n");
541 return EFI_DEBUG_CONTINUE
;