Skip to content
Permalink
Browse files

Write exit label for runctions and interrupt handlers

  • Loading branch information...
charlesbetros committed Aug 4, 2019
1 parent c4773d8 commit 5d7adf52df3d85da87f3787904437f241d3a3051
@@ -1,133 +0,0 @@
; namespace DebugStub

; Location where INT3 has been injected.
; 0 if no INT3 is active.
; var AsmBreakEIP
DebugStub_AsmBreakEIP dd 0

; Old byte before INT3 was injected.
; Only 1 byte is used.
; var AsmOrigByte
DebugStub_AsmOrigByte dd 0

; function DoAsmBreak {
DebugStub_DoAsmBreak:
; Since our Int3 is temp, we need to adjust return EIP to return to it, not after it.
; ESI = .CallerESP
Mov ESI, DWORD [DebugStub_CallerESP]
; EAX = .AsmBreakEIP
Mov EAX, DWORD [DebugStub_AsmBreakEIP]
; [ESI-12] = EAX
Mov DWORD [ESI - 12], EAX

; ClearAsmBreak()
Call DebugStub_ClearAsmBreak
; Break()
Call DebugStub_Break
; }

; function SetAsmBreak {
DebugStub_SetAsmBreak:
; ClearAsmBreak()
Call DebugStub_ClearAsmBreak

; ComReadEAX()
Call DebugStub_ComReadEAX
; Save EIP of the break
; .AsmBreakEIP = EAX
Mov DWORD [DebugStub_AsmBreakEIP], EAX
; EDI = EAX
Mov EDI, EAX

; Save the old byte
; AL = [EDI]
Mov AL, BYTE [EDI]
; .AsmOrigByte = AL
Mov BYTE [DebugStub_AsmOrigByte], AL

; Inject INT3
; Do in 2 steps to force a byte move to RAM (till X# can do byte in one step)
; AL = $CC
Mov AL, 0xCC
; [EDI] = AL
Mov BYTE [EDI], AL
; }

; function ClearAsmBreak {
DebugStub_ClearAsmBreak:
; EDI = .AsmBreakEIP
Mov EDI, DWORD [DebugStub_AsmBreakEIP]
; If 0, we don't need to clear an older one.
; if EDI = 0 return
; Clear old break point and set back to original opcode / partial opcode
; AL = .AsmOrigByte
Mov AL, BYTE [DebugStub_AsmOrigByte]
; [EDI] = AL
Mov BYTE [EDI], AL

; .AsmBreakEIP = 0
Mov DWORD [DebugStub_AsmBreakEIP], 0x0
; }

; function SetINT1_TrapFLAG {
DebugStub_SetINT1_TrapFLAG:
; Push EAX to make sure whatever we do below doesn't affect code afterwards
; +EBP
Push EBP
; +EAX
Push EAX

; Set base pointer to the caller ESP
; EBP = .CallerESP
Mov EBP, DWORD [DebugStub_CallerESP]
; Set the Trap Flag (http://en.wikipedia.org/wiki/Trap_flag)
; For EFLAGS we want - the interrupt frame = ESP + 12
; - The interrupt frame - 8 for correct byte = ESP + 12 - 8 = ESP + 4
; - Therefore, ESP - 4 to get to the correct position
; EBP -= 4
Sub EBP, 0x4
; EAX = [EBP]
Mov EAX, DWORD [EBP]
; EAX | $0100
; [EBP] = EAX
Mov DWORD [EBP], EAX

; Restore the base pointer
; Pop EAX - see +EAX at start of method
; -EAX
Pop EAX
; -EBP
Pop EBP
; }

; function ResetINT1_TrapFLAG {
DebugStub_ResetINT1_TrapFLAG:
; Push EAX to make sure whatever we do below doesn't affect code afterwards
; +EBP
Push EBP
; +EAX
Push EAX

; Set base pointer to the caller ESP
; EBP = .CallerESP
Mov EBP, DWORD [DebugStub_CallerESP]
; Clear the Trap Flag (http://en.wikipedia.org/wiki/Trap_flag)
; See comment in SetINT1_TrapFlag
; EBP -= 4
Sub EBP, 0x4
; EAX = [EBP]
Mov EAX, DWORD [EBP]
; EAX & $FEFF
; [EBP] = EAX
Mov DWORD [EBP], EAX
; Pop EAX - see +EAX at start of method
; -EAX
Pop EAX
; -EBP
Pop EBP
; }
@@ -8,17 +8,23 @@ DebugStub_Ping:
; ComWriteAL()
Call DebugStub_ComWriteAL
; }
DebugStub_Ping_Exit:
Ret

; function TraceOn {
DebugStub_TraceOn:
; Tracing.On
; .TraceMode = 1
Mov DWORD [DebugStub_TraceMode], 0x1
; }
DebugStub_TraceOn_Exit:
Ret

; function TraceOff {
DebugStub_TraceOff:
; Tracing.Off
; .TraceMode = 0
Mov DWORD [DebugStub_TraceMode], 0x0
; }
DebugStub_TraceOff_Exit:
Ret
@@ -172,6 +172,8 @@ DebugStub_AckCommand:
; ComWriteAL()
Call DebugStub_ComWriteAL
; }
DebugStub_AckCommand_Exit:
Ret

; function ProcessCommandBatch {
DebugStub_ProcessCommandBatch:
@@ -188,3 +190,5 @@ DebugStub_ProcessCommandBatch_Begin:
; AckCommand()
Call DebugStub_AckCommand
; }
DebugStub_ProcessCommandBatch_Exit:
Ret
@@ -25,6 +25,8 @@ DebugStub_SendRegisters:
; ComWrite32()
Call DebugStub_ComWrite32
; }
DebugStub_SendRegisters_Exit:
Ret

; function SendFrame {
DebugStub_SendFrame:
@@ -48,6 +50,8 @@ DebugStub_SendFrame:
; ComWriteX()
Call DebugStub_ComWriteX
; }
DebugStub_SendFrame_Exit:
Ret

; AL contains channel
; BL contains command
@@ -91,6 +95,8 @@ DebugStub_SendCommandOnChannel:
; }
DebugStub_SendCommandOnChannel_Block1_End:
; }
DebugStub_SendCommandOnChannel_Exit:
Ret

; function SendStack {
DebugStub_SendStack:
@@ -119,6 +125,8 @@ DebugStub_SendStack:
; }
DebugStub_SendStack_Block1_End:
; }
DebugStub_SendStack_Exit:
Ret

; sends a stack value
; Serial Params:
@@ -228,6 +236,8 @@ DebugStub_SendTrace:
; ComWrite32()
Call DebugStub_ComWrite32
; }
DebugStub_SendTrace_Exit:
Ret

; Input: Stack
; Output: None
@@ -286,6 +296,8 @@ DebugStub_SendText_Finalize:
; -EBP
Pop EBP
; }
DebugStub_SendText_Exit:
Ret

; Input: Stack
; Output: None
@@ -315,6 +327,8 @@ Mov EBP, ESP
; -EBP
Pop EBP
; }
DebugStub_SendSimpleNumber_Exit:
Ret

; Input: Stack
; Output: None
@@ -346,6 +360,8 @@ Mov EBP, ESP
; -EBP
Pop EBP
; }
DebugStub_SendKernelPanic_Exit:
Ret

; Input: Stack
; Output: None
@@ -380,6 +396,8 @@ DebugStub_SendSimpleLongNumber:
; -EBP
Pop EBP
; }
DebugStub_SendSimpleLongNumber_Exit:
Ret

; Input: Stack
; Output: None
@@ -410,6 +428,8 @@ DebugStub_SendComplexNumber:
; -EBP
Pop EBP
; }
DebugStub_SendComplexNumber_Exit:
Ret

; Input: Stack
; Output: None
@@ -444,6 +464,8 @@ DebugStub_SendComplexLongNumber:
; -EBP
Pop EBP
; }
DebugStub_SendComplexLongNumber_Exit:
Ret

; Input: Stack
; Output: None
@@ -462,6 +484,8 @@ DebugStub_SendPtr:
; ComWrite32()
Call DebugStub_ComWrite32
; }
DebugStub_SendPtr_Exit:
Ret

; Input: Stack
; Output: None
@@ -480,6 +504,8 @@ DebugStub_SendStackCorruptionOccurred:
; ComWrite32()
Call DebugStub_ComWrite32
; }
DebugStub_SendStackCorruptionOccurred_Exit:
Ret

; Input: Stack
; Output: None
@@ -498,6 +524,8 @@ DebugStub_SendStackOverflowOccurred:
; ComWrite32()
Call DebugStub_ComWrite32
; }
DebugStub_SendStackOverflowOccurred_Exit:
Ret

; Input: None
; Output: None
@@ -518,6 +546,8 @@ DebugStub_SendInterruptOccurred:
; ComWriteEAX()
Call DebugStub_ComWriteEAX
; }
DebugStub_SendInterruptOccurred_Exit:
Ret

; Input: Stack
; Output: None
@@ -536,6 +566,8 @@ DebugStub_SendNullReferenceOccurred:
; ComWrite32()
Call DebugStub_ComWrite32
; }
DebugStub_SendNullReferenceOccurred_Exit:
Ret

; Input: Stack
; Output: None
@@ -575,6 +607,8 @@ DebugStub_SendMessageBox_WriteChar:
; goto WriteChar
Jmp DebugStub_SendMessageBox_WriteChar
; }
DebugStub_SendMessageBox_Exit:
Ret

; function SendCoreDump {
DebugStub_SendCoreDump:
@@ -637,3 +671,5 @@ DebugStub_SendCoreDump:
; }
DebugStub_SendCoreDump_Block2_End:
; }
DebugStub_SendCoreDump_Exit:
Ret
@@ -355,6 +355,8 @@ DebugStub_Executing_CheckForCmd:
; }
DebugStub_Executing_Block11_End:
; }
DebugStub_Executing_Exit:
Ret

; function Break {
DebugStub_Break:
@@ -448,4 +450,6 @@ DebugStub_Break_Done:
; .DebugStatus = #Status_Run
Mov [DebugStub_DebugStatus], DebugStub_Const_Status_Run
; }
DebugStub_Break_Exit:
Ret

@@ -19,6 +19,8 @@ DebugStub_Init:
; Cls()
Call DebugStub_Cls
; }
DebugStub_Init_Exit:
Ret

; function WaitForSignature {
DebugStub_WaitForSignature:
@@ -34,6 +36,8 @@ DebugStub_WaitForSignature:
; }
DebugStub_WaitForSignature_Block1_End:
; }
DebugStub_WaitForSignature_Exit:
Ret

; QEMU (and possibly others) send some garbage across the serial line first.
; Actually they send the garbage inbound, but garbage could be inbound as well so we
@@ -85,11 +89,15 @@ DebugStub_WaitForDbgHandshake:
; Hook_OnHandshakeCompleted()
Call DebugStub_Hook_OnHandshakeCompleted
; }
DebugStub_WaitForDbgHandshake_Exit:
Ret

; //! %ifndef Exclude_Dummy_Hooks
%ifndef Exclude_Dummy_Hooks
; function Hook_OnHandshakeCompleted {
DebugStub_Hook_OnHandshakeCompleted:
; }
DebugStub_Hook_OnHandshakeCompleted_Exit:
Ret
; //! %endif
%endif
@@ -30,6 +30,8 @@ DebugStub_Cls:
; }
DebugStub_Cls_Block1_End:
; }
DebugStub_Cls_Exit:
Ret

; function DisplayWaitMsg {
DebugStub_DisplayWaitMsg:
@@ -55,6 +57,8 @@ DebugStub_DisplayWaitMsg:
; }
DebugStub_DisplayWaitMsg_Block1_End:
; }
DebugStub_DisplayWaitMsg_Exit:
Ret

; //! %endif
%endif

0 comments on commit 5d7adf5

Please sign in to comment.
You can’t perform that action at this time.