1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc_rhapsody.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,165 @@ 1.4 +/* -*- Mode: C -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "xptcprivate.h" 1.10 +#include "xptiprivate.h" 1.11 + 1.12 +/* Under the Mac OS X PowerPC ABI, the first 8 integer and 13 floating point 1.13 + * parameters are delivered in registers and are not on the stack, although 1.14 + * stack space is allocated for them. The integer parameters are delivered 1.15 + * in GPRs r3 through r10. The first 8 words of the parameter area on the 1.16 + * stack shadow these registers. A word will either be in a register or on 1.17 + * the stack, but not in both. Although the first floating point parameters 1.18 + * are passed in floating point registers, GPR space and stack space is 1.19 + * reserved for them as well. 1.20 + * 1.21 + * SharedStub has passed pointers to the parameter section of the stack 1.22 + * and saved copies of the GPRs and FPRs used for parameter passing. We 1.23 + * don't care about the first parameter (which is delivered here as the self 1.24 + * pointer), so SharedStub pointed us past that. argsGPR thus points to GPR 1.25 + * r4 (corresponding to the first argument after the self pointer) and 1.26 + * argsStack points to the parameter section of the caller's stack frame 1.27 + * reserved for the same argument. This way, it is possible to reference 1.28 + * either argsGPR or argsStack with the same index. 1.29 + * 1.30 + * Contrary to the assumption made by the previous implementation, the 1.31 + * Mac OS X PowerPC ABI doesn't impose any special alignment restrictions on 1.32 + * parameter sections of stacks. Values that are 64 bits wide appear on the 1.33 + * stack without any special padding. 1.34 + * 1.35 + * See also xptcstubs_asm_ppc_darwin.s.m4:_SharedStub. 1.36 + * 1.37 + * ABI reference: 1.38 + * http://developer.apple.com/documentation/DeveloperTools/Conceptual/ 1.39 + * MachORuntime/PowerPCConventions/chapter_3_section_1.html */ 1.40 + 1.41 +extern "C" nsresult ATTRIBUTE_USED 1.42 +PrepareAndDispatch( 1.43 + nsXPTCStubBase *self, 1.44 + uint32_t methodIndex, 1.45 + uint32_t *argsStack, 1.46 + uint32_t *argsGPR, 1.47 + double *argsFPR) { 1.48 +#define PARAM_BUFFER_COUNT 16 1.49 +#define PARAM_FPR_COUNT 13 1.50 +#define PARAM_GPR_COUNT 7 1.51 + 1.52 + nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; 1.53 + nsXPTCMiniVariant *dispatchParams = nullptr; 1.54 + const nsXPTMethodInfo *methodInfo; 1.55 + uint8_t paramCount; 1.56 + uint8_t i; 1.57 + nsresult result = NS_ERROR_FAILURE; 1.58 + uint32_t argIndex = 0; 1.59 + uint32_t fprIndex = 0; 1.60 + 1.61 + typedef struct { 1.62 + uint32_t hi; 1.63 + uint32_t lo; 1.64 + } DU; 1.65 + 1.66 + NS_ASSERTION(self, "no self"); 1.67 + 1.68 + self->mEntry->GetMethodInfo(uint16_t(methodIndex), &methodInfo); 1.69 + NS_ASSERTION(methodInfo, "no method info"); 1.70 + 1.71 + paramCount = methodInfo->GetParamCount(); 1.72 + 1.73 + if(paramCount > PARAM_BUFFER_COUNT) { 1.74 + dispatchParams = new nsXPTCMiniVariant[paramCount]; 1.75 + } 1.76 + else { 1.77 + dispatchParams = paramBuffer; 1.78 + } 1.79 + NS_ASSERTION(dispatchParams,"no place for params"); 1.80 + 1.81 + for(i = 0; i < paramCount; i++, argIndex++) { 1.82 + const nsXPTParamInfo ¶m = methodInfo->GetParam(i); 1.83 + const nsXPTType &type = param.GetType(); 1.84 + nsXPTCMiniVariant *dp = &dispatchParams[i]; 1.85 + uint32_t theParam; 1.86 + 1.87 + if(argIndex < PARAM_GPR_COUNT) 1.88 + theParam = argsGPR[argIndex]; 1.89 + else 1.90 + theParam = argsStack[argIndex]; 1.91 + 1.92 + if(param.IsOut() || !type.IsArithmetic()) 1.93 + dp->val.p = (void *) theParam; 1.94 + else { 1.95 + switch(type) { 1.96 + case nsXPTType::T_I8: 1.97 + dp->val.i8 = (int8_t) theParam; 1.98 + break; 1.99 + case nsXPTType::T_I16: 1.100 + dp->val.i16 = (int16_t) theParam; 1.101 + break; 1.102 + case nsXPTType::T_I32: 1.103 + dp->val.i32 = (int32_t) theParam; 1.104 + break; 1.105 + case nsXPTType::T_U8: 1.106 + dp->val.u8 = (uint8_t) theParam; 1.107 + break; 1.108 + case nsXPTType::T_U16: 1.109 + dp->val.u16 = (uint16_t) theParam; 1.110 + break; 1.111 + case nsXPTType::T_U32: 1.112 + dp->val.u32 = (uint32_t) theParam; 1.113 + break; 1.114 + case nsXPTType::T_I64: 1.115 + case nsXPTType::T_U64: 1.116 + ((DU *)dp)->hi = (uint32_t) theParam; 1.117 + if(++argIndex < PARAM_GPR_COUNT) 1.118 + ((DU *)dp)->lo = (uint32_t) argsGPR[argIndex]; 1.119 + else 1.120 + ((DU *)dp)->lo = (uint32_t) argsStack[argIndex]; 1.121 + break; 1.122 + case nsXPTType::T_BOOL: 1.123 + dp->val.b = (bool) theParam; 1.124 + break; 1.125 + case nsXPTType::T_CHAR: 1.126 + dp->val.c = (char) theParam; 1.127 + break; 1.128 + case nsXPTType::T_WCHAR: 1.129 + dp->val.wc = (wchar_t) theParam; 1.130 + break; 1.131 + case nsXPTType::T_FLOAT: 1.132 + if(fprIndex < PARAM_FPR_COUNT) 1.133 + dp->val.f = (float) argsFPR[fprIndex++]; 1.134 + else 1.135 + dp->val.f = *(float *) &argsStack[argIndex]; 1.136 + break; 1.137 + case nsXPTType::T_DOUBLE: 1.138 + if(fprIndex < PARAM_FPR_COUNT) 1.139 + dp->val.d = argsFPR[fprIndex++]; 1.140 + else 1.141 + dp->val.d = *(double *) &argsStack[argIndex]; 1.142 + argIndex++; 1.143 + break; 1.144 + default: 1.145 + NS_ERROR("bad type"); 1.146 + break; 1.147 + } 1.148 + } 1.149 + } 1.150 + 1.151 + result = self->mOuter-> 1.152 + CallMethod((uint16_t)methodIndex, methodInfo, dispatchParams); 1.153 + 1.154 + if(dispatchParams != paramBuffer) 1.155 + delete [] dispatchParams; 1.156 + 1.157 + return result; 1.158 +} 1.159 + 1.160 +#define STUB_ENTRY(n) 1.161 +#define SENTINEL_ENTRY(n) \ 1.162 +nsresult nsXPTCStubBase::Sentinel##n() \ 1.163 +{ \ 1.164 + NS_ERROR("nsXPTCStubBase::Sentinel called"); \ 1.165 + return NS_ERROR_NOT_IMPLEMENTED; \ 1.166 +} 1.167 + 1.168 +#include "xptcstubsdef.inc"