|
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 #include "xptiprivate.h" |
|
10 |
|
11 // The Linux/PPC ABI (aka PPC/SYSV ABI) passes the first 8 integral |
|
12 // parameters and the first 8 floating point parameters in registers |
|
13 // (r3-r10 and f1-f8), no stack space is allocated for these by the |
|
14 // caller. The rest of the parameters are passed in the callers stack |
|
15 // area. The stack pointer has to retain 16-byte alignment, longlongs |
|
16 // and doubles are aligned on 8-byte boundaries. |
|
17 |
|
18 #define PARAM_BUFFER_COUNT 16 |
|
19 #define GPR_COUNT 8 |
|
20 #define FPR_COUNT 8 |
|
21 |
|
22 // PrepareAndDispatch() is called by SharedStub() and calls the actual method. |
|
23 // |
|
24 // - 'args[]' contains the arguments passed on stack |
|
25 // - 'gprData[]' contains the arguments passed in integer registers |
|
26 // - 'fprData[]' contains the arguments passed in floating point registers |
|
27 // |
|
28 // The parameters are mapped into an array of type 'nsXPTCMiniVariant' |
|
29 // and then the method gets called. |
|
30 |
|
31 extern "C" nsresult ATTRIBUTE_USED |
|
32 PrepareAndDispatch(nsXPTCStubBase* self, |
|
33 uint32_t methodIndex, |
|
34 uint32_t* args, |
|
35 uint32_t *gprData, |
|
36 double *fprData) |
|
37 { |
|
38 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; |
|
39 nsXPTCMiniVariant* dispatchParams = nullptr; |
|
40 const nsXPTMethodInfo* info = nullptr; |
|
41 uint32_t paramCount; |
|
42 uint32_t i; |
|
43 nsresult result = NS_ERROR_FAILURE; |
|
44 |
|
45 NS_ASSERTION(self,"no self"); |
|
46 |
|
47 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); |
|
48 NS_ASSERTION(info,"no method info"); |
|
49 if (! info) |
|
50 return NS_ERROR_UNEXPECTED; |
|
51 |
|
52 paramCount = info->GetParamCount(); |
|
53 |
|
54 // setup variant array pointer |
|
55 if(paramCount > PARAM_BUFFER_COUNT) |
|
56 dispatchParams = new nsXPTCMiniVariant[paramCount]; |
|
57 else |
|
58 dispatchParams = paramBuffer; |
|
59 |
|
60 NS_ASSERTION(dispatchParams,"no place for params"); |
|
61 if (!dispatchParams) |
|
62 return NS_ERROR_OUT_OF_MEMORY; |
|
63 |
|
64 uint32_t* ap = args; |
|
65 uint32_t gpr = 1; // skip one GPR register |
|
66 uint32_t fpr = 0; |
|
67 uint32_t tempu32; |
|
68 uint64_t tempu64; |
|
69 |
|
70 for(i = 0; i < paramCount; i++) { |
|
71 const nsXPTParamInfo& param = info->GetParam(i); |
|
72 const nsXPTType& type = param.GetType(); |
|
73 nsXPTCMiniVariant* dp = &dispatchParams[i]; |
|
74 |
|
75 if (!param.IsOut() && type == nsXPTType::T_DOUBLE) { |
|
76 if (fpr < FPR_COUNT) |
|
77 dp->val.d = fprData[fpr++]; |
|
78 else { |
|
79 if ((uint32_t) ap & 4) ap++; // doubles are 8-byte aligned on stack |
|
80 dp->val.d = *(double*) ap; |
|
81 ap += 2; |
|
82 } |
|
83 continue; |
|
84 } |
|
85 else if (!param.IsOut() && type == nsXPTType::T_FLOAT) { |
|
86 if (fpr < FPR_COUNT) |
|
87 dp->val.f = (float) fprData[fpr++]; // in registers floats are passed as doubles |
|
88 else |
|
89 dp->val.f = *(float*) ap++; |
|
90 continue; |
|
91 } |
|
92 else if (!param.IsOut() && (type == nsXPTType::T_I64 |
|
93 || type == nsXPTType::T_U64)) { |
|
94 if (gpr & 1) gpr++; // longlongs are aligned in odd/even register pairs, eg. r5/r6 |
|
95 if ((gpr + 1) < GPR_COUNT) { |
|
96 tempu64 = *(uint64_t*) &gprData[gpr]; |
|
97 gpr += 2; |
|
98 } |
|
99 else { |
|
100 if ((uint32_t) ap & 4) ap++; // longlongs are 8-byte aligned on stack |
|
101 tempu64 = *(uint64_t*) ap; |
|
102 ap += 2; |
|
103 } |
|
104 } |
|
105 else { |
|
106 if (gpr < GPR_COUNT) |
|
107 tempu32 = gprData[gpr++]; |
|
108 else |
|
109 tempu32 = *ap++; |
|
110 } |
|
111 |
|
112 if(param.IsOut() || !type.IsArithmetic()) { |
|
113 dp->val.p = (void*) tempu32; |
|
114 continue; |
|
115 } |
|
116 |
|
117 switch(type) { |
|
118 case nsXPTType::T_I8: dp->val.i8 = (int8_t) tempu32; break; |
|
119 case nsXPTType::T_I16: dp->val.i16 = (int16_t) tempu32; break; |
|
120 case nsXPTType::T_I32: dp->val.i32 = (int32_t) tempu32; break; |
|
121 case nsXPTType::T_I64: dp->val.i64 = (int64_t) tempu64; break; |
|
122 case nsXPTType::T_U8: dp->val.u8 = (uint8_t) tempu32; break; |
|
123 case nsXPTType::T_U16: dp->val.u16 = (uint16_t) tempu32; break; |
|
124 case nsXPTType::T_U32: dp->val.u32 = (uint32_t) tempu32; break; |
|
125 case nsXPTType::T_U64: dp->val.u64 = (uint64_t) tempu64; break; |
|
126 case nsXPTType::T_BOOL: dp->val.b = (bool) tempu32; break; |
|
127 case nsXPTType::T_CHAR: dp->val.c = (char) tempu32; break; |
|
128 case nsXPTType::T_WCHAR: dp->val.wc = (wchar_t) tempu32; break; |
|
129 |
|
130 default: |
|
131 NS_ERROR("bad type"); |
|
132 break; |
|
133 } |
|
134 } |
|
135 |
|
136 result = self->mOuter->CallMethod((uint16_t)methodIndex, |
|
137 info, |
|
138 dispatchParams); |
|
139 |
|
140 if (dispatchParams != paramBuffer) |
|
141 delete [] dispatchParams; |
|
142 |
|
143 return result; |
|
144 } |
|
145 |
|
146 // Load r11 with the constant 'n' and branch to SharedStub(). |
|
147 // |
|
148 // XXX Yes, it's ugly that we're relying on gcc's name-mangling here; |
|
149 // however, it's quick, dirty, and'll break when the ABI changes on |
|
150 // us, which is what we want ;-). |
|
151 |
|
152 |
|
153 // gcc-3 version |
|
154 // |
|
155 // As G++3 ABI contains the length of the functionname in the mangled |
|
156 // name, it is difficult to get a generic assembler mechanism like |
|
157 // in the G++ 2.95 case. |
|
158 // Create names would be like: |
|
159 // _ZN14nsXPTCStubBase5Stub1Ev |
|
160 // _ZN14nsXPTCStubBase6Stub12Ev |
|
161 // _ZN14nsXPTCStubBase7Stub123Ev |
|
162 // _ZN14nsXPTCStubBase8Stub1234Ev |
|
163 // etc. |
|
164 // Use assembler directives to get the names right... |
|
165 |
|
166 # define STUB_ENTRY(n) \ |
|
167 __asm__ ( \ |
|
168 ".align 2 \n\t" \ |
|
169 ".if "#n" < 10 \n\t" \ |
|
170 ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t" \ |
|
171 ".type _ZN14nsXPTCStubBase5Stub"#n"Ev,@function \n\n" \ |
|
172 "_ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t" \ |
|
173 \ |
|
174 ".elseif "#n" < 100 \n\t" \ |
|
175 ".globl _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t" \ |
|
176 ".type _ZN14nsXPTCStubBase6Stub"#n"Ev,@function \n\n" \ |
|
177 "_ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t" \ |
|
178 \ |
|
179 ".elseif "#n" < 1000 \n\t" \ |
|
180 ".globl _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t" \ |
|
181 ".type _ZN14nsXPTCStubBase7Stub"#n"Ev,@function \n\n" \ |
|
182 "_ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t" \ |
|
183 \ |
|
184 ".else \n\t" \ |
|
185 ".err \"stub number "#n" >= 1000 not yet supported\"\n" \ |
|
186 ".endif \n\t" \ |
|
187 \ |
|
188 "li 11,"#n" \n\t" \ |
|
189 "b SharedStub@local \n" \ |
|
190 ); |
|
191 |
|
192 #define SENTINEL_ENTRY(n) \ |
|
193 nsresult nsXPTCStubBase::Sentinel##n() \ |
|
194 { \ |
|
195 NS_ERROR("nsXPTCStubBase::Sentinel called"); \ |
|
196 return NS_ERROR_NOT_IMPLEMENTED; \ |
|
197 } |
|
198 |
|
199 #include "xptcstubsdef.inc" |