LibreOffice Module bridges (master)  1
gcc3_linux_hppa/call.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 <malloc.h>
21 #include <rtl/alloc.h>
22 
23 #include <com/sun/star/uno/genfunc.hxx>
24 #include "com/sun/star/uno/RuntimeException.hpp"
25 #include <uno/data.h>
26 
27 #include <bridge.hxx>
28 #include <types.hxx>
29 #include <unointerfaceproxy.hxx>
30 #include <vtables.hxx>
31 
32 #include "share.hxx"
33 
34 #include <stdio.h>
35 #include <string.h>
36 
37 using namespace ::com::sun::star::uno;
38 
39 void MapReturn(sal_uInt32 ret0, sal_uInt32 ret1, typelib_TypeDescription *pReturnTypeDescr, bool bRegisterReturn, sal_uInt32 *pRegisterReturn)
40 {
41  register float fret asm("fr4");
42  register double dret asm("fr4");
43 
44  switch (pReturnTypeDescr->eTypeClass)
45  {
46  case typelib_TypeClass_HYPER:
47  case typelib_TypeClass_UNSIGNED_HYPER:
48  pRegisterReturn[1] = ret1;
49  case typelib_TypeClass_LONG:
50  case typelib_TypeClass_UNSIGNED_LONG:
51  case typelib_TypeClass_ENUM:
52  case typelib_TypeClass_CHAR:
53  case typelib_TypeClass_SHORT:
54  case typelib_TypeClass_UNSIGNED_SHORT:
55  case typelib_TypeClass_BOOLEAN:
56  case typelib_TypeClass_BYTE:
57  pRegisterReturn[0] = ret0;
58  break;
59  case typelib_TypeClass_FLOAT:
60  *(float*)pRegisterReturn = fret;
61  break;
62  case typelib_TypeClass_DOUBLE:
63  *(double*)pRegisterReturn = dret;
64  break;
65  case typelib_TypeClass_STRUCT:
66  case typelib_TypeClass_EXCEPTION:
67  {
68  if (bRegisterReturn)
69  {
70  pRegisterReturn[0] = ret0;
71  pRegisterReturn[1] = ret1;
72  }
73  break;
74  }
75  default:
76  break;
77  }
78 }
79 
80 //Moved callVirtual into this .cxx so that I can do this and get gcc to not
81 //touch r28 without having to learn any more pa-risc assembly than is
82 //strictly necessary
83 register sal_uInt32 r28 __asm__("%r28");
84 
85 void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
86  void * pRegisterReturn, typelib_TypeDescription *pReturnTypeDescr, bool bRegisterReturn,
87  sal_uInt32 *pStack, sal_uInt32 nStack, sal_uInt32 *pGPR, double *pFPR) __attribute__((noinline));
88 
89 void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
90  void * pRegisterReturn, typelib_TypeDescription *pReturnTypeDescr, bool bRegisterReturn,
91  sal_uInt32 *pStack, sal_uInt32 nStack, sal_uInt32 *pGPR, double *pFPR)
92 {
93  register sal_uInt32* sp __asm__("%r30");
94 
95  sal_uInt32 pMethod = *((sal_uInt32*)pThis);
96  pMethod += 4 * nVtableIndex;
97  pMethod = *((sal_uInt32 *)pMethod);
98 
99 #if OSL_DEBUG_LEVEL > 2
100  fprintf(stderr, "this is %p\n", pGPR[0]);
101  for (int i = 0; i < hppa::MAX_GPR_REGS ; ++i)
102  fprintf(stderr, "normal reg %d is %d %x\n", i, pGPR[i], pGPR[i]);
103 
104  for (int i = 0; i < hppa::MAX_SSE_REGS ; ++i)
105  fprintf(stderr, "float reg %d is %x\n", i, pFPR[i]);
106 
107  for (int i = 0; i < nStack; ++i)
108  fprintf(stderr, "stack bytes are %x\n", pStack[i]);
109 #endif
110 
111  //Always reserve 4 slots, and align to 8 bytes
112  sal_uInt32 nStackBytes = ( ( nStack + 4 + 1 ) >> 1 ) * 8;
113  __builtin_alloca(nStackBytes);
114  sal_uInt32 *stack = sp-8;
115  int o = -5;
116  for (sal_uInt32 i = 0; i < nStack; ++i, --o)
117  stack[o] = pStack[i];
118 
119  typedef int (* FunctionCall )( sal_uInt32, sal_uInt32, sal_uInt32, sal_uInt32 );
120  FunctionCall pFunc = (FunctionCall)pMethod;
121 
122  asm volatile("fldd %0, %%fr4" : : "m"(pFPR[0]) : "fr4");
123  asm volatile("fldd %0, %%fr5" : : "m"(pFPR[1]) : "fr5");
124  asm volatile("fldd %0, %%fr6" : : "m"(pFPR[2]) : "fr6");
125  asm volatile("fldd %0, %%fr7" : : "m"(pFPR[3]) : "fr7");
126  asm volatile("ldw %0, %%r28" : : "m"(pRegisterReturn) : "r28");
127  (*pFunc)(pGPR[0], pGPR[1], pGPR[2], pGPR[3]);
128 
129  register sal_uInt32 r29 __asm__("%r29");
130  MapReturn(r28, r29, pReturnTypeDescr, bRegisterReturn, (sal_uInt32*)pRegisterReturn);
131 }
132 
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
void MapReturn(sal_uInt32 ret0, sal_uInt32 ret1, typelib_TypeDescription *pReturnTypeDescr, bool bRegisterReturn, sal_uInt32 *pRegisterReturn)
void callVirtualMethod(void *pThis, sal_uInt32 nVtableIndex, void *pRegisterReturn, typelib_TypeDescription *pReturnTypeDescr, bool bRegisterReturn, sal_uInt32 *pStack, sal_uInt32 nStack, sal_uInt32 *pGPR, double *pFPR) __attribute__((noinline))
unsigned _Unwind_Word __attribute__((__mode__(__word__)))
Definition: unwind-cxx.h:45
int i
struct _typelib_TypeDescription typelib_TypeDescription
Definition: msvc/except.hxx:52
register sal_uInt32 r28 __asm__("%r28")