79 IN VOID *EbcEntryPoint,
98 IN OUT UINT64 *Version
337VOID *mStackBuffer[MAX_STACK_NUM];
368 if ((ImageType != EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) &&
369 (ImageType != EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER))
412 ZeroMem (&ImageContext,
sizeof (ImageContext));
418 if (EFI_ERROR (Status)) {
424 ImageContext.
ImageType == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION ||
425 ImageContext.
ImageType == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
436 (VOID *)(
UINTN)ImageBase,
437 (VOID *)(
UINTN)*EntryPoint,
467 EDKII_PECOFF_IMAGE_EMULATOR_VERSION,
498 EbcDebugProtocol =
NULL;
505 if (EbcProtocol ==
NULL) {
506 return EFI_OUT_OF_RESOURCES;
513 mEbcICacheFlush =
NULL;
520 Status =
gBS->LocateHandleBuffer (
522 &gEfiEbcProtocolGuid,
531 for (Index = 0; Index < NumHandles; Index++) {
532 Status =
gBS->HandleProtocol (
534 &gEfiEbcProtocolGuid,
535 (VOID **)&OldEbcProtocol
538 if (
gBS->ReinstallProtocolInterface (
540 &gEfiEbcProtocolGuid,
551 if (HandleBuffer !=
NULL) {
560 Status =
gBS->InstallMultipleProtocolInterfaces (
562 &gEfiEbcProtocolGuid,
564 &gEdkiiPeCoffImageEmulatorProtocolGuid,
568 if (EFI_ERROR (Status)) {
575 if (EFI_ERROR (Status)) {
584 if (EbcDebugProtocol ==
NULL) {
597 Status =
gBS->InstallProtocolInterface (
599 &gEfiDebugSupportProtocolGuid,
606 if (EFI_ERROR (Status)) {
631 Status =
gBS->LocateHandleBuffer (
633 &gEfiEbcProtocolGuid,
642 for (Index = 0; Index < NumHandles; Index++) {
643 Status =
gBS->HandleProtocol (
645 &gEfiEbcProtocolGuid,
646 (VOID **)&OldEbcProtocol
649 gBS->UninstallProtocolInterface (
651 &gEfiEbcProtocolGuid,
658 if (HandleBuffer !=
NULL) {
692 IN VOID *EbcEntryPoint,
702 FLAG_THUNK_ENTRY_POINT
725 *MaxProcessorIndex = 0;
758 if ((mDebugPeriodicCallback ==
NULL) && (PeriodicCallback ==
NULL)) {
759 return EFI_INVALID_PARAMETER;
762 if ((mDebugPeriodicCallback !=
NULL) && (PeriodicCallback !=
NULL)) {
763 return EFI_ALREADY_STARTED;
766 mDebugPeriodicCallback = PeriodicCallback;
805 return EFI_INVALID_PARAMETER;
808 if ((mDebugExceptionCallback[ExceptionType] ==
NULL) && (ExceptionCallback ==
NULL)) {
809 return EFI_INVALID_PARAMETER;
812 if ((mDebugExceptionCallback[ExceptionType] !=
NULL) && (ExceptionCallback !=
NULL)) {
813 return EFI_ALREADY_STARTED;
816 mDebugExceptionCallback[ExceptionType] = ExceptionCallback;
862 IN EXCEPTION_FLAGS ExceptionFlags,
873 VmPtr->ExceptionFlags |= ExceptionFlags;
874 VmPtr->LastException = (
UINTN)ExceptionType;
879 if ((ExceptionFlags & EXCEPTION_FLAG_FATAL) != 0) {
880 VmPtr->StopFlags |= STOPFLAG_APP_DONE;
889 if (mDebugExceptionCallback[ExceptionType] !=
NULL) {
893 EbcContext.R0 = (UINT64)VmPtr->Gpr[0];
894 EbcContext.R1 = (UINT64)VmPtr->Gpr[1];
895 EbcContext.R2 = (UINT64)VmPtr->Gpr[2];
896 EbcContext.R3 = (UINT64)VmPtr->Gpr[3];
897 EbcContext.R4 = (UINT64)VmPtr->Gpr[4];
898 EbcContext.R5 = (UINT64)VmPtr->Gpr[5];
899 EbcContext.R6 = (UINT64)VmPtr->Gpr[6];
900 EbcContext.R7 = (UINT64)VmPtr->Gpr[7];
901 EbcContext.Ip = (UINT64)(
UINTN)VmPtr->Ip;
902 EbcContext.Flags = VmPtr->Flags;
903 EbcContext.ControlFlags = 0;
904 SystemContext.SystemContextEbc = &EbcContext;
906 mDebugExceptionCallback[ExceptionType](ExceptionType, SystemContext);
910 VmPtr->Gpr[0] = EbcContext.R0;
911 VmPtr->Gpr[1] = EbcContext.R1;
912 VmPtr->Gpr[2] = EbcContext.R2;
913 VmPtr->Gpr[3] = EbcContext.R3;
914 VmPtr->Gpr[4] = EbcContext.R4;
915 VmPtr->Gpr[5] = EbcContext.R5;
916 VmPtr->Gpr[6] = EbcContext.R6;
917 VmPtr->Gpr[7] = EbcContext.R7;
919 VmPtr->Flags = EbcContext.Flags;
959 Status =
gBS->CreateEvent (
960 EVT_TIMER | EVT_NOTIFY_SIGNAL,
966 if (EFI_ERROR (Status)) {
970 Status =
gBS->SetTimer (
973 EBC_VM_PERIODIC_CALLBACK_RATE
975 if (EFI_ERROR (Status)) {
1003 "EBC Interrupter Version - 0x%016lx\n",
1004 (UINT64)(((VM_MAJOR_VERSION & 0xFFFF) << 16) | ((VM_MINOR_VERSION & 0xFFFF)))
1008 "Exception Type - 0x%016lx\n",
1009 (UINT64)(
UINTN)InterruptType
1013 " R0 - 0x%016lx, R1 - 0x%016lx\n",
1014 SystemContext.SystemContextEbc->R0,
1015 SystemContext.SystemContextEbc->R1
1019 " R2 - 0x%016lx, R3 - 0x%016lx\n",
1020 SystemContext.SystemContextEbc->R2,
1021 SystemContext.SystemContextEbc->R3
1025 " R4 - 0x%016lx, R5 - 0x%016lx\n",
1026 SystemContext.SystemContextEbc->R4,
1027 SystemContext.SystemContextEbc->R5
1031 " R6 - 0x%016lx, R7 - 0x%016lx\n",
1032 SystemContext.SystemContextEbc->R6,
1033 SystemContext.SystemContextEbc->R7
1037 " Flags - 0x%016lx\n",
1038 SystemContext.SystemContextEbc->Flags
1042 " ControlFlags - 0x%016lx\n",
1043 SystemContext.SystemContextEbc->ControlFlags
1047 " Ip - 0x%016lx\n\n",
1048 SystemContext.SystemContextEbc->Ip
1078 if (VmPtr !=
NULL) {
1107 if (mDebugPeriodicCallback !=
NULL) {
1111 EbcContext.R0 = (UINT64)VmPtr->Gpr[0];
1112 EbcContext.R1 = (UINT64)VmPtr->Gpr[1];
1113 EbcContext.R2 = (UINT64)VmPtr->Gpr[2];
1114 EbcContext.R3 = (UINT64)VmPtr->Gpr[3];
1115 EbcContext.R4 = (UINT64)VmPtr->Gpr[4];
1116 EbcContext.R5 = (UINT64)VmPtr->Gpr[5];
1117 EbcContext.R6 = (UINT64)VmPtr->Gpr[6];
1118 EbcContext.R7 = (UINT64)VmPtr->Gpr[7];
1119 EbcContext.Ip = (UINT64)(
UINTN)VmPtr->Ip;
1120 EbcContext.Flags = VmPtr->Flags;
1121 EbcContext.ControlFlags = 0;
1122 SystemContext.SystemContextEbc = &EbcContext;
1124 mDebugPeriodicCallback (SystemContext);
1129 VmPtr->Gpr[0] = EbcContext.R0;
1130 VmPtr->Gpr[1] = EbcContext.R1;
1131 VmPtr->Gpr[2] = EbcContext.R2;
1132 VmPtr->Gpr[3] = EbcContext.R3;
1133 VmPtr->Gpr[4] = EbcContext.R4;
1134 VmPtr->Gpr[5] = EbcContext.R5;
1135 VmPtr->Gpr[6] = EbcContext.R6;
1136 VmPtr->Gpr[7] = EbcContext.R7;
1138 VmPtr->Flags = EbcContext.Flags;
1175 PrevImageList =
NULL;
1176 for (ImageList = mEbcImageList; ImageList !=
NULL; ImageList = ImageList->Next) {
1177 if (ImageList->ImageHandle == ImageHandle) {
1184 PrevImageList = ImageList;
1187 if (ImageList ==
NULL) {
1188 return EFI_INVALID_PARAMETER;
1195 ThunkList = ImageList->ThunkList;
1196 while (ThunkList !=
NULL) {
1197 NextThunkList = ThunkList->Next;
1200 ThunkList = NextThunkList;
1206 if (PrevImageList ==
NULL) {
1210 mEbcImageList = ImageList->Next;
1212 PrevImageList->Next = ImageList->Next;
1241 IN VOID *ThunkBuffer,
1252 if (mEbcICacheFlush !=
NULL) {
1254 if (EFI_ERROR (Status)) {
1263 for (ImageList = mEbcImageList; ImageList !=
NULL; ImageList = ImageList->Next) {
1264 if (ImageList->ImageHandle == ImageHandle) {
1269 if (ImageList ==
NULL) {
1275 if (ImageList ==
NULL) {
1276 return EFI_OUT_OF_RESOURCES;
1279 ImageList->ThunkList =
NULL;
1280 ImageList->ImageHandle = ImageHandle;
1281 ImageList->Next = mEbcImageList;
1282 mEbcImageList = ImageList;
1290 if (ThunkList ==
NULL) {
1291 return EFI_OUT_OF_RESOURCES;
1297 ThunkList->Next = ImageList->ThunkList;
1298 ThunkList->ThunkBuffer = ThunkBuffer;
1299 ImageList->ThunkList = ThunkList;
1320 mEbcICacheFlush = Flush;
1339 IN OUT UINT64 *Version
1342 if (Version ==
NULL) {
1343 return EFI_INVALID_PARAMETER;
1366 OUT VOID **StackBuffer,
1373 OldTpl =
gBS->RaiseTPL (TPL_HIGH_LEVEL);
1374 for (Index = 0; Index < mStackNum; Index++) {
1375 if (mStackBufferIndex[Index] ==
NULL) {
1376 mStackBufferIndex[Index] = Handle;
1381 gBS->RestoreTPL (OldTpl);
1382 if (Index == mStackNum) {
1383 return EFI_OUT_OF_RESOURCES;
1386 *BufferIndex = Index;
1387 *StackBuffer = mStackBuffer[Index];
1404 mStackBufferIndex[Index] =
NULL;
1423 for (Index = 0; Index < mStackNum; Index++) {
1424 if (mStackBufferIndex[Index] == Handle) {
1429 if (Index == mStackNum) {
1430 return EFI_NOT_FOUND;
1433 mStackBufferIndex[Index] =
NULL;
1449 for (mStackNum = 0; mStackNum < MAX_STACK_NUM; mStackNum++) {
1450 mStackBuffer[mStackNum] =
AllocatePool (STACK_POOL_SIZE);
1451 mStackBufferIndex[mStackNum] =
NULL;
1452 if (mStackBuffer[mStackNum] ==
NULL) {
1457 if (mStackNum == 0) {
1458 return EFI_OUT_OF_RESOURCES;
1477 for (Index = 0; Index < mStackNum; Index++) {
1506 if (EbcVmTestProtocol ==
NULL) {
1507 return EFI_OUT_OF_RESOURCES;
1521 Status =
gBS->InstallProtocolInterface (&Handle, &gEfiEbcVmTestProtocolGuid,
EFI_NATIVE_INTERFACE, EbcVmTestProtocol);
1522 if (EFI_ERROR (Status)) {
1541 return EFI_UNSUPPORTED;
1562 if (EFI_ERROR (Status)) {
EFI_STATUS EbcCreateThunks(IN EFI_HANDLE ImageHandle, IN VOID *EbcEntryPoint, OUT VOID **Thunk, IN UINT32 Flags)
VOID *EFIAPI InvalidateInstructionCacheRange(IN VOID *Address, IN UINTN Length)
VOID EFIAPI CpuDeadLoop(VOID)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS(EFIAPI * EBC_ICACHE_FLUSH)(IN EFI_PHYSICAL_ADDRESS Start, IN UINT64 Length)
UINT64 GetVmVersion(VOID)
EFI_STATUS EFIAPI EbcExecuteInstructions(IN EFI_EBC_VM_TEST_PROTOCOL *This, IN VM_CONTEXT *VmPtr, IN OUT UINTN *InstructionCount)
EFI_STATUS EFIAPI EbcVmTestUnsupported(VOID)
EFI_STATUS EFIAPI EbcRegisterICacheFlush(IN EFI_EBC_PROTOCOL *This, IN EBC_ICACHE_FLUSH Flush)
EFI_STATUS EFIAPI EbcCreateThunk(IN EFI_EBC_PROTOCOL *This, IN EFI_HANDLE ImageHandle, IN VOID *EbcEntryPoint, OUT VOID **Thunk)
EFI_STATUS InitEbcVmTestProtocol(IN EFI_HANDLE *IHandle)
EFI_STATUS EFIAPI EbcDebugGetMaximumProcessorIndex(IN EFI_DEBUG_SUPPORT_PROTOCOL *This, OUT UINTN *MaxProcessorIndex)
EFI_STATUS EbcAddImageThunk(IN EFI_HANDLE ImageHandle, IN VOID *ThunkBuffer, IN UINT32 ThunkSize)
EFI_STATUS EFIAPI EbcUnloadImage(IN EFI_EBC_PROTOCOL *This, IN EFI_HANDLE ImageHandle)
VOID EFIAPI EbcPeriodicNotifyFunction(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI EbcDebugRegisterExceptionCallback(IN EFI_DEBUG_SUPPORT_PROTOCOL *This, IN UINTN ProcessorIndex, IN EFI_EXCEPTION_CALLBACK ExceptionCallback, IN EFI_EXCEPTION_TYPE ExceptionType)
VOID *EFIAPI EbcAllocatePoolForThunk(IN UINTN AllocationSize)
EFI_STATUS EFIAPI EbcGetVersion(IN EFI_EBC_PROTOCOL *This, IN OUT UINT64 *Version)
EFI_STATUS ReturnEBCStackByHandle(IN EFI_HANDLE Handle)
EFI_STATUS FreeEBCStack(VOID)
EFI_STATUS EFIAPI EbcRegisterImage(IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize, IN OUT EFI_IMAGE_ENTRY_POINT *EntryPoint)
EFI_STATUS EbcDebugSignalException(IN EFI_EXCEPTION_TYPE ExceptionType, IN EXCEPTION_FLAGS ExceptionFlags, IN VM_CONTEXT *VmPtr)
EFI_STATUS EFIAPI EbcDebugPeriodic(IN VM_CONTEXT *VmPtr)
EFI_STATUS EFIAPI EbcUnregisterImage(IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS ImageBase)
EFI_STATUS InitEBCStack(VOID)
EFI_STATUS EFIAPI EbcDebugRegisterPeriodicCallback(IN EFI_DEBUG_SUPPORT_PROTOCOL *This, IN UINTN ProcessorIndex, IN EFI_PERIODIC_CALLBACK PeriodicCallback)
EFI_STATUS EFIAPI InitializeEbcDriver(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS ReturnEBCStack(IN UINTN Index)
VOID EFIAPI CommonEbcExceptionHandler(IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_SYSTEM_CONTEXT SystemContext)
EFI_STATUS EFIAPI InitializeEbcCallback(IN EFI_DEBUG_SUPPORT_PROTOCOL *This)
EFI_STATUS GetEBCStack(IN EFI_HANDLE Handle, OUT VOID **StackBuffer, OUT UINTN *BufferIndex)
BOOLEAN EFIAPI EbcIsImageSupported(IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, IN UINT16 ImageType, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL)
EFI_STATUS EFIAPI EbcDebugInvalidateInstructionCache(IN EFI_DEBUG_SUPPORT_PROTOCOL *This, IN UINTN ProcessorIndex, IN VOID *Start, IN UINT64 Length)
EFI_STATUS(EFIAPI * EBC_VM_TEST_EXECUTE)(IN EFI_EBC_VM_TEST_PROTOCOL *This, IN VM_CONTEXT *VmPtr, IN OUT UINTN *InstructionCount)
EFI_STATUS(EFIAPI * EBC_VM_TEST_ASM)(IN EFI_EBC_VM_TEST_PROTOCOL *This, IN CHAR16 *AsmText, IN OUT INT8 *Buffer, IN OUT UINTN *BufferLen)
EFI_STATUS(EFIAPI * EBC_VM_TEST_DASM)(IN EFI_EBC_VM_TEST_PROTOCOL *This, IN OUT CHAR16 *AsmText, IN OUT INT8 *Buffer, IN OUT UINTN *Len)
VOID EbcDebuggerHookInit(IN EFI_HANDLE Handle, IN EFI_DEBUG_SUPPORT_PROTOCOL *EbcDebugProtocol)
VOID EbcDebuggerHookEbcUnloadImage(IN EFI_HANDLE Handle)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define DEBUG_CODE_BEGIN()
#define DEBUG(Expression)
VOID(EFIAPI * EFI_EXCEPTION_CALLBACK)(IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext)
#define MAX_EBC_EXCEPTION
VOID(EFIAPI * EFI_PERIODIC_CALLBACK)(IN OUT EFI_SYSTEM_CONTEXT SystemContext)
RETURN_STATUS EFIAPI PeCoffLoaderGetImageInfo(IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext)
RETURN_STATUS EFIAPI PeCoffLoaderImageReadFromMemory(IN VOID *FileHandle, IN UINTN FileOffset, IN OUT UINTN *ReadSize, OUT VOID *Buffer)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_IMAGE_MACHINE_EBC
EFI_STATUS(EFIAPI * EFI_IMAGE_ENTRY_POINT)(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_INSTRUCTION_SET_ARCHITECTURE Isa
PE_COFF_LOADER_READ_FILE ImageRead