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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/reflect/xptcall/src/md/win32/xptcinvoke_asm_x86_64.asm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     1.4 +; This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +; License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +; file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +extrn invoke_copy_to_stack:PROC
     1.9 +
    1.10 +
    1.11 +.CODE
    1.12 +
    1.13 +;
    1.14 +;XPTC__InvokebyIndex(nsISupports* that, uint32_t methodIndex,
    1.15 +;                   uint32_t paramCount, nsXPTCVariant* params)
    1.16 +;
    1.17 +
    1.18 +XPTC__InvokebyIndex PROC FRAME
    1.19 +
    1.20 +   ; store register parameters
    1.21 +
    1.22 +    mov     qword ptr [rsp+32], r9        ; params
    1.23 +    mov     dword ptr [rsp+24], r8d       ; paramCount
    1.24 +    mov     dword ptr [rsp+16], edx       ; methodIndex
    1.25 +    mov     qword ptr [rsp+8], rcx        ; that
    1.26 +
    1.27 +    push    rbp
    1.28 +    .PUSHREG rbp
    1.29 +    mov     rbp, rsp            ; store current RSP to RBP
    1.30 +    .SETFRAME rbp, 0
    1.31 +    .ENDPROLOG
    1.32 +
    1.33 +    sub     rsp, 32
    1.34 +
    1.35 +    ; maybe we don't have any parameters to copy
    1.36 +
    1.37 +    test    r8d, r8d
    1.38 +    jz      noparams
    1.39 +
    1.40 +    ;
    1.41 +    ; Build stack for stdcall
    1.42 +    ;
    1.43 +
    1.44 +    ; 1st parameter is space for parameters
    1.45 +
    1.46 +    mov     eax, r8d
    1.47 +    or      eax, 1
    1.48 +    shl     rax, 3              ; *= 8
    1.49 +    sub     rsp, rax
    1.50 +    mov     rcx, rsp
    1.51 +
    1.52 +    ; 2nd parameter is parameter count
    1.53 +
    1.54 +    mov     edx, r8d
    1.55 +
    1.56 +    ; 3rd parameter is params
    1.57 +
    1.58 +    mov     r8, r9
    1.59 +
    1.60 +    sub     rsp, 40
    1.61 +    call    invoke_copy_to_stack ; rcx = d
    1.62 +                                 ; edx = paramCount
    1.63 +                                 ; r8  = s
    1.64 +    add     rsp, 32
    1.65 +
    1.66 +    ; Current stack is the following.
    1.67 +    ;
    1.68 +    ;  0h: [space (for this)]
    1.69 +    ;  8h: [1st parameter]
    1.70 +    ; 10h: [2nd parameter]
    1.71 +    ; 18h: [3rd parameter]
    1.72 +    ; 20h: [4th parameter]
    1.73 +    ; ...
    1.74 +    ;
    1.75 +    ; On Win64 ABI, the first 4 parameters are passed using registers,
    1.76 +    ; and others are on stack. 
    1.77 +
    1.78 +    ; 1st, 2nd and 3rd arguments are passed via registers
    1.79 +
    1.80 +    mov     rdx, qword ptr [rsp+8] ; 1st parameter
    1.81 +    movsd   xmm1, qword ptr [rsp+8] ; for double
    1.82 +
    1.83 +    mov     r8, qword ptr [rsp+16] ; 2nd parameter
    1.84 +    movsd   xmm2, qword ptr [rsp+16] ; for double
    1.85 +
    1.86 +    mov     r9, qword ptr [rsp+24] ; 3rd parameter
    1.87 +    movsd   xmm3, qword ptr [rsp+24] ; for double
    1.88 +
    1.89 +    ; rcx register is this
    1.90 +
    1.91 +    mov     rcx, qword ptr [rbp+8+8] ; that
    1.92 +
    1.93 +noparams:
    1.94 +
    1.95 +    ; calculate call address
    1.96 +
    1.97 +    mov     r11, qword ptr [rcx]
    1.98 +    mov     eax, dword ptr [rbp+16+8] ; methodIndex
    1.99 +
   1.100 +    call    qword ptr [r11+rax*8]      ; stdcall, i.e. callee cleans up stack.
   1.101 +
   1.102 +    mov     rsp, rbp
   1.103 +    pop     rbp
   1.104 +
   1.105 +    ret
   1.106 +
   1.107 +XPTC__InvokebyIndex ENDP
   1.108 +
   1.109 +
   1.110 +END

mercurial