michael@0: /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* Platform specific code to invoke XPCOM methods on native objects */ michael@0: michael@0: #include "xptcprivate.h" michael@0: #include "xptc_gcc_x86_unix.h" michael@0: michael@0: extern "C" { michael@0: static void ATTRIBUTE_USED __attribute__ ((regparm(3))) michael@0: invoke_copy_to_stack(uint32_t paramCount, nsXPTCVariant* s, uint32_t* d) michael@0: { michael@0: for(uint32_t i = paramCount; i >0; i--, d++, s++) michael@0: { michael@0: if(s->IsPtrData()) michael@0: { michael@0: *((void**)d) = s->ptr; michael@0: continue; michael@0: } michael@0: michael@0: switch(s->type) michael@0: { michael@0: case nsXPTType::T_I64 : *((int64_t*) d) = s->val.i64; d++; break; michael@0: case nsXPTType::T_U64 : *((uint64_t*)d) = s->val.u64; d++; break; michael@0: case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++; break; michael@0: default : *((void**)d) = s->val.p; break; michael@0: } michael@0: } michael@0: } michael@0: } // extern "C" michael@0: michael@0: /* michael@0: EXPORT_XPCOM_API(nsresult) michael@0: NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, michael@0: uint32_t paramCount, nsXPTCVariant* params); michael@0: michael@0: Each param takes at most two 4-byte words. michael@0: It doesn't matter if we push too many words, and calculating the exact michael@0: amount takes time. michael@0: michael@0: that = ebp + 0x08 michael@0: methodIndex = ebp + 0x0c michael@0: paramCount = ebp + 0x10 michael@0: params = ebp + 0x14 michael@0: michael@0: */ michael@0: michael@0: __asm__ ( michael@0: ".text\n\t" michael@0: /* alignment here seems unimportant here; this was 16, now it's 2 which michael@0: is what xptcstubs uses. */ michael@0: ".align 2\n\t" michael@0: ".globl " SYMBOL_UNDERSCORE "NS_InvokeByIndex\n\t" michael@0: #ifndef XP_MACOSX michael@0: ".type " SYMBOL_UNDERSCORE "NS_InvokeByIndex,@function\n" michael@0: #endif michael@0: SYMBOL_UNDERSCORE "NS_InvokeByIndex:\n\t" michael@0: "pushl %ebp\n\t" michael@0: "movl %esp, %ebp\n\t" michael@0: "movl 0x10(%ebp), %eax\n\t" michael@0: "leal 0(,%eax,8),%edx\n\t" michael@0: michael@0: /* set up call frame for method. */ michael@0: "subl %edx, %esp\n\t" /* make room for params. */ michael@0: /* Align to maximum x86 data size: 128 bits == 16 bytes == XMM register size. michael@0: * This is to avoid protection faults where SSE+ alignment of stack pointer michael@0: * is assumed and required, e.g. by GCC4's -ftree-vectorize option. michael@0: */ michael@0: "andl $0xfffffff0, %esp\n\t" /* drop(?) stack ptr to 128-bit align */ michael@0: /* $esp should be aligned to a 16-byte boundary here (note we include an michael@0: * additional 4 bytes in a later push instruction). This will ensure $ebp michael@0: * in the function called below is aligned to a 0x8 boundary. SSE instructions michael@0: * like movapd/movdqa expect memory operand to be aligned on a 16-byte michael@0: * boundary. The GCC compiler will generate the memory operand using $ebp michael@0: * with an 8-byte offset. michael@0: */ michael@0: "subl $0xc, %esp\n\t" /* lower again; push/call below will re-align */ michael@0: "movl %esp, %ecx\n\t" /* ecx = d */ michael@0: "movl 8(%ebp), %edx\n\t" /* edx = this */ michael@0: "pushl %edx\n\t" /* push this. esp % 16 == 0 */ michael@0: michael@0: "movl 0x14(%ebp), %edx\n\t" michael@0: "call " SYMBOL_UNDERSCORE "invoke_copy_to_stack\n\t" michael@0: "movl 0x08(%ebp), %ecx\n\t" /* 'that' */ michael@0: "movl (%ecx), %edx\n\t" michael@0: "movl 0x0c(%ebp), %eax\n\t" /* function index */ michael@0: "leal (%edx,%eax,4), %edx\n\t" michael@0: "call *(%edx)\n\t" michael@0: "movl %ebp, %esp\n\t" michael@0: "popl %ebp\n\t" michael@0: "ret\n" michael@0: #ifndef XP_MACOSX michael@0: ".size " SYMBOL_UNDERSCORE "NS_InvokeByIndex, . -" SYMBOL_UNDERSCORE "NS_InvokeByIndex\n\t" michael@0: #endif michael@0: );