Fixup fromcvs/togit conversion
[pkgsrcv2.git] / www / seamonkey / patches / patch-xi
1 $NetBSD: patch-xi,v 1.1.1.1 2009/08/05 02:59:49 tnn Exp $
2
3 NetBSD/amd64 xptcall support code. Originally from pkgsrc/www/mozilla.
4
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
7 @@ -0,0 +1,206 @@
8 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
9 +
10 +// Implement shared vtbl methods.
11 +
12 +#include "xptcprivate.h"
13 +
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
18 +// area.
19 +
20 +const PRUint32 PARAM_BUFFER_COUNT   = 16;
21 +const PRUint32 GPR_COUNT            = 6;
22 +const PRUint32 FPR_COUNT            = 8;
23 +
24 +// PrepareAndDispatch() is called by SharedStub() and calls the actual method.
25 +//
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
29 +// 
30 +// The parameters are mapped into an array of type 'nsXPTCMiniVariant'
31 +// and then the method gets called.
32 +
33 +extern "C" nsresult
34 +PrepareAndDispatch(nsXPTCStubBase * self, PRUint32 methodIndex,
35 +                   PRUint64 * args, PRUint64 * gpregs, double *fpregs)
36 +{
37 +    nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
38 +    nsXPTCMiniVariant* dispatchParams = NULL;
39 +    nsIInterfaceInfo* iface_info = NULL;
40 +    const nsXPTMethodInfo* info;
41 +    PRUint32 paramCount;
42 +    PRUint32 i;
43 +    nsresult result = NS_ERROR_FAILURE;
44 +
45 +    NS_ASSERTION(self,"no self");
46 +
47 +    self->GetInterfaceInfo(&iface_info);
48 +    NS_ASSERTION(iface_info,"no interface info");
49 +    if (! iface_info)
50 +        return NS_ERROR_UNEXPECTED;
51 +
52 +    iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
53 +    NS_ASSERTION(info,"no method info");
54 +    if (! info)
55 +        return NS_ERROR_UNEXPECTED;
56 +
57 +    paramCount = info->GetParamCount();
58 +
59 +    // setup variant array pointer
60 +    if(paramCount > PARAM_BUFFER_COUNT)
61 +        dispatchParams = new nsXPTCMiniVariant[paramCount];
62 +    else
63 +        dispatchParams = paramBuffer;
64 +
65 +    NS_ASSERTION(dispatchParams,"no place for params");
66 +    if (! dispatchParams)
67 +        return NS_ERROR_OUT_OF_MEMORY;
68 +
69 +    PRUint64* ap = args;
70 +    PRUint32 nr_gpr = 1;    // skip one GPR register for 'that'
71 +    PRUint32 nr_fpr = 0;
72 +    PRUint64 value;
73 +
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];
78 +       
79 +        if (!param.IsOut() && type == nsXPTType::T_DOUBLE) {
80 +            if (nr_fpr < FPR_COUNT)
81 +                dp->val.d = fpregs[nr_fpr++];
82 +            else
83 +                dp->val.d = *(double*) ap++;
84 +            continue;
85 +        }
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++;
92 +            else
93 +                dp->val.f = *(float*) ap++;
94 +            continue;
95 +        }
96 +        else {
97 +            if (nr_gpr < GPR_COUNT)
98 +                value = gpregs[nr_gpr++];
99 +            else
100 +                value = *ap++;
101 +        }
102 +
103 +        if (param.IsOut() || !type.IsArithmetic()) {
104 +            dp->val.p = (void*) value;
105 +            continue;
106 +        }
107 +
108 +        switch (type) {
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;
120 +
121 +        default:
122 +            NS_ASSERTION(0, "bad type");
123 +            break;
124 +        }
125 +    }
126 +
127 +    result = self->CallMethod((PRUint16) methodIndex, info, dispatchParams);
128 +
129 +    NS_RELEASE(iface_info);
130 +
131 +    if (dispatchParams != paramBuffer)
132 +        delete [] dispatchParams;
133 +
134 +    return result;
135 +}
136 +
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" \
141 +    ".align    2\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" \
154 +    ".else\n\t" \
155 +    ".err      \"stub number " #n " >= 1000 not yet supported\"\n\t" \
156 +    ".endif\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" \
163 +    ".else\n\t" \
164 +    ".size     _ZN14nsXPTCStubBase7Stub" #n "Ev,.-_ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
165 +    ".endif");
166 +
167 +// static nsresult SharedStub(PRUint32 methodIndex)
168 +asm(".section   \".text\"\n\t"
169 +    ".align     2\n\t"
170 +    ".type      SharedStub,@function\n\t"
171 +    "SharedStub:\n\t"
172 +    // make room for gpregs (48), fpregs (64)
173 +    "pushq      %rbp\n\t"
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"
198 +    "leave\n\t"
199 +    "ret\n\t"
200 +    ".size      SharedStub,.-SharedStub");
201 +
202 +#define SENTINEL_ENTRY(n) \
203 +nsresult nsXPTCStubBase::Sentinel##n() \
204 +{ \
205 +    NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
206 +    return NS_ERROR_NOT_IMPLEMENTED; \
207 +}
208 +
209 +#include "xptcstubsdef.inc"
210 +
211 +#else
212 +#error "can't find a compiler to use"
213 +#endif /* __GNUC__ */