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

mercurial