1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ppc_openbsd.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 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 +// Platform specific code to invoke XPCOM methods on native objects 1.10 + 1.11 +// The purpose of NS_InvokeByIndex() is to map a platform 1.12 +// indepenpent call to the platform ABI. To do that, 1.13 +// NS_InvokeByIndex() has to determine the method to call via vtable 1.14 +// access. The parameters for the method are read from the 1.15 +// nsXPTCVariant* and prepared for th native ABI. For the Linux/PPC 1.16 +// ABI this means that the first 8 integral and floating point 1.17 +// parameters are passed in registers. 1.18 + 1.19 +#include "xptcprivate.h" 1.20 + 1.21 +// 8 integral parameters are passed in registers 1.22 +#define GPR_COUNT 8 1.23 + 1.24 +// 8 floating point parameters are passed in registers, floats are 1.25 +// promoted to doubles when passed in registers 1.26 +#define FPR_COUNT 8 1.27 + 1.28 +extern "C" uint32_t 1.29 +invoke_count_words(uint32_t paramCount, nsXPTCVariant* s) 1.30 +{ 1.31 + return uint32_t(((paramCount * 2) + 3) & ~3); 1.32 +} 1.33 + 1.34 +extern "C" void 1.35 +invoke_copy_to_stack(uint32_t* d, 1.36 + uint32_t paramCount, 1.37 + nsXPTCVariant* s, 1.38 + uint32_t* gpregs, 1.39 + double* fpregs) 1.40 +{ 1.41 + uint32_t gpr = 1; // skip one GP reg for 'that' 1.42 + uint32_t fpr = 0; 1.43 + uint32_t tempu32; 1.44 + uint64_t tempu64; 1.45 + 1.46 + for(uint32_t i = 0; i < paramCount; i++, s++) { 1.47 + if(s->IsPtrData()) { 1.48 + if(s->type == nsXPTType::T_JSVAL) 1.49 + tempu32 = (uint32_t) &(s->ptr); 1.50 + else 1.51 + tempu32 = (uint32_t) s->ptr; 1.52 + } else { 1.53 + switch(s->type) { 1.54 + case nsXPTType::T_FLOAT: break; 1.55 + case nsXPTType::T_DOUBLE: break; 1.56 + case nsXPTType::T_I8: tempu32 = s->val.i8; break; 1.57 + case nsXPTType::T_I16: tempu32 = s->val.i16; break; 1.58 + case nsXPTType::T_I32: tempu32 = s->val.i32; break; 1.59 + case nsXPTType::T_I64: tempu64 = s->val.i64; break; 1.60 + case nsXPTType::T_U8: tempu32 = s->val.u8; break; 1.61 + case nsXPTType::T_U16: tempu32 = s->val.u16; break; 1.62 + case nsXPTType::T_U32: tempu32 = s->val.u32; break; 1.63 + case nsXPTType::T_U64: tempu64 = s->val.u64; break; 1.64 + case nsXPTType::T_BOOL: tempu32 = s->val.b; break; 1.65 + case nsXPTType::T_CHAR: tempu32 = s->val.c; break; 1.66 + case nsXPTType::T_WCHAR: tempu32 = s->val.wc; break; 1.67 + default: tempu32 = (uint32_t) s->val.p; break; 1.68 + } 1.69 + } 1.70 + 1.71 + if (!s->IsPtrData() && s->type == nsXPTType::T_DOUBLE) { 1.72 + if (fpr < FPR_COUNT) 1.73 + fpregs[fpr++] = s->val.d; 1.74 + else { 1.75 + if ((uint32_t) d & 4) d++; // doubles are 8-byte aligned on stack 1.76 + *((double*) d) = s->val.d; 1.77 + d += 2; 1.78 + } 1.79 + } 1.80 + else if (!s->IsPtrData() && s->type == nsXPTType::T_FLOAT) { 1.81 + if (fpr < FPR_COUNT) 1.82 + fpregs[fpr++] = s->val.f; // if passed in registers, floats are promoted to doubles 1.83 + else 1.84 + *((float*) d++) = s->val.f; 1.85 + } 1.86 + else if (!s->IsPtrData() && (s->type == nsXPTType::T_I64 1.87 + || s->type == nsXPTType::T_U64)) { 1.88 + if ((gpr + 1) < GPR_COUNT) { 1.89 + if (gpr & 1) gpr++; // longlongs are aligned in odd/even register pairs, eg. r5/r6 1.90 + *((uint64_t*) &gpregs[gpr]) = tempu64; 1.91 + gpr += 2; 1.92 + } 1.93 + else { 1.94 + if ((uint32_t) d & 4) d++; // longlongs are 8-byte aligned on stack 1.95 + *((uint64_t*) d) = tempu64; 1.96 + d += 2; 1.97 + } 1.98 + } 1.99 + else { 1.100 + if (gpr < GPR_COUNT) 1.101 + gpregs[gpr++] = tempu32; 1.102 + else 1.103 + *d++ = tempu32; 1.104 + } 1.105 + 1.106 + } 1.107 +} 1.108 + 1.109 +extern "C" 1.110 +EXPORT_XPCOM_API(nsresult) 1.111 +NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, 1.112 + uint32_t paramCount, nsXPTCVariant* params);