michael@0: /* -*- Mode: C -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "xptcprivate.h" michael@0: #include "xptiprivate.h" michael@0: michael@0: /* Under the Mac OS X PowerPC ABI, the first 8 integer and 13 floating point michael@0: * parameters are delivered in registers and are not on the stack, although michael@0: * stack space is allocated for them. The integer parameters are delivered michael@0: * in GPRs r3 through r10. The first 8 words of the parameter area on the michael@0: * stack shadow these registers. A word will either be in a register or on michael@0: * the stack, but not in both. Although the first floating point parameters michael@0: * are passed in floating point registers, GPR space and stack space is michael@0: * reserved for them as well. michael@0: * michael@0: * SharedStub has passed pointers to the parameter section of the stack michael@0: * and saved copies of the GPRs and FPRs used for parameter passing. We michael@0: * don't care about the first parameter (which is delivered here as the self michael@0: * pointer), so SharedStub pointed us past that. argsGPR thus points to GPR michael@0: * r4 (corresponding to the first argument after the self pointer) and michael@0: * argsStack points to the parameter section of the caller's stack frame michael@0: * reserved for the same argument. This way, it is possible to reference michael@0: * either argsGPR or argsStack with the same index. michael@0: * michael@0: * Contrary to the assumption made by the previous implementation, the michael@0: * Mac OS X PowerPC ABI doesn't impose any special alignment restrictions on michael@0: * parameter sections of stacks. Values that are 64 bits wide appear on the michael@0: * stack without any special padding. michael@0: * michael@0: * See also xptcstubs_asm_ppc_darwin.s.m4:_SharedStub. michael@0: * michael@0: * ABI reference: michael@0: * http://developer.apple.com/documentation/DeveloperTools/Conceptual/ michael@0: * MachORuntime/PowerPCConventions/chapter_3_section_1.html */ michael@0: michael@0: extern "C" nsresult ATTRIBUTE_USED michael@0: PrepareAndDispatch( michael@0: nsXPTCStubBase *self, michael@0: uint32_t methodIndex, michael@0: uint32_t *argsStack, michael@0: uint32_t *argsGPR, michael@0: double *argsFPR) { michael@0: #define PARAM_BUFFER_COUNT 16 michael@0: #define PARAM_FPR_COUNT 13 michael@0: #define PARAM_GPR_COUNT 7 michael@0: michael@0: nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; michael@0: nsXPTCMiniVariant *dispatchParams = nullptr; michael@0: const nsXPTMethodInfo *methodInfo; michael@0: uint8_t paramCount; michael@0: uint8_t i; michael@0: nsresult result = NS_ERROR_FAILURE; michael@0: uint32_t argIndex = 0; michael@0: uint32_t fprIndex = 0; michael@0: michael@0: typedef struct { michael@0: uint32_t hi; michael@0: uint32_t lo; michael@0: } DU; michael@0: michael@0: NS_ASSERTION(self, "no self"); michael@0: michael@0: self->mEntry->GetMethodInfo(uint16_t(methodIndex), &methodInfo); michael@0: NS_ASSERTION(methodInfo, "no method info"); michael@0: michael@0: paramCount = methodInfo->GetParamCount(); michael@0: michael@0: if(paramCount > PARAM_BUFFER_COUNT) { michael@0: dispatchParams = new nsXPTCMiniVariant[paramCount]; michael@0: } michael@0: else { michael@0: dispatchParams = paramBuffer; michael@0: } michael@0: NS_ASSERTION(dispatchParams,"no place for params"); michael@0: michael@0: for(i = 0; i < paramCount; i++, argIndex++) { michael@0: const nsXPTParamInfo ¶m = methodInfo->GetParam(i); michael@0: const nsXPTType &type = param.GetType(); michael@0: nsXPTCMiniVariant *dp = &dispatchParams[i]; michael@0: uint32_t theParam; michael@0: michael@0: if(argIndex < PARAM_GPR_COUNT) michael@0: theParam = argsGPR[argIndex]; michael@0: else michael@0: theParam = argsStack[argIndex]; michael@0: michael@0: if(param.IsOut() || !type.IsArithmetic()) michael@0: dp->val.p = (void *) theParam; michael@0: else { michael@0: switch(type) { michael@0: case nsXPTType::T_I8: michael@0: dp->val.i8 = (int8_t) theParam; michael@0: break; michael@0: case nsXPTType::T_I16: michael@0: dp->val.i16 = (int16_t) theParam; michael@0: break; michael@0: case nsXPTType::T_I32: michael@0: dp->val.i32 = (int32_t) theParam; michael@0: break; michael@0: case nsXPTType::T_U8: michael@0: dp->val.u8 = (uint8_t) theParam; michael@0: break; michael@0: case nsXPTType::T_U16: michael@0: dp->val.u16 = (uint16_t) theParam; michael@0: break; michael@0: case nsXPTType::T_U32: michael@0: dp->val.u32 = (uint32_t) theParam; michael@0: break; michael@0: case nsXPTType::T_I64: michael@0: case nsXPTType::T_U64: michael@0: ((DU *)dp)->hi = (uint32_t) theParam; michael@0: if(++argIndex < PARAM_GPR_COUNT) michael@0: ((DU *)dp)->lo = (uint32_t) argsGPR[argIndex]; michael@0: else michael@0: ((DU *)dp)->lo = (uint32_t) argsStack[argIndex]; michael@0: break; michael@0: case nsXPTType::T_BOOL: michael@0: dp->val.b = (bool) theParam; michael@0: break; michael@0: case nsXPTType::T_CHAR: michael@0: dp->val.c = (char) theParam; michael@0: break; michael@0: case nsXPTType::T_WCHAR: michael@0: dp->val.wc = (wchar_t) theParam; michael@0: break; michael@0: case nsXPTType::T_FLOAT: michael@0: if(fprIndex < PARAM_FPR_COUNT) michael@0: dp->val.f = (float) argsFPR[fprIndex++]; michael@0: else michael@0: dp->val.f = *(float *) &argsStack[argIndex]; michael@0: break; michael@0: case nsXPTType::T_DOUBLE: michael@0: if(fprIndex < PARAM_FPR_COUNT) michael@0: dp->val.d = argsFPR[fprIndex++]; michael@0: else michael@0: dp->val.d = *(double *) &argsStack[argIndex]; michael@0: argIndex++; michael@0: break; michael@0: default: michael@0: NS_ERROR("bad type"); michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: michael@0: result = self->mOuter-> michael@0: CallMethod((uint16_t)methodIndex, methodInfo, dispatchParams); michael@0: michael@0: if(dispatchParams != paramBuffer) michael@0: delete [] dispatchParams; michael@0: michael@0: return result; michael@0: } michael@0: michael@0: #define STUB_ENTRY(n) michael@0: #define SENTINEL_ENTRY(n) \ michael@0: nsresult nsXPTCStubBase::Sentinel##n() \ michael@0: { \ michael@0: NS_ERROR("nsXPTCStubBase::Sentinel called"); \ michael@0: return NS_ERROR_NOT_IMPLEMENTED; \ michael@0: } michael@0: michael@0: #include "xptcstubsdef.inc"