3 Copyright (c) 2006, 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.
18 Main routines for the EBC interpreter. Includes the initialization and
19 main interpreter routines.
29 #include <Protocol/DebugSupport.h>
30 #include <Protocol/Ebc.h>
32 #include <Library/BaseLib.h>
33 #include <Library/DebugLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/MemoryAllocationLib.h>
39 typedef INT64 VM_REGISTER
;
40 typedef UINT8
*VMIP
; // instruction pointer for the VM
41 typedef UINT32 EXCEPTION_FLAGS
;
44 VM_REGISTER R
[8]; // General purpose registers.
45 UINT64 Flags
; // Flags register:
46 // 0 Set to 1 if the result of the last compare was true
47 // 1 Set to 1 if stepping
49 VMIP Ip
; // Instruction pointer.
50 UINTN LastException
; //
51 EXCEPTION_FLAGS ExceptionFlags
; // to keep track of exceptions
53 UINT32 CompilerVersion
; // via break(6)
54 UINTN HighStackBottom
; // bottom of the upper stack
55 UINTN LowStackTop
; // top of the lower stack
56 UINT64 StackRetAddr
; // location of final return address on stack
57 UINTN
*StackMagicPtr
; // pointer to magic value on stack to detect corruption
58 EFI_HANDLE ImageHandle
; // for this EBC driver
59 EFI_SYSTEM_TABLE
*SystemTable
; // for debugging only
60 UINTN LastAddrConverted
; // for debug
61 UINTN LastAddrConvertedValue
; // for debug
63 VOID
*EntryPoint
; // entry point of EBC image
69 extern VM_CONTEXT
*mVmPtr
;
72 // Bits of exception flags field of VM context
74 #define EXCEPTION_FLAG_FATAL 0x80000000 // can't continue
75 #define EXCEPTION_FLAG_ERROR 0x40000000 // bad, but try to continue
76 #define EXCEPTION_FLAG_WARNING 0x20000000 // harmless problem
77 #define EXCEPTION_FLAG_NONE 0x00000000 // for normal return
79 // Flags passed to the internal create-thunks function.
81 #define FLAG_THUNK_ENTRY_POINT 0x01 // thunk for an image entry point
82 #define FLAG_THUNK_PROTOCOL 0x00 // thunk for an EBC protocol service
84 // Put this value at the bottom of the VM's stack gap so we can check it on
85 // occasion to make sure the stack has not been corrupted.
87 #define VM_STACK_KEY_VALUE 0xDEADBEEF
91 IN EFI_HANDLE ImageHandle
,
92 IN VOID
*EbcEntryPoint
,
100 IN EFI_HANDLE ImageHandle
,
101 IN VOID
*ThunkBuffer
,
107 // The interpreter calls these when an exception is detected,
108 // or as a periodic callback.
111 EbcDebugSignalException (
112 IN EFI_EXCEPTION_TYPE ExceptionType
,
113 IN EXCEPTION_FLAGS ExceptionFlags
,
119 // Define a constant of how often to call the debugger periodic callback
122 #define EFI_TIMER_UNIT_1MS (1000 * 10)
123 #define EBC_VM_PERIODIC_CALLBACK_RATE (1000 * EFI_TIMER_UNIT_1MS)
124 #define STACK_POOL_SIZE (1024 * 1020)
125 #define MAX_STACK_NUM 4
128 EbcDebugSignalPeriodic (
134 // External low level functions that are native-processor dependent
137 EbcLLGetEbcEntryPoint (
143 EbcLLGetStackPointer (
158 IN VM_CONTEXT
*VmPtr
,
167 EbcLLGetReturnValue (
195 ReturnEBCStackByHandle(
199 // Defines for a simple EBC debugger interface
201 typedef struct _EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
;
203 #define EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL_GUID \
205 0x2a72d11e, 0x7376, 0x40f6, { 0x9c, 0x68, 0x23, 0xfa, 0x2f, 0xe3, 0x63, 0xf1 } \
210 (*EBC_DEBUGGER_SIGNAL_EXCEPTION
) (
211 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
* This
,
212 IN VM_CONTEXT
* VmPtr
,
213 IN EFI_EXCEPTION_TYPE ExceptionType
218 (*EBC_DEBUGGER_DEBUG
) (
219 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
* This
,
220 IN VM_CONTEXT
* VmPtr
225 (*EBC_DEBUGGER_DASM
) (
226 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
* This
,
227 IN VM_CONTEXT
* VmPtr
,
228 IN UINT16
*DasmString OPTIONAL
,
229 IN UINT32 DasmStringSize
233 // This interface allows you to configure the EBC debug support
234 // driver. For example, turn on or off saving and printing of
235 // delta VM even if called. Or to even disable the entire interface,
236 // in which case all functions become no-ops.
240 (*EBC_DEBUGGER_CONFIGURE
) (
241 IN EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
* This
,
247 // Prototype for the actual EBC debug support protocol interface
249 struct _EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL
{
250 EBC_DEBUGGER_DEBUG Debugger
;
251 EBC_DEBUGGER_SIGNAL_EXCEPTION SignalException
;
252 EBC_DEBUGGER_DASM Dasm
;
253 EBC_DEBUGGER_CONFIGURE Configure
;
257 EFI_EBC_PROTOCOL
*This
;
259 EFI_HANDLE ImageHandle
;
260 VM_CONTEXT VmContext
;
261 } EFI_EBC_THUNK_DATA
;
263 #define EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('e', 'b', 'c', 'p')
265 struct _EBC_PROTOCOL_PRIVATE_DATA
{
267 EFI_EBC_PROTOCOL EbcProtocol
;
273 #define EBC_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \
274 CR(a, EBC_PROTOCOL_PRIVATE_DATA, EbcProtocol, EBC_PROTOCOL_PRIVATE_DATA_SIGNATURE)
277 #endif // #ifndef _EBC_INT_H_