xpcom/reflect/xptcall/src/md/unix/xptcinvoke_gcc_x86_unix.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_gcc_x86_unix.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     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 +#include "xptc_gcc_x86_unix.h"
    1.13 +
    1.14 +extern "C" {
    1.15 +static void ATTRIBUTE_USED __attribute__ ((regparm(3)))
    1.16 +invoke_copy_to_stack(uint32_t paramCount, nsXPTCVariant* s, uint32_t* d)
    1.17 +{
    1.18 +    for(uint32_t i = paramCount; i >0; i--, d++, s++)
    1.19 +    {
    1.20 +        if(s->IsPtrData())
    1.21 +        {
    1.22 +            *((void**)d) = s->ptr;
    1.23 +            continue;
    1.24 +        }
    1.25 +
    1.26 +        switch(s->type)
    1.27 +        {
    1.28 +        case nsXPTType::T_I64    : *((int64_t*) d) = s->val.i64; d++;    break;
    1.29 +        case nsXPTType::T_U64    : *((uint64_t*)d) = s->val.u64; d++;    break;
    1.30 +        case nsXPTType::T_DOUBLE : *((double*)  d) = s->val.d;   d++;    break;
    1.31 +        default                  : *((void**)d)    = s->val.p;           break;
    1.32 +        }
    1.33 +    }
    1.34 +}
    1.35 +} // extern "C"
    1.36 +
    1.37 +/*
    1.38 +  EXPORT_XPCOM_API(nsresult)
    1.39 +  NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex,
    1.40 +                   uint32_t paramCount, nsXPTCVariant* params);
    1.41 +
    1.42 +  Each param takes at most two 4-byte words.
    1.43 +  It doesn't matter if we push too many words, and calculating the exact
    1.44 +  amount takes time.
    1.45 +
    1.46 +  that        = ebp + 0x08
    1.47 +  methodIndex = ebp + 0x0c
    1.48 +  paramCount  = ebp + 0x10
    1.49 +  params      = ebp + 0x14
    1.50 +
    1.51 +*/
    1.52 +
    1.53 +__asm__ (
    1.54 +	".text\n\t"
    1.55 +/* alignment here seems unimportant here; this was 16, now it's 2 which
    1.56 +   is what xptcstubs uses. */
    1.57 +	".align 2\n\t"
    1.58 +	".globl " SYMBOL_UNDERSCORE "NS_InvokeByIndex\n\t"
    1.59 +#ifndef XP_MACOSX
    1.60 +	".type  " SYMBOL_UNDERSCORE "NS_InvokeByIndex,@function\n"
    1.61 +#endif
    1.62 +	SYMBOL_UNDERSCORE "NS_InvokeByIndex:\n\t"
    1.63 +	"pushl %ebp\n\t"
    1.64 +	"movl  %esp, %ebp\n\t"
    1.65 +	"movl  0x10(%ebp), %eax\n\t"
    1.66 +	"leal  0(,%eax,8),%edx\n\t"
    1.67 +
    1.68 +        /* set up call frame for method. */
    1.69 +	"subl  %edx, %esp\n\t"       /* make room for params. */
    1.70 +/* Align to maximum x86 data size: 128 bits == 16 bytes == XMM register size.
    1.71 + * This is to avoid protection faults where SSE+ alignment of stack pointer
    1.72 + * is assumed and required, e.g. by GCC4's -ftree-vectorize option.
    1.73 + */
    1.74 +	"andl  $0xfffffff0, %esp\n\t"   /* drop(?) stack ptr to 128-bit align */
    1.75 +/* $esp should be aligned to a 16-byte boundary here (note we include an 
    1.76 + * additional 4 bytes in a later push instruction). This will ensure $ebp 
    1.77 + * in the function called below is aligned to a 0x8 boundary. SSE instructions 
    1.78 + * like movapd/movdqa expect memory operand to be aligned on a 16-byte
    1.79 + * boundary. The GCC compiler will generate the memory operand using $ebp
    1.80 + * with an 8-byte offset.
    1.81 + */
    1.82 +	"subl  $0xc, %esp\n\t"          /* lower again; push/call below will re-align */
    1.83 +	"movl  %esp, %ecx\n\t"          /* ecx = d */
    1.84 +	"movl  8(%ebp), %edx\n\t"       /* edx = this */
    1.85 +	"pushl %edx\n\t"                /* push this. esp % 16 == 0 */
    1.86 +
    1.87 +	"movl  0x14(%ebp), %edx\n\t"
    1.88 +	"call  " SYMBOL_UNDERSCORE "invoke_copy_to_stack\n\t"
    1.89 +	"movl  0x08(%ebp), %ecx\n\t"	/* 'that' */
    1.90 +	"movl  (%ecx), %edx\n\t"
    1.91 +	"movl  0x0c(%ebp), %eax\n\t"    /* function index */
    1.92 +	"leal  (%edx,%eax,4), %edx\n\t"
    1.93 +	"call  *(%edx)\n\t"
    1.94 +	"movl  %ebp, %esp\n\t"
    1.95 +	"popl  %ebp\n\t"
    1.96 +	"ret\n"
    1.97 +#ifndef XP_MACOSX
    1.98 +	".size " SYMBOL_UNDERSCORE "NS_InvokeByIndex, . -" SYMBOL_UNDERSCORE "NS_InvokeByIndex\n\t"
    1.99 +#endif
   1.100 +);

mercurial