1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 /* Implement shared vtbl methods. */
7 
8 #include "xptcprivate.h"
9 
10 #if defined(sparc) || defined(__sparc__)
11 
12 extern "C" nsresult ATTRIBUTE_USED
PrepareAndDispatch(nsXPTCStubBase * self,uint32_t methodIndex,uint32_t * args)13 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint32_t* args)
14 {
15 
16     typedef struct {
17         uint32_t hi;
18         uint32_t lo;
19     } DU;               // have to move 64 bit entities as 32 bit halves since
20                         // stack slots are not guaranteed 16 byte aligned
21 
22 
23     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
24     const nsXPTInterfaceInfo* iface_info = nullptr;
25     const nsXPTMethodInfo* info;
26     uint8_t paramCount;
27     uint8_t i;
28 
29     NS_ASSERTION(self,"no self");
30 
31     self->GetInterfaceInfo(&iface_info);
32     NS_ASSERTION(iface_info,"no interface info");
33 
34     iface_info->GetMethodInfo(uint16_t(methodIndex), &info);
35     NS_ASSERTION(info,"no interface info");
36 
37     paramCount = info->GetParamCount();
38 
39     uint32_t* ap = args;
40     for(i = 0; i < paramCount; i++, ap++)
41     {
42         const nsXPTParamInfo& param = info->GetParam(i);
43         const nsXPTType& type = param.GetType();
44         nsXPTCMiniVariant* dp = &paramBuffer[i];
45 
46         if(param.IsOut() || !type.IsArithmetic())
47         {
48             if (type == nsXPTType::T_JSVAL)
49                 dp->val.p = *((void**) *ap);
50             else
51                 dp->val.p = (void*) *ap;
52             continue;
53         }
54         // else
55         switch(type)
56         {
57         case nsXPTType::T_I8     : dp->val.i8  = *((int32_t*) ap);       break;
58         case nsXPTType::T_I16    : dp->val.i16 = *((int32_t*) ap);       break;
59         case nsXPTType::T_I32    : dp->val.i32 = *((int32_t*) ap);       break;
60         case nsXPTType::T_DOUBLE :
61         case nsXPTType::T_U64    :
62         case nsXPTType::T_I64    : ((DU *)dp)->hi = ((DU *)ap)->hi;
63                                    ((DU *)dp)->lo = ((DU *)ap)->lo;
64                                    ap++;
65                                    break;
66         case nsXPTType::T_U8     : dp->val.u8  = *((uint32_t*)ap);       break;
67         case nsXPTType::T_U16    : dp->val.u16 = *((uint32_t*)ap);       break;
68         case nsXPTType::T_U32    : dp->val.u32 = *((uint32_t*)ap);       break;
69         case nsXPTType::T_FLOAT  : dp->val.f   = *((float*)   ap);       break;
70         case nsXPTType::T_BOOL   : dp->val.b   = *((uint32_t*)ap);       break;
71         case nsXPTType::T_CHAR   : dp->val.c   = *((uint32_t*)ap);       break;
72         case nsXPTType::T_WCHAR  : dp->val.wc  = *((int32_t*) ap);       break;
73         default:
74             NS_ERROR("bad type");
75             break;
76         }
77     }
78 
79     nsresult result = self->CallMethod((uint16_t)methodIndex, info,
80                                        paramBuffer);
81 
82     return result;
83 }
84 
85 extern "C" nsresult SharedStub(int, int*);
86 
87 #define STUB_ENTRY(n) \
88 nsresult nsXPTCStubBase::Stub##n() \
89 { \
90 	int dummy; /* defeat tail-call optimization */ \
91 	return SharedStub(n, &dummy); \
92 }
93 
94 #define SENTINEL_ENTRY(n) \
95 nsresult nsXPTCStubBase::Sentinel##n() \
96 { \
97     NS_ERROR("nsXPTCStubBase::Sentinel called"); \
98     return NS_ERROR_NOT_IMPLEMENTED; \
99 }
100 
101 #include "xptcstubsdef.inc"
102 
103 #endif /* sparc || __sparc__ */
104