1 $NetBSD: patch-bv,v 1.1.1.1 2008/06/28 10:01:07 tnn Exp $
3 diff -ruN ../Orig/mozilla/xpcom/reflect/xptcall/src/md/unix/xptcstubs_unixish_amd64.cpp ./xpcom/reflect/xptcall/src/md/unix/xptcstubs_unixish_amd64.cpp
4 --- ../Orig/mozilla/xpcom/reflect/xptcall/src/md/unix/xptcstubs_unixish_amd64.cpp 1970-01-01 09:00:00.000000000 +0900
5 +++ ./xpcom/reflect/xptcall/src/md/unix/xptcstubs_unixish_amd64.cpp 2005-12-04 19:32:22.000000000 +0900
7 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
9 +// Implement shared vtbl methods.
11 +#include "xptcprivate.h"
13 +// The Linux/x86-64 ABI passes the first 6 integral parameters and the
14 +// first 8 floating point parameters in registers (rdi, rsi, rdx, rcx,
15 +// r8, r9 and xmm0-xmm7), no stack space is allocated for these by the
16 +// caller. The rest of the parameters are passed in the callers stack
19 +const PRUint32 PARAM_BUFFER_COUNT = 16;
20 +const PRUint32 GPR_COUNT = 6;
21 +const PRUint32 FPR_COUNT = 8;
23 +// PrepareAndDispatch() is called by SharedStub() and calls the actual method.
25 +// - 'args[]' contains the arguments passed on stack
26 +// - 'gpregs[]' contains the arguments passed in integer registers
27 +// - 'fpregs[]' contains the arguments passed in floating point registers
29 +// The parameters are mapped into an array of type 'nsXPTCMiniVariant'
30 +// and then the method gets called.
33 +PrepareAndDispatch(nsXPTCStubBase * self, PRUint32 methodIndex,
34 + PRUint64 * args, PRUint64 * gpregs, double *fpregs)
36 + nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
37 + nsXPTCMiniVariant* dispatchParams = NULL;
38 + nsIInterfaceInfo* iface_info = NULL;
39 + const nsXPTMethodInfo* info;
40 + PRUint32 paramCount;
42 + nsresult result = NS_ERROR_FAILURE;
44 + NS_ASSERTION(self,"no self");
46 + self->GetInterfaceInfo(&iface_info);
47 + NS_ASSERTION(iface_info,"no interface info");
49 + return NS_ERROR_UNEXPECTED;
51 + iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
52 + NS_ASSERTION(info,"no method info");
54 + return NS_ERROR_UNEXPECTED;
56 + paramCount = info->GetParamCount();
58 + // setup variant array pointer
59 + if(paramCount > PARAM_BUFFER_COUNT)
60 + dispatchParams = new nsXPTCMiniVariant[paramCount];
62 + dispatchParams = paramBuffer;
64 + NS_ASSERTION(dispatchParams,"no place for params");
65 + if (! dispatchParams)
66 + return NS_ERROR_OUT_OF_MEMORY;
68 + PRUint64* ap = args;
69 + PRUint32 nr_gpr = 1; // skip one GPR register for 'that'
70 + PRUint32 nr_fpr = 0;
73 + for(i = 0; i < paramCount; i++) {
74 + const nsXPTParamInfo& param = info->GetParam(i);
75 + const nsXPTType& type = param.GetType();
76 + nsXPTCMiniVariant* dp = &dispatchParams[i];
78 + if (!param.IsOut() && type == nsXPTType::T_DOUBLE) {
79 + if (nr_fpr < FPR_COUNT)
80 + dp->val.d = fpregs[nr_fpr++];
82 + dp->val.d = *(double*) ap++;
85 + else if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
86 + if (nr_fpr < FPR_COUNT)
87 + // The value in %xmm register is already prepared to
88 + // be retrieved as a float. Therefore, we pass the
89 + // value verbatim, as a double without conversion.
90 + dp->val.d = *(double*) ap++;
92 + dp->val.f = *(float*) ap++;
96 + if (nr_gpr < GPR_COUNT)
97 + value = gpregs[nr_gpr++];
102 + if (param.IsOut() || !type.IsArithmetic()) {
103 + dp->val.p = (void*) value;
108 + case nsXPTType::T_I8: dp->val.i8 = (PRInt8) value; break;
109 + case nsXPTType::T_I16: dp->val.i16 = (PRInt16) value; break;
110 + case nsXPTType::T_I32: dp->val.i32 = (PRInt32) value; break;
111 + case nsXPTType::T_I64: dp->val.i64 = (PRInt64) value; break;
112 + case nsXPTType::T_U8: dp->val.u8 = (PRUint8) value; break;
113 + case nsXPTType::T_U16: dp->val.u16 = (PRUint16) value; break;
114 + case nsXPTType::T_U32: dp->val.u32 = (PRUint32) value; break;
115 + case nsXPTType::T_U64: dp->val.u64 = (PRUint64) value; break;
116 + case nsXPTType::T_BOOL: dp->val.b = (PRBool) value; break;
117 + case nsXPTType::T_CHAR: dp->val.c = (char) value; break;
118 + case nsXPTType::T_WCHAR: dp->val.wc = (wchar_t) value; break;
121 + NS_ASSERTION(0, "bad type");
126 + result = self->CallMethod((PRUint16) methodIndex, info, dispatchParams);
128 + NS_RELEASE(iface_info);
130 + if (dispatchParams != paramBuffer)
131 + delete [] dispatchParams;
136 +#if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 /* G++ V3 ABI */
137 +// Linux/x86-64 uses gcc >= 3.1
138 +#define STUB_ENTRY(n) \
139 +asm(".section \".text\"\n\t" \
141 + ".if " #n " < 10\n\t" \
142 + ".globl _ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
143 + ".type _ZN14nsXPTCStubBase5Stub" #n "Ev,@function\n" \
144 + "_ZN14nsXPTCStubBase5Stub" #n "Ev:\n\t" \
145 + ".elseif " #n " < 100\n\t" \
146 + ".globl _ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
147 + ".type _ZN14nsXPTCStubBase6Stub" #n "Ev,@function\n" \
148 + "_ZN14nsXPTCStubBase6Stub" #n "Ev:\n\t" \
149 + ".elseif " #n " < 1000\n\t" \
150 + ".globl _ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
151 + ".type _ZN14nsXPTCStubBase7Stub" #n "Ev,@function\n" \
152 + "_ZN14nsXPTCStubBase7Stub" #n "Ev:\n\t" \
154 + ".err \"stub number " #n " >= 1000 not yet supported\"\n\t" \
156 + "movl $" #n ", %eax\n\t" \
157 + "jmp SharedStub\n\t" \
158 + ".if " #n " < 10\n\t" \
159 + ".size _ZN14nsXPTCStubBase5Stub" #n "Ev,.-_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
160 + ".elseif " #n " < 100\n\t" \
161 + ".size _ZN14nsXPTCStubBase6Stub" #n "Ev,.-_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
163 + ".size _ZN14nsXPTCStubBase7Stub" #n "Ev,.-_ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
166 +// static nsresult SharedStub(PRUint32 methodIndex)
167 +asm(".section \".text\"\n\t"
169 + ".type SharedStub,@function\n\t"
171 + // make room for gpregs (48), fpregs (64)
173 + "movq %rsp,%rbp\n\t"
174 + "subq $112,%rsp\n\t"
175 + // save GP registers
176 + "movq %rdi,-112(%rbp)\n\t"
177 + "movq %rsi,-104(%rbp)\n\t"
178 + "movq %rdx, -96(%rbp)\n\t"
179 + "movq %rcx, -88(%rbp)\n\t"
180 + "movq %r8 , -80(%rbp)\n\t"
181 + "movq %r9 , -72(%rbp)\n\t"
182 + "leaq -112(%rbp),%rcx\n\t"
183 + // save FP registers
184 + "movsd %xmm0,-64(%rbp)\n\t"
185 + "movsd %xmm1,-56(%rbp)\n\t"
186 + "movsd %xmm2,-48(%rbp)\n\t"
187 + "movsd %xmm3,-40(%rbp)\n\t"
188 + "movsd %xmm4,-32(%rbp)\n\t"
189 + "movsd %xmm5,-24(%rbp)\n\t"
190 + "movsd %xmm6,-16(%rbp)\n\t"
191 + "movsd %xmm7, -8(%rbp)\n\t"
192 + "leaq -64(%rbp),%r8\n\t"
193 + // rdi has the 'self' pointer already
194 + "movl %eax,%esi\n\t"
195 + "leaq 16(%rbp),%rdx\n\t"
196 + "call PrepareAndDispatch\n\t"
199 + ".size SharedStub,.-SharedStub");
201 +#define SENTINEL_ENTRY(n) \
202 +nsresult nsXPTCStubBase::Sentinel##n() \
204 + NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
205 + return NS_ERROR_NOT_IMPLEMENTED; \
208 +#include "xptcstubsdef.inc"
211 +#error "can't find a compiler to use"
212 +#endif /* __GNUC__ */