Remove ".intel_syntax", convert MASM to GAS.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9059 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
gikidy 2009-08-12 09:10:42 +00:00
parent e5d1b4f48b
commit 7b8c3785dc
1 changed files with 240 additions and 242 deletions

View File

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