1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * Version: MPL 1.1
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 #include "xptcprivate.h"
9
10 #include <stdint.h>
11
12 /*
13 * This is for MIPS O32 ABI
14 * Args contains a0-3 and then the stack.
15 * Because a0 is 'this', we want to skip it
16 */
17 extern "C" nsresult ATTRIBUTE_USED
PrepareAndDispatch(nsXPTCStubBase * self,uint32_t methodIndex,uint32_t * args)18 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint32_t* args)
19 {
20 args++; // always skip over a0
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 method 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 dp->val.p = (void*) *ap;
50 continue;
51 }
52
53 switch(type)
54 {
55 case nsXPTType::T_I64 :
56 if ((intptr_t)ap & 4) ap++;
57 dp->val.i64 = *((int64_t*) ap); ap++;
58 break;
59 case nsXPTType::T_U64 :
60 if ((intptr_t)ap & 4) ap++;
61 dp->val.u64 = *((int64_t*) ap); ap++;
62 break;
63 case nsXPTType::T_DOUBLE:
64 if ((intptr_t)ap & 4) ap++;
65 dp->val.d = *((double*) ap); ap++;
66 break;
67 #ifdef IS_LITTLE_ENDIAN
68 default:
69 dp->val.p = (void*) *ap;
70 break;
71 #else
72 case nsXPTType::T_I8 : dp->val.i8 = (int8_t) *ap; break;
73 case nsXPTType::T_I16 : dp->val.i16 = (int16_t) *ap; break;
74 case nsXPTType::T_I32 : dp->val.i32 = (int32_t) *ap; break;
75 case nsXPTType::T_U8 : dp->val.u8 = (uint8_t) *ap; break;
76 case nsXPTType::T_U16 : dp->val.u16 = (uint16_t) *ap; break;
77 case nsXPTType::T_U32 : dp->val.u32 = (uint32_t) *ap; break;
78 case nsXPTType::T_BOOL : dp->val.b = (bool) *ap; break;
79 case nsXPTType::T_CHAR : dp->val.c = (char) *ap; break;
80 case nsXPTType::T_WCHAR : dp->val.wc = (wchar_t) *ap; break;
81 case nsXPTType::T_FLOAT : dp->val.f = *(float *) ap; break;
82 default:
83 NS_ASSERTION(0, "bad type");
84 break;
85 #endif
86 }
87 }
88
89 nsresult result = self->mOuter->CallMethod((uint16_t)methodIndex, info,
90 paramBuffer);
91
92 return result;
93 }
94
95 #define STUB_ENTRY(n) // done in the .s file
96
97 #define SENTINEL_ENTRY(n) \
98 nsresult nsXPTCStubBase::Sentinel##n() \
99 { \
100 NS_ERROR("nsXPTCStubBase::Sentinel called"); \
101 return NS_ERROR_NOT_IMPLEMENTED; \
102 }
103
104 #include "xptcstubsdef.inc"
105