1 ; -*- Mode: text; tab-width: 8; indent-tabs-mode: nil comment-column: 44; comment-start: ";; " comment-start-skip: ";; *" -*-
3 ;; Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 ;; The contents of this file are subject to the Mozilla Public License Version
6 ;; 1.1 (the "License"); you may not use this file except in compliance with
7 ;; the License or as specified alternatively below. You may obtain a copy of
8 ;; the License at http://www.mozilla.org/MPL/
10 ;; Software distributed under the License is distributed on an "AS IS" basis,
11 ;; WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 ;; for the specific language governing rights and limitations under the
15 ;; The Initial Developer of the Original Code is
17 ;; Portions created by the Initial Developer are Copyright (C) 2011
18 ;; Novell, Inc. All Rights Reserved.
20 ;; Major Contributor(s):
21 ;; Tor Lillqvist <tml@iki.fi>
22 ;; Portions created by Tor Lillqvist are Copyright (C) 2011 Tor Lillqvist. All Rights Reserved.
24 ;; For minor contributions see the git repository.
26 ;; Alternatively, the contents of this file may be used under the terms of
27 ;; either the GNU General Public License Version 3 or later (the "GPLv3+"), or
28 ;; the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
29 ;; in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
30 ;; instead of those above.
32 ;; This is the function jumped to from the trampoline generated by
33 ;; codeSnippet() in cpp2uno.cxx. Here we call cpp_vtable_call() which
34 ;; then calls the actual UNO function.
36 ;; The code snippet generated is called from "normal" C++ code which
37 ;; has no idea that it is calling dynamically generated code.
39 ;; The generated short code snippet is not covered by any function
40 ;; table and unwind info, but that doesn't matter, as the instructions
41 ;; in it are not really going to cause any exception. Once it jumps
42 ;; here it is covered by a function table, and the calls further down
43 ;; through cpp_vtable_call() can be unwound cleanly.
45 ;; This is in a separate file for x86-64 as MSVC doesn't have in-line
48 ;; Random web links and other documentation about low-level
49 ;; implementation details for the C++/UNO bridge on x64 Windows kept
52 ;; Caolan's "Lazy Hackers Guide To Porting" is useful:
53 ;; http://wiki.services.openoffice.org/wiki/Lazy_Hackers_Guide_To_Porting
55 ;; As for details about the x64 Windows calling convention, register
56 ;; usage, stack usage, exception handling etc, the official
57 ;; documentation (?) on MSDN is a bit fragmented and split up into a
58 ;; needlessly large number of short pages. But still:
59 ;; http://msdn.microsoft.com/en-us/library/7kcdt6fy%28v=VS.90%29.aspx
61 ;; Also see Raymond Chen's blog post:
62 ;; http://blogs.msdn.com/b/oldnewthing/archive/2004/01/14/58579.aspx
64 ;; This one is actually more readable: "Improving Automated Analysis
65 ;; of Windows x64 Binaries": http://www.uninformed.org/?v=4&a=1
67 ;; This one has a mass of information about different architectures
68 ;; and compilers, and contains some details about the x64 Windows
69 ;; calling convention in particular that Microsoft doesn't mention
71 ;; http://www.agner.org/optimize/calling_conventions.pdf
73 ;; Random interesting discussion threads:
74 ;; http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/300bd6d3-9381-4d2d-8129-e48b392c05d8
76 ;; Ken Johnson's blog http://www.nynaeve.net/ has much interesting
77 ;; information, for instance:
78 ;; http://www.nynaeve.net/?p=11
80 typelib_TypeClass_FLOAT
equ 10
81 typelib_TypeClass_DOUBLE
equ 11
83 extern
cpp_vtable_call: proc
87 privateSnippetExecutor
proc frame
89 ;; Make stack frame. Re-align RSP at 16 bytes. We need just one
90 ;; qword of stack for our own purposes: Where cpp_vtable_call()
91 ;; will store the return value of the UNO callee. But we of course
92 ;; must also allocate space for the functions we call (i.e., just
93 ;; cpp_vtable_call()) to spill their register parameters.
99 ;; Call cpp_vtable_call() with 2 parameters:
101 ;; 1 (rcx): nOffsetAndIndex (already put there in code generated by codeSnippet)
102 ;; 2 (rdx): pointer to where to store return value, followed by our
103 ;; return address (uninteresting to cpp_vtable_call()), followed
104 ;; by our spilled register parameters, as stored above, followed
105 ;; by the rest of our parameters, if any.
111 ;; cpp_vtable_call() returns the typelib_TypeClass type of the
112 ;; return value of the called UNO function
114 cmp rax
, typelib_TypeClass_FLOAT
117 cmp rax
, typelib_TypeClass_DOUBLE
120 mov rax
, qword ptr 32[rsp
]
124 movsd xmm0
, qword ptr 32[rsp
]
129 privateSnippetExecutor
endp
133 ; vim:set shiftwidth=4 softtabstop=4 expandtab: