1
2 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
8 /* Implement shared vtbl methods. */
9
10 #include "xptcprivate.h"
11
12 #if _HPUX
13 #error "This code is for HP-PA RISC 32 bit mode only"
14 #endif
15
16 extern "C" nsresult ATTRIBUTE_USED
PrepareAndDispatch(nsXPTCStubBase * self,uint32_t methodIndex,uint32_t * args,uint32_t * floatargs)17 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex,
18 uint32_t* args, uint32_t* floatargs)
19 {
20
21 typedef struct {
22 uint32_t hi;
23 uint32_t lo;
24 } DU;
25
26
27 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
28 const nsXPTMethodInfo* info;
29 int32_t regwords = 1; /* self pointer is not in the variant records */
30 uint8_t paramCount;
31 uint8_t i;
32
33 NS_ASSERTION(self,"no self");
34
35 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
36 NS_ASSERTION(info,"no method info");
37 if (!info)
38 return NS_ERROR_UNEXPECTED;
39
40 paramCount = info->GetParamCount();
41
42 const uint8_t indexOfJSContext = info->IndexOfJSContext();
43
44 for(i = 0; i < paramCount; ++i, --args)
45 {
46 const nsXPTParamInfo& param = info->GetParam(i);
47 const nsXPTType& type = param.GetType();
48 nsXPTCMiniVariant* dp = ¶mBuffer[i];
49
50 MOZ_CRASH("NYI: support implicit JSContext*, bug 1475699");
51
52 if(param.IsOut() || !type.IsArithmetic())
53 {
54 dp->val.p = (void*) *args;
55 ++regwords;
56 continue;
57 }
58 switch(type)
59 {
60 case nsXPTType::T_I8 : dp->val.i8 = *((int32_t*) args); break;
61 case nsXPTType::T_I16 : dp->val.i16 = *((int32_t*) args); break;
62 case nsXPTType::T_I32 : dp->val.i32 = *((int32_t*) args); break;
63 case nsXPTType::T_DOUBLE :
64 if (regwords & 1)
65 {
66 ++regwords; /* align on double word */
67 --args;
68 }
69 if (regwords == 0 || regwords == 2)
70 {
71 dp->val.d=*((double*) (floatargs + regwords));
72 --args;
73 }
74 else
75 {
76 dp->val.d = *((double*) --args);
77 }
78 regwords += 2;
79 continue;
80 case nsXPTType::T_U64 :
81 case nsXPTType::T_I64 :
82 if (regwords & 1)
83 {
84 ++regwords; /* align on double word */
85 --args;
86 }
87 ((DU *)dp)->lo = *((uint32_t*) args);
88 ((DU *)dp)->hi = *((uint32_t*) --args);
89 regwords += 2;
90 continue;
91 case nsXPTType::T_FLOAT :
92 if (regwords >= 4)
93 dp->val.f = *((float*) args);
94 else
95 dp->val.f = *((float*) floatargs+4+regwords);
96 break;
97 case nsXPTType::T_U8 : dp->val.u8 = *((uint32_t*) args); break;
98 case nsXPTType::T_U16 : dp->val.u16 = *((uint32_t*) args); break;
99 case nsXPTType::T_U32 : dp->val.u32 = *((uint32_t*) args); break;
100 case nsXPTType::T_BOOL : dp->val.b = *((uint32_t*) args); break;
101 case nsXPTType::T_CHAR : dp->val.c = *((uint32_t*) args); break;
102 case nsXPTType::T_WCHAR : dp->val.wc = *((int32_t*) args); break;
103 default:
104 NS_ERROR("bad type");
105 break;
106 }
107 ++regwords;
108 }
109
110 nsresult result = self->mOuter->CallMethod((uint16_t) methodIndex, info,
111 paramBuffer);
112
113 return result;
114 }
115
116 extern "C" nsresult SharedStub(int);
117
118 #ifdef __GNUC__
119 #define STUB_ENTRY(n) \
120 nsresult nsXPTCStubBase::Stub##n() \
121 { \
122 /* Save arg0 in its stack slot. This assumes the frame size is 64. */ \
123 __asm__ __volatile__ ("STW %r26, -36-64(%sp)"); \
124 return SharedStub(n); \
125 }
126 #else
127 #define STUB_ENTRY(n) \
128 nsresult nsXPTCStubBase::Stub##n() \
129 { \
130 return SharedStub(n); \
131 }
132 #endif
133
134 #define SENTINEL_ENTRY(n) \
135 nsresult nsXPTCStubBase::Sentinel##n() \
136 { \
137 NS_ERROR("nsXPTCStubBase::Sentinel called"); \
138 return NS_ERROR_NOT_IMPLEMENTED; \
139 }
140
141 #include "xptcstubsdef.inc"
142