2 Main routines for the EBC interpreter. Includes the initialization and
3 main interpreter routines.
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <Protocol/DebugSupport.h>
23 #include <Protocol/Ebc.h>
25 #include <Library/BaseLib.h>
26 #include <Library/DebugLib.h>
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/MemoryAllocationLib.h>
32 typedef INT64 VM_REGISTER
;
33 typedef UINT8
*VMIP
; // instruction pointer for the VM
34 typedef UINT32 EXCEPTION_FLAGS
;
37 VM_REGISTER R
[8]; // General purpose registers.
38 UINT64 Flags
; // Flags register:
39 // 0 Set to 1 if the result of the last compare was true
40 // 1 Set to 1 if stepping
42 VMIP Ip
; // Instruction pointer.
43 UINTN LastException
; //
44 EXCEPTION_FLAGS ExceptionFlags
; // to keep track of exceptions
46 UINT32 CompilerVersion
; // via break(6)
47 UINTN HighStackBottom
; // bottom of the upper stack
48 UINTN LowStackTop
; // top of the lower stack
49 UINT64 StackRetAddr
; // location of final return address on stack
50 UINTN
*StackMagicPtr
; // pointer to magic value on stack to detect corruption
51 EFI_HANDLE ImageHandle
; // for this EBC driver
52 EFI_SYSTEM_TABLE
*SystemTable
; // for debugging only
53 UINTN LastAddrConverted
; // for debug
54 UINTN LastAddrConvertedValue
; // for debug
56 VOID
*EntryPoint
; // entry point of EBC image
62 extern VM_CONTEXT
*mVmPtr
;
65 // Bits of exception flags field of VM context
67 #define EXCEPTION_FLAG_FATAL 0x80000000 // can't continue
68 #define EXCEPTION_FLAG_ERROR 0x40000000 // bad, but try to continue
69 #define EXCEPTION_FLAG_WARNING 0x20000000 // harmless problem
70 #define EXCEPTION_FLAG_NONE 0x00000000 // for normal return
72 // Flags passed to the internal create-thunks function.
74 #define FLAG_THUNK_ENTRY_POINT 0x01 // thunk for an image entry point
75 #define FLAG_THUNK_PROTOCOL 0x00 // thunk for an EBC protocol service
77 // Put this value at the bottom of the VM's stack gap so we can check it on
78 // occasion to make sure the stack has not been corrupted.
80 #define VM_STACK_KEY_VALUE 0xDEADBEEF
84 IN EFI_HANDLE ImageHandle
,
85 IN VOID
*EbcEntryPoint
,
93 IN EFI_HANDLE ImageHandle
,
100 // The interpreter calls these when an exception is detected,
101 // or as a periodic callback.
104 EbcDebugSignalException (
105 IN EFI_EXCEPTION_TYPE ExceptionType
,
106 IN EXCEPTION_FLAGS ExceptionFlags
,
112 // Define a constant of how often to call the debugger periodic callback
115 #define EFI_TIMER_UNIT_1MS (1000 * 10)
116 #define EBC_VM_PERIODIC_CALLBACK_RATE (1000 * EFI_TIMER_UNIT_1MS)
117 #define STACK_POOL_SIZE (1024 * 1020)
118 #define MAX_STACK_NUM 4
121 EbcDebugSignalPeriodic (
127 // External low level functions that are native-processor dependent
130 EbcLLGetEbcEntryPoint (
136 EbcLLGetStackPointer (
151 IN VM_CONTEXT
*VmPtr
,
160 EbcLLGetReturnValue (
188 ReturnEBCStackByHandle(
192 // Defines for a simple EBC debugger interface
194 typedef struct _EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
;
196 #define EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL_GUID \
198 0x2a72d11e, 0x7376, 0x40f6, { 0x9c, 0x68, 0x23, 0xfa, 0x2f, 0xe3, 0x63, 0xf1 } \
203 (*EBC_DEBUGGER_SIGNAL_EXCEPTION
) (
204 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
* This
,
205 IN VM_CONTEXT
* VmPtr
,
206 IN EFI_EXCEPTION_TYPE ExceptionType
211 (*EBC_DEBUGGER_DEBUG
) (
212 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
* This
,
213 IN VM_CONTEXT
* VmPtr
218 (*EBC_DEBUGGER_DASM
) (
219 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
* This
,
220 IN VM_CONTEXT
* VmPtr
,
221 IN UINT16
*DasmString OPTIONAL
,
222 IN UINT32 DasmStringSize
226 // This interface allows you to configure the EBC debug support
227 // driver. For example, turn on or off saving and printing of
228 // delta VM even if called. Or to even disable the entire interface,
229 // in which case all functions become no-ops.
233 (*EBC_DEBUGGER_CONFIGURE
) (
234 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
* This
,
240 // Prototype for the actual EBC debug support protocol interface
242 struct _EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
{
243 EBC_DEBUGGER_DEBUG Debugger
;
244 EBC_DEBUGGER_SIGNAL_EXCEPTION SignalException
;
245 EBC_DEBUGGER_DASM Dasm
;
246 EBC_DEBUGGER_CONFIGURE Configure
;
250 EFI_EBC_PROTOCOL
*This
;
252 EFI_HANDLE ImageHandle
;
253 VM_CONTEXT VmContext
;
254 } EFI_EBC_THUNK_DATA
;
256 #define EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('e', 'b', 'c', 'p')
258 struct _EBC_PROTOCOL_PRIVATE_DATA
{
260 EFI_EBC_PROTOCOL EbcProtocol
;
266 #define EBC_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \
267 CR(a, EBC_PROTOCOL_PRIVATE_DATA, EbcProtocol, EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE)
270 #endif // #ifndef _EBC_INT_H_