xpcom/reflect/xptcall/src/md/unix/xptcstubs_linux_alpha.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 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /* Implement shared vtbl methods. */
     8 #include "xptcprivate.h"
     9 #include "xptiprivate.h"
    11 /* Prototype specifies unmangled function name and disables unused warning */
    12 static nsresult
    13 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint64_t* args)
    14 __asm__("PrepareAndDispatch") ATTRIBUTE_USED;
    16 static nsresult
    17 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint64_t* args)
    18 {
    19     const uint8_t PARAM_BUFFER_COUNT = 16;
    20     const uint8_t NUM_ARG_REGS = 6-1;        // -1 for "this" pointer
    22     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
    23     nsXPTCMiniVariant* dispatchParams = nullptr;
    24     const nsXPTMethodInfo* info;
    25     uint8_t paramCount;
    26     uint8_t i;
    27     nsresult result = NS_ERROR_FAILURE;
    29     NS_ASSERTION(self,"no self");
    31     self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
    33     paramCount = info->GetParamCount();
    35     // setup variant array pointer
    36     if(paramCount > PARAM_BUFFER_COUNT)
    37         dispatchParams = new nsXPTCMiniVariant[paramCount];
    38     else
    39         dispatchParams = paramBuffer;
    40     NS_ASSERTION(dispatchParams,"no place for params");
    42     // args[0] to args[NUM_ARG_REGS] hold floating point register values
    43     uint64_t* ap = args + NUM_ARG_REGS;
    44     for(i = 0; i < paramCount; i++, ap++)
    45     {
    46         const nsXPTParamInfo& param = info->GetParam(i);
    47         const nsXPTType& type = param.GetType();
    48         nsXPTCMiniVariant* dp = &dispatchParams[i];
    50         if(param.IsOut() || !type.IsArithmetic())
    51         {
    52             dp->val.p = (void*) *ap;
    53             continue;
    54         }
    55         // else
    56         switch(type)
    57         {
    58         case nsXPTType::T_I8     : dp->val.i8  = (int8_t)    *ap;    break;
    59         case nsXPTType::T_I16    : dp->val.i16 = (int16_t)   *ap;    break;
    60         case nsXPTType::T_I32    : dp->val.i32 = (int32_t)   *ap;    break;
    61         case nsXPTType::T_I64    : dp->val.i64 = (int64_t)   *ap;    break;
    62         case nsXPTType::T_U8     : dp->val.u8  = (uint8_t)   *ap;    break;
    63         case nsXPTType::T_U16    : dp->val.u16 = (uint16_t)  *ap;    break;
    64         case nsXPTType::T_U32    : dp->val.u32 = (uint32_t)  *ap;    break;
    65         case nsXPTType::T_U64    : dp->val.u64 = (uint64_t)  *ap;    break;
    66         case nsXPTType::T_FLOAT  :
    67             if(i < NUM_ARG_REGS)
    68             {
    69                 // floats passed via registers are stored as doubles
    70                 // in the first NUM_ARG_REGS entries in args
    71                 dp->val.u64 = (uint64_t) args[i];
    72                 dp->val.f = (float) dp->val.d;    // convert double to float
    73             }
    74             else
    75                 dp->val.u32 = (uint32_t) *ap;
    76             break;
    77         case nsXPTType::T_DOUBLE :
    78             // doubles passed via registers are also stored
    79             // in the first NUM_ARG_REGS entries in args
    80             dp->val.u64 = (i < NUM_ARG_REGS) ? args[i] : *ap;
    81             break;
    82         case nsXPTType::T_BOOL   : dp->val.b   = (bool)    *ap;    break;
    83         case nsXPTType::T_CHAR   : dp->val.c   = (char)      *ap;    break;
    84         case nsXPTType::T_WCHAR  : dp->val.wc  = (char16_t) *ap;    break;
    85         default:
    86             NS_ERROR("bad type");
    87             break;
    88         }
    89     }
    91     result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams);
    93     if(dispatchParams != paramBuffer)
    94         delete [] dispatchParams;
    96     return result;
    97 }
    99 /*
   100  * SharedStub()
   101  *  Collects arguments and calls PrepareAndDispatch.  The "methodIndex" is
   102  *  passed to this function via $1 to preserve the argument registers.
   103  */
   104 __asm__(
   105     "#### SharedStub ####\n"
   106 ".text\n\t"
   107     ".align 5\n\t"
   108     ".ent SharedStub\n"
   109 "SharedStub:\n\t"
   110     ".frame $30,96,$26,0\n\t"
   111     ".mask 0x4000000,-96\n\t"
   112     "ldgp $29,0($27)\n"
   113 "$SharedStub..ng:\n\t"
   114     "subq $30,96,$30\n\t"
   115     "stq $26,0($30)\n\t"
   116     ".prologue 1\n\t"
   118     /*
   119      * Store arguments passed via registers to the stack.
   120      * Floating point registers are stored as doubles and converted
   121      * to floats in PrepareAndDispatch if necessary.
   122      */
   123     "stt $f17,16($30)\n\t"   /* floating point registers */
   124     "stt $f18,24($30)\n\t"
   125     "stt $f19,32($30)\n\t"
   126     "stt $f20,40($30)\n\t"
   127     "stt $f21,48($30)\n\t"
   128     "stq $17,56($30)\n\t"    /* integer registers */
   129     "stq $18,64($30)\n\t"
   130     "stq $19,72($30)\n\t"
   131     "stq $20,80($30)\n\t"
   132     "stq $21,88($30)\n\t"
   134     /*
   135      * Call PrepareAndDispatch function.
   136      */
   137     "bis $1,$1,$17\n\t"      /* pass "methodIndex" */
   138     "addq $30,16,$18\n\t"    /* pass "args" */
   139     "bsr $26,$PrepareAndDispatch..ng\n\t"
   141     "ldq $26,0($30)\n\t"
   142     "addq $30,96,$30\n\t"
   143     "ret $31,($26),1\n\t"
   144     ".end SharedStub"
   145     );
   147 /*
   148  * nsresult nsXPTCStubBase::Stub##n()
   149  *  Sets register $1 to "methodIndex" and jumps to SharedStub.
   150  */
   151 #define STUB_MANGLED_ENTRY(n, symbol) \
   152     "#### Stub"#n" ####"      "\n\t" \
   153     ".text"                   "\n\t" \
   154     ".align 5"                "\n\t" \
   155     ".globl " symbol          "\n\t" \
   156     ".ent " symbol            "\n"   \
   157 symbol ":"                    "\n\t" \
   158     ".frame $30,0,$26,0"      "\n\t" \
   159     "ldgp $29,0($27)"         "\n"   \
   160 "$" symbol "..ng:"            "\n\t" \
   161     ".prologue 1"             "\n\t" \
   162     "lda $1,"#n               "\n\t" \
   163     "br $31,$SharedStub..ng"  "\n\t" \
   164     ".end " symbol
   166 #define STUB_ENTRY(n) \
   167 __asm__( \
   168     ".if "#n" < 10"                                              "\n\t" \
   169         STUB_MANGLED_ENTRY(n, "_ZN14nsXPTCStubBase5Stub"#n"Ev")  "\n\t" \
   170     ".elseif "#n" < 100"                                         "\n\t" \
   171         STUB_MANGLED_ENTRY(n, "_ZN14nsXPTCStubBase6Stub"#n"Ev")  "\n\t" \
   172     ".elseif "#n" < 1000"                                        "\n\t" \
   173         STUB_MANGLED_ENTRY(n, "_ZN14nsXPTCStubBase7Stub"#n"Ev")  "\n\t" \
   174     ".else"                                                      "\n\t" \
   175     ".err \"Stub"#n" >= 1000 not yet supported.\""               "\n\t" \
   176     ".endif" \
   177     );
   180 #define SENTINEL_ENTRY(n) \
   181 nsresult nsXPTCStubBase::Sentinel##n() \
   182 { \
   183     NS_ERROR("nsXPTCStubBase::Sentinel called"); \
   184     return NS_ERROR_NOT_IMPLEMENTED; \
   185 }
   187 #include "xptcstubsdef.inc"

mercurial