161dff127SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
361dff127SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
461dff127SAndrew Rist * or more contributor license agreements. See the NOTICE file
561dff127SAndrew Rist * distributed with this work for additional information
661dff127SAndrew Rist * regarding copyright ownership. The ASF licenses this file
761dff127SAndrew Rist * to you under the Apache License, Version 2.0 (the
861dff127SAndrew Rist * "License"); you may not use this file except in compliance
961dff127SAndrew Rist * with the License. You may obtain a copy of the License at
1061dff127SAndrew Rist *
1161dff127SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1261dff127SAndrew Rist *
1361dff127SAndrew Rist * Unless required by applicable law or agreed to in writing,
1461dff127SAndrew Rist * software distributed under the License is distributed on an
1561dff127SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1661dff127SAndrew Rist * KIND, either express or implied. See the License for the
1761dff127SAndrew Rist * specific language governing permissions and limitations
1861dff127SAndrew Rist * under the License.
1961dff127SAndrew Rist *
2061dff127SAndrew Rist *************************************************************/
2161dff127SAndrew Rist
2261dff127SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_bridges.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.hxx>
28cdf0e10cSrcweir #include <uno/data.h>
29cdf0e10cSrcweir #include <typelib/typedescription.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "bridges/cpp_uno/shared/bridge.hxx"
32cdf0e10cSrcweir #include "bridges/cpp_uno/shared/cppinterfaceproxy.hxx"
33cdf0e10cSrcweir #include "bridges/cpp_uno/shared/types.hxx"
34cdf0e10cSrcweir #include "bridges/cpp_uno/shared/vtablefactory.hxx"
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include "share.hxx"
37cdf0e10cSrcweir #include <stdio.h>
38cdf0e10cSrcweir
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir
41cdf0e10cSrcweir namespace
42cdf0e10cSrcweir {
cpp2uno_call(bridges::cpp_uno::shared::CppInterfaceProxy * pThis,const typelib_TypeDescription * pMemberTypeDescr,typelib_TypeDescriptionReference * pReturnTypeRef,sal_Int32 nParams,typelib_MethodParameter * pParams,void ** gpreg,void ** fpreg,void ** ovrflw,sal_Int64 * pRegisterReturn)43cdf0e10cSrcweir static typelib_TypeClass cpp2uno_call(
44cdf0e10cSrcweir bridges::cpp_uno::shared::CppInterfaceProxy * pThis,
45cdf0e10cSrcweir const typelib_TypeDescription * pMemberTypeDescr,
46cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return
47cdf0e10cSrcweir sal_Int32 nParams, typelib_MethodParameter * pParams,
48cdf0e10cSrcweir void ** gpreg, void ** fpreg, void ** ovrflw,
49cdf0e10cSrcweir sal_Int64 * pRegisterReturn /* space for register return */ )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir #ifdef CMC_DEBUG
52cdf0e10cSrcweir fprintf(stderr, "as far as cpp2uno_call\n");
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir int ng = 0; //number of gpr registers used
55cdf0e10cSrcweir int nf = 0; //number of fpr regsiters used
56cdf0e10cSrcweir
57cdf0e10cSrcweir // gpreg: [ret *], this, [gpr params]
58cdf0e10cSrcweir // fpreg: [fpr params]
59cdf0e10cSrcweir // ovrflw: [gpr or fpr params (properly aligned)]
60cdf0e10cSrcweir
61cdf0e10cSrcweir // return
62cdf0e10cSrcweir typelib_TypeDescription * pReturnTypeDescr = 0;
63cdf0e10cSrcweir if (pReturnTypeRef)
64cdf0e10cSrcweir TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
65cdf0e10cSrcweir
66cdf0e10cSrcweir void * pUnoReturn = 0;
67cdf0e10cSrcweir void * pCppReturn = 0; // complex return ptr: if != 0 && != pUnoReturn, reconversion need
68cdf0e10cSrcweir
69cdf0e10cSrcweir if (pReturnTypeDescr)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
72cdf0e10cSrcweir {
73cdf0e10cSrcweir pUnoReturn = pRegisterReturn; // direct way for simple types
74cdf0e10cSrcweir }
75cdf0e10cSrcweir else // complex return via ptr (pCppReturn)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir pCppReturn = *(void **)gpreg;
78cdf0e10cSrcweir gpreg++;
79cdf0e10cSrcweir ng++;
80cdf0e10cSrcweir
81cdf0e10cSrcweir pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
82cdf0e10cSrcweir ? alloca( pReturnTypeDescr->nSize )
83cdf0e10cSrcweir : pCppReturn); // direct way
84cdf0e10cSrcweir }
85cdf0e10cSrcweir }
86cdf0e10cSrcweir // pop this
87cdf0e10cSrcweir gpreg++;
88cdf0e10cSrcweir ng++;
89cdf0e10cSrcweir
90cdf0e10cSrcweir // stack space
91cdf0e10cSrcweir OSL_ENSURE( sizeof(void *) == sizeof(sal_Int64), "### unexpected size!" );
92cdf0e10cSrcweir // parameters
93cdf0e10cSrcweir void ** pUnoArgs = (void **)alloca( 4 * sizeof(void *) * nParams );
94cdf0e10cSrcweir void ** pCppArgs = pUnoArgs + nParams;
95cdf0e10cSrcweir // indizes of values this have to be converted (interface conversion cpp<=>uno)
96cdf0e10cSrcweir sal_Int32 * pTempIndizes = (sal_Int32 *)(pUnoArgs + (2 * nParams));
97cdf0e10cSrcweir // type descriptions for reconversions
98cdf0e10cSrcweir typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pUnoArgs + (3 * nParams));
99cdf0e10cSrcweir
100cdf0e10cSrcweir sal_Int32 nTempIndizes = 0;
101cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir const typelib_MethodParameter & rParam = pParams[nPos];
104cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = 0;
105cdf0e10cSrcweir TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
106cdf0e10cSrcweir
107cdf0e10cSrcweir #ifdef CMC_DEBUG
108cdf0e10cSrcweir fprintf(stderr, "arg %d of %d\n", nPos, nParams);
109cdf0e10cSrcweir #endif
110cdf0e10cSrcweir
111cdf0e10cSrcweir if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr )) // value
112cdf0e10cSrcweir {
113cdf0e10cSrcweir #ifdef CMC_DEBUG
114cdf0e10cSrcweir fprintf(stderr, "simple\n");
115cdf0e10cSrcweir #endif
116cdf0e10cSrcweir
117cdf0e10cSrcweir switch (pParamTypeDescr->eTypeClass)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
120cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
121cdf0e10cSrcweir if (nf < s390x::MAX_SSE_REGS)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir if (pParamTypeDescr->eTypeClass == typelib_TypeClass_FLOAT)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir float tmp = (float) (*((double *)fpreg));
126cdf0e10cSrcweir (*((float *) fpreg)) = tmp;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = fpreg++;
130cdf0e10cSrcweir nf++;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir else
133cdf0e10cSrcweir {
134cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
135cdf0e10cSrcweir ovrflw++;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir break;
138cdf0e10cSrcweir case typelib_TypeClass_BYTE:
139cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
140cdf0e10cSrcweir if (ng < s390x::MAX_GPR_REGS)
141cdf0e10cSrcweir {
142cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + (sizeof(void*)-1));
143cdf0e10cSrcweir ng++;
144cdf0e10cSrcweir gpreg++;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir else
147cdf0e10cSrcweir {
148cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + (sizeof(void*)-1));
149cdf0e10cSrcweir ovrflw++;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir break;
152cdf0e10cSrcweir case typelib_TypeClass_CHAR:
153cdf0e10cSrcweir case typelib_TypeClass_SHORT:
154cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
155cdf0e10cSrcweir if (ng < s390x::MAX_GPR_REGS)
156cdf0e10cSrcweir {
157cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + (sizeof(void*)-2));
158cdf0e10cSrcweir ng++;
159cdf0e10cSrcweir gpreg++;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir else
162cdf0e10cSrcweir {
163cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + (sizeof(void*)-2));
164cdf0e10cSrcweir ovrflw++;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir break;
167cdf0e10cSrcweir case typelib_TypeClass_ENUM:
168cdf0e10cSrcweir case typelib_TypeClass_LONG:
169cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG:
170cdf0e10cSrcweir if (ng < s390x::MAX_GPR_REGS)
171cdf0e10cSrcweir {
172cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + (sizeof(void*)-4));
173cdf0e10cSrcweir ng++;
174cdf0e10cSrcweir gpreg++;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir else
177cdf0e10cSrcweir {
178cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + (sizeof(void*)-4));
179cdf0e10cSrcweir ovrflw++;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir break;
182cdf0e10cSrcweir default:
183cdf0e10cSrcweir if (ng < s390x::MAX_GPR_REGS)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = gpreg++;
186cdf0e10cSrcweir ng++;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir else
189cdf0e10cSrcweir {
190cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
191cdf0e10cSrcweir ovrflw++;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir break;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
196cdf0e10cSrcweir // no longer needed
197cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
198cdf0e10cSrcweir }
199cdf0e10cSrcweir else // ptr to complex value | ref
200cdf0e10cSrcweir {
201cdf0e10cSrcweir #ifdef CMC_DEBUG
202cdf0e10cSrcweir fprintf(stderr, "complex, ng is %d\n", ng);
203cdf0e10cSrcweir #endif
204cdf0e10cSrcweir
205cdf0e10cSrcweir void *pCppStack; //temporary stack pointer
206cdf0e10cSrcweir
207cdf0e10cSrcweir if (ng < s390x::MAX_GPR_REGS)
208cdf0e10cSrcweir {
209cdf0e10cSrcweir pCppArgs[nPos] = pCppStack = *gpreg++;
210cdf0e10cSrcweir ng++;
211cdf0e10cSrcweir }
212cdf0e10cSrcweir else
213cdf0e10cSrcweir {
214cdf0e10cSrcweir pCppArgs[nPos] = pCppStack = *ovrflw;
215cdf0e10cSrcweir ovrflw++;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir if (! rParam.bIn) // is pure out
219cdf0e10cSrcweir {
220cdf0e10cSrcweir // uno out is unconstructed mem!
221cdf0e10cSrcweir pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
222cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos;
223cdf0e10cSrcweir // will be released at reconversion
224cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir // is in/inout
227cdf0e10cSrcweir else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
228cdf0e10cSrcweir {
229cdf0e10cSrcweir uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ),
230cdf0e10cSrcweir pCppStack, pParamTypeDescr,
231cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
232cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
233cdf0e10cSrcweir // will be released at reconversion
234cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir else // direct way
237cdf0e10cSrcweir {
238cdf0e10cSrcweir pUnoArgs[nPos] = pCppStack;
239cdf0e10cSrcweir // no longer needed
240cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
241cdf0e10cSrcweir }
242cdf0e10cSrcweir }
243cdf0e10cSrcweir }
244cdf0e10cSrcweir
245cdf0e10cSrcweir #ifdef CMC_DEBUG
246cdf0e10cSrcweir fprintf(stderr, "end of params\n");
247cdf0e10cSrcweir #endif
248cdf0e10cSrcweir
249cdf0e10cSrcweir // ExceptionHolder
250cdf0e10cSrcweir uno_Any aUnoExc; // Any will be constructed by callee
251cdf0e10cSrcweir uno_Any * pUnoExc = &aUnoExc;
252cdf0e10cSrcweir
253cdf0e10cSrcweir // invoke uno dispatch call
254cdf0e10cSrcweir (*pThis->getUnoI()->pDispatcher)( pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
255cdf0e10cSrcweir
256*07a3d7f1SPedro Giffuni // in case an exception occurred...
257cdf0e10cSrcweir if (pUnoExc)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir // destruct temporary in/inout params
260cdf0e10cSrcweir for ( ; nTempIndizes--; )
261cdf0e10cSrcweir {
262cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
263cdf0e10cSrcweir
264cdf0e10cSrcweir if (pParams[nIndex].bIn) // is in/inout => was constructed
265cdf0e10cSrcweir uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], 0 );
266cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
267cdf0e10cSrcweir }
268cdf0e10cSrcweir if (pReturnTypeDescr)
269cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
270cdf0e10cSrcweir
271cdf0e10cSrcweir CPPU_CURRENT_NAMESPACE::raiseException( &aUnoExc, pThis->getBridge()->getUno2Cpp() ); // has to destruct the any
272cdf0e10cSrcweir // is here for dummy
273cdf0e10cSrcweir return typelib_TypeClass_VOID;
274cdf0e10cSrcweir }
275*07a3d7f1SPedro Giffuni else // else no exception occurred...
276cdf0e10cSrcweir {
277cdf0e10cSrcweir // temporary params
278cdf0e10cSrcweir for ( ; nTempIndizes--; )
279cdf0e10cSrcweir {
280cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
281cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
282cdf0e10cSrcweir
283cdf0e10cSrcweir if (pParams[nIndex].bOut) // inout/out
284cdf0e10cSrcweir {
285cdf0e10cSrcweir // convert and assign
286cdf0e10cSrcweir uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
287cdf0e10cSrcweir uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex], pParamTypeDescr,
288cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
289cdf0e10cSrcweir }
290cdf0e10cSrcweir // destroy temp uno param
291cdf0e10cSrcweir uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
292cdf0e10cSrcweir
293cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
294cdf0e10cSrcweir }
295cdf0e10cSrcweir // return
296cdf0e10cSrcweir if (pCppReturn) // has complex return
297cdf0e10cSrcweir {
298cdf0e10cSrcweir if (pUnoReturn != pCppReturn) // needs reconversion
299cdf0e10cSrcweir {
300cdf0e10cSrcweir uno_copyAndConvertData( pCppReturn, pUnoReturn, pReturnTypeDescr,
301cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
302cdf0e10cSrcweir // destroy temp uno return
303cdf0e10cSrcweir uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
304cdf0e10cSrcweir }
305cdf0e10cSrcweir // complex return ptr is set to return reg
306cdf0e10cSrcweir *(void **)pRegisterReturn = pCppReturn;
307cdf0e10cSrcweir }
308cdf0e10cSrcweir if (pReturnTypeDescr)
309cdf0e10cSrcweir {
310cdf0e10cSrcweir typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
311cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
312cdf0e10cSrcweir return eRet;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir else
315cdf0e10cSrcweir return typelib_TypeClass_VOID;
316cdf0e10cSrcweir }
317cdf0e10cSrcweir }
318cdf0e10cSrcweir
319cdf0e10cSrcweir
320cdf0e10cSrcweir //============================================================================
cpp_mediate(sal_uInt64 nOffsetAndIndex,void ** gpreg,void ** fpreg,void ** ovrflw,sal_Int64 * pRegisterReturn)321cdf0e10cSrcweir static typelib_TypeClass cpp_mediate(
322cdf0e10cSrcweir sal_uInt64 nOffsetAndIndex,
323cdf0e10cSrcweir void ** gpreg, void ** fpreg, void ** ovrflw,
324cdf0e10cSrcweir sal_Int64 * pRegisterReturn /* space for register return */ )
325cdf0e10cSrcweir {
326cdf0e10cSrcweir OSL_ENSURE( sizeof(sal_Int64)==sizeof(void *), "### unexpected!" );
327cdf0e10cSrcweir
328cdf0e10cSrcweir sal_Int32 nVtableOffset = (nOffsetAndIndex >> 32);
329cdf0e10cSrcweir sal_Int32 nFunctionIndex = (nOffsetAndIndex & 0xFFFFFFFF);
330cdf0e10cSrcweir
331cdf0e10cSrcweir #ifdef CMC_DEBUG
332cdf0e10cSrcweir fprintf(stderr, "nVTableOffset, nFunctionIndex are %x %x\n", nVtableOffset, nFunctionIndex);
333cdf0e10cSrcweir #endif
334cdf0e10cSrcweir
335cdf0e10cSrcweir #ifdef CMC_DEBUG
336cdf0e10cSrcweir // Let's figure out what is really going on here
337cdf0e10cSrcweir {
338cdf0e10cSrcweir fprintf( stderr, "= cpp_mediate () =\nGPR's (%d): ", 5 );
339cdf0e10cSrcweir for ( unsigned int i = 0; i < 5; ++i )
340cdf0e10cSrcweir fprintf( stderr, "0x%lx, ", gpreg[i] );
341cdf0e10cSrcweir fprintf( stderr, "\n");
342cdf0e10cSrcweir fprintf( stderr, "\nFPR's (%d): ", 4 );
343cdf0e10cSrcweir for ( unsigned int i = 0; i < 4; ++i )
344cdf0e10cSrcweir fprintf( stderr, "0x%lx (%f), ", fpreg[i], fpreg[i] );
345cdf0e10cSrcweir fprintf( stderr, "\n");
346cdf0e10cSrcweir }
347cdf0e10cSrcweir #endif
348cdf0e10cSrcweir
349cdf0e10cSrcweir
350cdf0e10cSrcweir // gpreg: [ret *], this, [other gpr params]
351cdf0e10cSrcweir // fpreg: [fpr params]
352cdf0e10cSrcweir // ovrflw: [gpr or fpr params (properly aligned)]
353cdf0e10cSrcweir
354cdf0e10cSrcweir // _this_ ptr is patched cppu_XInterfaceProxy object
355cdf0e10cSrcweir void * pThis;
356cdf0e10cSrcweir if( nFunctionIndex & 0x80000000 )
357cdf0e10cSrcweir {
358cdf0e10cSrcweir nFunctionIndex &= 0x7fffffff;
359cdf0e10cSrcweir pThis = gpreg[1];
360cdf0e10cSrcweir }
361cdf0e10cSrcweir else
362cdf0e10cSrcweir {
363cdf0e10cSrcweir pThis = gpreg[0];
364cdf0e10cSrcweir }
365cdf0e10cSrcweir
366cdf0e10cSrcweir pThis = static_cast< char * >(pThis) - nVtableOffset;
367cdf0e10cSrcweir
368cdf0e10cSrcweir bridges::cpp_uno::shared::CppInterfaceProxy * pCppI
369cdf0e10cSrcweir = bridges::cpp_uno::shared::CppInterfaceProxy::castInterfaceToProxy(
370cdf0e10cSrcweir pThis);
371cdf0e10cSrcweir
372cdf0e10cSrcweir typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
373cdf0e10cSrcweir
374cdf0e10cSrcweir
375cdf0e10cSrcweir OSL_ENSURE( nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex, "### illegal vtable index!" );
376cdf0e10cSrcweir if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
377cdf0e10cSrcweir {
378cdf0e10cSrcweir throw RuntimeException(
379cdf0e10cSrcweir rtl::OUString::createFromAscii("illegal vtable index!"),
380cdf0e10cSrcweir (XInterface *)pCppI );
381cdf0e10cSrcweir }
382cdf0e10cSrcweir
383cdf0e10cSrcweir // determine called method
384cdf0e10cSrcweir OSL_ENSURE( nVtableCall < pTypeDescr->nMapFunctionIndexToMemberIndex, "### illegal vtable index!" );
385cdf0e10cSrcweir sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
386cdf0e10cSrcweir OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### illegal member index!" );
387cdf0e10cSrcweir
388cdf0e10cSrcweir TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
389cdf0e10cSrcweir
390cdf0e10cSrcweir typelib_TypeClass eRet;
391cdf0e10cSrcweir switch (aMemberDescr.get()->eTypeClass)
392cdf0e10cSrcweir {
393cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
394cdf0e10cSrcweir {
395cdf0e10cSrcweir if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
396cdf0e10cSrcweir {
397cdf0e10cSrcweir // is GET method
398cdf0e10cSrcweir eRet = cpp2uno_call(
399cdf0e10cSrcweir pCppI, aMemberDescr.get(),
400cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
401cdf0e10cSrcweir 0, 0, // no params
402cdf0e10cSrcweir gpreg, fpreg, ovrflw, pRegisterReturn );
403cdf0e10cSrcweir }
404cdf0e10cSrcweir else
405cdf0e10cSrcweir {
406cdf0e10cSrcweir // is SET method
407cdf0e10cSrcweir typelib_MethodParameter aParam;
408cdf0e10cSrcweir aParam.pTypeRef =
409cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
410cdf0e10cSrcweir aParam.bIn = sal_True;
411cdf0e10cSrcweir aParam.bOut = sal_False;
412cdf0e10cSrcweir
413cdf0e10cSrcweir eRet = cpp2uno_call(
414cdf0e10cSrcweir pCppI, aMemberDescr.get(),
415cdf0e10cSrcweir 0, // indicates void return
416cdf0e10cSrcweir 1, &aParam,
417cdf0e10cSrcweir gpreg, fpreg, ovrflw, pRegisterReturn );
418cdf0e10cSrcweir }
419cdf0e10cSrcweir break;
420cdf0e10cSrcweir }
421cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
422cdf0e10cSrcweir {
423cdf0e10cSrcweir // is METHOD
424cdf0e10cSrcweir switch (nFunctionIndex)
425cdf0e10cSrcweir {
426cdf0e10cSrcweir case 1: // acquire()
427cdf0e10cSrcweir pCppI->acquireProxy(); // non virtual call!
428cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
429cdf0e10cSrcweir break;
430cdf0e10cSrcweir case 2: // release()
431cdf0e10cSrcweir pCppI->releaseProxy(); // non virtual call!
432cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
433cdf0e10cSrcweir break;
434cdf0e10cSrcweir case 0: // queryInterface() opt
435cdf0e10cSrcweir {
436cdf0e10cSrcweir typelib_TypeDescription * pTD = 0;
437cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( gpreg[2] )->getTypeLibType() );
438cdf0e10cSrcweir if (pTD)
439cdf0e10cSrcweir {
440cdf0e10cSrcweir XInterface * pInterface = 0;
441cdf0e10cSrcweir (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
442cdf0e10cSrcweir pCppI->getBridge()->getCppEnv(),
443cdf0e10cSrcweir (void **)&pInterface, pCppI->getOid().pData,
444cdf0e10cSrcweir (typelib_InterfaceTypeDescription *)pTD );
445cdf0e10cSrcweir
446cdf0e10cSrcweir if (pInterface)
447cdf0e10cSrcweir {
448cdf0e10cSrcweir ::uno_any_construct(
449cdf0e10cSrcweir reinterpret_cast< uno_Any * >( gpreg[0] ),
450cdf0e10cSrcweir &pInterface, pTD, cpp_acquire );
451cdf0e10cSrcweir pInterface->release();
452cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
453cdf0e10cSrcweir *(void **)pRegisterReturn = gpreg[0];
454cdf0e10cSrcweir eRet = typelib_TypeClass_ANY;
455cdf0e10cSrcweir break;
456cdf0e10cSrcweir }
457cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
458cdf0e10cSrcweir }
459cdf0e10cSrcweir } // else perform queryInterface()
460cdf0e10cSrcweir default:
461cdf0e10cSrcweir eRet = cpp2uno_call(
462cdf0e10cSrcweir pCppI, aMemberDescr.get(),
463cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
464cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
465cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
466cdf0e10cSrcweir gpreg, fpreg, ovrflw, pRegisterReturn );
467cdf0e10cSrcweir }
468cdf0e10cSrcweir break;
469cdf0e10cSrcweir }
470cdf0e10cSrcweir default:
471cdf0e10cSrcweir {
472cdf0e10cSrcweir throw RuntimeException(
473cdf0e10cSrcweir rtl::OUString::createFromAscii("no member description found!"),
474cdf0e10cSrcweir (XInterface *)pCppI );
475cdf0e10cSrcweir // is here for dummy
476cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
477cdf0e10cSrcweir }
478cdf0e10cSrcweir }
479cdf0e10cSrcweir
480cdf0e10cSrcweir return eRet;
481cdf0e10cSrcweir }
482cdf0e10cSrcweir
privateSnippetExecutor(long r2,long r3,long r4,long r5,long r6,long firstonstack)483cdf0e10cSrcweir long privateSnippetExecutor(long r2, long r3, long r4, long r5, long r6, long firstonstack)
484cdf0e10cSrcweir {
485cdf0e10cSrcweir register long r0 asm("r0");
486cdf0e10cSrcweir sal_uInt64 nOffsetAndIndex = r0;
487cdf0e10cSrcweir
488cdf0e10cSrcweir long sp = (long)&firstonstack;
489cdf0e10cSrcweir
490cdf0e10cSrcweir sal_uInt64 gpreg[s390x::MAX_GPR_REGS];
491cdf0e10cSrcweir gpreg[0] = r2;
492cdf0e10cSrcweir gpreg[1] = r3;
493cdf0e10cSrcweir gpreg[2] = r4;
494cdf0e10cSrcweir gpreg[3] = r5;
495cdf0e10cSrcweir gpreg[4] = r6;
496cdf0e10cSrcweir
497cdf0e10cSrcweir double fpreg[s390x::MAX_SSE_REGS];
498cdf0e10cSrcweir register double f0 asm("f0"); fpreg[0] = f0;
499cdf0e10cSrcweir register double f2 asm("f2"); fpreg[1] = f2;
500cdf0e10cSrcweir register double f4 asm("f4"); fpreg[2] = f4;
501cdf0e10cSrcweir register double f6 asm("f6"); fpreg[3] = f6;
502cdf0e10cSrcweir
503cdf0e10cSrcweir volatile long nRegReturn[1];
504cdf0e10cSrcweir #ifdef CMC_DEBUG
505cdf0e10cSrcweir fprintf(stderr, "before mediate with %lx\n",nOffsetAndIndex);
506cdf0e10cSrcweir fprintf(stderr, "doubles are %f %f %f %f\n", fpreg[0], fpreg[1], fpreg[2], fpreg[3]);
507cdf0e10cSrcweir #endif
508cdf0e10cSrcweir typelib_TypeClass aType =
509cdf0e10cSrcweir cpp_mediate( nOffsetAndIndex, (void**)gpreg, (void**)fpreg, (void**)sp,
510cdf0e10cSrcweir (sal_Int64*)nRegReturn );
511cdf0e10cSrcweir #ifdef CMC_DEBUG
512cdf0e10cSrcweir fprintf(stderr, "after mediate ret is %lx %ld\n", nRegReturn[0], nRegReturn[0]);
513cdf0e10cSrcweir #endif
514cdf0e10cSrcweir
515cdf0e10cSrcweir switch( aType )
516cdf0e10cSrcweir {
517cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
518cdf0e10cSrcweir case typelib_TypeClass_BYTE:
519cdf0e10cSrcweir nRegReturn[0] = (unsigned long)(*(unsigned char *)nRegReturn);
520cdf0e10cSrcweir break;
521cdf0e10cSrcweir case typelib_TypeClass_CHAR:
522cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
523cdf0e10cSrcweir case typelib_TypeClass_SHORT:
524cdf0e10cSrcweir nRegReturn[0] = (unsigned long)(*(unsigned short *)nRegReturn);
525cdf0e10cSrcweir break;
526cdf0e10cSrcweir case typelib_TypeClass_ENUM:
527cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG:
528cdf0e10cSrcweir case typelib_TypeClass_LONG:
529cdf0e10cSrcweir nRegReturn[0] = (unsigned long)(*(unsigned int *)nRegReturn);
530cdf0e10cSrcweir break;
531cdf0e10cSrcweir case typelib_TypeClass_VOID:
532cdf0e10cSrcweir default:
533cdf0e10cSrcweir break;
534cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
535cdf0e10cSrcweir {
536cdf0e10cSrcweir double tmp = (double) (*((float *)nRegReturn));
537cdf0e10cSrcweir (*((double *) nRegReturn)) = tmp;
538cdf0e10cSrcweir }
539cdf0e10cSrcweir //deliberate fall through
540cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
541cdf0e10cSrcweir __asm__ ( "ld 0,%0\n\t"
542cdf0e10cSrcweir : : "m" (*((double*)nRegReturn)) );
543cdf0e10cSrcweir break;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir return nRegReturn[0];
546cdf0e10cSrcweir }
547cdf0e10cSrcweir
548cdf0e10cSrcweir const int codeSnippetSize = 32;
549cdf0e10cSrcweir
codeSnippet(unsigned char * code,sal_Int32 nFunctionIndex,sal_Int32 nVtableOffset,bool simple_ret_type)550cdf0e10cSrcweir unsigned char *codeSnippet( unsigned char * code, sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset, bool simple_ret_type )
551cdf0e10cSrcweir {
552cdf0e10cSrcweir sal_uInt64 nOffsetAndIndex = ( ( (sal_uInt64) nVtableOffset ) << 32 ) | ( (sal_Int64) nFunctionIndex );
553cdf0e10cSrcweir
554cdf0e10cSrcweir if (! simple_ret_type)
555cdf0e10cSrcweir nOffsetAndIndex |= 0x80000000;
556cdf0e10cSrcweir
557cdf0e10cSrcweir unsigned char * p = code;
558cdf0e10cSrcweir *(short *)&p[0] = 0x0d10; /* basr %r1,0 */
559cdf0e10cSrcweir *(short *)&p[2] = 0xeb01; /* lmg %r0,%r1,14(%r1) */
560cdf0e10cSrcweir *(short *)&p[4] = 0x100e;
561cdf0e10cSrcweir *(short *)&p[6] = 0x0004;
562cdf0e10cSrcweir *(short *)&p[8] = 0x07f1; /* br %r1 */
563cdf0e10cSrcweir *(long *)&p[16] = (long)nOffsetAndIndex;
564cdf0e10cSrcweir *(long *)&p[24] = (long)&privateSnippetExecutor;
565cdf0e10cSrcweir return (code + codeSnippetSize);
566cdf0e10cSrcweir }
567cdf0e10cSrcweir }
568cdf0e10cSrcweir
flushCode(unsigned char const *,unsigned char const *)569cdf0e10cSrcweir void bridges::cpp_uno::shared::VtableFactory::flushCode(unsigned char const *, unsigned char const *)
570cdf0e10cSrcweir {
571cdf0e10cSrcweir }
572cdf0e10cSrcweir
573cdf0e10cSrcweir struct bridges::cpp_uno::shared::VtableFactory::Slot { void * fn; };
574cdf0e10cSrcweir
575cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot *
mapBlockToVtable(void * block)576cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::mapBlockToVtable(void * block)
577cdf0e10cSrcweir {
578cdf0e10cSrcweir return static_cast< Slot * >(block) + 2;
579cdf0e10cSrcweir }
580cdf0e10cSrcweir
getBlockSize(sal_Int32 slotCount)581cdf0e10cSrcweir sal_Size bridges::cpp_uno::shared::VtableFactory::getBlockSize(
582cdf0e10cSrcweir sal_Int32 slotCount)
583cdf0e10cSrcweir {
584cdf0e10cSrcweir return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
585cdf0e10cSrcweir }
586cdf0e10cSrcweir
587cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot *
initializeBlock(void * block,sal_Int32 slotCount)588cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::initializeBlock(
589cdf0e10cSrcweir void * block, sal_Int32 slotCount)
590cdf0e10cSrcweir {
591cdf0e10cSrcweir Slot * slots = mapBlockToVtable(block);
592cdf0e10cSrcweir slots[-2].fn = 0;
593cdf0e10cSrcweir slots[-1].fn = 0;
594cdf0e10cSrcweir return slots + slotCount;
595cdf0e10cSrcweir }
596cdf0e10cSrcweir
addLocalFunctions(Slot ** slots,unsigned char * code,sal_PtrDiff writetoexecdiff,typelib_InterfaceTypeDescription const * type,sal_Int32 functionOffset,sal_Int32 functionCount,sal_Int32 vtableOffset)597cdf0e10cSrcweir unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
598cdf0e10cSrcweir Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
599cdf0e10cSrcweir typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
600cdf0e10cSrcweir sal_Int32 functionCount, sal_Int32 vtableOffset)
601cdf0e10cSrcweir {
602cdf0e10cSrcweir (*slots) -= functionCount;
603cdf0e10cSrcweir Slot * s = *slots;
604cdf0e10cSrcweir #ifdef CMC_DEBUG
605cdf0e10cSrcweir fprintf(stderr, "in addLocalFunctions functionOffset is %x\n",functionOffset);
606cdf0e10cSrcweir fprintf(stderr, "in addLocalFunctions vtableOffset is %x\n",vtableOffset);
607cdf0e10cSrcweir #endif
608cdf0e10cSrcweir
609cdf0e10cSrcweir for (sal_Int32 i = 0; i < type->nMembers; ++i) {
610cdf0e10cSrcweir typelib_TypeDescription * member = 0;
611cdf0e10cSrcweir TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
612cdf0e10cSrcweir OSL_ASSERT(member != 0);
613cdf0e10cSrcweir switch (member->eTypeClass) {
614cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
615cdf0e10cSrcweir // Getter:
616cdf0e10cSrcweir (s++)->fn = code + writetoexecdiff;
617cdf0e10cSrcweir code = codeSnippet(
618cdf0e10cSrcweir code, functionOffset++, vtableOffset,
619cdf0e10cSrcweir bridges::cpp_uno::shared::isSimpleType(
620cdf0e10cSrcweir reinterpret_cast<
621cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription * >(
622cdf0e10cSrcweir member)->pAttributeTypeRef));
623cdf0e10cSrcweir
624cdf0e10cSrcweir // Setter:
625cdf0e10cSrcweir if (!reinterpret_cast<
626cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription * >(
627cdf0e10cSrcweir member)->bReadOnly)
628cdf0e10cSrcweir {
629cdf0e10cSrcweir (s++)->fn = code + writetoexecdiff;
630cdf0e10cSrcweir code = codeSnippet(code, functionOffset++, vtableOffset, true);
631cdf0e10cSrcweir }
632cdf0e10cSrcweir break;
633cdf0e10cSrcweir
634cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
635cdf0e10cSrcweir (s++)->fn = code + writetoexecdiff;
636cdf0e10cSrcweir code = codeSnippet(
637cdf0e10cSrcweir code, functionOffset++, vtableOffset,
638cdf0e10cSrcweir bridges::cpp_uno::shared::isSimpleType(
639cdf0e10cSrcweir reinterpret_cast<
640cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription * >(
641cdf0e10cSrcweir member)->pReturnTypeRef));
642cdf0e10cSrcweir break;
643cdf0e10cSrcweir
644cdf0e10cSrcweir default:
645cdf0e10cSrcweir OSL_ASSERT(false);
646cdf0e10cSrcweir break;
647cdf0e10cSrcweir }
648cdf0e10cSrcweir TYPELIB_DANGER_RELEASE(member);
649cdf0e10cSrcweir }
650cdf0e10cSrcweir return code;
651cdf0e10cSrcweir }
652cdf0e10cSrcweir
653cdf0e10cSrcweir /* vi:set tabstop=4 shiftwidth=4 expandtab: */
654