xpcom/reflect/xptcall/src/md/win32/xptcstubs_x86_64_gnu.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/reflect/xptcall/src/md/win32/xptcstubs_x86_64_gnu.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,297 @@
     1.4 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "xptcprivate.h"
    1.11 +#include "xptiprivate.h"
    1.12 +
    1.13 +/*
    1.14 + * This is for Windows 64 bit (x86_64) using GCC syntax
    1.15 + * Code was copied from the MSVC version.
    1.16 + */
    1.17 +
    1.18 +#if !defined(_AMD64_) || !defined(__GNUC__)
    1.19 +#  error xptcstubs_x86_64_gnu.cpp being used unexpectedly
    1.20 +#endif
    1.21 +
    1.22 +extern "C" nsresult __attribute__((__used__))
    1.23 +PrepareAndDispatch(nsXPTCStubBase * self, uint32_t methodIndex,
    1.24 +                   uint64_t * args, uint64_t * gprData, double *fprData)
    1.25 +{
    1.26 +#define PARAM_BUFFER_COUNT  16
    1.27 +//
    1.28 +// "this" pointer is first parameter, so parameter count is 3.
    1.29 +//
    1.30 +#define PARAM_GPR_COUNT   3
    1.31 +#define PARAM_FPR_COUNT   3
    1.32 +
    1.33 +    nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
    1.34 +    nsXPTCMiniVariant* dispatchParams = nullptr;
    1.35 +    const nsXPTMethodInfo* info = nullptr;
    1.36 +    uint8_t paramCount;
    1.37 +    uint8_t i;
    1.38 +    nsresult result = NS_ERROR_FAILURE;
    1.39 +
    1.40 +    NS_ASSERTION(self, "no self");
    1.41 +
    1.42 +    self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
    1.43 +    NS_ASSERTION(info, "no method info");
    1.44 +
    1.45 +    paramCount = info->GetParamCount();
    1.46 +
    1.47 +    //
    1.48 +    // setup variant array pointer
    1.49 +    //
    1.50 +
    1.51 +    if(paramCount > PARAM_BUFFER_COUNT)
    1.52 +        dispatchParams = new nsXPTCMiniVariant[paramCount];
    1.53 +    else
    1.54 +        dispatchParams = paramBuffer;
    1.55 +
    1.56 +    NS_ASSERTION(dispatchParams,"no place for params");
    1.57 +
    1.58 +    uint64_t* ap = args;
    1.59 +    uint32_t iCount = 0;
    1.60 +
    1.61 +    for(i = 0; i < paramCount; i++)
    1.62 +    {
    1.63 +        const nsXPTParamInfo& param = info->GetParam(i);
    1.64 +        const nsXPTType& type = param.GetType();
    1.65 +        nsXPTCMiniVariant* dp = &dispatchParams[i];
    1.66 +
    1.67 +        if(param.IsOut() || !type.IsArithmetic())
    1.68 +        {
    1.69 +            if (iCount < PARAM_GPR_COUNT)
    1.70 +                dp->val.p = (void*)gprData[iCount++];
    1.71 +            else
    1.72 +                dp->val.p = (void*)*ap++;
    1.73 +
    1.74 +            continue;
    1.75 +        }
    1.76 +        // else
    1.77 +        switch(type)
    1.78 +        {
    1.79 +        case nsXPTType::T_I8:
    1.80 +           if (iCount < PARAM_GPR_COUNT)
    1.81 +              dp->val.i8  = (int8_t)gprData[iCount++];
    1.82 +           else
    1.83 +              dp->val.i8  = *((int8_t*)ap++);
    1.84 +           break;
    1.85 +
    1.86 +        case nsXPTType::T_I16:
    1.87 +            if (iCount < PARAM_GPR_COUNT)
    1.88 +               dp->val.i16  = (int16_t)gprData[iCount++];
    1.89 +            else
    1.90 +               dp->val.i16  = *((int16_t*)ap++);
    1.91 +            break;
    1.92 +
    1.93 +        case nsXPTType::T_I32:
    1.94 +            if (iCount < PARAM_GPR_COUNT)
    1.95 +               dp->val.i32  = (int32_t)gprData[iCount++];
    1.96 +            else
    1.97 +               dp->val.i32  = *((int32_t*)ap++);
    1.98 +            break;
    1.99 +
   1.100 +        case nsXPTType::T_I64:
   1.101 +            if (iCount < PARAM_GPR_COUNT)
   1.102 +               dp->val.i64  = (int64_t)gprData[iCount++];
   1.103 +            else
   1.104 +               dp->val.i64  = *((int64_t*)ap++);
   1.105 +            break;
   1.106 +
   1.107 +        case nsXPTType::T_U8:
   1.108 +            if (iCount < PARAM_GPR_COUNT)
   1.109 +               dp->val.u8  = (uint8_t)gprData[iCount++];
   1.110 +            else
   1.111 +               dp->val.u8  = *((uint8_t*)ap++);
   1.112 +            break;
   1.113 +
   1.114 +        case nsXPTType::T_U16:
   1.115 +            if (iCount < PARAM_GPR_COUNT)
   1.116 +               dp->val.u16  = (uint16_t)gprData[iCount++];
   1.117 +            else
   1.118 +                dp->val.u16  = *((uint16_t*)ap++);
   1.119 +            break;
   1.120 +
   1.121 +        case nsXPTType::T_U32:
   1.122 +            if (iCount < PARAM_GPR_COUNT)
   1.123 +               dp->val.u32  = (uint32_t)gprData[iCount++];
   1.124 +            else
   1.125 +               dp->val.u32  = *((uint32_t*)ap++);
   1.126 +            break;
   1.127 +
   1.128 +        case nsXPTType::T_U64:
   1.129 +            if (iCount < PARAM_GPR_COUNT)
   1.130 +               dp->val.u64  = (uint64_t)gprData[iCount++];
   1.131 +            else
   1.132 +               dp->val.u64  = *((uint64_t*)ap++);
   1.133 +            break;
   1.134 +
   1.135 +        case nsXPTType::T_FLOAT:
   1.136 +             if (iCount < PARAM_FPR_COUNT)
   1.137 +                dp->val.f  = (float)fprData[iCount++];
   1.138 +             else
   1.139 +                dp->val.f  = *((float*)ap++);
   1.140 +             break;
   1.141 +
   1.142 +        case nsXPTType::T_DOUBLE:
   1.143 +              if (iCount < PARAM_FPR_COUNT)
   1.144 +                 dp->val.d  = (double)fprData[iCount++];
   1.145 +              else
   1.146 +                 dp->val.d  = *((double*)ap++);
   1.147 +              break;
   1.148 +
   1.149 +        case nsXPTType::T_BOOL:
   1.150 +           if (iCount < PARAM_GPR_COUNT)
   1.151 +              dp->val.b  = (bool)gprData[iCount++];
   1.152 +           else
   1.153 +              dp->val.b  = *((bool*)ap++);
   1.154 +           break;
   1.155 +
   1.156 +        case nsXPTType::T_CHAR:
   1.157 +           if (iCount < PARAM_GPR_COUNT)
   1.158 +              dp->val.c  = (char)gprData[iCount++];
   1.159 +           else
   1.160 +              dp->val.c  = *((char*)ap++);
   1.161 +           break;
   1.162 +
   1.163 +        case nsXPTType::T_WCHAR:
   1.164 +           if (iCount < PARAM_GPR_COUNT)
   1.165 +              dp->val.wc  = (wchar_t)gprData[iCount++];
   1.166 +           else
   1.167 +              dp->val.wc  = *((wchar_t*)ap++);
   1.168 +           break;
   1.169 +
   1.170 +        default:
   1.171 +            NS_ASSERTION(0, "bad type");
   1.172 +            break;
   1.173 +        }
   1.174 +    }
   1.175 +
   1.176 +    result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams);
   1.177 +
   1.178 +    if(dispatchParams != paramBuffer)
   1.179 +        delete [] dispatchParams;
   1.180 +
   1.181 +    return result;
   1.182 +}
   1.183 +
   1.184 +__asm__ (
   1.185 +  ".text\n"
   1.186 +  ".intel_syntax noprefix\n"            /* switch to Intel syntax to look like the MSVC assembly */
   1.187 +  ".globl SharedStub\n"
   1.188 +  ".def SharedStub ; .scl 3 ; .type 46 ; .endef \n"
   1.189 +  "SharedStub:\n"
   1.190 +  "sub     rsp, 104\n"
   1.191 +
   1.192 +  /* rcx is this pointer.  Need backup for optimized build */
   1.193 +
   1.194 +  "mov      qword ptr [rsp+88], rcx\n"
   1.195 +
   1.196 +  /*
   1.197 +   * fist 4 parameters (1st is "this" pointer) are passed in registers.
   1.198 +   */
   1.199 +
   1.200 +  /* for floating value */
   1.201 +
   1.202 +  "movsd   qword ptr [rsp+64], xmm1\n"
   1.203 +  "movsd   qword ptr [rsp+72], xmm2\n"
   1.204 +  "movsd   qword ptr [rsp+80], xmm3\n"
   1.205 +
   1.206 +  /* for integer value */
   1.207 +
   1.208 +  "mov     qword ptr [rsp+40], rdx\n"
   1.209 +  "mov     qword ptr [rsp+48], r8\n"
   1.210 +  "mov     qword ptr [rsp+56], r9\n"
   1.211 +
   1.212 +  /*
   1.213 +   * Call PrepareAndDispatch function
   1.214 +   */
   1.215 +
   1.216 +  /* 5th parameter (floating parameters) of PrepareAndDispatch */
   1.217 +
   1.218 +  "lea     r9, qword ptr [rsp+64]\n"
   1.219 +  "mov     qword ptr [rsp+32], r9\n"
   1.220 +
   1.221 +  /* 4th parameter (normal parameters) of PrepareAndDispatch */
   1.222 +
   1.223 +  "lea     r9, qword ptr [rsp+40]\n"
   1.224 +
   1.225 +  /* 3rd parameter (pointer to args on stack) */
   1.226 +
   1.227 +  "lea     r8, qword ptr [rsp+40+104]\n"
   1.228 +
   1.229 +  /* 2nd parameter (vtbl_index) */
   1.230 +
   1.231 +  "mov     rdx, r11\n"
   1.232 +
   1.233 +  /* 1st parameter (this) (rcx) */
   1.234 +
   1.235 +  "call    PrepareAndDispatch\n"
   1.236 +
   1.237 +  /* restore rcx */
   1.238 +
   1.239 +  "mov     rcx, qword ptr [rsp+88]\n"
   1.240 +
   1.241 +  /*
   1.242 +   * clean up register
   1.243 +   */
   1.244 +
   1.245 +  "add     rsp, 104+8\n"
   1.246 +
   1.247 +  /* set return address */
   1.248 +
   1.249 +  "mov     rdx, qword ptr [rsp-8]\n"
   1.250 +
   1.251 +  /* simulate __stdcall return */
   1.252 +
   1.253 +  "jmp     rdx\n"
   1.254 +
   1.255 +  /* back to AT&T syntax */
   1.256 +  ".att_syntax\n"
   1.257 +);
   1.258 +
   1.259 +#define STUB_ENTRY(n) \
   1.260 +asm(".intel_syntax noprefix\n" /* this is in intel syntax */ \
   1.261 +    ".text\n" \
   1.262 +    ".align 2\n" \
   1.263 +    ".if        " #n " < 10\n" \
   1.264 +    ".globl       _ZN14nsXPTCStubBase5Stub" #n "Ev@4\n" \
   1.265 +    ".def         _ZN14nsXPTCStubBase5Stub" #n "Ev@4\n" \
   1.266 +    ".scl         3\n" /* private */ \
   1.267 +    ".type        46\n" /* function returning unsigned int */ \
   1.268 +    ".endef\n" \
   1.269 +    "_ZN14nsXPTCStubBase5Stub" #n "Ev@4:\n" \
   1.270 +    ".elseif    " #n " < 100\n" \
   1.271 +    ".globl       _ZN14nsXPTCStubBase6Stub" #n "Ev@4\n" \
   1.272 +    ".def         _ZN14nsXPTCStubBase6Stub" #n "Ev@4\n" \
   1.273 +    ".scl         3\n" /* private */\
   1.274 +    ".type        46\n" /* function returning unsigned int */ \
   1.275 +    ".endef\n" \
   1.276 +    "_ZN14nsXPTCStubBase6Stub" #n "Ev@4:\n" \
   1.277 +    ".elseif    " #n " < 1000\n" \
   1.278 +    ".globl       _ZN14nsXPTCStubBase7Stub" #n "Ev@4\n" \
   1.279 +    ".def         _ZN14nsXPTCStubBase7Stub" #n "Ev@4\n" \
   1.280 +    ".scl         3\n" /* private */ \
   1.281 +    ".type        46\n" /* function returning unsigned int */ \
   1.282 +    ".endef\n" \
   1.283 +    "_ZN14nsXPTCStubBase7Stub" #n "Ev@4:\n" \
   1.284 +    ".else\n" \
   1.285 +    ".err       \"stub number " #n " >= 1000 not yet supported\"\n" \
   1.286 +    ".endif\n" \
   1.287 +    "mov          r11, " #n "\n" \
   1.288 +    "jmp          SharedStub\n" \
   1.289 +    ".att_syntax\n" /* back to AT&T syntax */ \
   1.290 +    "");
   1.291 +
   1.292 +#define SENTINEL_ENTRY(n) \
   1.293 +nsresult nsXPTCStubBase::Sentinel##n() \
   1.294 +{ \
   1.295 +    NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
   1.296 +    return NS_ERROR_NOT_IMPLEMENTED; \
   1.297 +}
   1.298 +
   1.299 +#include "xptcstubsdef.inc"
   1.300 +

mercurial