xpcom/reflect/xptcall/src/md/win32/xptcinvoke_asm_x86_64.asm

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 ; This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 ; License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 ; file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 extrn invoke_copy_to_stack:PROC
michael@0 6
michael@0 7
michael@0 8 .CODE
michael@0 9
michael@0 10 ;
michael@0 11 ;XPTC__InvokebyIndex(nsISupports* that, uint32_t methodIndex,
michael@0 12 ; uint32_t paramCount, nsXPTCVariant* params)
michael@0 13 ;
michael@0 14
michael@0 15 XPTC__InvokebyIndex PROC FRAME
michael@0 16
michael@0 17 ; store register parameters
michael@0 18
michael@0 19 mov qword ptr [rsp+32], r9 ; params
michael@0 20 mov dword ptr [rsp+24], r8d ; paramCount
michael@0 21 mov dword ptr [rsp+16], edx ; methodIndex
michael@0 22 mov qword ptr [rsp+8], rcx ; that
michael@0 23
michael@0 24 push rbp
michael@0 25 .PUSHREG rbp
michael@0 26 mov rbp, rsp ; store current RSP to RBP
michael@0 27 .SETFRAME rbp, 0
michael@0 28 .ENDPROLOG
michael@0 29
michael@0 30 sub rsp, 32
michael@0 31
michael@0 32 ; maybe we don't have any parameters to copy
michael@0 33
michael@0 34 test r8d, r8d
michael@0 35 jz noparams
michael@0 36
michael@0 37 ;
michael@0 38 ; Build stack for stdcall
michael@0 39 ;
michael@0 40
michael@0 41 ; 1st parameter is space for parameters
michael@0 42
michael@0 43 mov eax, r8d
michael@0 44 or eax, 1
michael@0 45 shl rax, 3 ; *= 8
michael@0 46 sub rsp, rax
michael@0 47 mov rcx, rsp
michael@0 48
michael@0 49 ; 2nd parameter is parameter count
michael@0 50
michael@0 51 mov edx, r8d
michael@0 52
michael@0 53 ; 3rd parameter is params
michael@0 54
michael@0 55 mov r8, r9
michael@0 56
michael@0 57 sub rsp, 40
michael@0 58 call invoke_copy_to_stack ; rcx = d
michael@0 59 ; edx = paramCount
michael@0 60 ; r8 = s
michael@0 61 add rsp, 32
michael@0 62
michael@0 63 ; Current stack is the following.
michael@0 64 ;
michael@0 65 ; 0h: [space (for this)]
michael@0 66 ; 8h: [1st parameter]
michael@0 67 ; 10h: [2nd parameter]
michael@0 68 ; 18h: [3rd parameter]
michael@0 69 ; 20h: [4th parameter]
michael@0 70 ; ...
michael@0 71 ;
michael@0 72 ; On Win64 ABI, the first 4 parameters are passed using registers,
michael@0 73 ; and others are on stack.
michael@0 74
michael@0 75 ; 1st, 2nd and 3rd arguments are passed via registers
michael@0 76
michael@0 77 mov rdx, qword ptr [rsp+8] ; 1st parameter
michael@0 78 movsd xmm1, qword ptr [rsp+8] ; for double
michael@0 79
michael@0 80 mov r8, qword ptr [rsp+16] ; 2nd parameter
michael@0 81 movsd xmm2, qword ptr [rsp+16] ; for double
michael@0 82
michael@0 83 mov r9, qword ptr [rsp+24] ; 3rd parameter
michael@0 84 movsd xmm3, qword ptr [rsp+24] ; for double
michael@0 85
michael@0 86 ; rcx register is this
michael@0 87
michael@0 88 mov rcx, qword ptr [rbp+8+8] ; that
michael@0 89
michael@0 90 noparams:
michael@0 91
michael@0 92 ; calculate call address
michael@0 93
michael@0 94 mov r11, qword ptr [rcx]
michael@0 95 mov eax, dword ptr [rbp+16+8] ; methodIndex
michael@0 96
michael@0 97 call qword ptr [r11+rax*8] ; stdcall, i.e. callee cleans up stack.
michael@0 98
michael@0 99 mov rsp, rbp
michael@0 100 pop rbp
michael@0 101
michael@0 102 ret
michael@0 103
michael@0 104 XPTC__InvokebyIndex ENDP
michael@0 105
michael@0 106
michael@0 107 END

mercurial