1 ; -*- Mode: text; tab-width: 8; indent-tabs-mode: nil comment-column: 44; comment-start: ";; " comment-start-skip: ";; *" -*-
4 ;; This file is part of the LibreOffice project.
6 ;; This Source Code Form is subject to the terms of the Mozilla Public
7 ;; License, v. 2.0. If a copy of the MPL was not distributed with this
8 ;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 ;; This is the function jumped to from the trampoline generated by
12 ;; codeSnippet() in cpp2uno.cxx. Here we call cpp_vtable_call() which
13 ;; then calls the actual UNO function.
15 ;; The code snippet generated is called from "normal" C++ code which
16 ;; has no idea that it is calling dynamically generated code.
18 ;; The generated short code snippet is not covered by any function
19 ;; table and unwind info, but that doesn't matter, as the instructions
20 ;; in it are not really going to cause any exception. Once it jumps
21 ;; here it is covered by a function table, and the calls further down
22 ;; through cpp_vtable_call() can be unwound cleanly.
24 ;; This is in a separate file for x86-64 as MSVC doesn't have in-line
27 ;; Random web links and other documentation about low-level
28 ;; implementation details for the C++/UNO bridge on x64 Windows kept
31 ;; Caolan's "Lazy Hackers Guide To Porting" is useful:
32 ;; http://wiki.openoffice.org/wiki/Lazy_Hackers_Guide_To_Porting
34 ;; As for details about the x64 Windows calling convention, register
35 ;; usage, stack usage, exception handling etc, the official
36 ;; documentation (?) on MSDN is a bit fragmented and split up into a
37 ;; needlessly large number of short pages. But still:
38 ;; http://msdn.microsoft.com/en-us/library/7kcdt6fy%28v=VS.90%29.aspx
40 ;; Also see Raymond Chen's blog post:
41 ;; http://blogs.msdn.com/b/oldnewthing/archive/2004/01/14/58579.aspx
43 ;; This one is actually more readable: "Improving Automated Analysis
44 ;; of Windows x64 Binaries": http://www.uninformed.org/?v=4&a=1
46 ;; This one has a mass of information about different architectures
47 ;; and compilers, and contains some details about the x64 Windows
48 ;; calling convention in particular that Microsoft doesn't mention
50 ;; http://www.agner.org/optimize/calling_conventions.pdf
52 ;; Random interesting discussion threads:
53 ;; http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/300bd6d3-9381-4d2d-8129-e48b392c05d8
55 ;; Ken Johnson's blog http://www.nynaeve.net/ has much interesting
56 ;; information, for instance:
57 ;; http://www.nynaeve.net/?p=11
59 typelib_TypeClass_FLOAT
equ 10
60 typelib_TypeClass_DOUBLE
equ 11
62 extern
cpp_vtable_call: proc
66 privateSnippetExecutor
proc frame
68 ;; Make stack frame. Re-align RSP at 16 bytes. We need just one
69 ;; qword of stack for our own purposes: Where cpp_vtable_call()
70 ;; will store the return value of the UNO callee. But we of course
71 ;; must also allocate space for the functions we call (i.e., just
72 ;; cpp_vtable_call()) to spill their register parameters.
78 ;; Call cpp_vtable_call() with 2 parameters:
80 ;; 1 (rcx): nOffsetAndIndex (already put there in code generated by codeSnippet)
81 ;; 2 (rdx): pointer to where to store return value, followed by our
82 ;; return address (uninteresting to cpp_vtable_call()), followed
83 ;; by our spilled register parameters, as stored above, followed
84 ;; by the rest of our parameters, if any.
90 ;; cpp_vtable_call() returns the typelib_TypeClass type of the
91 ;; return value of the called UNO function
93 cmp rax
, typelib_TypeClass_FLOAT
96 cmp rax
, typelib_TypeClass_DOUBLE
99 mov rax
, qword ptr 32[rsp
]
103 movsd xmm0
, qword ptr 32[rsp
]
108 privateSnippetExecutor
endp
112 ; vim:set shiftwidth=4 softtabstop=4 expandtab: