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 nsXPTMethodInfo* info;
25 uint8_t paramCount;
26 uint8_t i;
27
28 NS_ASSERTION(self,"no self");
29
30 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
31 NS_ASSERTION(info,"no interface info");
32
33 paramCount = info->GetParamCount();
34
35 const uint8_t indexOfJSContext = info->IndexOfJSContext();
36
37 uint32_t* ap = args;
38 for(i = 0; i < paramCount; i++, ap++)
39 {
40 const nsXPTParamInfo& param = info->GetParam(i);
41 const nsXPTType& type = param.GetType();
42 nsXPTCMiniVariant* dp = ¶mBuffer[i];
43
44 if (i == indexOfJSContext)
45 ap++;
46
47 if(param.IsOut() || !type.IsArithmetic())
48 {
49 if (type == nsXPTType::T_JSVAL)
50 dp->val.p = *((void**) *ap);
51 else
52 dp->val.p = (void*) *ap;
53 continue;
54 }
55 // else
56 switch(type)
57 {
58 case nsXPTType::T_I8 : dp->val.i8 = *((int32_t*) ap); break;
59 case nsXPTType::T_I16 : dp->val.i16 = *((int32_t*) ap); break;
60 case nsXPTType::T_I32 : dp->val.i32 = *((int32_t*) ap); break;
61 case nsXPTType::T_DOUBLE :
62 case nsXPTType::T_U64 :
63 case nsXPTType::T_I64 : ((DU *)dp)->hi = ((DU *)ap)->hi;
64 ((DU *)dp)->lo = ((DU *)ap)->lo;
65 ap++;
66 break;
67 case nsXPTType::T_U8 : dp->val.u8 = *((uint32_t*)ap); break;
68 case nsXPTType::T_U16 : dp->val.u16 = *((uint32_t*)ap); break;
69 case nsXPTType::T_U32 : dp->val.u32 = *((uint32_t*)ap); break;
70 case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break;
71 case nsXPTType::T_BOOL : dp->val.b = *((uint32_t*)ap); break;
72 case nsXPTType::T_CHAR : dp->val.c = *((uint32_t*)ap); break;
73 case nsXPTType::T_WCHAR : dp->val.wc = *((int32_t*) ap); break;
74 default:
75 NS_ERROR("bad type");
76 break;
77 }
78 }
79
80 nsresult result = self->mOuter->CallMethod((uint16_t)methodIndex, info,
81 paramBuffer);
82
83 return result;
84 }
85
86 extern "C" nsresult SharedStub(int, int*);
87
88 #define STUB_ENTRY(n) \
89 nsresult nsXPTCStubBase::Stub##n() \
90 { \
91 int dummy; /* defeat tail-call optimization */ \
92 return SharedStub(n, &dummy); \
93 }
94
95 #define SENTINEL_ENTRY(n) \
96 nsresult nsXPTCStubBase::Sentinel##n() \
97 { \
98 NS_ERROR("nsXPTCStubBase::Sentinel called"); \
99 return NS_ERROR_NOT_IMPLEMENTED; \
100 }
101
102 #include "xptcstubsdef.inc"
103
104 #endif /* sparc || __sparc__ */
105