|
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/. */ |
|
5 |
|
6 /* Platform specific code to invoke XPCOM methods on native objects */ |
|
7 |
|
8 #include "xptcprivate.h" |
|
9 |
|
10 extern "C" { |
|
11 void __attribute__ ((__used__)) __attribute__ ((regparm(3))) |
|
12 invoke_copy_to_stack(uint32_t paramCount, nsXPTCVariant* s, uint32_t* d) |
|
13 { |
|
14 for(uint32_t i = paramCount; i >0; i--, d++, s++) |
|
15 { |
|
16 if(s->IsPtrData()) |
|
17 { |
|
18 *((void**)d) = s->ptr; |
|
19 continue; |
|
20 } |
|
21 |
|
22 switch(s->type) |
|
23 { |
|
24 case nsXPTType::T_I8 : *((int8_t*) d) = s->val.i8; break; |
|
25 case nsXPTType::T_I16 : *((int16_t*) d) = s->val.i16; break; |
|
26 case nsXPTType::T_I32 : *((int32_t*) d) = s->val.i32; break; |
|
27 case nsXPTType::T_I64 : *((int64_t*) d) = s->val.i64; d++; break; |
|
28 case nsXPTType::T_U8 : *((uint8_t*) d) = s->val.u8; break; |
|
29 case nsXPTType::T_U16 : *((uint16_t*)d) = s->val.u16; break; |
|
30 case nsXPTType::T_U32 : *((uint32_t*)d) = s->val.u32; break; |
|
31 case nsXPTType::T_U64 : *((uint64_t*)d) = s->val.u64; d++; break; |
|
32 case nsXPTType::T_FLOAT : *((float*) d) = s->val.f; break; |
|
33 case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++; break; |
|
34 case nsXPTType::T_BOOL : *((bool*) d) = s->val.b; break; |
|
35 case nsXPTType::T_CHAR : *((char*) d) = s->val.c; break; |
|
36 case nsXPTType::T_WCHAR : *((wchar_t*) d) = s->val.wc; break; |
|
37 default: |
|
38 // all the others are plain pointer types |
|
39 *((void**)d) = s->val.p; |
|
40 break; |
|
41 } |
|
42 } |
|
43 } |
|
44 } // extern "C" |
|
45 |
|
46 /* |
|
47 EXPORT_XPCOM_API(nsresult) |
|
48 NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, |
|
49 uint32_t paramCount, nsXPTCVariant* params); |
|
50 |
|
51 Each param takes at most two 4-byte words. |
|
52 It doesn't matter if we push too many words, and calculating the exact |
|
53 amount takes time. |
|
54 |
|
55 that = ebp + 0x08 |
|
56 methodIndex = ebp + 0x0c |
|
57 paramCount = ebp + 0x10 |
|
58 params = ebp + 0x14 |
|
59 |
|
60 */ |
|
61 |
|
62 __asm__ ( |
|
63 ".text\n\t" |
|
64 /* alignment here seems unimportant here; this was 16, now it's 2 which |
|
65 is what xptcstubs uses. */ |
|
66 ".align 2\n\t" |
|
67 ".globl _NS_InvokeByIndex\n\t" |
|
68 "_NS_InvokeByIndex:\n\t" |
|
69 "pushl %ebp\n\t" |
|
70 "movl %esp, %ebp\n\t" |
|
71 "movl 0x10(%ebp), %eax\n\t" |
|
72 "leal 0(,%eax,8),%edx\n\t" |
|
73 |
|
74 /* set up call frame for method. */ |
|
75 "subl %edx, %esp\n\t" /* make room for params. */ |
|
76 /* Align to maximum x86 data size: 128 bits == 16 bytes == XMM register size. |
|
77 * This is to avoid protection faults where SSE+ alignment of stack pointer |
|
78 * is assumed and required, e.g. by GCC4's -ftree-vectorize option. |
|
79 */ |
|
80 "andl $0xfffffff0, %esp\n\t" /* drop(?) stack ptr to 128-bit align */ |
|
81 /* $esp should be aligned to a 16-byte boundary here (note we include an |
|
82 * additional 4 bytes in a later push instruction). This will ensure $ebp |
|
83 * in the function called below is aligned to a 0x8 boundary. SSE instructions |
|
84 * like movapd/movdqa expect memory operand to be aligned on a 16-byte |
|
85 * boundary. The GCC compiler will generate the memory operand using $ebp |
|
86 * with an 8-byte offset. |
|
87 */ |
|
88 "subl $0xc, %esp\n\t" /* lower again; push/call below will re-align */ |
|
89 "movl %esp, %ecx\n\t" /* ecx = d */ |
|
90 "movl 8(%ebp), %edx\n\t" /* edx = this */ |
|
91 "pushl %edx\n\t" /* push this. esp % 16 == 0 */ |
|
92 |
|
93 "movl 0x14(%ebp), %edx\n\t" |
|
94 "call _invoke_copy_to_stack\n\t" |
|
95 "movl 0x08(%ebp), %ecx\n\t" /* 'that' */ |
|
96 "movl (%ecx), %edx\n\t" |
|
97 "movl 0x0c(%ebp), %eax\n\t" /* function index */ |
|
98 "leal (%edx,%eax,4), %edx\n\t" |
|
99 "call *(%edx)\n\t" |
|
100 "movl %ebp, %esp\n\t" |
|
101 "popl %ebp\n\t" |
|
102 "ret\n" |
|
103 ".section .drectve\n\t" |
|
104 ".ascii \" -export:NS_InvokeByIndex\"\n\t" |
|
105 ".text\n\t" |
|
106 ); |