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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  *
     3  * This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 // Implement shared vtbl methods.
     9 #include "xptcprivate.h"
    10 #include "xptiprivate.h"
    12 // The Linux/x86-64 ABI passes the first 6 integer parameters and the
    13 // first 8 floating point parameters in registers (rdi, rsi, rdx, rcx,
    14 // r8, r9 and xmm0-xmm7), no stack space is allocated for these by the
    15 // caller.  The rest of the parameters are passed in the callers stack
    16 // area.
    18 const uint32_t PARAM_BUFFER_COUNT   = 16;
    19 const uint32_t GPR_COUNT            = 6;
    20 const uint32_t FPR_COUNT            = 8;
    22 // PrepareAndDispatch() is called by SharedStub() and calls the actual method.
    23 //
    24 // - 'args[]' contains the arguments passed on stack
    25 // - 'gpregs[]' contains the arguments passed in integer registers
    26 // - 'fpregs[]' contains the arguments passed in floating point registers
    27 // 
    28 // The parameters are mapped into an array of type 'nsXPTCMiniVariant'
    29 // and then the method gets called.
    31 extern "C" nsresult ATTRIBUTE_USED
    32 PrepareAndDispatch(nsXPTCStubBase * self, uint32_t methodIndex,
    33                    uint64_t * args, uint64_t * gpregs, double *fpregs)
    34 {
    35     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
    36     nsXPTCMiniVariant* dispatchParams = nullptr;
    37     const nsXPTMethodInfo* info;
    38     uint32_t paramCount;
    39     uint32_t i;
    40     nsresult result = NS_ERROR_FAILURE;
    42     NS_ASSERTION(self,"no self");
    44     self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
    45     NS_ASSERTION(info,"no method info");
    46     if (!info)
    47         return NS_ERROR_UNEXPECTED;
    49     paramCount = info->GetParamCount();
    51     // setup variant array pointer
    52     if (paramCount > PARAM_BUFFER_COUNT)
    53         dispatchParams = new nsXPTCMiniVariant[paramCount];
    54     else
    55         dispatchParams = paramBuffer;
    57     NS_ASSERTION(dispatchParams,"no place for params");
    58     if (!dispatchParams)
    59         return NS_ERROR_OUT_OF_MEMORY;
    61     uint64_t* ap = args;
    62     uint32_t nr_gpr = 1;    // skip one GPR register for 'that'
    63     uint32_t nr_fpr = 0;
    64     uint64_t value;
    66     for (i = 0; i < paramCount; i++) {
    67         const nsXPTParamInfo& param = info->GetParam(i);
    68         const nsXPTType& type = param.GetType();
    69         nsXPTCMiniVariant* dp = &dispatchParams[i];
    71         if (!param.IsOut() && type == nsXPTType::T_DOUBLE) {
    72             if (nr_fpr < FPR_COUNT)
    73                 dp->val.d = fpregs[nr_fpr++];
    74             else
    75                 dp->val.d = *(double*) ap++;
    76             continue;
    77         }
    78         else if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
    79             if (nr_fpr < FPR_COUNT)
    80                 // The value in %xmm register is already prepared to
    81                 // be retrieved as a float. Therefore, we pass the
    82                 // value verbatim, as a double without conversion.
    83                 dp->val.d = *(double*) ap++;
    84             else
    85                 dp->val.f = *(float*) ap++;
    86             continue;
    87         }
    88         else {
    89             if (nr_gpr < GPR_COUNT)
    90                 value = gpregs[nr_gpr++];
    91             else
    92                 value = *ap++;
    93         }
    95         if (param.IsOut() || !type.IsArithmetic()) {
    96             dp->val.p = (void*) value;
    97             continue;
    98         }
   100         switch (type) {
   101         case nsXPTType::T_I8:      dp->val.i8  = (int8_t)   value; break;
   102         case nsXPTType::T_I16:     dp->val.i16 = (int16_t)  value; break;
   103         case nsXPTType::T_I32:     dp->val.i32 = (int32_t)  value; break;
   104         case nsXPTType::T_I64:     dp->val.i64 = (int64_t)  value; break;
   105         case nsXPTType::T_U8:      dp->val.u8  = (uint8_t)  value; break;
   106         case nsXPTType::T_U16:     dp->val.u16 = (uint16_t) value; break;
   107         case nsXPTType::T_U32:     dp->val.u32 = (uint32_t) value; break;
   108         case nsXPTType::T_U64:     dp->val.u64 = (uint64_t) value; break;
   109         case nsXPTType::T_BOOL:    dp->val.b   = (bool)   value; break;
   110         case nsXPTType::T_CHAR:    dp->val.c   = (char)     value; break;
   111         case nsXPTType::T_WCHAR:   dp->val.wc  = (wchar_t)  value; break;
   113         default:
   114             NS_ERROR("bad type");
   115             break;
   116         }
   117     }
   119     result = self->mOuter->CallMethod((uint16_t) methodIndex, info, dispatchParams);
   121     if (dispatchParams != paramBuffer)
   122         delete [] dispatchParams;
   124     return result;
   125 }
   127 // Linux/x86-64 uses gcc >= 3.1
   128 #define STUB_ENTRY(n) \
   129 asm(".section	\".text\"\n\t" \
   130     ".align	2\n\t" \
   131     ".if	" #n " < 10\n\t" \
   132     ".globl	_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
   133     ".hidden	_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
   134     ".type	_ZN14nsXPTCStubBase5Stub" #n "Ev,@function\n" \
   135     "_ZN14nsXPTCStubBase5Stub" #n "Ev:\n\t" \
   136     ".elseif	" #n " < 100\n\t" \
   137     ".globl	_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
   138     ".hidden	_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
   139     ".type	_ZN14nsXPTCStubBase6Stub" #n "Ev,@function\n" \
   140     "_ZN14nsXPTCStubBase6Stub" #n "Ev:\n\t" \
   141     ".elseif    " #n " < 1000\n\t" \
   142     ".globl     _ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
   143     ".hidden    _ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
   144     ".type      _ZN14nsXPTCStubBase7Stub" #n "Ev,@function\n" \
   145     "_ZN14nsXPTCStubBase7Stub" #n "Ev:\n\t" \
   146     ".else\n\t" \
   147     ".err	\"stub number " #n " >= 1000 not yet supported\"\n\t" \
   148     ".endif\n\t" \
   149     "movl	$" #n ", %eax\n\t" \
   150     "jmp	SharedStub\n\t" \
   151     ".if	" #n " < 10\n\t" \
   152     ".size	_ZN14nsXPTCStubBase5Stub" #n "Ev,.-_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
   153     ".elseif	" #n " < 100\n\t" \
   154     ".size	_ZN14nsXPTCStubBase6Stub" #n "Ev,.-_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
   155     ".else\n\t" \
   156     ".size	_ZN14nsXPTCStubBase7Stub" #n "Ev,.-_ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
   157     ".endif");
   159 // static nsresult SharedStub(uint32_t methodIndex)
   160 asm(".section   \".text\"\n\t"
   161     ".align     2\n\t"
   162     ".type      SharedStub,@function\n\t"
   163     "SharedStub:\n\t"
   164     // make room for gpregs (48), fpregs (64)
   165     "pushq      %rbp\n\t"
   166     "movq       %rsp,%rbp\n\t"
   167     "subq       $112,%rsp\n\t"
   168     // save GP registers
   169     "movq       %rdi,-112(%rbp)\n\t"
   170     "movq       %rsi,-104(%rbp)\n\t"
   171     "movq       %rdx, -96(%rbp)\n\t"
   172     "movq       %rcx, -88(%rbp)\n\t"
   173     "movq       %r8 , -80(%rbp)\n\t"
   174     "movq       %r9 , -72(%rbp)\n\t"
   175     "leaq       -112(%rbp),%rcx\n\t"
   176     // save FP registers
   177     "movsd      %xmm0,-64(%rbp)\n\t"
   178     "movsd      %xmm1,-56(%rbp)\n\t"
   179     "movsd      %xmm2,-48(%rbp)\n\t"
   180     "movsd      %xmm3,-40(%rbp)\n\t"
   181     "movsd      %xmm4,-32(%rbp)\n\t"
   182     "movsd      %xmm5,-24(%rbp)\n\t"
   183     "movsd      %xmm6,-16(%rbp)\n\t"
   184     "movsd      %xmm7, -8(%rbp)\n\t"
   185     "leaq       -64(%rbp),%r8\n\t"
   186     // rdi has the 'self' pointer already
   187     "movl       %eax,%esi\n\t"
   188     "leaq       16(%rbp),%rdx\n\t"
   189     "call       PrepareAndDispatch@plt\n\t"
   190     "leave\n\t"
   191     "ret\n\t"
   192     ".size      SharedStub,.-SharedStub");
   194 #define SENTINEL_ENTRY(n) \
   195 nsresult nsXPTCStubBase::Sentinel##n() \
   196 { \
   197     NS_ERROR("nsXPTCStubBase::Sentinel called"); \
   198     return NS_ERROR_NOT_IMPLEMENTED; \
   199 }
   201 #include "xptcstubsdef.inc"

mercurial