1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc_linux.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,217 @@ 1.4 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 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 +// Implement shared vtbl methods. 1.10 + 1.11 +#include "xptcprivate.h" 1.12 +#include "xptiprivate.h" 1.13 + 1.14 +// The Linux/PPC ABI (aka PPC/SYSV ABI) passes the first 8 integral 1.15 +// parameters and the first 8 floating point parameters in registers 1.16 +// (r3-r10 and f1-f8), no stack space is allocated for these by the 1.17 +// caller. The rest of the parameters are passed in the callers stack 1.18 +// area. The stack pointer has to retain 16-byte alignment, longlongs 1.19 +// and doubles are aligned on 8-byte boundaries. 1.20 +#ifndef __NO_FPRS__ 1.21 +#define PARAM_BUFFER_COUNT 16 1.22 +#define GPR_COUNT 8 1.23 +#define FPR_COUNT 8 1.24 +#else 1.25 +#define PARAM_BUFFER_COUNT 8 1.26 +#define GPR_COUNT 8 1.27 +#endif 1.28 +// PrepareAndDispatch() is called by SharedStub() and calls the actual method. 1.29 +// 1.30 +// - 'args[]' contains the arguments passed on stack 1.31 +// - 'gprData[]' contains the arguments passed in integer registers 1.32 +// - 'fprData[]' contains the arguments passed in floating point registers 1.33 +// 1.34 +// The parameters are mapped into an array of type 'nsXPTCMiniVariant' 1.35 +// and then the method gets called. 1.36 + 1.37 +extern "C" nsresult ATTRIBUTE_USED 1.38 +PrepareAndDispatch(nsXPTCStubBase* self, 1.39 + uint32_t methodIndex, 1.40 + uint32_t* args, 1.41 + uint32_t *gprData, 1.42 + double *fprData) 1.43 +{ 1.44 + nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; 1.45 + nsXPTCMiniVariant* dispatchParams = nullptr; 1.46 + const nsXPTMethodInfo* info = nullptr; 1.47 + uint32_t paramCount; 1.48 + uint32_t i; 1.49 + nsresult result = NS_ERROR_FAILURE; 1.50 + 1.51 + NS_ASSERTION(self,"no self"); 1.52 + 1.53 + self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); 1.54 + NS_ASSERTION(info,"no method info"); 1.55 + if (! info) 1.56 + return NS_ERROR_UNEXPECTED; 1.57 + 1.58 + paramCount = info->GetParamCount(); 1.59 + 1.60 + // setup variant array pointer 1.61 + if(paramCount > PARAM_BUFFER_COUNT) 1.62 + dispatchParams = new nsXPTCMiniVariant[paramCount]; 1.63 + else 1.64 + dispatchParams = paramBuffer; 1.65 + 1.66 + NS_ASSERTION(dispatchParams,"no place for params"); 1.67 + if (! dispatchParams) 1.68 + return NS_ERROR_OUT_OF_MEMORY; 1.69 + 1.70 + uint32_t* ap = args; 1.71 + uint32_t gpr = 1; // skip one GPR register 1.72 +#ifndef __NO_FPRS__ 1.73 + uint32_t fpr = 0; 1.74 +#endif 1.75 + uint32_t tempu32; 1.76 + uint64_t tempu64; 1.77 + 1.78 + for(i = 0; i < paramCount; i++) { 1.79 + const nsXPTParamInfo& param = info->GetParam(i); 1.80 + const nsXPTType& type = param.GetType(); 1.81 + nsXPTCMiniVariant* dp = &dispatchParams[i]; 1.82 + 1.83 + if (!param.IsOut() && type == nsXPTType::T_DOUBLE) { 1.84 +#ifndef __NO_FPRS__ 1.85 + if (fpr < FPR_COUNT) 1.86 + dp->val.d = fprData[fpr++]; 1.87 +#else 1.88 + if (gpr & 1) 1.89 + gpr++; 1.90 + if (gpr + 1 < GPR_COUNT) { 1.91 + dp->val.d = *(double*) &gprData[gpr]; 1.92 + gpr += 2; 1.93 + } 1.94 +#endif 1.95 + else { 1.96 + if ((uint32_t) ap & 4) ap++; // doubles are 8-byte aligned on stack 1.97 + dp->val.d = *(double*) ap; 1.98 + ap += 2; 1.99 + } 1.100 + continue; 1.101 + } 1.102 + else if (!param.IsOut() && type == nsXPTType::T_FLOAT) { 1.103 +#ifndef __NO_FPRS__ 1.104 + if (fpr < FPR_COUNT) 1.105 + dp->val.f = (float) fprData[fpr++]; // in registers floats are passed as doubles 1.106 +#else 1.107 + if (gpr < GPR_COUNT) 1.108 + dp->val.f = *(float*) &gprData[gpr++]; 1.109 +#endif 1.110 + else 1.111 + dp->val.f = *(float*) ap++; 1.112 + continue; 1.113 + } 1.114 + else if (!param.IsOut() && (type == nsXPTType::T_I64 1.115 + || type == nsXPTType::T_U64)) { 1.116 + if (gpr & 1) gpr++; // longlongs are aligned in odd/even register pairs, eg. r5/r6 1.117 + if ((gpr + 1) < GPR_COUNT) { 1.118 + tempu64 = *(uint64_t*) &gprData[gpr]; 1.119 + gpr += 2; 1.120 + } 1.121 + else { 1.122 + if ((uint32_t) ap & 4) ap++; // longlongs are 8-byte aligned on stack 1.123 + tempu64 = *(uint64_t*) ap; 1.124 + ap += 2; 1.125 + } 1.126 + } 1.127 + else { 1.128 + if (gpr < GPR_COUNT) 1.129 + tempu32 = gprData[gpr++]; 1.130 + else 1.131 + tempu32 = *ap++; 1.132 + } 1.133 + 1.134 + if(param.IsOut() || !type.IsArithmetic()) { 1.135 + dp->val.p = (void*) tempu32; 1.136 + continue; 1.137 + } 1.138 + 1.139 + switch(type) { 1.140 + case nsXPTType::T_I8: dp->val.i8 = (int8_t) tempu32; break; 1.141 + case nsXPTType::T_I16: dp->val.i16 = (int16_t) tempu32; break; 1.142 + case nsXPTType::T_I32: dp->val.i32 = (int32_t) tempu32; break; 1.143 + case nsXPTType::T_I64: dp->val.i64 = (int64_t) tempu64; break; 1.144 + case nsXPTType::T_U8: dp->val.u8 = (uint8_t) tempu32; break; 1.145 + case nsXPTType::T_U16: dp->val.u16 = (uint16_t) tempu32; break; 1.146 + case nsXPTType::T_U32: dp->val.u32 = (uint32_t) tempu32; break; 1.147 + case nsXPTType::T_U64: dp->val.u64 = (uint64_t) tempu64; break; 1.148 + case nsXPTType::T_BOOL: dp->val.b = (bool) tempu32; break; 1.149 + case nsXPTType::T_CHAR: dp->val.c = (char) tempu32; break; 1.150 + case nsXPTType::T_WCHAR: dp->val.wc = (wchar_t) tempu32; break; 1.151 + 1.152 + default: 1.153 + NS_ERROR("bad type"); 1.154 + break; 1.155 + } 1.156 + } 1.157 + 1.158 + result = self->mOuter->CallMethod((uint16_t)methodIndex, 1.159 + info, 1.160 + dispatchParams); 1.161 + 1.162 + if (dispatchParams != paramBuffer) 1.163 + delete [] dispatchParams; 1.164 + 1.165 + return result; 1.166 +} 1.167 + 1.168 +// Load r11 with the constant 'n' and branch to SharedStub(). 1.169 +// 1.170 +// XXX Yes, it's ugly that we're relying on gcc's name-mangling here; 1.171 +// however, it's quick, dirty, and'll break when the ABI changes on 1.172 +// us, which is what we want ;-). 1.173 + 1.174 +// gcc-3 version 1.175 +// 1.176 +// As G++3 ABI contains the length of the functionname in the mangled 1.177 +// name, it is difficult to get a generic assembler mechanism like 1.178 +// in the G++ 2.95 case. 1.179 +// Create names would be like: 1.180 +// _ZN14nsXPTCStubBase5Stub1Ev 1.181 +// _ZN14nsXPTCStubBase6Stub12Ev 1.182 +// _ZN14nsXPTCStubBase7Stub123Ev 1.183 +// _ZN14nsXPTCStubBase8Stub1234Ev 1.184 +// etc. 1.185 +// Use assembler directives to get the names right... 1.186 + 1.187 +# define STUB_ENTRY(n) \ 1.188 +__asm__ ( \ 1.189 + ".align 2 \n\t" \ 1.190 + ".if "#n" < 10 \n\t" \ 1.191 + ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t" \ 1.192 + ".type _ZN14nsXPTCStubBase5Stub"#n"Ev,@function \n\n" \ 1.193 +"_ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t" \ 1.194 + \ 1.195 + ".elseif "#n" < 100 \n\t" \ 1.196 + ".globl _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t" \ 1.197 + ".type _ZN14nsXPTCStubBase6Stub"#n"Ev,@function \n\n" \ 1.198 +"_ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t" \ 1.199 + \ 1.200 + ".elseif "#n" < 1000 \n\t" \ 1.201 + ".globl _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t" \ 1.202 + ".type _ZN14nsXPTCStubBase7Stub"#n"Ev,@function \n\n" \ 1.203 +"_ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t" \ 1.204 + \ 1.205 + ".else \n\t" \ 1.206 + ".err \"stub number "#n" >= 1000 not yet supported\"\n" \ 1.207 + ".endif \n\t" \ 1.208 + \ 1.209 + "li 11,"#n" \n\t" \ 1.210 + "b SharedStub@local \n" \ 1.211 +); 1.212 + 1.213 +#define SENTINEL_ENTRY(n) \ 1.214 +nsresult nsXPTCStubBase::Sentinel##n() \ 1.215 +{ \ 1.216 + NS_ERROR("nsXPTCStubBase::Sentinel called"); \ 1.217 + return NS_ERROR_NOT_IMPLEMENTED; \ 1.218 +} 1.219 + 1.220 +#include "xptcstubsdef.inc"