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 #include "xptcprivate.h"
7 
8 #if (_MIPS_SIM != _ABIN32) && (_MIPS_SIM != _ABI64)
9 #error "This code is for MIPS n32/n64 only"
10 #endif
11 
12 /*
13  * This is for MIPS n32/n64 ABI
14  *
15  * When we're called, the "gp" registers are stored in gprData and
16  * the "fp" registers are stored in fprData.  There are 8 regs
17  * available which correspond to the first 7 parameters of the
18  * function and the "this" pointer.  If there are additional parms,
19  * they are stored on the stack at address "args".
20  *
21  */
22 extern "C" nsresult ATTRIBUTE_USED
PrepareAndDispatch(nsXPTCStubBase * self,uint32_t methodIndex,uint64_t * args,uint64_t * gprData,double * fprData)23 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint64_t* args,
24                    uint64_t *gprData, double *fprData)
25 {
26 #define PARAM_GPR_COUNT            7
27 #define PARAM_FPR_COUNT            7
28 
29     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
30     const nsXPTMethodInfo* info;
31     uint8_t paramCount;
32     uint8_t i;
33 
34     NS_ASSERTION(self,"no self");
35 
36     self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
37     NS_ASSERTION(info,"no method info");
38 
39     paramCount = info->GetParamCount();
40 
41     const uint8_t indexOfJSContext = info->IndexOfJSContext();
42 
43     uint64_t* ap = args;
44     uint32_t iCount = 0;
45     for(i = 0; i < paramCount; i++)
46     {
47         const nsXPTParamInfo& param = info->GetParam(i);
48         const nsXPTType& type = param.GetType();
49         nsXPTCMiniVariant* dp = &paramBuffer[i];
50 
51         if (i == indexOfJSContext) {
52             if (iCount < PARAM_GPR_COUNT)
53                 iCount++;
54             else
55                 ap++;
56         }
57 
58         if(param.IsOut() || !type.IsArithmetic())
59         {
60             if (iCount < PARAM_GPR_COUNT)
61                 dp->val.p = (void*)gprData[iCount++];
62             else
63                 dp->val.p = (void*)*ap++;
64             continue;
65         }
66         // else
67         switch(type)
68         {
69         case nsXPTType::T_I8:
70             if (iCount < PARAM_GPR_COUNT)
71                 dp->val.i8  = (int8_t)gprData[iCount++];
72             else
73                 dp->val.i8  = (int8_t)*ap++;
74             break;
75 
76         case nsXPTType::T_I16:
77              if (iCount < PARAM_GPR_COUNT)
78                  dp->val.i16  = (int16_t)gprData[iCount++];
79              else
80                  dp->val.i16  = (int16_t)*ap++;
81              break;
82 
83         case nsXPTType::T_I32:
84              if (iCount < PARAM_GPR_COUNT)
85                  dp->val.i32  = (int32_t)gprData[iCount++];
86              else
87                  dp->val.i32  = (int32_t)*ap++;
88              break;
89 
90         case nsXPTType::T_I64:
91              if (iCount < PARAM_GPR_COUNT)
92                  dp->val.i64  = (int64_t)gprData[iCount++];
93              else
94                  dp->val.i64  = (int64_t)*ap++;
95              break;
96 
97         case nsXPTType::T_U8:
98              if (iCount < PARAM_GPR_COUNT)
99                  dp->val.u8  = (uint8_t)gprData[iCount++];
100              else
101                  dp->val.u8  = (uint8_t)*ap++;
102              break;
103 
104         case nsXPTType::T_U16:
105              if (iCount < PARAM_GPR_COUNT)
106                  dp->val.u16  = (uint16_t)gprData[iCount++];
107              else
108                   dp->val.u16  = (uint16_t)*ap++;
109              break;
110 
111         case nsXPTType::T_U32:
112              if (iCount < PARAM_GPR_COUNT)
113                  dp->val.u32  = (uint32_t)gprData[iCount++];
114              else
115                  dp->val.u32  = (uint32_t)*ap++;
116              break;
117 
118         case nsXPTType::T_U64:
119              if (iCount < PARAM_GPR_COUNT)
120                  dp->val.u64  = (uint64_t)gprData[iCount++];
121              else
122                  dp->val.u64  = (uint64_t)*ap++;
123              break;
124 
125         case nsXPTType::T_FLOAT:
126               // the float data formate must not be converted!
127               // Just only copy without conversion.
128               if (iCount < PARAM_FPR_COUNT)
129                   dp->val.f  = *(float*)&fprData[iCount++];
130               else
131                   dp->val.f  = *((float*)ap++);
132               break;
133 
134         case nsXPTType::T_DOUBLE:
135                if (iCount < PARAM_FPR_COUNT)
136                    dp->val.d  = (double)fprData[iCount++];
137                else
138                    dp->val.d  = *((double*)ap++);
139                break;
140 
141         case nsXPTType::T_BOOL:
142             if (iCount < PARAM_GPR_COUNT)
143                 dp->val.b  = (bool)gprData[iCount++];
144             else
145                 dp->val.b  = (bool)*ap++;
146             break;
147 
148         case nsXPTType::T_CHAR:
149             if (iCount < PARAM_GPR_COUNT)
150                 dp->val.c  = (char)gprData[iCount++];
151             else
152                 dp->val.c  = (char)*ap++;
153             break;
154 
155         case nsXPTType::T_WCHAR:
156             if (iCount < PARAM_GPR_COUNT)
157                 dp->val.wc  = (wchar_t)gprData[iCount++];
158             else
159                 dp->val.wc  = (wchar_t)*ap++;
160             break;
161 
162         default:
163             NS_ASSERTION(0, "bad type");
164             break;
165         }
166     }
167 
168     nsresult result = self->mOuter->CallMethod((uint16_t)methodIndex, info,
169                                                paramBuffer);
170 
171     return result;
172 }
173 
174 #define STUB_ENTRY(n)        /* defined in the assembly file */
175 
176 #define SENTINEL_ENTRY(n)                              \
177 nsresult nsXPTCStubBase::Sentinel##n()                 \
178 {                                                      \
179     NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
180     return NS_ERROR_NOT_IMPLEMENTED;                   \
181 }
182 
183 #include "xptcstubsdef.inc"
184