xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc_netbsd.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/xptcstubs_ppc_netbsd.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,182 @@
     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 +
    1.13 +// The Linux/PPC ABI (aka PPC/SYSV ABI) passes the first 8 integral
    1.14 +// parameters and the first 8 floating point parameters in registers
    1.15 +// (r3-r10 and f1-f8), no stack space is allocated for these by the
    1.16 +// caller.  The rest of the parameters are passed in the callers stack
    1.17 +// area. The stack pointer has to retain 16-byte alignment, longlongs
    1.18 +// and doubles are aligned on 8-byte boundaries.
    1.19 +
    1.20 +#define PARAM_BUFFER_COUNT     16
    1.21 +#define GPR_COUNT               8
    1.22 +#define FPR_COUNT               8
    1.23 +
    1.24 +// PrepareAndDispatch() is called by SharedStub() and calls the actual method.
    1.25 +//
    1.26 +// - 'args[]' contains the arguments passed on stack
    1.27 +// - 'gprData[]' contains the arguments passed in integer registers
    1.28 +// - 'fprData[]' contains the arguments passed in floating point registers
    1.29 +// 
    1.30 +// The parameters are mapped into an array of type 'nsXPTCMiniVariant'
    1.31 +// and then the method gets called.
    1.32 +
    1.33 +extern "C" nsresult ATTRIBUTE_USED
    1.34 +PrepareAndDispatch(nsXPTCStubBase* self,
    1.35 +                   uint32_t methodIndex,
    1.36 +                   uint32_t* args,
    1.37 +                   uint32_t *gprData,
    1.38 +                   double *fprData)
    1.39 +{
    1.40 +    nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
    1.41 +    nsXPTCMiniVariant* dispatchParams = nullptr;
    1.42 +    nsIInterfaceInfo* iface_info = nullptr;
    1.43 +    const nsXPTMethodInfo* info;
    1.44 +    uint32_t paramCount;
    1.45 +    uint32_t i;
    1.46 +    nsresult result = NS_ERROR_FAILURE;
    1.47 +
    1.48 +    NS_ASSERTION(self,"no self");
    1.49 +
    1.50 +    self->GetInterfaceInfo(&iface_info);
    1.51 +    NS_ASSERTION(iface_info,"no interface info");
    1.52 +    if (! iface_info)
    1.53 +        return NS_ERROR_UNEXPECTED;
    1.54 +
    1.55 +    iface_info->GetMethodInfo(uint16_t(methodIndex), &info);
    1.56 +    NS_ASSERTION(info,"no method info");
    1.57 +    if (! info)
    1.58 +        return NS_ERROR_UNEXPECTED;
    1.59 +
    1.60 +    paramCount = info->GetParamCount();
    1.61 +
    1.62 +    // setup variant array pointer
    1.63 +    if(paramCount > PARAM_BUFFER_COUNT)
    1.64 +        dispatchParams = new nsXPTCMiniVariant[paramCount];
    1.65 +    else
    1.66 +        dispatchParams = paramBuffer;
    1.67 +
    1.68 +    NS_ASSERTION(dispatchParams,"no place for params");
    1.69 +    if (! dispatchParams)
    1.70 +        return NS_ERROR_OUT_OF_MEMORY;
    1.71 +
    1.72 +    uint32_t* ap = args;
    1.73 +    uint32_t gpr = 1;    // skip one GPR register
    1.74 +    uint32_t fpr = 0;
    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 +            if (fpr < FPR_COUNT)
    1.85 +                dp->val.d = fprData[fpr++];
    1.86 +            else {
    1.87 +                if ((uint32_t) ap & 4) ap++; // doubles are 8-byte aligned on stack
    1.88 +                dp->val.d = *(double*) ap;
    1.89 +                ap += 2;
    1.90 +		if (gpr < GPR_COUNT)
    1.91 +		    gpr += 2;
    1.92 +            }
    1.93 +            continue;
    1.94 +        }
    1.95 +        else if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
    1.96 +            if (fpr < FPR_COUNT)
    1.97 +                dp->val.f = (float) fprData[fpr++]; // in registers floats are passed as doubles
    1.98 +            else {
    1.99 +                dp->val.f = *(float*) ap;
   1.100 +		ap += 1;
   1.101 +		if (gpr < GPR_COUNT)
   1.102 +		    gpr += 1;
   1.103 +            }
   1.104 +            continue;
   1.105 +        }
   1.106 +        else if (!param.IsOut() && (type == nsXPTType::T_I64
   1.107 +                                    || type == nsXPTType::T_U64)) {
   1.108 +            if (gpr & 1) gpr++; // longlongs are aligned in odd/even register pairs, eg. r5/r6
   1.109 +            if ((gpr + 1) < GPR_COUNT) {
   1.110 +                tempu64 = *(uint64_t*) &gprData[gpr];
   1.111 +                gpr += 2;
   1.112 +            }
   1.113 +            else {
   1.114 +                if ((uint32_t) ap & 4) ap++; // longlongs are 8-byte aligned on stack
   1.115 +                tempu64 = *(uint64_t*) ap;
   1.116 +                ap += 2;
   1.117 +            }
   1.118 +        }
   1.119 +        else {
   1.120 +            if (gpr < GPR_COUNT)
   1.121 +                tempu32 = gprData[gpr++];
   1.122 +            else
   1.123 +                tempu32 = *ap++;
   1.124 +        }
   1.125 +
   1.126 +        if(param.IsOut() || !type.IsArithmetic()) {
   1.127 +            dp->val.p = (void*) tempu32;
   1.128 +            continue;
   1.129 +        }
   1.130 +
   1.131 +        switch(type) {
   1.132 +        case nsXPTType::T_I8:      dp->val.i8  = (int8_t)   tempu32; break;
   1.133 +        case nsXPTType::T_I16:     dp->val.i16 = (int16_t)  tempu32; break;
   1.134 +        case nsXPTType::T_I32:     dp->val.i32 = (int32_t)  tempu32; break;
   1.135 +        case nsXPTType::T_I64:     dp->val.i64 = (int64_t)  tempu64; break;
   1.136 +        case nsXPTType::T_U8:      dp->val.u8  = (uint8_t)  tempu32; break;
   1.137 +        case nsXPTType::T_U16:     dp->val.u16 = (uint16_t) tempu32; break;
   1.138 +        case nsXPTType::T_U32:     dp->val.u32 = (uint32_t) tempu32; break;
   1.139 +        case nsXPTType::T_U64:     dp->val.u64 = (uint64_t) tempu64; break;
   1.140 +        case nsXPTType::T_BOOL:    dp->val.b   = (bool)   tempu32; break;
   1.141 +        case nsXPTType::T_CHAR:    dp->val.c   = (char)     tempu32; break;
   1.142 +        case nsXPTType::T_WCHAR:   dp->val.wc  = (wchar_t)  tempu32; break;
   1.143 +
   1.144 +        default:
   1.145 +            NS_ERROR("bad type");
   1.146 +            break;
   1.147 +        }
   1.148 +    }
   1.149 +
   1.150 +    result = self->CallMethod((uint16_t) methodIndex, info, dispatchParams);
   1.151 +
   1.152 +    NS_RELEASE(iface_info);
   1.153 +
   1.154 +    if (dispatchParams != paramBuffer)
   1.155 +        delete [] dispatchParams;
   1.156 +
   1.157 +    return result;
   1.158 +}
   1.159 +
   1.160 +// Load r11 with the constant 'n' and branch to SharedStub().
   1.161 +//
   1.162 +// XXX Yes, it's ugly that we're relying on gcc's name-mangling here;
   1.163 +// however, it's quick, dirty, and'll break when the ABI changes on
   1.164 +// us, which is what we want ;-).
   1.165 +
   1.166 +#define STUB_ENTRY(n)                                       \
   1.167 +__asm__ (                                                   \
   1.168 +        ".section \".text\" \n\t"                           \
   1.169 +        ".align 2 \n\t"                                     \
   1.170 +	".globl  Stub"#n"__14nsXPTCStubBase \n\t"           \
   1.171 +	".type   Stub"#n"__14nsXPTCStubBase,@function \n\n" \
   1.172 +                                                            \
   1.173 +"Stub"#n"__14nsXPTCStubBase: \n\t"                          \
   1.174 +	"li     11,"#n" \n\t"                               \
   1.175 +	"b      SharedStub@local \n"                        \
   1.176 +);
   1.177 +
   1.178 +#define SENTINEL_ENTRY(n)                            \
   1.179 +nsresult nsXPTCStubBase::Sentinel##n()               \
   1.180 +{                                                    \
   1.181 +  NS_ERROR("nsXPTCStubBase::Sentinel called"); \
   1.182 +  return NS_ERROR_NOT_IMPLEMENTED;                   \
   1.183 +}
   1.184 +
   1.185 +#include "xptcstubsdef.inc"

mercurial