|
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 /* Implement shared vtbl methods. */ |
|
8 |
|
9 #include "xptcprivate.h" |
|
10 #include "xptiprivate.h" |
|
11 |
|
12 static nsresult ATTRIBUTE_USED |
|
13 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, |
|
14 uint64_t* a_gpr, uint64_t *a_fpr, uint64_t *a_ov) |
|
15 { |
|
16 #define PARAM_BUFFER_COUNT 16 |
|
17 |
|
18 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; |
|
19 nsXPTCMiniVariant* dispatchParams = nullptr; |
|
20 const nsXPTMethodInfo* info; |
|
21 uint8_t paramCount; |
|
22 uint8_t i; |
|
23 nsresult result = NS_ERROR_FAILURE; |
|
24 |
|
25 NS_ASSERTION(self,"no self"); |
|
26 |
|
27 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); |
|
28 NS_ASSERTION(info,"no info"); |
|
29 |
|
30 paramCount = info->GetParamCount(); |
|
31 |
|
32 // setup variant array pointer |
|
33 if(paramCount > PARAM_BUFFER_COUNT) |
|
34 dispatchParams = new nsXPTCMiniVariant[paramCount]; |
|
35 else |
|
36 dispatchParams = paramBuffer; |
|
37 NS_ASSERTION(dispatchParams,"no place for params"); |
|
38 |
|
39 uint32_t gpr = 1, fpr = 0; |
|
40 |
|
41 for(i = 0; i < paramCount; i++) |
|
42 { |
|
43 const nsXPTParamInfo& param = info->GetParam(i); |
|
44 const nsXPTType& type = param.GetType(); |
|
45 nsXPTCMiniVariant* dp = &dispatchParams[i]; |
|
46 |
|
47 if(param.IsOut() || !type.IsArithmetic()) |
|
48 { |
|
49 if (gpr < 5) |
|
50 dp->val.p = (void*) *a_gpr++, gpr++; |
|
51 else |
|
52 dp->val.p = (void*) *a_ov++; |
|
53 continue; |
|
54 } |
|
55 // else |
|
56 switch(type) |
|
57 { |
|
58 case nsXPTType::T_I8 : |
|
59 if (gpr < 5) |
|
60 dp->val.i8 = *((int64_t*) a_gpr), a_gpr++, gpr++; |
|
61 else |
|
62 dp->val.i8 = *((int64_t*) a_ov ), a_ov++; |
|
63 break; |
|
64 case nsXPTType::T_I16 : |
|
65 if (gpr < 5) |
|
66 dp->val.i16 = *((int64_t*) a_gpr), a_gpr++, gpr++; |
|
67 else |
|
68 dp->val.i16 = *((int64_t*) a_ov ), a_ov++; |
|
69 break; |
|
70 case nsXPTType::T_I32 : |
|
71 if (gpr < 5) |
|
72 dp->val.i32 = *((int64_t*) a_gpr), a_gpr++, gpr++; |
|
73 else |
|
74 dp->val.i32 = *((int64_t*) a_ov ), a_ov++; |
|
75 break; |
|
76 case nsXPTType::T_I64 : |
|
77 if (gpr < 5) |
|
78 dp->val.i64 = *((int64_t*) a_gpr), a_gpr++, gpr++; |
|
79 else |
|
80 dp->val.i64 = *((int64_t*) a_ov ), a_ov++; |
|
81 break; |
|
82 case nsXPTType::T_U8 : |
|
83 if (gpr < 5) |
|
84 dp->val.u8 = *((uint64_t*)a_gpr), a_gpr++, gpr++; |
|
85 else |
|
86 dp->val.u8 = *((uint64_t*)a_ov ), a_ov++; |
|
87 break; |
|
88 case nsXPTType::T_U16 : |
|
89 if (gpr < 5) |
|
90 dp->val.u16 = *((uint64_t*)a_gpr), a_gpr++, gpr++; |
|
91 else |
|
92 dp->val.u16 = *((uint64_t*)a_ov ), a_ov++; |
|
93 break; |
|
94 case nsXPTType::T_U32 : |
|
95 if (gpr < 5) |
|
96 dp->val.u32 = *((uint64_t*)a_gpr), a_gpr++, gpr++; |
|
97 else |
|
98 dp->val.u32 = *((uint64_t*)a_ov ), a_ov++; |
|
99 break; |
|
100 case nsXPTType::T_U64 : |
|
101 if (gpr < 5) |
|
102 dp->val.u64 = *((uint64_t*)a_gpr), a_gpr++, gpr++; |
|
103 else |
|
104 dp->val.u64 = *((uint64_t*)a_ov ), a_ov++; |
|
105 break; |
|
106 case nsXPTType::T_FLOAT : |
|
107 if (fpr < 4) |
|
108 dp->val.f = *((float*) a_fpr), a_fpr++, fpr++; |
|
109 else |
|
110 dp->val.f = *(((float*) a_ov )+1), a_ov++; |
|
111 break; |
|
112 case nsXPTType::T_DOUBLE : |
|
113 if (fpr < 4) |
|
114 dp->val.d = *((double*) a_fpr), a_fpr++, fpr++; |
|
115 else |
|
116 dp->val.d = *((double*) a_ov ), a_ov++; |
|
117 break; |
|
118 case nsXPTType::T_BOOL : |
|
119 if (gpr < 5) |
|
120 dp->val.b = *((uint64_t*)a_gpr), a_gpr++, gpr++; |
|
121 else |
|
122 dp->val.b = *((uint64_t*)a_ov ), a_ov++; |
|
123 break; |
|
124 case nsXPTType::T_CHAR : |
|
125 if (gpr < 5) |
|
126 dp->val.c = *((uint64_t*)a_gpr), a_gpr++, gpr++; |
|
127 else |
|
128 dp->val.c = *((uint64_t*)a_ov ), a_ov++; |
|
129 break; |
|
130 case nsXPTType::T_WCHAR : |
|
131 if (gpr < 5) |
|
132 dp->val.wc = *((uint64_t*)a_gpr), a_gpr++, gpr++; |
|
133 else |
|
134 dp->val.wc = *((uint64_t*)a_ov ), a_ov++; |
|
135 break; |
|
136 default: |
|
137 NS_ERROR("bad type"); |
|
138 break; |
|
139 } |
|
140 } |
|
141 |
|
142 result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams); |
|
143 |
|
144 if(dispatchParams != paramBuffer) |
|
145 delete [] dispatchParams; |
|
146 |
|
147 return result; |
|
148 } |
|
149 |
|
150 #define STUB_ENTRY(n) \ |
|
151 nsresult nsXPTCStubBase::Stub##n() \ |
|
152 { \ |
|
153 uint64_t a_gpr[4]; \ |
|
154 uint64_t a_fpr[4]; \ |
|
155 uint64_t *a_ov; \ |
|
156 \ |
|
157 __asm__ __volatile__ \ |
|
158 ( \ |
|
159 "lg %0,0(15)\n\t" \ |
|
160 "aghi %0,160\n\t" \ |
|
161 "stmg 3,6,0(%5)\n\t"\ |
|
162 "std 0,%1\n\t" \ |
|
163 "std 2,%2\n\t" \ |
|
164 "std 4,%3\n\t" \ |
|
165 "std 6,%4\n\t" \ |
|
166 : "=&a" (a_ov), \ |
|
167 "=m" (a_fpr[0]), \ |
|
168 "=m" (a_fpr[1]), \ |
|
169 "=m" (a_fpr[2]), \ |
|
170 "=m" (a_fpr[3]) \ |
|
171 : "a" (a_gpr) \ |
|
172 : "memory", "cc", \ |
|
173 "3", "4", "5", "6" \ |
|
174 ); \ |
|
175 \ |
|
176 return PrepareAndDispatch(this, n, a_gpr, a_fpr, a_ov); \ |
|
177 } |
|
178 |
|
179 #define SENTINEL_ENTRY(n) \ |
|
180 nsresult nsXPTCStubBase::Sentinel##n() \ |
|
181 { \ |
|
182 NS_ERROR("nsXPTCStubBase::Sentinel called"); \ |
|
183 return NS_ERROR_NOT_IMPLEMENTED; \ |
|
184 } |
|
185 |
|
186 #include "xptcstubsdef.inc" |
|
187 |