#\r
#**/ \r
\r
-.intel_syntax noprefix\r
-\r
ASM_GLOBAL ASM_PFX(OrigVector)\r
ASM_GLOBAL ASM_PFX(InterruptEntryStub)\r
ASM_GLOBAL ASM_PFX(StubSize)\r
#\r
# cpuid corrupts rbx which must be preserved per the C calling convention\r
#\r
- push rbx\r
- mov rax, 1\r
+ pushq %rbx\r
+ movq $1, %rax\r
cpuid\r
- mov eax, edx\r
- and rax, 0x01000000\r
- shr rax, 24\r
- pop rbx\r
+ movl %edx, %eax\r
+ andq $0x01000000, %rax\r
+ shrq $24, %rax\r
+ popq %rbx\r
ret\r
#------------------------------------------------------------------------------\r
# void\r
#\r
ASM_GLOBAL ASM_PFX(Vect2Desc)\r
ASM_PFX(Vect2Desc):\r
- mov rax, rdx\r
- mov word ptr [rcx], ax # write bits 15..0 of offset\r
- mov dx, cs\r
- mov word ptr [rcx+2], dx # SYS_CODE_SEL from GDT\r
- mov word ptr [rcx+4], 0x0e00 OR 0x8000 # type = 386 interrupt gate, present\r
- shr rax, 16\r
- mov word ptr [rcx+6], ax # write bits 31..16 of offset\r
- shr rax, 16\r
- mov dword ptr [rcx+8], eax # write bits 63..32 of offset\r
+ movq %rdx, %rax\r
+ movw %ax, (%rcx) # write bits 15..0 of offset\r
+ movw %cs, %dx\r
+ movw %dx, 2(%rcx) # SYS_CODE_SEL from GDT\r
+ movw $(0x0e00 | 0x8000), 4(%rcx) # type = 386 interrupt gate, present\r
+ shrq $16, %rax\r
+ movw %ax, 6(%rcx) # write bits 31..16 of offset\r
+ shrq $16, %rax\r
+ movl %eax, 8(%rcx) # write bits 63..32 of offset\r
\r
ret\r
\r
ASM_GLOBAL ASM_PFX(InterruptEntryStub)\r
ASM_PFX(InterruptEntryStub):\r
\r
- push 0 # push vector number - will be modified before installed\r
+ pushq $0 # push vector number - will be modified before installed\r
jmp ASM_PFX(CommonIdtEntry)\r
\r
ASM_GLOBAL ASM_PFX(InterruptEntryStubEnd)\r
## } SYSTEM_CONTEXT_X64; // 64\r
ASM_PFX(CommonIdtEntry):\r
## NOTE: we save rsp here to prevent compiler put rip reference cause error AppRsp\r
- push rax\r
- mov rax, qword ptr [rsp][8] # save vector number\r
- mov ASM_PFX(ExceptionNumber), rax # save vector number\r
- pop rax\r
- add rsp, 8 # pop vector number\r
- mov ASM_PFX(AppRsp), rsp # save stack top\r
- mov rsp, offset DebugStackBegin # switch to debugger stack\r
- sub rsp, 8 # leave space for vector number\r
+ pushq %rax\r
+ movq (8)(%rsp), %rax # save vector number\r
+ movq %rax, ASM_PFX(ExceptionNumber) # save vector number\r
+ popq %rax\r
+ addq $8, %rsp # pop vector number\r
+ movq %rsp, ASM_PFX(AppRsp) # save stack top\r
+ movq DebugStackBegin, %rsp # switch to debugger stack\r
+ subq $8, %rsp # leave space for vector number\r
## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;\r
## UINT64 R8, R9, R10, R11, R12, R13, R14, R15;\r
- push r15\r
- push r14\r
- push r13\r
- push r12\r
- push r11\r
- push r10\r
- push r9\r
- push r8\r
- push rax\r
- push rcx\r
- push rdx\r
- push rbx\r
- push rsp\r
- push rbp\r
- push rsi\r
- push rdi\r
+ pushq %r15\r
+ pushq %r14\r
+ pushq %r13\r
+ pushq %r12\r
+ pushq %r11\r
+ pushq %r10\r
+ pushq %r9\r
+ pushq %r8\r
+ pushq %rax\r
+ pushq %rcx\r
+ pushq %rdx\r
+ pushq %rbx\r
+ pushq %rsp\r
+ pushq %rbp\r
+ pushq %rsi\r
+ pushq %rdi\r
## Save interrupt state rflags register...\r
pushfq\r
- pop rax\r
- mov qword ptr ASM_PFX(Rflags), rax\r
+ popq %rax\r
+ movq %rax, ASM_PFX(Rflags)\r
## We need to determine if any extra data was pushed by the exception, and if so, save it\r
## To do this, we check the exception number pushed by the stub, and cache the\r
## result in a variable since we'll need this again.\r
- cmp dword ptr ASM_PFX(ExceptionNumber), 0\r
+ cmpl $0, ASM_PFX(ExceptionNumber)\r
jz ExtraPushOne\r
- cmp dword ptr ASM_PFX(ExceptionNumber), 10\r
+ cmpl $10, ASM_PFX(ExceptionNumber)\r
jz ExtraPushOne\r
- cmp dword ptr ASM_PFX(ExceptionNumber), 11\r
+ cmpl $11, ASM_PFX(ExceptionNumber)\r
jz ExtraPushOne\r
- cmp dword ptr ASM_PFX(ExceptionNumber), 12\r
+ cmpl $12, ASM_PFX(ExceptionNumber)\r
jz ExtraPushOne\r
- cmp dword ptr ASM_PFX(ExceptionNumber), 13\r
+ cmpl $13, ASM_PFX(ExceptionNumber)\r
jz ExtraPushOne\r
- cmp dword ptr ASM_PFX(ExceptionNumber), 14\r
+ cmpl $14, ASM_PFX(ExceptionNumber)\r
jz ExtraPushOne\r
- cmp dword ptr ASM_PFX(ExceptionNumber), 17\r
+ cmpl $17, ASM_PFX(ExceptionNumber)\r
jz ExtraPushOne\r
- mov dword ptr ASM_PFX(ExtraPush), 0\r
- mov dword ptr ASM_PFX(ExceptData), 0\r
+ movl $0, ASM_PFX(ExtraPush)\r
+ movl $0, ASM_PFX(ExceptData)\r
jmp ExtraPushDone\r
ExtraPushOne:\r
- mov dword ptr ASM_PFX(ExtraPush), 1\r
+ movl $1, ASM_PFX(ExtraPush)\r
\r
## If there's some extra data, save it also, and modify the saved AppRsp to effectively\r
## pop this value off the application's stack.\r
- mov rax, ASM_PFX(AppRsp)\r
- mov rbx, [rax]\r
- mov ASM_PFX(ExceptData), rbx\r
- add rax, 8\r
- mov ASM_PFX(AppRsp), rax\r
+ movq ASM_PFX(AppRsp), %rax \r
+ movq (%rax), %rbx\r
+ movq %rbx, ASM_PFX(ExceptData)\r
+ addq $8, %rax\r
+ movq %rax, ASM_PFX(AppRsp)\r
\r
ExtraPushDone:\r
\r
## The "push" above pushed the debug stack rsp. Since what we're actually doing\r
## is building the context record on the debug stack, we need to save the pushed\r
## debug RSP, and replace it with the application's last stack entry...\r
- mov rax, [rsp + 24]\r
- mov ASM_PFX(DebugRsp), rax\r
- mov rax, ASM_PFX(AppRsp)\r
- add rax, 40\r
+ movq 24(%rsp), %rax\r
+ movq %rax, ASM_PFX(DebugRsp)\r
+ movq ASM_PFX(AppRsp), %rax \r
+ addq $40, %rax\r
# application stack has ss, rsp, rflags, cs, & rip, so\r
# last actual application stack entry is 40 bytes\r
# into the application stack.\r
- mov [rsp + 24], rax\r
+ movq %rax, 24(%rsp)\r
\r
## continue building context record\r
## UINT64 Gs, Fs, Es, Ds, Cs, Ss; insure high 16 bits of each is zero\r
- mov rax, ss\r
- push rax\r
+ movq %ss, %rax\r
+ pushq %rax\r
# CS from application is one entry back in application stack\r
- mov rax, ASM_PFX(AppRsp)\r
- movzx rax, word ptr [rax + 8]\r
- push rax\r
-\r
- mov rax, ds\r
- push rax\r
- mov rax, es\r
- push rax\r
- mov rax, fs\r
- push rax\r
- mov rax, gs\r
- push rax\r
+ movq ASM_PFX(AppRsp), %rax\r
+ movzxw 8(%rax), %rax\r
+ pushq %rax\r
+\r
+ movq %ds, %rax\r
+ pushq %rax\r
+ movq %es, %rax\r
+ pushq %rax\r
+ movq %fs, %rax\r
+ pushq %rax\r
+ movq %gs, %rax\r
+ pushq %rax\r
## UINT64 Rip;\r
# Rip from application is on top of application stack\r
- mov rax, ASM_PFX(AppRsp)\r
- push qword ptr [rax]\r
+ movq ASM_PFX(AppRsp), %rax \r
+ pushq (%rax)\r
## UINT64 Gdtr[2], Idtr[2];\r
- push 0\r
- push 0\r
- sidt [rsp]\r
- push 0\r
- push 0\r
- sgdt [rsp]\r
+ push $0\r
+ push $0\r
+ sidtq (%rsp)\r
+ push $0\r
+ push $0\r
+ sgdtq (%rsp)\r
\r
## UINT64 Ldtr, Tr;\r
- xor rax, rax\r
- str ax\r
- push rax\r
- sldt ax\r
- push rax\r
+ xorq %rax, %rax\r
+ str %ax\r
+ pushq %rax\r
+ sldt %ax\r
+ pushq %rax\r
\r
## UINT64 RFlags;\r
## Rflags from application is two entries back in application stack\r
- mov rax, ASM_PFX(AppRsp)\r
- push qword ptr [rax + 16]\r
+ movq ASM_PFX(AppRsp), %rax \r
+ pushq 16(%rax)\r
## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;\r
## insure FXSAVE/FXRSTOR is enabled in CR4...\r
## ... while we're at it, make sure DE is also enabled...\r
- mov rax, cr8\r
- push rax\r
- mov rax, cr4\r
- or rax, 0x208\r
- mov cr4, rax\r
- push rax\r
- mov rax, cr3\r
- push rax\r
- mov rax, cr2\r
- push rax\r
- push 0\r
- mov rax, cr0\r
- push rax\r
+ movq %cr8, %rax\r
+ pushq %rax\r
+ movq %cr4, %rax\r
+ orq $0x208, %rax\r
+ movq %rax, %cr4\r
+ pushq %rax\r
+ movq %cr3, %rax\r
+ pushq %rax\r
+ movq %cr2, %rax\r
+ pushq %rax\r
+ push $0\r
+ movq %cr0, %rax\r
+ pushq %rax\r
## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
- mov rax, dr7\r
- push rax\r
+ movq %dr7, %rax\r
+ pushq %rax\r
## clear Dr7 while executing debugger itself\r
- xor rax, rax\r
- mov dr7, rax\r
+ xorq %rax, %rax\r
+ movq %rax, %dr7\r
\r
- mov rax, dr6\r
- push rax\r
+ movq %dr6, %rax\r
+ pushq %rax\r
## insure all status bits in dr6 are clear...\r
- xor rax, rax\r
- mov dr6, rax\r
-\r
- mov rax, dr3\r
- push rax\r
- mov rax, dr2\r
- push rax\r
- mov rax, dr1\r
- push rax\r
- mov rax, dr0\r
- push rax\r
+ xorq %rax, %rax\r
+ movq %rax, %dr6\r
+\r
+ movq %dr3, %rax\r
+ pushq %rax\r
+ movq %dr2, %rax\r
+ pushq %rax\r
+ movq %dr1, %rax\r
+ pushq %rax\r
+ movq %dr0, %rax\r
+ pushq %rax\r
\r
## FX_SAVE_STATE_X64 FxSaveState;\r
- sub rsp, 512\r
- mov rdi, rsp\r
+ subq $512, %rsp\r
+ movq %rsp, %rdi\r
# IMPORTANT!! The debug stack has been carefully constructed to\r
# insure that rsp and rdi are 16 byte aligned when we get here.\r
# They MUST be. If they are not, a GP fault will occur.\r
\r
# FXSTOR_RDI\r
- fxsave [rdi]\r
+ fxsave (%rdi)\r
\r
## UINT64 ExceptionData;\r
- mov rax, ASM_PFX(ExceptData)\r
- push rax\r
+ movq ASM_PFX(ExceptData), %rax\r
+ pushq %rax\r
\r
# call to C code which will in turn call registered handler\r
# pass in the vector number\r
- mov rdx, rsp\r
- mov rcx, ASM_PFX(ExceptionNumber)\r
- sub rsp, 40\r
+ movq %rsp, %rdx\r
+ movq ASM_PFX(ExceptionNumber), %rcx \r
+ subq $40, %rsp\r
call ASM_PFX(InterruptDistrubutionHub)\r
- add rsp, 40\r
+ addq $40, %rsp\r
# restore context...\r
## UINT64 ExceptionData;\r
- add rsp, 8\r
+ addq $8, %rsp\r
\r
## FX_SAVE_STATE_X64 FxSaveState;\r
- mov rsi, rsp\r
+ movq %rsp, %rsi\r
\r
# FXRSTOR_RSI\r
- fxrstor [rsi]\r
+ fxrstor (%rsi)\r
\r
- add rsp, 512\r
+ addq $512, %rsp\r
\r
## UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
- pop rax\r
- mov dr0, rax\r
- pop rax\r
- mov dr1, rax\r
- pop rax\r
- mov dr2, rax\r
- pop rax\r
- mov dr3, rax\r
+ popq %rax\r
+ movq %rax, %dr0\r
+ popq %rax\r
+ movq %rax, %dr1\r
+ popq %rax\r
+ movq %rax, %dr2\r
+ popq %rax\r
+ movq %rax, %dr3\r
\r
## skip restore of dr6. We cleared dr6 during the context save.\r
- add rsp, 8\r
- pop rax\r
- mov dr7, rax\r
+ addq $8, %rsp\r
+ popq %rax\r
+ movq %rax, %dr7\r
\r
## UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;\r
- pop rax\r
- mov cr0, rax\r
- add rsp, 8\r
- pop rax\r
- mov cr2, rax\r
- pop rax\r
- mov cr3, rax\r
- pop rax\r
- mov cr4, rax\r
- pop rax\r
- mov cr8, rax\r
+ popq %rax\r
+ movq %rax, %cr0\r
+ addq $8, %rsp\r
+ popq %rax\r
+ movq %rax, %cr2\r
+ popq %rax\r
+ movq %rax, %cr3\r
+ popq %rax\r
+ movq %rax, %cr4\r
+ popq %rax\r
+ movq %rax, %cr8\r
## UINT64 RFlags;\r
- mov rax, ASM_PFX(AppRsp)\r
- pop qword ptr [rax + 16]\r
+ movq ASM_PFX(AppRsp), %rax \r
+ popq 16(%rax)\r
## UINT64 Ldtr, Tr;\r
## UINT64 Gdtr[2], Idtr[2];\r
## Best not let anyone mess with these particular registers...\r
- add rsp, 48\r
+ addq $48, %rsp\r
## UINT64 Rip;\r
- pop qword ptr [rax]\r
+ popq (%rax)\r
\r
## UINT64 Gs, Fs, Es, Ds, Cs, Ss;\r
## NOTE - modified segment registers could hang the debugger... We\r
## but that poses risks as well.\r
##\r
\r
- pop rax\r
- # mov gs, rax\r
- pop rax\r
- # mov fs, rax\r
- pop rax\r
- mov es, rax\r
- pop rax\r
- mov ds, rax\r
- mov rax, ASM_PFX(AppRsp)\r
- pop qword ptr [rax + 8]\r
- pop rax\r
- mov ss, rax\r
+ popq %rax\r
+ # movq %rax, %gs\r
+ popq %rax\r
+ # movq %rax, %fs\r
+ popq %rax\r
+ movq %rax, %es\r
+ popq %rax\r
+ movq %rax, %ds\r
+ movq ASM_PFX(AppRsp), %rax \r
+ popq 8(%rax)\r
+ popq %rax\r
+ movq %rax, %ss\r
## The next stuff to restore is the general purpose registers that were pushed\r
## using the "push" instruction.\r
##\r
## itself. It may have been modified by the debug agent, so we need to\r
## determine if we need to relocate the application stack.\r
\r
- mov rbx, [rsp + 24] # move the potentially modified AppRsp into rbx\r
- mov rax, ASM_PFX(AppRsp)\r
- add rax, 40\r
- cmp rbx, rax\r
+ movq 24(%rsp), %rbx # move the potentially modified AppRsp into rbx\r
+ movq ASM_PFX(AppRsp), %rax \r
+ addq $40, %rax\r
+ cmpq %rax, %rbx\r
je NoAppStackMove\r
\r
- mov rax, ASM_PFX(AppRsp)\r
- mov rcx, [rax] # RIP\r
- mov [rbx], rcx\r
+ movq ASM_PFX(AppRsp), %rax \r
+ movq (%rax), %rcx # RIP\r
+ movq %rcx, (%rbx)\r
\r
- mov rcx, [rax + 8] # CS\r
- mov [rbx + 8], rcx\r
+ movq 8(%rax), %rcx # CS\r
+ movq %rcx, 8(%rbx)\r
\r
- mov rcx, [rax + 16] # RFLAGS\r
- mov [rbx + 16], rcx\r
+ movq 16(%rax), %rcx # RFLAGS\r
+ movq %rcx, 16(%rbx)\r
\r
- mov rcx, [rax + 24] # RSP\r
- mov [rbx + 24], rcx\r
+ movq 24(%rax), %rcx # RSP\r
+ movq %rcx, 24(%rbx)\r
\r
- mov rcx, [rax + 32] # SS\r
- mov [rbx + 32], rcx\r
+ movq 32(%rax), %rcx # SS\r
+ movq %rcx, 32(%rbx)\r
\r
- mov rax, rbx # modify the saved AppRsp to the new AppRsp\r
- mov ASM_PFX(AppRsp), rax\r
+ movq %rbx, %rax # modify the saved AppRsp to the new AppRsp\r
+ movq %rax, ASM_PFX(AppRsp)\r
NoAppStackMove:\r
- mov rax, ASM_PFX(DebugRsp) # restore the DebugRsp on the debug stack\r
+ movq ASM_PFX(DebugRsp), %rax # restore the DebugRsp on the debug stack\r
# so our "pop" will not cause a stack switch\r
- mov [rsp + 24], rax\r
+ movq %rax, 24(%rsp)\r
\r
- cmp dword ptr ASM_PFX(ExceptionNumber), 0x068\r
+ cmpl $0x068, ASM_PFX(ExceptionNumber)\r
jne NoChain\r
\r
Chain:\r
\r
## Restore rflags so when we chain, the flags will be exactly as if we were never here.\r
## We gin up the stack to do an iretq so we can get ALL the flags.\r
- mov rax, ASM_PFX(AppRsp)\r
- mov rbx, [rax + 40]\r
- push rbx\r
- mov rax, ss\r
- push rax\r
- mov rax, rsp\r
- add rax, 16\r
- push rax\r
- mov rax, ASM_PFX(AppRsp)\r
- mov rbx, [rax + 16]\r
- and rbx, NOT 0x300 # special handling for IF and TF\r
- push rbx\r
- mov rax, cs\r
- push rax\r
- mov rax, offset PhonyIretq\r
- push rax\r
+ movq ASM_PFX(AppRsp), %rax \r
+ movq 40(%rax), %rbx\r
+ pushq %rbx\r
+ movq %ss, %rax\r
+ pushq %rax\r
+ movq %rsp, %rax\r
+ addq $16, %rax\r
+ pushq %rax\r
+ movq ASM_PFX(AppRsp), %rax \r
+ movq 16(%rax), %rbx\r
+ andq $0xfffffffffffffcff, %rbx # special handling for IF and TF\r
+ pushq %rbx\r
+ movq %cs, %rax\r
+ pushq %rax\r
+ movq PhonyIretq, %rax \r
+ pushq %rax\r
iretq\r
PhonyIretq:\r
\r
## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;\r
## UINT64 R8, R9, R10, R11, R12, R13, R14, R15;\r
- pop rdi\r
- pop rsi\r
- pop rbp\r
- pop rsp\r
- pop rbx\r
- pop rdx\r
- pop rcx\r
- pop rax\r
- pop r8\r
- pop r9\r
- pop r10\r
- pop r11\r
- pop r12\r
- pop r13\r
- pop r14\r
- pop r15\r
+ popq %rdi\r
+ popq %rsi\r
+ popq %rbp\r
+ popq %rsp\r
+ popq %rbx\r
+ popq %rdx\r
+ popq %rcx\r
+ popq %rax\r
+ popq %r8\r
+ popq %r9\r
+ popq %r10\r
+ popq %r11\r
+ popq %r12\r
+ popq %r13\r
+ popq %r14\r
+ popq %r15\r
\r
## Switch back to application stack\r
- mov rsp, ASM_PFX(AppRsp)\r
+ movq ASM_PFX(AppRsp), %rsp \r
## Jump to original handler\r
jmp ASM_PFX(OrigVector)\r
NoChain:\r
## UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;\r
## UINT64 R8, R9, R10, R11, R12, R13, R14, R15;\r
- pop rdi\r
- pop rsi\r
- pop rbp\r
- pop rsp\r
- pop rbx\r
- pop rdx\r
- pop rcx\r
- pop rax\r
- pop r8\r
- pop r9\r
- pop r10\r
- pop r11\r
- pop r12\r
- pop r13\r
- pop r14\r
- pop r15\r
+ popq %rdi\r
+ popq %rsi\r
+ popq %rbp\r
+ popq %rsp\r
+ popq %rbx\r
+ popq %rdx\r
+ popq %rcx\r
+ popq %rax\r
+ popq %r8\r
+ popq %r9\r
+ popq %r10\r
+ popq %r11\r
+ popq %r12\r
+ popq %r13\r
+ popq %r14\r
+ popq %r15\r
\r
## Switch back to application stack\r
- mov rsp, ASM_PFX(AppRsp)\r
+ movq ASM_PFX(AppRsp), %rsp \r
\r
## We're outa here...\r
iret\r