17 { EXCEPT_X64_DEBUG, GDB_SIGTRAP },
18 { EXCEPT_X64_NMI, GDB_SIGEMT },
19 { EXCEPT_X64_BREAKPOINT, GDB_SIGTRAP },
20 { EXCEPT_X64_OVERFLOW, GDB_SIGSEGV },
21 { EXCEPT_X64_BOUND, GDB_SIGSEGV },
22 { EXCEPT_X64_INVALID_OPCODE, GDB_SIGILL },
23 { EXCEPT_X64_DOUBLE_FAULT, GDB_SIGEMT },
24 { EXCEPT_X64_STACK_FAULT, GDB_SIGSEGV },
25 { EXCEPT_X64_GP_FAULT, GDB_SIGSEGV },
26 { EXCEPT_X64_PAGE_FAULT, GDB_SIGSEGV },
27 { EXCEPT_X64_FP_ERROR, GDB_SIGEMT },
28 { EXCEPT_X64_ALIGNMENT_CHECK, GDB_SIGEMT },
29 { EXCEPT_X64_MACHINE_CHECK, GDB_SIGEMT }
36UINTN gRegisterOffsets[] = {
86 return sizeof (gRegisterOffsets)/
sizeof (
UINTN);
100 return (BOOLEAN)(Isa ==
IsaX64);
118 TempPtr = ((UINT8 *)SystemContext.SystemContextX64) + gRegisterOffsets[RegNumber];
119 return (
UINTN *)TempPtr;
139 while (RegSize < 64) {
140 *OutBufPtr++ = mHexToStr[((*
FindPointerToRegister (SystemContext, RegNumber) >> (RegSize+4)) & 0xf)];
142 RegSize = RegSize + 8;
170 OutBufPtr = OutBuffer;
189 CHAR8 OutBuffer[385];
192 OutBufPtr = OutBuffer;
223 while (RegSize < 64) {
231 NewValue += (TempValue << (RegSize+4));
239 NewValue += (TempValue << RegSize);
240 RegSize = RegSize + 8;
261 CHAR8 RegNumBuffer[MAX_REG_NUM_BUF_SIZE];
266 InBufPtr = &InBuffer[1];
267 RegNumBufPtr = RegNumBuffer;
268 while (*InBufPtr !=
'=') {
269 *RegNumBufPtr++ = *InBufPtr++;
272 *RegNumBufPtr =
'\0';
311 InBufPtr = &InBuffer[1];
333 SystemContext.SystemContextX64->Rflags |= TF_BIT;
346 SystemContext.SystemContextX64->Rflags &= ~TF_BIT;
362 if (PacketData[1] !=
'\0') {
380 if (PacketData[1] !=
'\0') {
399GetBreakpointDataAddress (
406 if (BreakpointNumber == 1) {
407 Address = SystemContext.SystemContextIa32->Dr0;
408 }
else if (BreakpointNumber == 2) {
409 Address = SystemContext.SystemContextIa32->Dr1;
410 }
else if (BreakpointNumber == 3) {
411 Address = SystemContext.SystemContextIa32->Dr2;
412 }
else if (BreakpointNumber == 4) {
413 Address = SystemContext.SystemContextIa32->Dr3;
433GetBreakpointDetected (
438 UINTN BreakpointNumber;
440 Dr6.UintN = SystemContext.SystemContextIa32->Dr6;
442 if (Dr6.Bits.B0 == 1) {
443 BreakpointNumber = 1;
444 }
else if (Dr6.Bits.B1 == 1) {
445 BreakpointNumber = 2;
446 }
else if (Dr6.Bits.B2 == 1) {
447 BreakpointNumber = 3;
448 }
else if (Dr6.Bits.B3 == 1) {
449 BreakpointNumber = 4;
451 BreakpointNumber = 0;
454 return BreakpointNumber;
475 BREAK_TYPE Type = NotSupported;
477 Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
479 if (BreakpointNumber == 1) {
480 Type = (BREAK_TYPE)Dr7.Bits.RW0;
481 }
else if (BreakpointNumber == 2) {
482 Type = (BREAK_TYPE)Dr7.Bits.RW1;
483 }
else if (BreakpointNumber == 3) {
484 Type = (BREAK_TYPE)Dr7.Bits.RW2;
485 }
else if (BreakpointNumber == 4) {
486 Type = (BREAK_TYPE)Dr7.Bits.RW3;
510 }
else if (Length == 2) {
513 }
else if (Length == 4) {
540 Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
542 if (Dr7.Bits.G0 == 0) {
544 }
else if (Dr7.Bits.G1 == 0) {
546 }
else if (Dr7.Bits.G2 == 0) {
548 }
else if (Dr7.Bits.G3 == 0) {
551 return EFI_OUT_OF_RESOURCES;
586 if ((Type == 0) && (Length != 0)) {
587 return EFI_INVALID_PARAMETER;
592 if ((Type == (BREAK_TYPE)DataRead) ||
593 (Type == (BREAK_TYPE)SoftwareBreakpoint))
595 return EFI_UNSUPPORTED;
599 Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
602 SystemContext.SystemContextIa32->Dr0 = Address;
605 Dr7.Bits.LEN0 = Length;
607 SystemContext.SystemContextIa32->Dr1 = Address;
610 Dr7.Bits.LEN1 = Length;
612 SystemContext.SystemContextIa32->Dr2 = Address;
615 Dr7.Bits.LEN2 = Length;
617 SystemContext.SystemContextIa32->Dr3 = Address;
620 Dr7.Bits.LEN3 = Length;
622 return EFI_INVALID_PARAMETER;
626 SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
660 if ((Type == (BREAK_TYPE)DataRead) ||
661 (Type == (BREAK_TYPE)SoftwareBreakpoint))
663 return EFI_UNSUPPORTED;
669 Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
671 if ((Dr7.Bits.G0 == 1) &&
672 (Dr7.Bits.LEN0 == Length) &&
673 (Dr7.Bits.RW0 == Type) &&
674 (Address == SystemContext.SystemContextIa32->Dr0))
677 }
else if ((Dr7.Bits.G1 == 1) &&
678 (Dr7.Bits.LEN1 == Length) &&
679 (Dr7.Bits.RW1 == Type) &&
680 (Address == SystemContext.SystemContextIa32->Dr1))
683 }
else if ((Dr7.Bits.G2 == 1) &&
684 (Dr7.Bits.LEN2 == Length) &&
685 (Dr7.Bits.RW2 == Type) &&
686 (Address == SystemContext.SystemContextIa32->Dr2))
689 }
else if ((Dr7.Bits.G3 == 1) &&
690 (Dr7.Bits.LEN3 == Length) &&
691 (Dr7.Bits.RW3 == Type) &&
692 (Address == SystemContext.SystemContextIa32->Dr3))
696 Print ((CHAR16 *)L
"No match found..\n");
697 return EFI_NOT_FOUND;
722 Dr7.UintN = SystemContext.SystemContextIa32->Dr7;
725 SystemContext.SystemContextIa32->Dr0 = Address;
730 SystemContext.SystemContextIa32->Dr1 = Address;
735 SystemContext.SystemContextIa32->Dr2 = Address;
740 SystemContext.SystemContextIa32->Dr3 = Address;
745 return EFI_INVALID_PARAMETER;
749 SystemContext.SystemContextIa32->Dr7 = Dr7.UintN;
778 BREAK_TYPE BreakType = NotSupported;
789 BreakType = SoftwareBreakpoint;
793 BreakType = InstructionExecution;
797 BreakType = DataWrite;
801 BreakType = DataRead;
805 BreakType = DataReadWrite;
809 Print ((CHAR16 *)L
"Insert breakpoint default: %x\n", Type);
816 if (EFI_ERROR (Status)) {
817 Print ((CHAR16 *)L
"No space left on device\n");
824 if (EFI_ERROR (Status)) {
825 if (Status == EFI_UNSUPPORTED) {
826 Print ((CHAR16 *)L
"Not supported\n");
831 Print ((CHAR16 *)L
"Invalid argument\n");
861 BREAK_TYPE BreakType = NotSupported;
874 BreakType = SoftwareBreakpoint;
878 BreakType = InstructionExecution;
882 BreakType = DataWrite;
886 BreakType = DataRead;
890 BreakType = DataReadWrite;
900 if (EFI_ERROR (Status)) {
901 if (Status == EFI_UNSUPPORTED) {
902 Print ((CHAR16 *)L
"Not supported.\n");
907 Print ((CHAR16 *)L
"No matching register found.\n");
914 if (EFI_ERROR (Status)) {
915 Print ((CHAR16 *)L
"Invalid argument.\n");
UINTN MaxEfiException(VOID)
VOID EFIAPI RemoveBreakPoint(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData)
UINTN MaxRegisterCount(VOID)
VOID EFIAPI WriteGeneralRegisters(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *InBuffer)
CHAR8 * BasicReadRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN RegNumber, IN CHAR8 *OutBufPtr)
VOID EFIAPI InsertBreakPoint(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData)
VOID ReadNthRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *InBuffer)
CHAR8 * BasicWriteRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN RegNumber, IN CHAR8 *InBufPtr)
BOOLEAN CheckIsa(IN EFI_INSTRUCTION_SET_ARCHITECTURE Isa)
VOID EFIAPI ReadGeneralRegisters(IN EFI_SYSTEM_CONTEXT SystemContext)
VOID RemoveSingleStep(IN EFI_SYSTEM_CONTEXT SystemContext)
VOID AddSingleStep(IN EFI_SYSTEM_CONTEXT SystemContext)
VOID EFIAPI SingleStep(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData)
VOID WriteNthRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *InBuffer)
UINTN * FindPointerToRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN RegNumber)
VOID EFIAPI ContinueAtAddress(IN EFI_SYSTEM_CONTEXT SystemContext, IN CHAR8 *PacketData)
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
UINTN EFIAPI AsciiStrHexToUintn(IN CONST CHAR8 *String)
UINTN ParseBreakpointPacket(IN CHAR8 *PacketData, OUT UINTN *Type, OUT UINTN *Address, OUT UINTN *Length)
VOID EFIAPI SendNotSupported(VOID)
UINTN SendPacket(IN CHAR8 *PacketData)
VOID EFIAPI SendSuccess(VOID)
INTN HexCharToInt(IN CHAR8 Char)
VOID EFIAPI SendError(IN UINT8 ErrorNum)
UINTN ConvertLengthData(IN UINTN Length)
EFI_STATUS FindMatchingDebugRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN Address, IN UINTN Length, IN UINTN Type, OUT UINTN *Register)
EFI_STATUS DisableDebugRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN Register)
EFI_STATUS EnableDebugRegister(IN EFI_SYSTEM_CONTEXT SystemContext, IN UINTN Register, IN UINTN Address, IN UINTN Length, IN UINTN Type)
EFI_STATUS FindNextFreeDebugRegister(IN EFI_SYSTEM_CONTEXT SystemContext, OUT UINTN *Register)
#define OFFSET_OF(TYPE, Field)
EFI_INSTRUCTION_SET_ARCHITECTURE
#define EXCEPT_X64_DIVIDE_ERROR
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)