1 /** @file
2 
3 Copyright (c) 2007, 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
8 
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.
11 
12 
13 **/
14 
15 #include "Edb.h"
16 
17 /**
18 
19   Check whether current IP is EBC CALL instruction (NOTE: CALLEX is exclusive)
20 
21   @param  Address   - EBC IP address.
22 
23   @retval TRUE  - Current IP is EBC CALL instruction
24   @retval FALSE - Current IP is not EBC CALL instruction
25 
26 **/
27 BOOLEAN
IsEBCCALL(IN UINTN Address)28 IsEBCCALL (
29   IN UINTN            Address
30   )
31 {
32   if (GET_OPCODE(Address) != OPCODE_CALL) {
33     return FALSE;
34   }
35 
36   if (GET_OPERANDS (Address) & OPERAND_M_NATIVE_CALL) {
37     return FALSE;
38   } else {
39     return TRUE;
40   }
41 }
42 
43 /**
44 
45   Check whether current IP is EBC RET instruction.
46 
47   @param  Address   - EBC IP address.
48 
49   @retval TRUE  - Current IP is EBC RET instruction
50   @retval FALSE - Current IP is not EBC RET instruction
51 
52 **/
53 BOOLEAN
IsEBCRET(IN UINTN Address)54 IsEBCRET (
55   IN UINTN            Address
56   )
57 {
58   if (GET_OPCODE(Address) != OPCODE_RET) {
59     return FALSE;
60   }
61 
62   if (GET_OPERANDS (Address) != 0) {
63     return FALSE;
64   } else {
65     return TRUE;
66   }
67 }
68 
69 /**
70 
71   DebuggerCommand - StepInto.
72 
73   @param  CommandArg      - The argument for this command
74   @param  DebuggerPrivate - EBC Debugger private data structure
75   @param  ExceptionType   - Exception type.
76   @param  SystemContext   - EBC system context.
77 
78   @retval EFI_DEBUG_CONTINUE - formal return value
79 
80 **/
81 EFI_DEBUG_STATUS
DebuggerStepInto(IN CHAR16 * CommandArg,IN EFI_DEBUGGER_PRIVATE_DATA * DebuggerPrivate,IN EFI_EXCEPTION_TYPE ExceptionType,IN OUT EFI_SYSTEM_CONTEXT SystemContext)82 DebuggerStepInto (
83   IN     CHAR16                    *CommandArg,
84   IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
85   IN     EFI_EXCEPTION_TYPE        ExceptionType,
86   IN OUT EFI_SYSTEM_CONTEXT        SystemContext
87   )
88 {
89   SystemContext.SystemContextEbc->Flags |= VMFLAGS_STEP;
90 
91   return EFI_DEBUG_BREAK;
92 }
93 
94 /**
95 
96   DebuggerCommand - StepOver.
97 
98   @param  CommandArg      - The argument for this command
99   @param  DebuggerPrivate - EBC Debugger private data structure
100   @param  ExceptionType   - Exception type.
101   @param  SystemContext   - EBC system context.
102 
103   @retval EFI_DEBUG_CONTINUE - formal return value
104 
105 **/
106 EFI_DEBUG_STATUS
DebuggerStepOver(IN CHAR16 * CommandArg,IN EFI_DEBUGGER_PRIVATE_DATA * DebuggerPrivate,IN EFI_EXCEPTION_TYPE ExceptionType,IN OUT EFI_SYSTEM_CONTEXT SystemContext)107 DebuggerStepOver (
108   IN     CHAR16                    *CommandArg,
109   IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
110   IN     EFI_EXCEPTION_TYPE        ExceptionType,
111   IN OUT EFI_SYSTEM_CONTEXT        SystemContext
112   )
113 {
114   if (IsEBCCALL((UINTN)SystemContext.SystemContextEbc->Ip)) {
115     //
116     // Check CALL (NOTE: CALLEX is exclusive)
117     //
118     DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_STEPOVER;
119   } else {
120     //
121     // Other instruction including CALLEX
122     //
123     SystemContext.SystemContextEbc->Flags |= VMFLAGS_STEP;
124   }
125 
126   return EFI_DEBUG_BREAK;
127 }
128 
129 /**
130 
131   DebuggerCommand - StepOut.
132 
133   @param  CommandArg      - The argument for this command
134   @param  DebuggerPrivate - EBC Debugger private data structure
135   @param  ExceptionType   - Exception type.
136   @param  SystemContext   - EBC system context.
137 
138   @retval EFI_DEBUG_CONTINUE - formal return value
139 
140 **/
141 EFI_DEBUG_STATUS
DebuggerStepOut(IN CHAR16 * CommandArg,IN EFI_DEBUGGER_PRIVATE_DATA * DebuggerPrivate,IN EFI_EXCEPTION_TYPE ExceptionType,IN OUT EFI_SYSTEM_CONTEXT SystemContext)142 DebuggerStepOut (
143   IN     CHAR16                    *CommandArg,
144   IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,
145   IN     EFI_EXCEPTION_TYPE        ExceptionType,
146   IN OUT EFI_SYSTEM_CONTEXT        SystemContext
147   )
148 {
149   if (IsEBCRET((UINTN)SystemContext.SystemContextEbc->Ip)) {
150     //
151     // Check RET
152     //
153     SystemContext.SystemContextEbc->Flags |= VMFLAGS_STEP;
154   } else {
155     //
156     // Other instruction
157     //
158     DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_STEPOUT;
159   }
160 
161   return EFI_DEBUG_BREAK;
162 }
163