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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_ppc64_linux.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     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 +// independent 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 the native ABI.
    1.16 +
    1.17 +// The PowerPC64 platform ABI can be found here:
    1.18 +// http://www.freestandards.org/spec/ELF/ppc64/
    1.19 +// and in particular:
    1.20 +// http://www.freestandards.org/spec/ELF/ppc64/PPC-elf64abi-1.9.html#FUNC-CALL
    1.21 +
    1.22 +#include <stdio.h>
    1.23 +#include "xptcprivate.h"
    1.24 +
    1.25 +// 8 integral parameters are passed in registers, not including 'that'
    1.26 +#define GPR_COUNT     7
    1.27 +
    1.28 +// 8 floating point parameters are passed in registers, floats are
    1.29 +// promoted to doubles when passed in registers
    1.30 +#define FPR_COUNT     13
    1.31 +
    1.32 +extern "C" uint32_t
    1.33 +invoke_count_words(uint32_t paramCount, nsXPTCVariant* s)
    1.34 +{
    1.35 +    return uint32_t(((paramCount * 2) + 3) & ~3);
    1.36 +}
    1.37 +
    1.38 +extern "C" void
    1.39 +invoke_copy_to_stack(uint64_t* gpregs,
    1.40 +                     double* fpregs,
    1.41 +                     uint32_t paramCount,
    1.42 +                     nsXPTCVariant* s, 
    1.43 +                     uint64_t* d)
    1.44 +{
    1.45 +    uint64_t tempu64;
    1.46 +
    1.47 +    for(uint32_t i = 0; i < paramCount; i++, s++) {
    1.48 +        if(s->IsPtrData())
    1.49 +            tempu64 = (uint64_t) s->ptr;
    1.50 +        else {
    1.51 +            switch(s->type) {
    1.52 +            case nsXPTType::T_FLOAT:                                  break;
    1.53 +            case nsXPTType::T_DOUBLE:                                 break;
    1.54 +            case nsXPTType::T_I8:     tempu64 = s->val.i8;            break;
    1.55 +            case nsXPTType::T_I16:    tempu64 = s->val.i16;           break;
    1.56 +            case nsXPTType::T_I32:    tempu64 = s->val.i32;           break;
    1.57 +            case nsXPTType::T_I64:    tempu64 = s->val.i64;           break;
    1.58 +            case nsXPTType::T_U8:     tempu64 = s->val.u8;            break;
    1.59 +            case nsXPTType::T_U16:    tempu64 = s->val.u16;           break;
    1.60 +            case nsXPTType::T_U32:    tempu64 = s->val.u32;           break;
    1.61 +            case nsXPTType::T_U64:    tempu64 = s->val.u64;           break;
    1.62 +            case nsXPTType::T_BOOL:   tempu64 = s->val.b;             break;
    1.63 +            case nsXPTType::T_CHAR:   tempu64 = s->val.c;             break;
    1.64 +            case nsXPTType::T_WCHAR:  tempu64 = s->val.wc;            break;
    1.65 +            default:                  tempu64 = (uint64_t) s->val.p;  break;
    1.66 +            }
    1.67 +        }
    1.68 +
    1.69 +        if (!s->IsPtrData() && s->type == nsXPTType::T_DOUBLE) {
    1.70 +            if (i < FPR_COUNT)
    1.71 +                fpregs[i]    = s->val.d;
    1.72 +            else
    1.73 +                *(double *)d = s->val.d;
    1.74 +        }
    1.75 +        else if (!s->IsPtrData() && s->type == nsXPTType::T_FLOAT) {
    1.76 +            if (i < FPR_COUNT) {
    1.77 +                fpregs[i]   = s->val.f; // if passed in registers, floats are promoted to doubles
    1.78 +            } else {
    1.79 +                float *p = (float *)d;
    1.80 +#ifndef __LITTLE_ENDIAN__
    1.81 +                p++;
    1.82 +#endif
    1.83 +                *p = s->val.f;
    1.84 +            }
    1.85 +        }
    1.86 +        else {
    1.87 +            if (i < GPR_COUNT)
    1.88 +                gpregs[i] = tempu64;
    1.89 +            else
    1.90 +                *d = tempu64;
    1.91 +        }
    1.92 +        if (i >= 7)
    1.93 +            d++;
    1.94 +    }
    1.95 +}
    1.96 +
    1.97 +EXPORT_XPCOM_API(nsresult)
    1.98 +NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex,
    1.99 +                   uint32_t paramCount, nsXPTCVariant* params);
   1.100 +

mercurial