xpcom/reflect/xptcall/src/md/unix/xptcstubs_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/xptcstubs_ppc64_linux.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,246 @@
     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/PPC64 ABI passes the first 8 integral
    1.15 +// parameters and the first 13 floating point parameters in registers
    1.16 +// (r3-r10 and f1-f13), no stack space is allocated for these by the
    1.17 +// caller.  The rest of the parameters are passed in the caller's stack
    1.18 +// area. The stack pointer has to retain 16-byte alignment.
    1.19 +
    1.20 +// The PowerPC64 platform ABI can be found here:
    1.21 +// http://www.freestandards.org/spec/ELF/ppc64/
    1.22 +// and in particular:
    1.23 +// http://www.freestandards.org/spec/ELF/ppc64/PPC-elf64abi-1.9.html#FUNC-CALL
    1.24 +
    1.25 +#define PARAM_BUFFER_COUNT      16
    1.26 +#define GPR_COUNT                7
    1.27 +#define FPR_COUNT               13
    1.28 +
    1.29 +// PrepareAndDispatch() is called by SharedStub() and calls the actual method.
    1.30 +//
    1.31 +// - 'args[]' contains the arguments passed on stack
    1.32 +// - 'gprData[]' contains the arguments passed in integer registers
    1.33 +// - 'fprData[]' contains the arguments passed in floating point registers
    1.34 +// 
    1.35 +// The parameters are mapped into an array of type 'nsXPTCMiniVariant'
    1.36 +// and then the method gets called.
    1.37 +#include <stdio.h>
    1.38 +extern "C" nsresult ATTRIBUTE_USED
    1.39 +PrepareAndDispatch(nsXPTCStubBase* self,
    1.40 +                   uint64_t methodIndex,
    1.41 +                   uint64_t* args,
    1.42 +                   uint64_t *gprData,
    1.43 +                   double *fprData)
    1.44 +{
    1.45 +    nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
    1.46 +    nsXPTCMiniVariant* dispatchParams = nullptr;
    1.47 +    const nsXPTMethodInfo* info;
    1.48 +    uint32_t paramCount;
    1.49 +    uint32_t i;
    1.50 +    nsresult result = NS_ERROR_FAILURE;
    1.51 +
    1.52 +    NS_ASSERTION(self,"no self");
    1.53 +
    1.54 +    self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
    1.55 +    NS_ASSERTION(info,"no method info");
    1.56 +    if (! info)
    1.57 +        return NS_ERROR_UNEXPECTED;
    1.58 +
    1.59 +    paramCount = info->GetParamCount();
    1.60 +
    1.61 +    // setup variant array pointer
    1.62 +    if(paramCount > PARAM_BUFFER_COUNT)
    1.63 +        dispatchParams = new nsXPTCMiniVariant[paramCount];
    1.64 +    else
    1.65 +        dispatchParams = paramBuffer;
    1.66 +
    1.67 +    NS_ASSERTION(dispatchParams,"no place for params");
    1.68 +    if (! dispatchParams)
    1.69 +        return NS_ERROR_OUT_OF_MEMORY;
    1.70 +
    1.71 +    uint64_t* ap = args;
    1.72 +    uint64_t tempu64;
    1.73 +
    1.74 +    for(i = 0; i < paramCount; i++) {
    1.75 +        const nsXPTParamInfo& param = info->GetParam(i);
    1.76 +        const nsXPTType& type = param.GetType();
    1.77 +        nsXPTCMiniVariant* dp = &dispatchParams[i];
    1.78 +	
    1.79 +        if (!param.IsOut() && type == nsXPTType::T_DOUBLE) {
    1.80 +            if (i < FPR_COUNT)
    1.81 +                dp->val.d = fprData[i];
    1.82 +            else
    1.83 +                dp->val.d = *(double*) ap;
    1.84 +        } else if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
    1.85 +            if (i < FPR_COUNT)
    1.86 +                dp->val.f = (float) fprData[i]; // in registers floats are passed as doubles
    1.87 +            else {
    1.88 +                float *p = (float *)ap;
    1.89 +#ifndef __LITTLE_ENDIAN__
    1.90 +                p++;
    1.91 +#endif
    1.92 +                dp->val.f = *p;
    1.93 +            }
    1.94 +        } else { /* integer type or pointer */
    1.95 +            if (i < GPR_COUNT)
    1.96 +                tempu64 = gprData[i];
    1.97 +            else
    1.98 +                tempu64 = *ap;
    1.99 +
   1.100 +            if (param.IsOut() || !type.IsArithmetic())
   1.101 +                dp->val.p = (void*) tempu64;
   1.102 +            else if (type == nsXPTType::T_I8)
   1.103 +                dp->val.i8  = (int8_t)   tempu64;
   1.104 +            else if (type == nsXPTType::T_I16)
   1.105 +                dp->val.i16 = (int16_t)  tempu64;
   1.106 +            else if (type == nsXPTType::T_I32)
   1.107 +                dp->val.i32 = (int32_t)  tempu64;
   1.108 +            else if (type == nsXPTType::T_I64)
   1.109 +                dp->val.i64 = (int64_t)  tempu64;
   1.110 +            else if (type == nsXPTType::T_U8)
   1.111 +                dp->val.u8  = (uint8_t)  tempu64;
   1.112 +            else if (type == nsXPTType::T_U16)
   1.113 +                dp->val.u16 = (uint16_t) tempu64;
   1.114 +            else if (type == nsXPTType::T_U32)
   1.115 +                dp->val.u32 = (uint32_t) tempu64;
   1.116 +            else if (type == nsXPTType::T_U64)
   1.117 +                dp->val.u64 = (uint64_t) tempu64;
   1.118 +            else if (type == nsXPTType::T_BOOL)
   1.119 +                dp->val.b   = (bool)   tempu64;
   1.120 +            else if (type == nsXPTType::T_CHAR)
   1.121 +                dp->val.c   = (char)     tempu64;
   1.122 +            else if (type == nsXPTType::T_WCHAR)
   1.123 +                dp->val.wc  = (wchar_t)  tempu64;
   1.124 +            else
   1.125 +                NS_ERROR("bad type");
   1.126 +        }
   1.127 +
   1.128 +        if (i >= 7)
   1.129 +            ap++;
   1.130 +    }
   1.131 +
   1.132 +    result = self->mOuter->CallMethod((uint16_t) methodIndex, info,
   1.133 +                                      dispatchParams);
   1.134 +
   1.135 +    if (dispatchParams != paramBuffer)
   1.136 +        delete [] dispatchParams;
   1.137 +
   1.138 +    return result;
   1.139 +}
   1.140 +
   1.141 +// Load r11 with the constant 'n' and branch to SharedStub().
   1.142 +//
   1.143 +// XXX Yes, it's ugly that we're relying on gcc's name-mangling here;
   1.144 +// however, it's quick, dirty, and'll break when the ABI changes on
   1.145 +// us, which is what we want ;-).
   1.146 +
   1.147 +
   1.148 +// gcc-3 version
   1.149 +//
   1.150 +// As G++3 ABI contains the length of the functionname in the mangled
   1.151 +// name, it is difficult to get a generic assembler mechanism like
   1.152 +// in the G++ 2.95 case.
   1.153 +// Create names would be like:
   1.154 +// _ZN14nsXPTCStubBase5Stub1Ev
   1.155 +// _ZN14nsXPTCStubBase6Stub12Ev
   1.156 +// _ZN14nsXPTCStubBase7Stub123Ev
   1.157 +// _ZN14nsXPTCStubBase8Stub1234Ev
   1.158 +// etc.
   1.159 +// Use assembler directives to get the names right...
   1.160 +
   1.161 +#if _CALL_ELF == 2
   1.162 +# define STUB_ENTRY(n)                                                  \
   1.163 +__asm__ (                                                               \
   1.164 +        ".section \".text\" \n\t"                                       \
   1.165 +        ".align 2 \n\t"                                                 \
   1.166 +        ".if "#n" < 10 \n\t"                                            \
   1.167 +        ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t"                    \
   1.168 +        ".type  _ZN14nsXPTCStubBase5Stub"#n"Ev,@function \n\n"          \
   1.169 +"_ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t"                                  \
   1.170 +        "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
   1.171 +        "addi     2,2,.TOC.-0b@l \n\t"                                  \
   1.172 +        ".localentry _ZN14nsXPTCStubBase5Stub"#n"Ev,.-_ZN14nsXPTCStubBase5Stub"#n"Ev \n\t" \
   1.173 +                                                                        \
   1.174 +        ".elseif "#n" < 100 \n\t"                                       \
   1.175 +        ".globl _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t"                    \
   1.176 +        ".type  _ZN14nsXPTCStubBase6Stub"#n"Ev,@function \n\n"          \
   1.177 +"_ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t"                                  \
   1.178 +        "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
   1.179 +        "addi     2,2,.TOC.-0b@l \n\t"                                  \
   1.180 +        ".localentry _ZN14nsXPTCStubBase6Stub"#n"Ev,.-_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 +        "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
   1.187 +        "addi     2,2,.TOC.-0b@l \n\t"                                  \
   1.188 +        ".localentry _ZN14nsXPTCStubBase7Stub"#n"Ev,.-_ZN14nsXPTCStubBase7Stub"#n"Ev \n\t" \
   1.189 +                                                                        \
   1.190 +        ".else  \n\t"                                                   \
   1.191 +        ".err   \"stub number "#n" >= 1000 not yet supported\"\n"       \
   1.192 +        ".endif \n\t"                                                   \
   1.193 +                                                                        \
   1.194 +        "li     11,"#n" \n\t"                                           \
   1.195 +        "b      SharedStub \n"                                          \
   1.196 +);
   1.197 +#else
   1.198 +# define STUB_ENTRY(n)                                                  \
   1.199 +__asm__ (                                                               \
   1.200 +        ".section \".toc\",\"aw\" \n\t"                                 \
   1.201 +        ".section \".text\" \n\t"                                       \
   1.202 +        ".align 2 \n\t"                                                 \
   1.203 +        ".if "#n" < 10 \n\t"                                            \
   1.204 +        ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t"                    \
   1.205 +        ".section \".opd\",\"aw\" \n\t"                                 \
   1.206 +        ".align 3 \n\t"                                                 \
   1.207 +"_ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t"                                  \
   1.208 +        ".quad  ._ZN14nsXPTCStubBase5Stub"#n"Ev,.TOC.@tocbase \n\t"     \
   1.209 +        ".previous \n\t"                                                \
   1.210 +        ".type  _ZN14nsXPTCStubBase5Stub"#n"Ev,@function \n\n"          \
   1.211 +"._ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t"                                 \
   1.212 +                                                                        \
   1.213 +        ".elseif "#n" < 100 \n\t"                                       \
   1.214 +        ".globl _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t"                    \
   1.215 +        ".section \".opd\",\"aw\" \n\t"                                 \
   1.216 +        ".align 3 \n\t"                                                 \
   1.217 +"_ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t"                                  \
   1.218 +        ".quad  ._ZN14nsXPTCStubBase6Stub"#n"Ev,.TOC.@tocbase \n\t"     \
   1.219 +        ".previous \n\t"                                                \
   1.220 +        ".type  _ZN14nsXPTCStubBase6Stub"#n"Ev,@function \n\n"          \
   1.221 +"._ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t"                                 \
   1.222 +                                                                        \
   1.223 +        ".elseif "#n" < 1000 \n\t"                                      \
   1.224 +        ".globl _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t"                    \
   1.225 +        ".section \".opd\",\"aw\" \n\t"                                 \
   1.226 +        ".align 3 \n\t"                                                 \
   1.227 +"_ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t"                                  \
   1.228 +        ".quad  ._ZN14nsXPTCStubBase7Stub"#n"Ev,.TOC.@tocbase \n\t"     \
   1.229 +        ".previous \n\t"                                                \
   1.230 +        ".type  _ZN14nsXPTCStubBase7Stub"#n"Ev,@function \n\n"          \
   1.231 +"._ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t"                                 \
   1.232 +                                                                        \
   1.233 +        ".else  \n\t"                                                   \
   1.234 +        ".err   \"stub number "#n" >= 1000 not yet supported\"\n"       \
   1.235 +        ".endif \n\t"                                                   \
   1.236 +                                                                        \
   1.237 +        "li     11,"#n" \n\t"                                           \
   1.238 +        "b      SharedStub \n"                                          \
   1.239 +);
   1.240 +#endif
   1.241 +
   1.242 +#define SENTINEL_ENTRY(n)                                               \
   1.243 +nsresult nsXPTCStubBase::Sentinel##n()                                  \
   1.244 +{                                                                       \
   1.245 +    NS_ERROR("nsXPTCStubBase::Sentinel called");                  \
   1.246 +    return NS_ERROR_NOT_IMPLEMENTED;                                    \
   1.247 +}
   1.248 +
   1.249 +#include "xptcstubsdef.inc"

mercurial