1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcstubs_amd64_openbsd.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,201 @@ 1.4 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +// Implement shared vtbl methods. 1.11 + 1.12 +#include "xptcprivate.h" 1.13 +#include "xptiprivate.h" 1.14 + 1.15 +// The Linux/x86-64 ABI passes the first 6 integer parameters and the 1.16 +// first 8 floating point parameters in registers (rdi, rsi, rdx, rcx, 1.17 +// r8, r9 and xmm0-xmm7), no stack space is allocated for these by the 1.18 +// caller. The rest of the parameters are passed in the callers stack 1.19 +// area. 1.20 + 1.21 +const uint32_t PARAM_BUFFER_COUNT = 16; 1.22 +const uint32_t GPR_COUNT = 6; 1.23 +const uint32_t FPR_COUNT = 8; 1.24 + 1.25 +// PrepareAndDispatch() is called by SharedStub() and calls the actual method. 1.26 +// 1.27 +// - 'args[]' contains the arguments passed on stack 1.28 +// - 'gpregs[]' contains the arguments passed in integer registers 1.29 +// - 'fpregs[]' contains the arguments passed in floating point registers 1.30 +// 1.31 +// The parameters are mapped into an array of type 'nsXPTCMiniVariant' 1.32 +// and then the method gets called. 1.33 + 1.34 +extern "C" nsresult ATTRIBUTE_USED 1.35 +PrepareAndDispatch(nsXPTCStubBase * self, uint32_t methodIndex, 1.36 + uint64_t * args, uint64_t * gpregs, double *fpregs) 1.37 +{ 1.38 + nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; 1.39 + nsXPTCMiniVariant* dispatchParams = nullptr; 1.40 + const nsXPTMethodInfo* info; 1.41 + uint32_t paramCount; 1.42 + uint32_t i; 1.43 + nsresult result = NS_ERROR_FAILURE; 1.44 + 1.45 + NS_ASSERTION(self,"no self"); 1.46 + 1.47 + self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); 1.48 + NS_ASSERTION(info,"no method info"); 1.49 + if (!info) 1.50 + return NS_ERROR_UNEXPECTED; 1.51 + 1.52 + paramCount = info->GetParamCount(); 1.53 + 1.54 + // setup variant array pointer 1.55 + if (paramCount > PARAM_BUFFER_COUNT) 1.56 + dispatchParams = new nsXPTCMiniVariant[paramCount]; 1.57 + else 1.58 + dispatchParams = paramBuffer; 1.59 + 1.60 + NS_ASSERTION(dispatchParams,"no place for params"); 1.61 + if (!dispatchParams) 1.62 + return NS_ERROR_OUT_OF_MEMORY; 1.63 + 1.64 + uint64_t* ap = args; 1.65 + uint32_t nr_gpr = 1; // skip one GPR register for 'that' 1.66 + uint32_t nr_fpr = 0; 1.67 + uint64_t value; 1.68 + 1.69 + for (i = 0; i < paramCount; i++) { 1.70 + const nsXPTParamInfo& param = info->GetParam(i); 1.71 + const nsXPTType& type = param.GetType(); 1.72 + nsXPTCMiniVariant* dp = &dispatchParams[i]; 1.73 + 1.74 + if (!param.IsOut() && type == nsXPTType::T_DOUBLE) { 1.75 + if (nr_fpr < FPR_COUNT) 1.76 + dp->val.d = fpregs[nr_fpr++]; 1.77 + else 1.78 + dp->val.d = *(double*) ap++; 1.79 + continue; 1.80 + } 1.81 + else if (!param.IsOut() && type == nsXPTType::T_FLOAT) { 1.82 + if (nr_fpr < FPR_COUNT) 1.83 + // The value in %xmm register is already prepared to 1.84 + // be retrieved as a float. Therefore, we pass the 1.85 + // value verbatim, as a double without conversion. 1.86 + dp->val.d = *(double*) ap++; 1.87 + else 1.88 + dp->val.f = *(float*) ap++; 1.89 + continue; 1.90 + } 1.91 + else { 1.92 + if (nr_gpr < GPR_COUNT) 1.93 + value = gpregs[nr_gpr++]; 1.94 + else 1.95 + value = *ap++; 1.96 + } 1.97 + 1.98 + if (param.IsOut() || !type.IsArithmetic()) { 1.99 + dp->val.p = (void*) value; 1.100 + continue; 1.101 + } 1.102 + 1.103 + switch (type) { 1.104 + case nsXPTType::T_I8: dp->val.i8 = (int8_t) value; break; 1.105 + case nsXPTType::T_I16: dp->val.i16 = (int16_t) value; break; 1.106 + case nsXPTType::T_I32: dp->val.i32 = (int32_t) value; break; 1.107 + case nsXPTType::T_I64: dp->val.i64 = (int64_t) value; break; 1.108 + case nsXPTType::T_U8: dp->val.u8 = (uint8_t) value; break; 1.109 + case nsXPTType::T_U16: dp->val.u16 = (uint16_t) value; break; 1.110 + case nsXPTType::T_U32: dp->val.u32 = (uint32_t) value; break; 1.111 + case nsXPTType::T_U64: dp->val.u64 = (uint64_t) value; break; 1.112 + case nsXPTType::T_BOOL: dp->val.b = (bool) value; break; 1.113 + case nsXPTType::T_CHAR: dp->val.c = (char) value; break; 1.114 + case nsXPTType::T_WCHAR: dp->val.wc = (wchar_t) value; break; 1.115 + 1.116 + default: 1.117 + NS_ERROR("bad type"); 1.118 + break; 1.119 + } 1.120 + } 1.121 + 1.122 + result = self->mOuter->CallMethod((uint16_t) methodIndex, info, dispatchParams); 1.123 + 1.124 + if (dispatchParams != paramBuffer) 1.125 + delete [] dispatchParams; 1.126 + 1.127 + return result; 1.128 +} 1.129 + 1.130 +// Linux/x86-64 uses gcc >= 3.1 1.131 +#define STUB_ENTRY(n) \ 1.132 +asm(".section \".text\"\n\t" \ 1.133 + ".align 2\n\t" \ 1.134 + ".if " #n " < 10\n\t" \ 1.135 + ".globl _ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \ 1.136 + ".hidden _ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \ 1.137 + ".type _ZN14nsXPTCStubBase5Stub" #n "Ev,@function\n" \ 1.138 + "_ZN14nsXPTCStubBase5Stub" #n "Ev:\n\t" \ 1.139 + ".elseif " #n " < 100\n\t" \ 1.140 + ".globl _ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \ 1.141 + ".hidden _ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \ 1.142 + ".type _ZN14nsXPTCStubBase6Stub" #n "Ev,@function\n" \ 1.143 + "_ZN14nsXPTCStubBase6Stub" #n "Ev:\n\t" \ 1.144 + ".elseif " #n " < 1000\n\t" \ 1.145 + ".globl _ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \ 1.146 + ".hidden _ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \ 1.147 + ".type _ZN14nsXPTCStubBase7Stub" #n "Ev,@function\n" \ 1.148 + "_ZN14nsXPTCStubBase7Stub" #n "Ev:\n\t" \ 1.149 + ".else\n\t" \ 1.150 + ".err \"stub number " #n " >= 1000 not yet supported\"\n\t" \ 1.151 + ".endif\n\t" \ 1.152 + "movl $" #n ", %eax\n\t" \ 1.153 + "jmp SharedStub\n\t" \ 1.154 + ".if " #n " < 10\n\t" \ 1.155 + ".size _ZN14nsXPTCStubBase5Stub" #n "Ev,.-_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \ 1.156 + ".elseif " #n " < 100\n\t" \ 1.157 + ".size _ZN14nsXPTCStubBase6Stub" #n "Ev,.-_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \ 1.158 + ".else\n\t" \ 1.159 + ".size _ZN14nsXPTCStubBase7Stub" #n "Ev,.-_ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \ 1.160 + ".endif"); 1.161 + 1.162 +// static nsresult SharedStub(uint32_t methodIndex) 1.163 +asm(".section \".text\"\n\t" 1.164 + ".align 2\n\t" 1.165 + ".type SharedStub,@function\n\t" 1.166 + "SharedStub:\n\t" 1.167 + // make room for gpregs (48), fpregs (64) 1.168 + "pushq %rbp\n\t" 1.169 + "movq %rsp,%rbp\n\t" 1.170 + "subq $112,%rsp\n\t" 1.171 + // save GP registers 1.172 + "movq %rdi,-112(%rbp)\n\t" 1.173 + "movq %rsi,-104(%rbp)\n\t" 1.174 + "movq %rdx, -96(%rbp)\n\t" 1.175 + "movq %rcx, -88(%rbp)\n\t" 1.176 + "movq %r8 , -80(%rbp)\n\t" 1.177 + "movq %r9 , -72(%rbp)\n\t" 1.178 + "leaq -112(%rbp),%rcx\n\t" 1.179 + // save FP registers 1.180 + "movsd %xmm0,-64(%rbp)\n\t" 1.181 + "movsd %xmm1,-56(%rbp)\n\t" 1.182 + "movsd %xmm2,-48(%rbp)\n\t" 1.183 + "movsd %xmm3,-40(%rbp)\n\t" 1.184 + "movsd %xmm4,-32(%rbp)\n\t" 1.185 + "movsd %xmm5,-24(%rbp)\n\t" 1.186 + "movsd %xmm6,-16(%rbp)\n\t" 1.187 + "movsd %xmm7, -8(%rbp)\n\t" 1.188 + "leaq -64(%rbp),%r8\n\t" 1.189 + // rdi has the 'self' pointer already 1.190 + "movl %eax,%esi\n\t" 1.191 + "leaq 16(%rbp),%rdx\n\t" 1.192 + "call PrepareAndDispatch@plt\n\t" 1.193 + "leave\n\t" 1.194 + "ret\n\t" 1.195 + ".size SharedStub,.-SharedStub"); 1.196 + 1.197 +#define SENTINEL_ENTRY(n) \ 1.198 +nsresult nsXPTCStubBase::Sentinel##n() \ 1.199 +{ \ 1.200 + NS_ERROR("nsXPTCStubBase::Sentinel called"); \ 1.201 + return NS_ERROR_NOT_IMPLEMENTED; \ 1.202 +} 1.203 + 1.204 +#include "xptcstubsdef.inc"