1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* ***** BEGIN LICENSE BLOCK *****
4
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
6
* The contents of this file are subject to the Mozilla Public License Version
7
* 1.1 (the "License"); you may not use this file except in compliance with
8
* the License. You may obtain a copy of the License at
9
* http://www.mozilla.org/MPL/
11
* Software distributed under the License is distributed on an "AS IS" basis,
12
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
* for the specific language governing rights and limitations under the
16
* The Original Code is mozilla.org Code.
18
* The Initial Developer of the Original Code is
19
* Netscape Communications Corporation.
20
* Portions created by the Initial Developer are Copyright (C) 1999
21
* the Initial Developer. All Rights Reserved.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either of the GNU General Public License Version 2 or later (the "GPL"),
27
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the MPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the MPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
// Platform specific code to invoke XPCOM methods on native objects
41
#include "xptcprivate.h"
43
// 6 integral parameters are passed in registers
44
const PRUint32 GPR_COUNT = 6;
46
// 8 floating point parameters are passed in SSE registers
47
const PRUint32 FPR_COUNT = 8;
49
// Remember that these 'words' are 64-bit long
51
invoke_count_words(PRUint32 paramCount, nsXPTCVariant * s,
52
PRUint32 & nr_gpr, PRUint32 & nr_fpr, PRUint32 & nr_stack)
54
nr_gpr = 1; // skip one GP register for 'that'
58
/* Compute number of eightbytes of class MEMORY. */
59
for (uint32 i = 0; i < paramCount; i++, s++) {
61
&& (s->type == nsXPTType::T_FLOAT || s->type == nsXPTType::T_DOUBLE)) {
62
if (nr_fpr < FPR_COUNT)
68
if (nr_gpr < GPR_COUNT)
77
invoke_copy_to_stack(PRUint64 * d, PRUint32 paramCount, nsXPTCVariant * s,
78
PRUint64 * gpregs, double * fpregs)
80
PRUint32 nr_gpr = 1; // skip one GP register for 'that'
84
for (uint32 i = 0; i < paramCount; i++, s++) {
86
value = (PRUint64) s->ptr;
89
case nsXPTType::T_FLOAT: break;
90
case nsXPTType::T_DOUBLE: break;
91
case nsXPTType::T_I8: value = s->val.i8; break;
92
case nsXPTType::T_I16: value = s->val.i16; break;
93
case nsXPTType::T_I32: value = s->val.i32; break;
94
case nsXPTType::T_I64: value = s->val.i64; break;
95
case nsXPTType::T_U8: value = s->val.u8; break;
96
case nsXPTType::T_U16: value = s->val.u16; break;
97
case nsXPTType::T_U32: value = s->val.u32; break;
98
case nsXPTType::T_U64: value = s->val.u64; break;
99
case nsXPTType::T_BOOL: value = s->val.b; break;
100
case nsXPTType::T_CHAR: value = s->val.c; break;
101
case nsXPTType::T_WCHAR: value = s->val.wc; break;
102
default: value = (PRUint64) s->val.p; break;
106
if (!s->IsPtrData() && s->type == nsXPTType::T_DOUBLE) {
107
if (nr_fpr < FPR_COUNT)
108
fpregs[nr_fpr++] = s->val.d;
110
*((double *)d) = s->val.d;
114
else if (!s->IsPtrData() && s->type == nsXPTType::T_FLOAT) {
115
if (nr_fpr < FPR_COUNT)
116
// The value in %xmm register is already prepared to
117
// be retrieved as a float. Therefore, we pass the
118
// value verbatim, as a double without conversion.
119
fpregs[nr_fpr++] = s->val.d;
121
*((float *)d) = s->val.f;
126
if (nr_gpr < GPR_COUNT)
127
gpregs[nr_gpr++] = value;
135
XPTC_PUBLIC_API(nsresult)
136
XPTC_InvokeByIndex(nsISupports * that, PRUint32 methodIndex,
137
PRUint32 paramCount, nsXPTCVariant * params)
139
PRUint32 nr_gpr, nr_fpr, nr_stack;
140
invoke_count_words(paramCount, params, nr_gpr, nr_fpr, nr_stack);
142
// Stack, if used, must be 16-bytes aligned
144
nr_stack = (nr_stack + 1) & ~1;
146
// Load parameters to stack, if necessary
147
PRUint64 *stack = (PRUint64 *) __builtin_alloca(nr_stack * 8);
148
PRUint64 gpregs[GPR_COUNT];
149
double fpregs[FPR_COUNT];
150
invoke_copy_to_stack(stack, paramCount, params, gpregs, fpregs);
152
// Load FPR registers from fpregs[]
153
register double d0 asm("xmm0");
154
register double d1 asm("xmm1");
155
register double d2 asm("xmm2");
156
register double d3 asm("xmm3");
157
register double d4 asm("xmm4");
158
register double d5 asm("xmm5");
159
register double d6 asm("xmm6");
160
register double d7 asm("xmm7");
164
case N+1: d##N = fpregs[N];
177
// Load GPR registers from gpregs[]
178
register PRUint64 a0 asm("rdi");
179
register PRUint64 a1 asm("rsi");
180
register PRUint64 a2 asm("rdx");
181
register PRUint64 a3 asm("rcx");
182
register PRUint64 a4 asm("r8");
183
register PRUint64 a5 asm("r9");
187
case N+1: a##N = gpregs[N];
193
case 1: a0 = (PRUint64) that;
198
// Ensure that assignments to SSE registers won't be optimized away
200
"x" (d0), "x" (d1), "x" (d2), "x" (d3),
201
"x" (d4), "x" (d5), "x" (d6), "x" (d7));
203
// Get pointer to method
204
PRUint64 methodAddress = *((PRUint64 *)that);
205
methodAddress += 8 * methodIndex;
206
methodAddress = *((PRUint64 *)methodAddress);
208
typedef PRUint32 (*Method)(PRUint64, PRUint64, PRUint64, PRUint64, PRUint64, PRUint64);
209
PRUint32 result = ((Method)methodAddress)(a0, a1, a2, a3, a4, a5);