3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
31 Check whether current IP is EBC BREAK3 instruction
35 Address - EBC IP address.
39 TRUE - Current IP is EBC BREAK3 instruction
40 FALSE - Current IP is not EBC BREAK3 instruction
44 if (GET_OPCODE(Address
) != OPCODE_BREAK
) {
48 if (GET_OPERANDS (Address
) != 3) {
56 DebuggerBreakpointIsDuplicated (
57 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
64 Check whether the Address is already set in breakpoint
68 DebuggerPrivate - EBC Debugger private data structure
69 Address - Breakpoint Address
73 TRUE - breakpoint is found
74 FALSE - breakpoint is not found
81 // Go through each breakpoint context
83 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
84 if (DebuggerPrivate
->DebuggerBreakpointContext
[Index
].BreakpointAddress
== Address
) {
99 DebuggerBreakpointAdd (
100 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
111 DebuggerPrivate - EBC Debugger private data structure
112 Address - Breakpoint Address
116 EFI_SUCCESS - breakpoint added successfully
117 EFI_ALREADY_STARTED - breakpoint is already added
118 EFI_OUT_OF_RESOURCES - all the breakpoint entries are used
123 // Check duplicated breakpoint
125 if (DebuggerBreakpointIsDuplicated (DebuggerPrivate
, Address
)) {
126 EDBPrint (L
"Breakpoint duplicated!\n");
127 return EFI_ALREADY_STARTED
;
131 // Check whether the address is a breakpoint 3 instruction
133 if (IsEBCBREAK3 (Address
)) {
134 EDBPrint (L
"Breakpoint can not be set on BREAK 3 instruction!\n");
135 return EFI_ALREADY_STARTED
;
138 if (DebuggerPrivate
->DebuggerBreakpointCount
>= EFI_DEBUGGER_BREAKPOINT_MAX
) {
139 EDBPrint (L
"Breakpoint out of resource!\n");
140 return EFI_OUT_OF_RESOURCES
;
144 // Set the breakpoint
146 DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].BreakpointAddress
= Address
;
147 DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].State
= TRUE
;
148 DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].OldInstruction
= 0;
150 &DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].OldInstruction
,
155 DebuggerPrivate
->DebuggerBreakpointCount
++;
164 DebuggerBreakpointDel (
165 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
172 Delete this breakpoint
176 DebuggerPrivate - EBC Debugger private data structure
177 Index - Breakpoint Index
181 EFI_SUCCESS - breakpoint deleted successfully
182 EFI_NOT_FOUND - breakpoint not found
188 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
189 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
)) {
190 return EFI_NOT_FOUND
;
194 // Delete this breakpoint
196 for (BpIndex
= Index
; BpIndex
< DebuggerPrivate
->DebuggerBreakpointCount
- 1; BpIndex
++) {
197 DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
] = DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
+ 1];
200 &DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
],
201 sizeof(DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
])
204 DebuggerPrivate
->DebuggerBreakpointCount
--;
213 DebuggerBreakpointDis (
214 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
221 Disable this breakpoint
225 DebuggerPrivate - EBC Debugger private data structure
226 Index - Breakpoint Index
230 EFI_SUCCESS - breakpoint disabled successfully
231 EFI_NOT_FOUND - breakpoint not found
235 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
236 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
)) {
237 return EFI_NOT_FOUND
;
241 // Disable this breakpoint
243 DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
= FALSE
;
249 DebuggerBreakpointEn (
250 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
257 Enable this breakpoint
261 DebuggerPrivate - EBC Debugger private data structure
262 Index - Breakpoint Index
266 EFI_SUCCESS - breakpoint enabled successfully
267 EFI_NOT_FOUND - breakpoint not found
271 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
272 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
)) {
273 return EFI_NOT_FOUND
;
277 // Enable this breakpoint
279 DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
= TRUE
;
285 DebuggerBreakpointList (
286 IN CHAR16
*CommandArg
,
287 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
288 IN EFI_EXCEPTION_TYPE ExceptionType
,
289 IN OUT EFI_SYSTEM_CONTEXT SystemContext
295 DebuggerCommand - BreakpointList
299 CommandArg - The argument for this command
300 DebuggerPrivate - EBC Debugger private data structure
301 InterruptType - Interrupt type.
302 SystemContext - EBC system context.
306 EFI_DEBUG_CONTINUE - formal return value
313 // Check breakpoint cound
315 if (DebuggerPrivate
->DebuggerBreakpointCount
== 0) {
316 EDBPrint (L
"No Breakpoint\n");
317 return EFI_DEBUG_CONTINUE
;
318 } else if (DebuggerPrivate
->DebuggerBreakpointCount
> EFI_DEBUGGER_BREAKPOINT_MAX
) {
319 EDBPrint (L
"Breakpoint too many!\n");
320 DebuggerPrivate
->DebuggerBreakpointCount
= 0;
321 return EFI_DEBUG_CONTINUE
;
325 // Go through each breakpoint
327 EDBPrint (L
"Breakpoint :\n");
328 EDBPrint (L
" Index Address Status\n");
329 EDBPrint (L
"======= ================== ========\n");
330 //EDBPrint (L" 1 0xFFFFFFFF00000000 *\n");
331 //EDBPrint (L" 12 0x00000000FFFFFFFF\n");
332 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
334 // Print the breakpoint
336 EDBPrint (L
" %2d 0x%016lx", Index
, DebuggerPrivate
->DebuggerBreakpointContext
[Index
].BreakpointAddress
);
337 if (DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
) {
347 return EFI_DEBUG_CONTINUE
;
351 DebuggerBreakpointSet (
352 IN CHAR16
*CommandArg
,
353 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
354 IN EFI_EXCEPTION_TYPE ExceptionType
,
355 IN OUT EFI_SYSTEM_CONTEXT SystemContext
361 DebuggerCommand - BreakpointSet
365 CommandArg - The argument for this command
366 DebuggerPrivate - EBC Debugger private data structure
367 InterruptType - Interrupt type.
368 SystemContext - EBC system context.
372 EFI_DEBUG_CONTINUE - formal return value
379 if (CommandArg
== NULL
) {
380 EDBPrint (L
"BreakpointSet Argument error!\n");
381 return EFI_DEBUG_CONTINUE
;
385 // Get breakpoint address
387 Status
= Symboltoi (CommandArg
, &Address
);
388 if (EFI_ERROR (Status
)) {
389 if (Status
== EFI_NOT_FOUND
) {
390 Address
= Xtoi(CommandArg
);
393 // Something wrong, let Symboltoi print error info.
395 EDBPrint (L
"Command Argument error!\n");
396 return EFI_DEBUG_CONTINUE
;
403 Status
= DebuggerBreakpointAdd (DebuggerPrivate
, Address
);
404 if (EFI_ERROR(Status
)) {
405 EDBPrint (L
"BreakpointSet error!\n");
411 return EFI_DEBUG_CONTINUE
;
415 DebuggerBreakpointClear (
416 IN CHAR16
*CommandArg
,
417 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
418 IN EFI_EXCEPTION_TYPE ExceptionType
,
419 IN OUT EFI_SYSTEM_CONTEXT SystemContext
425 DebuggerCommand - BreakpointClear
429 CommandArg - The argument for this command
430 DebuggerPrivate - EBC Debugger private data structure
431 InterruptType - Interrupt type.
432 SystemContext - EBC system context.
436 EFI_DEBUG_CONTINUE - formal return value
443 UINT16 OldInstruction
;
445 if (CommandArg
== NULL
) {
446 EDBPrint (L
"BreakpointClear Argument error!\n");
447 return EFI_DEBUG_CONTINUE
;
450 if (StriCmp (CommandArg
, L
"*") == 0) {
452 // delete all breakpoint
454 DebuggerPrivate
->DebuggerBreakpointCount
= 0;
455 ZeroMem (DebuggerPrivate
->DebuggerBreakpointContext
, sizeof(DebuggerPrivate
->DebuggerBreakpointContext
));
456 EDBPrint (L
"All the Breakpoint is cleared\n");
457 return EFI_DEBUG_CONTINUE
;
461 // Get breakpoint index
463 Index
= Atoi(CommandArg
);
465 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
466 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
)) {
467 EDBPrint (L
"BreakpointClear error!\n");
468 return EFI_DEBUG_CONTINUE
;
470 Address
= (UINTN
)DebuggerPrivate
->DebuggerBreakpointContext
[Index
].BreakpointAddress
;
471 OldInstruction
= (UINT16
)DebuggerPrivate
->DebuggerBreakpointContext
[Index
].OldInstruction
;
477 Status
= DebuggerBreakpointDel (DebuggerPrivate
, Index
);
478 if (EFI_ERROR(Status
)) {
479 EDBPrint (L
"BreakpointClear error!\n");
485 return EFI_DEBUG_CONTINUE
;
489 DebuggerBreakpointDisable (
490 IN CHAR16
*CommandArg
,
491 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
492 IN EFI_EXCEPTION_TYPE ExceptionType
,
493 IN OUT EFI_SYSTEM_CONTEXT SystemContext
499 DebuggerCommand - BreakpointDisable
503 CommandArg - The argument for this command
504 DebuggerPrivate - EBC Debugger private data structure
505 InterruptType - Interrupt type.
506 SystemContext - EBC system context.
510 EFI_DEBUG_CONTINUE - formal return value
517 if (CommandArg
== NULL
) {
518 EDBPrint (L
"BreakpointDisable Argument error!\n");
519 return EFI_DEBUG_CONTINUE
;
522 if (StriCmp (CommandArg
, L
"*") == 0) {
524 // disable all breakpoint
526 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
527 Status
= DebuggerBreakpointDis (DebuggerPrivate
, Index
);
529 EDBPrint (L
"All the Breakpoint is disabled\n");
530 return EFI_DEBUG_CONTINUE
;
534 // Get breakpoint index
536 Index
= Atoi(CommandArg
);
539 // Disable breakpoint
541 Status
= DebuggerBreakpointDis (DebuggerPrivate
, Index
);
542 if (EFI_ERROR(Status
)) {
543 EDBPrint (L
"BreakpointDisable error!\n");
549 return EFI_DEBUG_CONTINUE
;
553 DebuggerBreakpointEnable (
554 IN CHAR16
*CommandArg
,
555 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
556 IN EFI_EXCEPTION_TYPE ExceptionType
,
557 IN OUT EFI_SYSTEM_CONTEXT SystemContext
563 DebuggerCommand - BreakpointEnable
567 CommandArg - The argument for this command
568 DebuggerPrivate - EBC Debugger private data structure
569 InterruptType - Interrupt type.
570 SystemContext - EBC system context.
574 EFI_DEBUG_CONTINUE - formal return value
581 if (CommandArg
== NULL
) {
582 EDBPrint (L
"BreakpointEnable Argument error!\n");
583 return EFI_DEBUG_CONTINUE
;
586 if (StriCmp (CommandArg
, L
"*") == 0) {
588 // enable all breakpoint
590 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
591 Status
= DebuggerBreakpointEn (DebuggerPrivate
, Index
);
593 EDBPrint (L
"All the Breakpoint is enabled\n");
594 return EFI_DEBUG_CONTINUE
;
598 // Get breakpoint index
600 Index
= Atoi(CommandArg
);
605 Status
= DebuggerBreakpointEn (DebuggerPrivate
, Index
);
606 if (EFI_ERROR(Status
)) {
607 EDBPrint (L
"BreakpointEnable error!\n");
613 return EFI_DEBUG_CONTINUE
;