3 Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
4 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.
19 Check whether current IP is EBC BREAK3 instruction.
21 @param Address EBC IP address.
23 @retval TRUE Current IP is EBC BREAK3 instruction
24 @retval FALSE Current IP is not EBC BREAK3 instruction
32 if (GET_OPCODE(Address
) != OPCODE_BREAK
) {
36 if (GET_OPERANDS (Address
) != 3) {
45 Check whether the Address is already set in breakpoint.
47 @param DebuggerPrivate EBC Debugger private data structure
48 @param Address Breakpoint Address
50 @retval TRUE breakpoint is found
51 @retval FALSE breakpoint is not found
55 DebuggerBreakpointIsDuplicated (
56 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
63 // Go through each breakpoint context
65 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
66 if (DebuggerPrivate
->DebuggerBreakpointContext
[Index
].BreakpointAddress
== Address
) {
84 @param DebuggerPrivate EBC Debugger private data structure
85 @param Address Breakpoint Address
87 @retval EFI_SUCCESS breakpoint added successfully
88 @retval EFI_ALREADY_STARTED breakpoint is already added
89 @retval EFI_OUT_OF_RESOURCES all the breakpoint entries are used
93 DebuggerBreakpointAdd (
94 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
99 // Check duplicated breakpoint
101 if (DebuggerBreakpointIsDuplicated (DebuggerPrivate
, Address
)) {
102 EDBPrint (L
"Breakpoint duplicated!\n");
103 return EFI_ALREADY_STARTED
;
107 // Check whether the address is a breakpoint 3 instruction
109 if (IsEBCBREAK3 (Address
)) {
110 EDBPrint (L
"Breakpoint can not be set on BREAK 3 instruction!\n");
111 return EFI_ALREADY_STARTED
;
114 if (DebuggerPrivate
->DebuggerBreakpointCount
>= EFI_DEBUGGER_BREAKPOINT_MAX
) {
115 EDBPrint (L
"Breakpoint out of resource!\n");
116 return EFI_OUT_OF_RESOURCES
;
120 // Set the breakpoint
122 DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].BreakpointAddress
= Address
;
123 DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].State
= TRUE
;
124 DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].OldInstruction
= 0;
126 &DebuggerPrivate
->DebuggerBreakpointContext
[DebuggerPrivate
->DebuggerBreakpointCount
].OldInstruction
,
131 DebuggerPrivate
->DebuggerBreakpointCount
++;
141 Delete this breakpoint.
143 @param DebuggerPrivate EBC Debugger private data structure
144 @param Index Breakpoint Index
146 @retval EFI_SUCCESS breakpoint deleted successfully
147 @retval EFI_NOT_FOUND breakpoint not found
151 DebuggerBreakpointDel (
152 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
158 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
159 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
)) {
160 return EFI_NOT_FOUND
;
164 // Delete this breakpoint
166 for (BpIndex
= Index
; BpIndex
< DebuggerPrivate
->DebuggerBreakpointCount
- 1; BpIndex
++) {
167 DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
] = DebuggerPrivate
->DebuggerBreakpointContext
[BpIndex
+ 1];
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
)) {
201 return EFI_NOT_FOUND
;
205 // Disable this breakpoint
207 DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
= FALSE
;
214 Enable this breakpoint.
216 @param DebuggerPrivate - EBC Debugger private data structure
217 @param Index - Breakpoint Index
219 @retval EFI_SUCCESS - breakpoint enabled successfully
220 @retval EFI_NOT_FOUND - breakpoint not found
224 DebuggerBreakpointEn (
225 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
229 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
230 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
)) {
231 return EFI_NOT_FOUND
;
235 // Enable this breakpoint
237 DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
= TRUE
;
244 DebuggerCommand - BreakpointList.
246 @param CommandArg - The argument for this command
247 @param DebuggerPrivate - EBC Debugger private data structure
248 @param ExceptionType - Exception type.
249 @param SystemContext - EBC system context.
251 @retval EFI_DEBUG_CONTINUE - formal return value
255 DebuggerBreakpointList (
256 IN CHAR16
*CommandArg
,
257 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
258 IN EFI_EXCEPTION_TYPE ExceptionType
,
259 IN OUT EFI_SYSTEM_CONTEXT SystemContext
265 // Check breakpoint cound
267 if (DebuggerPrivate
->DebuggerBreakpointCount
== 0) {
268 EDBPrint (L
"No Breakpoint\n");
269 return EFI_DEBUG_CONTINUE
;
270 } else if (DebuggerPrivate
->DebuggerBreakpointCount
> EFI_DEBUGGER_BREAKPOINT_MAX
) {
271 EDBPrint (L
"Breakpoint too many!\n");
272 DebuggerPrivate
->DebuggerBreakpointCount
= 0;
273 return EFI_DEBUG_CONTINUE
;
277 // Go through each breakpoint
279 EDBPrint (L
"Breakpoint :\n");
280 EDBPrint (L
" Index Address Status\n");
281 EDBPrint (L
"======= ================== ========\n");
282 //EDBPrint (L" 1 0xFFFFFFFF00000000 *\n");
283 //EDBPrint (L" 12 0x00000000FFFFFFFF\n");
284 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
286 // Print the breakpoint
288 EDBPrint (L
" %2d 0x%016lx", Index
, DebuggerPrivate
->DebuggerBreakpointContext
[Index
].BreakpointAddress
);
289 if (DebuggerPrivate
->DebuggerBreakpointContext
[Index
].State
) {
299 return EFI_DEBUG_CONTINUE
;
304 DebuggerCommand - BreakpointSet.
306 @param CommandArg The argument for this command
307 @param DebuggerPrivate EBC Debugger private data structure
308 @param ExceptionType Exception type.
309 @param SystemContext EBC system context.
311 @retval EFI_DEBUG_CONTINUE - formal return value
315 DebuggerBreakpointSet (
316 IN CHAR16
*CommandArg
,
317 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
318 IN EFI_EXCEPTION_TYPE ExceptionType
,
319 IN OUT EFI_SYSTEM_CONTEXT SystemContext
325 if (CommandArg
== NULL
) {
326 EDBPrint (L
"BreakpointSet Argument error!\n");
327 return EFI_DEBUG_CONTINUE
;
331 // Get breakpoint address
333 Status
= Symboltoi (CommandArg
, &Address
);
334 if (EFI_ERROR (Status
)) {
335 if (Status
== EFI_NOT_FOUND
) {
336 Address
= Xtoi(CommandArg
);
339 // Something wrong, let Symboltoi print error info.
341 EDBPrint (L
"Command Argument error!\n");
342 return EFI_DEBUG_CONTINUE
;
349 Status
= DebuggerBreakpointAdd (DebuggerPrivate
, Address
);
350 if (EFI_ERROR(Status
)) {
351 EDBPrint (L
"BreakpointSet error!\n");
357 return EFI_DEBUG_CONTINUE
;
362 DebuggerCommand - BreakpointClear
364 @param CommandArg The argument for this command
365 @param DebuggerPrivate EBC Debugger private data structure
366 @param ExceptionType Exception type.
367 @param SystemContext EBC system context.
369 @retval EFI_DEBUG_CONTINUE formal return value
373 DebuggerBreakpointClear (
374 IN CHAR16
*CommandArg
,
375 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
376 IN EFI_EXCEPTION_TYPE ExceptionType
,
377 IN OUT EFI_SYSTEM_CONTEXT SystemContext
383 if (CommandArg
== NULL
) {
384 EDBPrint (L
"BreakpointClear Argument error!\n");
385 return EFI_DEBUG_CONTINUE
;
388 if (StriCmp (CommandArg
, L
"*") == 0) {
390 // delete all breakpoint
392 DebuggerPrivate
->DebuggerBreakpointCount
= 0;
393 ZeroMem (DebuggerPrivate
->DebuggerBreakpointContext
, sizeof(DebuggerPrivate
->DebuggerBreakpointContext
));
394 EDBPrint (L
"All the Breakpoint is cleared\n");
395 return EFI_DEBUG_CONTINUE
;
399 // Get breakpoint index
401 Index
= Atoi(CommandArg
);
402 if (Index
== (UINTN
) -1) {
403 EDBPrint (L
"BreakpointClear Argument error!\n");
404 return EFI_DEBUG_CONTINUE
;
407 if ((Index
>= EFI_DEBUGGER_BREAKPOINT_MAX
) ||
408 (Index
>= DebuggerPrivate
->DebuggerBreakpointCount
)) {
409 EDBPrint (L
"BreakpointClear error!\n");
410 return EFI_DEBUG_CONTINUE
;
416 Status
= DebuggerBreakpointDel (DebuggerPrivate
, Index
);
417 if (EFI_ERROR(Status
)) {
418 EDBPrint (L
"BreakpointClear error!\n");
424 return EFI_DEBUG_CONTINUE
;
429 DebuggerCommand - BreakpointDisable
431 @param CommandArg The argument for this command
432 @param DebuggerPrivate EBC Debugger private data structure
433 @param ExceptionType Exception type.
434 @param SystemContext EBC system context.
436 @retval EFI_DEBUG_CONTINUE formal return value
440 DebuggerBreakpointDisable (
441 IN CHAR16
*CommandArg
,
442 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
443 IN EFI_EXCEPTION_TYPE ExceptionType
,
444 IN OUT EFI_SYSTEM_CONTEXT SystemContext
450 if (CommandArg
== NULL
) {
451 EDBPrint (L
"BreakpointDisable Argument error!\n");
452 return EFI_DEBUG_CONTINUE
;
455 if (StriCmp (CommandArg
, L
"*") == 0) {
457 // disable all breakpoint
459 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
460 Status
= DebuggerBreakpointDis (DebuggerPrivate
, Index
);
462 EDBPrint (L
"All the Breakpoint is disabled\n");
463 return EFI_DEBUG_CONTINUE
;
467 // Get breakpoint index
469 Index
= Atoi(CommandArg
);
470 if (Index
== (UINTN
) -1) {
471 EDBPrint (L
"BreakpointDisable Argument error!\n");
472 return EFI_DEBUG_CONTINUE
;
476 // Disable breakpoint
478 Status
= DebuggerBreakpointDis (DebuggerPrivate
, Index
);
479 if (EFI_ERROR(Status
)) {
480 EDBPrint (L
"BreakpointDisable error!\n");
486 return EFI_DEBUG_CONTINUE
;
490 DebuggerCommand - BreakpointEnable.
492 @param CommandArg The argument for this command
493 @param DebuggerPrivate EBC Debugger private data structure
494 @param ExceptionType Exception type.
495 @param SystemContext EBC system context.
497 @retval EFI_DEBUG_CONTINUE formal return value
501 DebuggerBreakpointEnable (
502 IN CHAR16
*CommandArg
,
503 IN EFI_DEBUGGER_PRIVATE_DATA
*DebuggerPrivate
,
504 IN EFI_EXCEPTION_TYPE ExceptionType
,
505 IN OUT EFI_SYSTEM_CONTEXT SystemContext
511 if (CommandArg
== NULL
) {
512 EDBPrint (L
"BreakpointEnable Argument error!\n");
513 return EFI_DEBUG_CONTINUE
;
516 if (StriCmp (CommandArg
, L
"*") == 0) {
518 // enable all breakpoint
520 for (Index
= 0; Index
< DebuggerPrivate
->DebuggerBreakpointCount
; Index
++) {
521 Status
= DebuggerBreakpointEn (DebuggerPrivate
, Index
);
523 EDBPrint (L
"All the Breakpoint is enabled\n");
524 return EFI_DEBUG_CONTINUE
;
528 // Get breakpoint index
530 Index
= Atoi(CommandArg
);
531 if (Index
== (UINTN
) -1) {
532 EDBPrint (L
"BreakpointEnable Argument error!\n");
533 return EFI_DEBUG_CONTINUE
;
539 Status
= DebuggerBreakpointEn (DebuggerPrivate
, Index
);
540 if (EFI_ERROR(Status
)) {
541 EDBPrint (L
"BreakpointEnable error!\n");
547 return EFI_DEBUG_CONTINUE
;