xpcom/reflect/xptcall/src/md/unix/xptcinvoke_linux_m68k.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/xptcinvoke_linux_m68k.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,130 @@
     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 +/* Platform specific code to invoke XPCOM methods on native objects */
    1.10 +
    1.11 +#include "xptcprivate.h"
    1.12 +
    1.13 +// Remember that these 'words' are 32bit DWORDS
    1.14 +
    1.15 +extern "C" {
    1.16 +    static uint32_t
    1.17 +    invoke_count_words(uint32_t paramCount, nsXPTCVariant* s)
    1.18 +    {
    1.19 +        uint32_t result = 0;
    1.20 +        for(uint32_t i = 0; i < paramCount; i++, s++)
    1.21 +        {
    1.22 +            if(s->IsPtrData())
    1.23 +            {
    1.24 +                result++;
    1.25 +                continue;
    1.26 +            }
    1.27 +            switch(s->type)
    1.28 +            {
    1.29 +            case nsXPTType::T_I8     :
    1.30 +            case nsXPTType::T_I16    :
    1.31 +            case nsXPTType::T_I32    :
    1.32 +                result++;
    1.33 +                break;
    1.34 +            case nsXPTType::T_I64    :
    1.35 +                result+=2;
    1.36 +                break;
    1.37 +            case nsXPTType::T_U8     :
    1.38 +            case nsXPTType::T_U16    :
    1.39 +            case nsXPTType::T_U32    :
    1.40 +                result++;
    1.41 +                break;
    1.42 +            case nsXPTType::T_U64    :
    1.43 +                result+=2;
    1.44 +                break;
    1.45 +            case nsXPTType::T_FLOAT  :
    1.46 +                result++;
    1.47 +                break;
    1.48 +            case nsXPTType::T_DOUBLE :
    1.49 +                result+=2;
    1.50 +                break;
    1.51 +            case nsXPTType::T_BOOL   :
    1.52 +            case nsXPTType::T_CHAR   :
    1.53 +            case nsXPTType::T_WCHAR  :
    1.54 +                result++;
    1.55 +                break;
    1.56 +            default:
    1.57 +                // all the others are plain pointer types
    1.58 +                result++;
    1.59 +                break;
    1.60 +            }
    1.61 +        }
    1.62 +        return result;
    1.63 +    }
    1.64 +
    1.65 +    void
    1.66 +    invoke_copy_to_stack(uint32_t* d, uint32_t paramCount, nsXPTCVariant* s)
    1.67 +    {
    1.68 +        for(uint32_t i = 0; i < paramCount; i++, d++, s++)
    1.69 +        {
    1.70 +            if(s->IsPtrData())
    1.71 +            {
    1.72 +                *((void**)d) = s->ptr;
    1.73 +                continue;
    1.74 +            }
    1.75 +            switch(s->type)
    1.76 +            {
    1.77 +            // 8 and 16 bit types should be promoted to 32 bits when copying
    1.78 +            // onto the stack.
    1.79 +            case nsXPTType::T_I8     : *((uint32_t*)d) = s->val.i8;          break;
    1.80 +            case nsXPTType::T_I16    : *((uint32_t*)d) = s->val.i16;         break;
    1.81 +            case nsXPTType::T_I32    : *((int32_t*) d) = s->val.i32;         break;
    1.82 +            case nsXPTType::T_I64    : *((int64_t*) d) = s->val.i64; d++;    break;
    1.83 +            case nsXPTType::T_U8     : *((uint32_t*)d) = s->val.u8;          break;
    1.84 +            case nsXPTType::T_U16    : *((uint32_t*)d) = s->val.u16;         break;
    1.85 +            case nsXPTType::T_U32    : *((uint32_t*)d) = s->val.u32;         break;
    1.86 +            case nsXPTType::T_U64    : *((uint64_t*)d) = s->val.u64; d++;    break;
    1.87 +            case nsXPTType::T_FLOAT  : *((float*)   d) = s->val.f;           break;
    1.88 +            case nsXPTType::T_DOUBLE : *((double*)  d) = s->val.d;   d++;    break;
    1.89 +            case nsXPTType::T_BOOL   : *((uint32_t*)d) = s->val.b;           break;
    1.90 +            case nsXPTType::T_CHAR   : *((uint32_t*)d) = s->val.c;           break;
    1.91 +            case nsXPTType::T_WCHAR  : *((wchar_t*) d) = s->val.wc;          break;
    1.92 +
    1.93 +            default:
    1.94 +                // all the others are plain pointer types
    1.95 +                *((void**)d) = s->val.p;
    1.96 +                break;
    1.97 +            }
    1.98 +        }
    1.99 +    }
   1.100 +}
   1.101 +
   1.102 +EXPORT_XPCOM_API(nsresult)
   1.103 +NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex,
   1.104 +                   uint32_t paramCount, nsXPTCVariant* params)
   1.105 +{
   1.106 +    uint32_t result, n;
   1.107 +
   1.108 +    n = invoke_count_words(paramCount, params) * 4;
   1.109 +
   1.110 + __asm__ __volatile__(
   1.111 +    "subl  %5, %%sp\n\t"      /* make room for params */
   1.112 +    "movel %4, %%sp@-\n\t"
   1.113 +    "movel %3, %%sp@-\n\t"
   1.114 +    "pea   %%sp@(8)\n\t"
   1.115 +    "jbsr  invoke_copy_to_stack\n\t"   /* copy params */
   1.116 +    "addw  #12, %%sp\n\t"
   1.117 +    "movel %1, %%sp@-\n\t"
   1.118 +    "movel %1@, %%a0\n\t"
   1.119 +    "movel %%a0@(%2:l:4), %%a0\n\t"
   1.120 +    "jbsr  %%a0@\n\t"         /* safe to not cleanup sp */
   1.121 +    "lea   %%sp@(4,%5:l), %%sp\n\t"
   1.122 +    "movel %%d0, %0"
   1.123 +    : "=d" (result)         /* %0 */
   1.124 +    : "a" (that),           /* %1 */
   1.125 +      "d" (methodIndex),    /* %2 */
   1.126 +      "g" (paramCount),     /* %3 */
   1.127 +      "g" (params),         /* %4 */
   1.128 +      "d" (n)               /* %5 */
   1.129 +    : "a0", "a1", "d0", "d1", "memory"
   1.130 +    );
   1.131 +  
   1.132 +  return result;
   1.133 +}

mercurial