"Fossies" - the Fresh Open Source Software Archive

Member "AutoHotkey_L-1.1.33.09/source/libx64call/x64call.asm" (8 May 2021, 3112 Bytes) of package /windows/misc/AutoHotkey_L-1.1.33.09.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Generic Assembler source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 ;///////////////////////////////////////////////////////////////////////
    2 ;
    3 ;   Windows x64 dynamic function call
    4 ;   Code adapted from http://www.dyncall.org/
    5 ;
    6 ;///////////////////////////////////////////////////////////////////////
    7 
    8 ;//////////////////////////////////////////////////////////////////////////////
    9 ;
   10 ; Copyright (c) 2007-2009 Daniel Adler <dadler@uni-goettingen.de>, 
   11 ;                         Tassilo Philipp <tphilipp@potion-studios.com>
   12 ;
   13 ; Permission to use, copy, modify, and distribute this software for any
   14 ; purpose with or without fee is hereby granted, provided that the above
   15 ; copyright notice and this permission notice appear in all copies.
   16 ;
   17 ; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   18 ; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   19 ; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   20 ; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   21 ; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   22 ; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   23 ; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   24 ;
   25 ;//////////////////////////////////////////////////////////////////////////////
   26 
   27 .code
   28 
   29 PerformDynaCall proc frame
   30     option prologue:none, epilogue:none
   31 
   32     ; Arguments:
   33     ; rcx: size of arguments to be passed via stack
   34     ; rdx: pointer to arguments to be passed via stack
   35     ; r8:  pointer to arguments to be passed by registers
   36     ; r9:  target function pointer
   37 
   38     ; Save some registers
   39     push rbp
   40 .pushreg rbp
   41     push rsi
   42 .pushreg rsi
   43     push rdi
   44 .pushreg rdi
   45 
   46     ; Save the stack pointer
   47     mov rbp, rsp
   48 .setframe rbp, 0
   49 .endprolog
   50 
   51     ; Setup stack frame by subtracting the size of the arguments
   52     sub rsp, rcx
   53 
   54     ; Ensure the stack is 16-byte aligned
   55     mov rax, rcx
   56     and rax, 15
   57     mov rsi, 16
   58     sub rsi, rax
   59     sub rsp, rsi
   60 
   61     ; Save function address
   62     mov rax, r9
   63 
   64     ; Copy the stack arguments
   65     mov rsi, rdx ; let rsi point to the arguments.
   66     mov rdi, rsp ; store pointer to beginning of stack arguments in rdi (for rep movsb).
   67     rep movsb    ; @@@ should be optimized (e.g. movq)
   68 
   69     ; Copy the register arguments
   70     mov rcx,  qword ptr[r8   ] ; copy first four arguments to rcx, rdx, r8, r9 and xmm0-xmm3.
   71     mov rdx,  qword ptr[r8+ 8]
   72     mov r9,   qword ptr[r8+24] ; set r9 first to not overwrite r8 too soon.
   73     mov r8,   qword ptr[r8+16]
   74     movd xmm0, rcx
   75     movd xmm1, rdx
   76     movd xmm2, r8
   77     movd xmm3, r9
   78 
   79     ; Call function
   80     sub rsp, 8*4 ; spill area
   81     call rax
   82 
   83     ; Restore stack pointer
   84     ;mov rsp, rbp   ; Although mov works too, MSDN says "add RSP,constant or lea RSP,constant[FPReg]" must be used for exception-handling to work reliably. http://msdn.microsoft.com/en-us/library/tawsa7cb.aspx
   85     lea rsp, [rbp]
   86 
   87     ; Restore some registers and return
   88     pop rdi
   89     pop rsi
   90     pop rbp
   91     ret
   92 PerformDynaCall endp
   93 
   94 read_xmm0_float proc
   95     option prologue:none, epilogue:none
   96     ; Nothing is actually done here - we just declare the appropriate return type in C++.
   97     ret
   98 read_xmm0_float endp
   99 
  100 read_xmm0_double proc
  101     option prologue:none, epilogue:none
  102     ; See above.
  103     ret
  104 read_xmm0_double endp
  105 
  106 end