1 $NetBSD: patch-xi,v 1.1.1.1 2009/08/05 02:59:49 tnn Exp $
3 NetBSD/amd64 xptcall support code. Originally from pkgsrc/www/mozilla.
5 --- mozilla/xpcom/reflect/xptcall/src/md/unix/xptcstubs_unixish_amd64.cpp.orig 2009-06-30 22:20:24.000000000 +0200
6 +++ mozilla/xpcom/reflect/xptcall/src/md/unix/xptcstubs_unixish_amd64.cpp
8 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
10 +// Implement shared vtbl methods.
12 +#include "xptcprivate.h"
14 +// The Linux/x86-64 ABI passes the first 6 integral parameters and the
15 +// first 8 floating point parameters in registers (rdi, rsi, rdx, rcx,
16 +// r8, r9 and xmm0-xmm7), no stack space is allocated for these by the
17 +// caller. The rest of the parameters are passed in the callers stack
20 +const PRUint32 PARAM_BUFFER_COUNT = 16;
21 +const PRUint32 GPR_COUNT = 6;
22 +const PRUint32 FPR_COUNT = 8;
24 +// PrepareAndDispatch() is called by SharedStub() and calls the actual method.
26 +// - 'args[]' contains the arguments passed on stack
27 +// - 'gpregs[]' contains the arguments passed in integer registers
28 +// - 'fpregs[]' contains the arguments passed in floating point registers
30 +// The parameters are mapped into an array of type 'nsXPTCMiniVariant'
31 +// and then the method gets called.
34 +PrepareAndDispatch(nsXPTCStubBase * self, PRUint32 methodIndex,
35 + PRUint64 * args, PRUint64 * gpregs, double *fpregs)
37 + nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
38 + nsXPTCMiniVariant* dispatchParams = NULL;
39 + nsIInterfaceInfo* iface_info = NULL;
40 + const nsXPTMethodInfo* info;
41 + PRUint32 paramCount;
43 + nsresult result = NS_ERROR_FAILURE;
45 + NS_ASSERTION(self,"no self");
47 + self->GetInterfaceInfo(&iface_info);
48 + NS_ASSERTION(iface_info,"no interface info");
50 + return NS_ERROR_UNEXPECTED;
52 + iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
53 + NS_ASSERTION(info,"no method info");
55 + return NS_ERROR_UNEXPECTED;
57 + paramCount = info->GetParamCount();
59 + // setup variant array pointer
60 + if(paramCount > PARAM_BUFFER_COUNT)
61 + dispatchParams = new nsXPTCMiniVariant[paramCount];
63 + dispatchParams = paramBuffer;
65 + NS_ASSERTION(dispatchParams,"no place for params");
66 + if (! dispatchParams)
67 + return NS_ERROR_OUT_OF_MEMORY;
69 + PRUint64* ap = args;
70 + PRUint32 nr_gpr = 1; // skip one GPR register for 'that'
71 + PRUint32 nr_fpr = 0;
74 + for(i = 0; i < paramCount; i++) {
75 + const nsXPTParamInfo& param = info->GetParam(i);
76 + const nsXPTType& type = param.GetType();
77 + nsXPTCMiniVariant* dp = &dispatchParams[i];
79 + if (!param.IsOut() && type == nsXPTType::T_DOUBLE) {
80 + if (nr_fpr < FPR_COUNT)
81 + dp->val.d = fpregs[nr_fpr++];
83 + dp->val.d = *(double*) ap++;
86 + else if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
87 + if (nr_fpr < FPR_COUNT)
88 + // The value in %xmm register is already prepared to
89 + // be retrieved as a float. Therefore, we pass the
90 + // value verbatim, as a double without conversion.
91 + dp->val.d = *(double*) ap++;
93 + dp->val.f = *(float*) ap++;
97 + if (nr_gpr < GPR_COUNT)
98 + value = gpregs[nr_gpr++];
103 + if (param.IsOut() || !type.IsArithmetic()) {
104 + dp->val.p = (void*) value;
109 + case nsXPTType::T_I8: dp->val.i8 = (PRInt8) value; break;
110 + case nsXPTType::T_I16: dp->val.i16 = (PRInt16) value; break;
111 + case nsXPTType::T_I32: dp->val.i32 = (PRInt32) value; break;
112 + case nsXPTType::T_I64: dp->val.i64 = (PRInt64) value; break;
113 + case nsXPTType::T_U8: dp->val.u8 = (PRUint8) value; break;
114 + case nsXPTType::T_U16: dp->val.u16 = (PRUint16) value; break;
115 + case nsXPTType::T_U32: dp->val.u32 = (PRUint32) value; break;
116 + case nsXPTType::T_U64: dp->val.u64 = (PRUint64) value; break;
117 + case nsXPTType::T_BOOL: dp->val.b = (PRBool) value; break;
118 + case nsXPTType::T_CHAR: dp->val.c = (char) value; break;
119 + case nsXPTType::T_WCHAR: dp->val.wc = (wchar_t) value; break;
122 + NS_ASSERTION(0, "bad type");
127 + result = self->CallMethod((PRUint16) methodIndex, info, dispatchParams);
129 + NS_RELEASE(iface_info);
131 + if (dispatchParams != paramBuffer)
132 + delete [] dispatchParams;
137 +#if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 /* G++ V3 ABI */
138 +// Linux/x86-64 uses gcc >= 3.1
139 +#define STUB_ENTRY(n) \
140 +asm(".section \".text\"\n\t" \
142 + ".if " #n " < 10\n\t" \
143 + ".globl _ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
144 + ".type _ZN14nsXPTCStubBase5Stub" #n "Ev,@function\n" \
145 + "_ZN14nsXPTCStubBase5Stub" #n "Ev:\n\t" \
146 + ".elseif " #n " < 100\n\t" \
147 + ".globl _ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
148 + ".type _ZN14nsXPTCStubBase6Stub" #n "Ev,@function\n" \
149 + "_ZN14nsXPTCStubBase6Stub" #n "Ev:\n\t" \
150 + ".elseif " #n " < 1000\n\t" \
151 + ".globl _ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
152 + ".type _ZN14nsXPTCStubBase7Stub" #n "Ev,@function\n" \
153 + "_ZN14nsXPTCStubBase7Stub" #n "Ev:\n\t" \
155 + ".err \"stub number " #n " >= 1000 not yet supported\"\n\t" \
157 + "movl $" #n ", %eax\n\t" \
158 + "jmp SharedStub\n\t" \
159 + ".if " #n " < 10\n\t" \
160 + ".size _ZN14nsXPTCStubBase5Stub" #n "Ev,.-_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
161 + ".elseif " #n " < 100\n\t" \
162 + ".size _ZN14nsXPTCStubBase6Stub" #n "Ev,.-_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
164 + ".size _ZN14nsXPTCStubBase7Stub" #n "Ev,.-_ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
167 +// static nsresult SharedStub(PRUint32 methodIndex)
168 +asm(".section \".text\"\n\t"
170 + ".type SharedStub,@function\n\t"
172 + // make room for gpregs (48), fpregs (64)
174 + "movq %rsp,%rbp\n\t"
175 + "subq $112,%rsp\n\t"
176 + // save GP registers
177 + "movq %rdi,-112(%rbp)\n\t"
178 + "movq %rsi,-104(%rbp)\n\t"
179 + "movq %rdx, -96(%rbp)\n\t"
180 + "movq %rcx, -88(%rbp)\n\t"
181 + "movq %r8 , -80(%rbp)\n\t"
182 + "movq %r9 , -72(%rbp)\n\t"
183 + "leaq -112(%rbp),%rcx\n\t"
184 + // save FP registers
185 + "movsd %xmm0,-64(%rbp)\n\t"
186 + "movsd %xmm1,-56(%rbp)\n\t"
187 + "movsd %xmm2,-48(%rbp)\n\t"
188 + "movsd %xmm3,-40(%rbp)\n\t"
189 + "movsd %xmm4,-32(%rbp)\n\t"
190 + "movsd %xmm5,-24(%rbp)\n\t"
191 + "movsd %xmm6,-16(%rbp)\n\t"
192 + "movsd %xmm7, -8(%rbp)\n\t"
193 + "leaq -64(%rbp),%r8\n\t"
194 + // rdi has the 'self' pointer already
195 + "movl %eax,%esi\n\t"
196 + "leaq 16(%rbp),%rdx\n\t"
197 + "call PrepareAndDispatch\n\t"
200 + ".size SharedStub,.-SharedStub");
202 +#define SENTINEL_ENTRY(n) \
203 +nsresult nsXPTCStubBase::Sentinel##n() \
205 + NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
206 + return NS_ERROR_NOT_IMPLEMENTED; \
209 +#include "xptcstubsdef.inc"
212 +#error "can't find a compiler to use"
213 +#endif /* __GNUC__ */