1*61dff127SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*61dff127SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*61dff127SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*61dff127SAndrew Rist  * distributed with this work for additional information
6*61dff127SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*61dff127SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*61dff127SAndrew Rist  * "License"); you may not use this file except in compliance
9*61dff127SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*61dff127SAndrew Rist  *
11*61dff127SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*61dff127SAndrew Rist  *
13*61dff127SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*61dff127SAndrew Rist  * software distributed under the License is distributed on an
15*61dff127SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*61dff127SAndrew Rist  * KIND, either express or implied.  See the License for the
17*61dff127SAndrew Rist  * specific language governing permissions and limitations
18*61dff127SAndrew Rist  * under the License.
19*61dff127SAndrew Rist  *
20*61dff127SAndrew Rist  *************************************************************/
21*61dff127SAndrew Rist 
22*61dff127SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include <malloc.h>
25cdf0e10cSrcweir #include <rtl/alloc.h>
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.hxx>
28cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
29cdf0e10cSrcweir #include <uno/data.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <bridges/cpp_uno/shared/bridge.hxx>
32cdf0e10cSrcweir #include <bridges/cpp_uno/shared/types.hxx>
33cdf0e10cSrcweir #include <bridges/cpp_uno/shared/unointerfaceproxy.hxx>
34cdf0e10cSrcweir #include <bridges/cpp_uno/shared/vtables.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "share.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <stdio.h>
39cdf0e10cSrcweir #include <string.h>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using namespace ::rtl;
42cdf0e10cSrcweir using namespace ::com::sun::star::uno;
43cdf0e10cSrcweir 
MapReturn(sal_uInt32 ret0,sal_uInt32 ret1,typelib_TypeDescription * pReturnTypeDescr,bool bRegisterReturn,sal_uInt32 * pRegisterReturn)44cdf0e10cSrcweir void MapReturn(sal_uInt32 ret0, sal_uInt32 ret1, typelib_TypeDescription *pReturnTypeDescr, bool bRegisterReturn, sal_uInt32 *pRegisterReturn)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     register float fret asm("fr4");
47cdf0e10cSrcweir     register double dret asm("fr4");
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     switch (pReturnTypeDescr->eTypeClass)
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         case typelib_TypeClass_HYPER:
52cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_HYPER:
53cdf0e10cSrcweir             pRegisterReturn[1] = ret1;
54cdf0e10cSrcweir         case typelib_TypeClass_LONG:
55cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_LONG:
56cdf0e10cSrcweir         case typelib_TypeClass_ENUM:
57cdf0e10cSrcweir         case typelib_TypeClass_CHAR:
58cdf0e10cSrcweir         case typelib_TypeClass_SHORT:
59cdf0e10cSrcweir         case typelib_TypeClass_UNSIGNED_SHORT:
60cdf0e10cSrcweir         case typelib_TypeClass_BOOLEAN:
61cdf0e10cSrcweir         case typelib_TypeClass_BYTE:
62cdf0e10cSrcweir             pRegisterReturn[0] = ret0;
63cdf0e10cSrcweir             break;
64cdf0e10cSrcweir         case typelib_TypeClass_FLOAT:
65cdf0e10cSrcweir             *(float*)pRegisterReturn = fret;
66cdf0e10cSrcweir 	    break;
67cdf0e10cSrcweir         case typelib_TypeClass_DOUBLE:
68cdf0e10cSrcweir             *(double*)pRegisterReturn = dret;
69cdf0e10cSrcweir             break;
70cdf0e10cSrcweir         case typelib_TypeClass_STRUCT:
71cdf0e10cSrcweir         case typelib_TypeClass_EXCEPTION:
72cdf0e10cSrcweir         {
73cdf0e10cSrcweir             if (bRegisterReturn)
74cdf0e10cSrcweir             {
75cdf0e10cSrcweir                 pRegisterReturn[0] = ret0;
76cdf0e10cSrcweir                 pRegisterReturn[1] = ret1;
77cdf0e10cSrcweir             }
78cdf0e10cSrcweir             break;
79cdf0e10cSrcweir         }
80cdf0e10cSrcweir         default:
81cdf0e10cSrcweir             break;
82cdf0e10cSrcweir     }
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir //Moved callVirtual into this .cxx so that I can do this and get gcc to not
86cdf0e10cSrcweir //touch r28 without having to learn any more pa-risc assembly than is
87cdf0e10cSrcweir //strictly necessary
88cdf0e10cSrcweir register sal_uInt32 r28 __asm__("%r28");
89cdf0e10cSrcweir 
90cdf0e10cSrcweir void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
91cdf0e10cSrcweir     void * pRegisterReturn, typelib_TypeDescription *pReturnTypeDescr, bool bRegisterReturn,
92cdf0e10cSrcweir     sal_uInt32 *pStack, sal_uInt32 nStack, sal_uInt32 *pGPR, double *pFPR) __attribute__((noinline));
93cdf0e10cSrcweir 
callVirtualMethod(void * pThis,sal_uInt32 nVtableIndex,void * pRegisterReturn,typelib_TypeDescription * pReturnTypeDescr,bool bRegisterReturn,sal_uInt32 * pStack,sal_uInt32 nStack,sal_uInt32 * pGPR,double * pFPR)94cdf0e10cSrcweir void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
95cdf0e10cSrcweir     void * pRegisterReturn, typelib_TypeDescription *pReturnTypeDescr, bool bRegisterReturn,
96cdf0e10cSrcweir     sal_uInt32 *pStack, sal_uInt32 nStack, sal_uInt32 *pGPR, double *pFPR)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     register sal_uInt32* sp __asm__("%r30");
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     sal_uInt32 pMethod = *((sal_uInt32*)pThis);
101cdf0e10cSrcweir     pMethod += 4 * nVtableIndex;
102cdf0e10cSrcweir     pMethod = *((sal_uInt32 *)pMethod);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir #ifdef CMC_DEBUG
105cdf0e10cSrcweir     fprintf(stderr, "this is %p\n", pGPR[0]);
106cdf0e10cSrcweir     for (int i = 0; i < hppa::MAX_GPR_REGS ; ++i)
107cdf0e10cSrcweir         fprintf(stderr, "normal reg %d is %d %x\n", i, pGPR[i], pGPR[i]);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     for (int i = 0; i < hppa::MAX_SSE_REGS ; ++i)
110cdf0e10cSrcweir         fprintf(stderr, "float reg %d is %x\n", i, pFPR[i]);
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     for (int i = 0; i < nStack; ++i)
113cdf0e10cSrcweir         fprintf(stderr, "stack bytes are %x\n", pStack[i]);
114cdf0e10cSrcweir #endif
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     //Always reserve 4 slots, and align to 8 bytes
117cdf0e10cSrcweir     sal_uInt32 nStackBytes = ( ( nStack + 4 + 1 ) >> 1 ) * 8;
118cdf0e10cSrcweir     __builtin_alloca(nStackBytes);
119cdf0e10cSrcweir     sal_uInt32 *stack = sp-8;
120cdf0e10cSrcweir     int o = -5;
121cdf0e10cSrcweir     for (sal_uInt32 i = 0; i < nStack; ++i, --o)
122cdf0e10cSrcweir         stack[o] = pStack[i];
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     typedef int (* FunctionCall )( sal_uInt32, sal_uInt32, sal_uInt32, sal_uInt32 );
125cdf0e10cSrcweir     FunctionCall pFunc = (FunctionCall)pMethod;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     asm volatile("fldd %0, %%fr4" : : "m"(pFPR[0]) : "fr4");
128cdf0e10cSrcweir     asm volatile("fldd %0, %%fr5" : : "m"(pFPR[1]) : "fr5");
129cdf0e10cSrcweir     asm volatile("fldd %0, %%fr6" : : "m"(pFPR[2]) : "fr6");
130cdf0e10cSrcweir     asm volatile("fldd %0, %%fr7" : : "m"(pFPR[3]) : "fr7");
131cdf0e10cSrcweir     asm volatile("ldw %0, %%r28" : : "m"(pRegisterReturn) : "r28");
132cdf0e10cSrcweir     (*pFunc)(pGPR[0], pGPR[1], pGPR[2], pGPR[3]);
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     register sal_uInt32 r29 __asm__("%r29");
135cdf0e10cSrcweir     MapReturn(r28, r29, pReturnTypeDescr, bRegisterReturn, (sal_uInt32*)pRegisterReturn);
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir /* vi:set tabstop=4 shiftwidth=4 expandtab: */
139