xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ppc_linux.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 // Platform specific code to invoke XPCOM methods on native objects
michael@0 7
michael@0 8 // The purpose of NS_InvokeByIndex() is to map a platform
michael@0 9 // indepenpent call to the platform ABI. To do that,
michael@0 10 // NS_InvokeByIndex() has to determine the method to call via vtable
michael@0 11 // access. The parameters for the method are read from the
michael@0 12 // nsXPTCVariant* and prepared for th native ABI. For the Linux/PPC
michael@0 13 // ABI this means that the first 8 integral and floating point
michael@0 14 // parameters are passed in registers.
michael@0 15
michael@0 16 #include "xptcprivate.h"
michael@0 17
michael@0 18 // 8 integral parameters are passed in registers
michael@0 19 #define GPR_COUNT 8
michael@0 20
michael@0 21 // With hardfloat support 8 floating point parameters are passed in registers,
michael@0 22 // floats are promoted to doubles when passed in registers
michael@0 23 // In Softfloat mode, everything is handled via gprs
michael@0 24 #ifndef __NO_FPRS__
michael@0 25 #define FPR_COUNT 8
michael@0 26 #endif
michael@0 27 extern "C" uint32_t
michael@0 28 invoke_count_words(uint32_t paramCount, nsXPTCVariant* s)
michael@0 29 {
michael@0 30 return uint32_t(((paramCount * 2) + 3) & ~3);
michael@0 31 }
michael@0 32
michael@0 33 extern "C" void
michael@0 34 invoke_copy_to_stack(uint32_t* d,
michael@0 35 uint32_t paramCount,
michael@0 36 nsXPTCVariant* s,
michael@0 37 uint32_t* gpregs,
michael@0 38 double* fpregs)
michael@0 39 {
michael@0 40 uint32_t gpr = 1; // skip one GP reg for 'that'
michael@0 41 #ifndef __NO_FPRS__
michael@0 42 uint32_t fpr = 0;
michael@0 43 #endif
michael@0 44 uint32_t tempu32;
michael@0 45 uint64_t tempu64;
michael@0 46
michael@0 47 for(uint32_t i = 0; i < paramCount; i++, s++) {
michael@0 48 if(s->IsPtrData()) {
michael@0 49 if(s->type == nsXPTType::T_JSVAL)
michael@0 50 tempu32 = (uint32_t) &s->ptr;
michael@0 51 else
michael@0 52 tempu32 = (uint32_t) s->ptr;
michael@0 53 }
michael@0 54 else {
michael@0 55 switch(s->type) {
michael@0 56 case nsXPTType::T_FLOAT: break;
michael@0 57 case nsXPTType::T_DOUBLE: break;
michael@0 58 case nsXPTType::T_I8: tempu32 = s->val.i8; break;
michael@0 59 case nsXPTType::T_I16: tempu32 = s->val.i16; break;
michael@0 60 case nsXPTType::T_I32: tempu32 = s->val.i32; break;
michael@0 61 case nsXPTType::T_I64: tempu64 = s->val.i64; break;
michael@0 62 case nsXPTType::T_U8: tempu32 = s->val.u8; break;
michael@0 63 case nsXPTType::T_U16: tempu32 = s->val.u16; break;
michael@0 64 case nsXPTType::T_U32: tempu32 = s->val.u32; break;
michael@0 65 case nsXPTType::T_U64: tempu64 = s->val.u64; break;
michael@0 66 case nsXPTType::T_BOOL: tempu32 = s->val.b; break;
michael@0 67 case nsXPTType::T_CHAR: tempu32 = s->val.c; break;
michael@0 68 case nsXPTType::T_WCHAR: tempu32 = s->val.wc; break;
michael@0 69 default: tempu32 = (uint32_t) s->val.p; break;
michael@0 70 }
michael@0 71 }
michael@0 72
michael@0 73 if (!s->IsPtrData() && s->type == nsXPTType::T_DOUBLE) {
michael@0 74 #ifndef __NO_FPRS__
michael@0 75 if (fpr < FPR_COUNT)
michael@0 76 fpregs[fpr++] = s->val.d;
michael@0 77 #else
michael@0 78 if (gpr & 1)
michael@0 79 gpr++;
michael@0 80 if ((gpr + 1) < GPR_COUNT) {
michael@0 81 *((double*) &gpregs[gpr]) = s->val.d;
michael@0 82 gpr += 2;
michael@0 83 }
michael@0 84 #endif
michael@0 85 else {
michael@0 86 if ((uint32_t) d & 4) d++; // doubles are 8-byte aligned on stack
michael@0 87 *((double*) d) = s->val.d;
michael@0 88 d += 2;
michael@0 89 }
michael@0 90 }
michael@0 91 else if (!s->IsPtrData() && s->type == nsXPTType::T_FLOAT) {
michael@0 92 #ifndef __NO_FPRS__
michael@0 93 if (fpr < FPR_COUNT)
michael@0 94 fpregs[fpr++] = s->val.f; // if passed in registers, floats are promoted to doubles
michael@0 95 #else
michael@0 96 if (gpr < GPR_COUNT)
michael@0 97 *((float*) &gpregs[gpr++]) = s->val.f;
michael@0 98 #endif
michael@0 99 else
michael@0 100 *((float*) d++) = s->val.f;
michael@0 101 }
michael@0 102 else if (!s->IsPtrData() && (s->type == nsXPTType::T_I64
michael@0 103 || s->type == nsXPTType::T_U64)) {
michael@0 104 if (gpr & 1) gpr++; // longlongs are aligned in odd/even register pairs, eg. r5/r6
michael@0 105 if ((gpr + 1) < GPR_COUNT) {
michael@0 106 *((uint64_t*) &gpregs[gpr]) = tempu64;
michael@0 107 gpr += 2;
michael@0 108 }
michael@0 109 else {
michael@0 110 if ((uint32_t) d & 4) d++; // longlongs are 8-byte aligned on stack
michael@0 111 *((uint64_t*) d) = tempu64;
michael@0 112 d += 2;
michael@0 113 }
michael@0 114 }
michael@0 115 else {
michael@0 116 if (gpr < GPR_COUNT)
michael@0 117 gpregs[gpr++] = tempu32;
michael@0 118 else
michael@0 119 *d++ = tempu32;
michael@0 120 }
michael@0 121
michael@0 122 }
michael@0 123 }
michael@0 124
michael@0 125 extern "C"
michael@0 126 EXPORT_XPCOM_API(nsresult)
michael@0 127 NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex,
michael@0 128 uint32_t paramCount, nsXPTCVariant* params);

mercurial