|
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 // Remember that these 'words' are 32bit DWORDS |
|
11 |
|
12 extern "C" { |
|
13 static uint32_t |
|
14 invoke_count_words(uint32_t paramCount, nsXPTCVariant* s) |
|
15 { |
|
16 uint32_t result = 0; |
|
17 for(uint32_t i = 0; i < paramCount; i++, s++) |
|
18 { |
|
19 if(s->IsPtrData()) |
|
20 { |
|
21 result++; |
|
22 continue; |
|
23 } |
|
24 switch(s->type) |
|
25 { |
|
26 case nsXPTType::T_I8 : |
|
27 case nsXPTType::T_I16 : |
|
28 case nsXPTType::T_I32 : |
|
29 result++; |
|
30 break; |
|
31 case nsXPTType::T_I64 : |
|
32 result+=2; |
|
33 break; |
|
34 case nsXPTType::T_U8 : |
|
35 case nsXPTType::T_U16 : |
|
36 case nsXPTType::T_U32 : |
|
37 result++; |
|
38 break; |
|
39 case nsXPTType::T_U64 : |
|
40 result+=2; |
|
41 break; |
|
42 case nsXPTType::T_FLOAT : |
|
43 result++; |
|
44 break; |
|
45 case nsXPTType::T_DOUBLE : |
|
46 result+=2; |
|
47 break; |
|
48 case nsXPTType::T_BOOL : |
|
49 case nsXPTType::T_CHAR : |
|
50 case nsXPTType::T_WCHAR : |
|
51 result++; |
|
52 break; |
|
53 default: |
|
54 // all the others are plain pointer types |
|
55 result++; |
|
56 break; |
|
57 } |
|
58 } |
|
59 return result; |
|
60 } |
|
61 |
|
62 void |
|
63 invoke_copy_to_stack(uint32_t* d, uint32_t paramCount, nsXPTCVariant* s) |
|
64 { |
|
65 for(uint32_t i = 0; i < paramCount; i++, d++, s++) |
|
66 { |
|
67 if(s->IsPtrData()) |
|
68 { |
|
69 *((void**)d) = s->ptr; |
|
70 continue; |
|
71 } |
|
72 switch(s->type) |
|
73 { |
|
74 // 8 and 16 bit types should be promoted to 32 bits when copying |
|
75 // onto the stack. |
|
76 case nsXPTType::T_I8 : *((uint32_t*)d) = s->val.i8; break; |
|
77 case nsXPTType::T_I16 : *((uint32_t*)d) = s->val.i16; break; |
|
78 case nsXPTType::T_I32 : *((int32_t*) d) = s->val.i32; break; |
|
79 case nsXPTType::T_I64 : *((int64_t*) d) = s->val.i64; d++; break; |
|
80 case nsXPTType::T_U8 : *((uint32_t*)d) = s->val.u8; break; |
|
81 case nsXPTType::T_U16 : *((uint32_t*)d) = s->val.u16; break; |
|
82 case nsXPTType::T_U32 : *((uint32_t*)d) = s->val.u32; break; |
|
83 case nsXPTType::T_U64 : *((uint64_t*)d) = s->val.u64; d++; break; |
|
84 case nsXPTType::T_FLOAT : *((float*) d) = s->val.f; break; |
|
85 case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++; break; |
|
86 case nsXPTType::T_BOOL : *((uint32_t*)d) = s->val.b; break; |
|
87 case nsXPTType::T_CHAR : *((uint32_t*)d) = s->val.c; break; |
|
88 case nsXPTType::T_WCHAR : *((wchar_t*) d) = s->val.wc; break; |
|
89 |
|
90 default: |
|
91 // all the others are plain pointer types |
|
92 *((void**)d) = s->val.p; |
|
93 break; |
|
94 } |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 EXPORT_XPCOM_API(nsresult) |
|
100 NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, |
|
101 uint32_t paramCount, nsXPTCVariant* params) |
|
102 { |
|
103 uint32_t result, n; |
|
104 |
|
105 n = invoke_count_words(paramCount, params) * 4; |
|
106 |
|
107 __asm__ __volatile__( |
|
108 "subl %5, %%sp\n\t" /* make room for params */ |
|
109 "movel %4, %%sp@-\n\t" |
|
110 "movel %3, %%sp@-\n\t" |
|
111 "pea %%sp@(8)\n\t" |
|
112 "jbsr invoke_copy_to_stack\n\t" /* copy params */ |
|
113 "addw #12, %%sp\n\t" |
|
114 "movel %1, %%sp@-\n\t" |
|
115 "movel %1@, %%a0\n\t" |
|
116 "movel %%a0@(%2:l:4), %%a0\n\t" |
|
117 "jbsr %%a0@\n\t" /* safe to not cleanup sp */ |
|
118 "lea %%sp@(4,%5:l), %%sp\n\t" |
|
119 "movel %%d0, %0" |
|
120 : "=d" (result) /* %0 */ |
|
121 : "a" (that), /* %1 */ |
|
122 "d" (methodIndex), /* %2 */ |
|
123 "g" (paramCount), /* %3 */ |
|
124 "g" (params), /* %4 */ |
|
125 "d" (n) /* %5 */ |
|
126 : "a0", "a1", "d0", "d1", "memory" |
|
127 ); |
|
128 |
|
129 return result; |
|
130 } |