LibreOffice Module bridges (master) 1
callvirtualfunction.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <sal/config.h>
21
22#include <cstring>
23
24#include <sal/types.h>
25#include <sal/alloca.h>
26
28
30 unsigned long function, unsigned long * gpr, unsigned long * fpr,
31 unsigned long * stack, sal_Int32 sp, void * ret)
32{
33 void * stackargs;
34 if (sp != 0) {
35 stackargs = alloca(((sp + 1) >> 1) * 16);
36 std::memcpy(stackargs, stack, sp * 8);
37 }
38 asm volatile(
39 "ldp x0, x1, [%[gpr_]]\n\t"
40 "ldp x2, x3, [%[gpr_], #16]\n\t"
41 "ldp x4, x5, [%[gpr_], #32]\n\t"
42 "ldp x6, x7, [%[gpr_], #48]\n\t"
43 "ldr x8, %[ret_]\n\t"
44 "ldr x9, %[function_]\n\t"
45 "ldp d0, d1, [%[fpr_]]\n\t"
46 "ldp d2, d3, [%[fpr_], #16]\n\t"
47 "ldp d4, d5, [%[fpr_], #32]\n\t"
48 "ldp d6, d7, [%[fpr_], #48]\n\t"
49 "blr x9\n\t"
50 "stp x0, x1, [%[gpr_]]\n\t"
51 "stp d0, d1, [%[fpr_]]\n\t"
52 "stp d2, d3, [%[fpr_], #16]\n\t"
53 :: [gpr_]"r" (gpr), [fpr_]"r" (fpr), [function_]"m" (function),
54 [ret_]"m" (ret),
55 "m" (stackargs) // dummy input to prevent optimizing the alloca away
56 : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",
57 "r11", "r12", "r13", "r14", "r15", "r16", "r17",
58#if !defined ANDROID && !defined MACOSX
59 "r18"/*TODO?*/,
60#endif
61 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11",
62 "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21",
63 "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
64 "memory"
65 // only the bottom 64 bits of v8--15 need to be preserved by callees
66 );
67}
68
69/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void callVirtualFunction(unsigned long function, unsigned long *gpr, unsigned long *fpr, unsigned long *stack, sal_Int32 sp, void *ret)