1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcstubs_aarch64.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,219 @@ 1.4 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "xptcprivate.h" 1.10 +#include "xptiprivate.h" 1.11 + 1.12 +#ifndef __AARCH64EL__ 1.13 +#error "Only little endian compatibility was tested" 1.14 +#endif 1.15 + 1.16 +/* 1.17 + * This is for AArch64 ABI 1.18 + * 1.19 + * When we're called, the "gp" registers are stored in gprData and 1.20 + * the "fp" registers are stored in fprData. Each array has 8 regs 1.21 + * but first reg in gprData is a placeholder for 'self'. 1.22 + */ 1.23 +extern "C" nsresult 1.24 +PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint64_t* args, 1.25 + uint64_t *gprData, double *fprData) 1.26 +{ 1.27 +#define PARAM_BUFFER_COUNT 16 1.28 +#define PARAM_GPR_COUNT 8 1.29 +#define PARAM_FPR_COUNT 8 1.30 + 1.31 + nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; 1.32 + nsXPTCMiniVariant* dispatchParams = NULL; 1.33 + const nsXPTMethodInfo* info; 1.34 + nsresult result = NS_ERROR_FAILURE; 1.35 + 1.36 + NS_ASSERTION(self,"no self"); 1.37 + 1.38 + self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); 1.39 + NS_ASSERTION(info,"no method info"); 1.40 + 1.41 + uint32_t paramCount = info->GetParamCount(); 1.42 + 1.43 + // setup variant array pointer 1.44 + if (paramCount > PARAM_BUFFER_COUNT) { 1.45 + dispatchParams = new nsXPTCMiniVariant[paramCount]; 1.46 + } else { 1.47 + dispatchParams = paramBuffer; 1.48 + } 1.49 + NS_ASSERTION(dispatchParams,"no place for params"); 1.50 + 1.51 + uint64_t* ap = args; 1.52 + uint32_t next_gpr = 1; // skip first arg which is 'self' 1.53 + uint32_t next_fpr = 0; 1.54 + for (uint32_t i = 0; i < paramCount; i++) { 1.55 + const nsXPTParamInfo& param = info->GetParam(i); 1.56 + const nsXPTType& type = param.GetType(); 1.57 + nsXPTCMiniVariant* dp = &dispatchParams[i]; 1.58 + 1.59 + if (param.IsOut() || !type.IsArithmetic()) { 1.60 + if (next_gpr < PARAM_GPR_COUNT) { 1.61 + dp->val.p = (void*)gprData[next_gpr++]; 1.62 + } else { 1.63 + dp->val.p = (void*)*ap++; 1.64 + } 1.65 + continue; 1.66 + } 1.67 + 1.68 + switch (type) { 1.69 + case nsXPTType::T_I8: 1.70 + if (next_gpr < PARAM_GPR_COUNT) { 1.71 + dp->val.i8 = (int8_t)gprData[next_gpr++]; 1.72 + } else { 1.73 + dp->val.i8 = (int8_t)*ap++; 1.74 + } 1.75 + break; 1.76 + 1.77 + case nsXPTType::T_I16: 1.78 + if (next_gpr < PARAM_GPR_COUNT) { 1.79 + dp->val.i16 = (int16_t)gprData[next_gpr++]; 1.80 + } else { 1.81 + dp->val.i16 = (int16_t)*ap++; 1.82 + } 1.83 + break; 1.84 + 1.85 + case nsXPTType::T_I32: 1.86 + if (next_gpr < PARAM_GPR_COUNT) { 1.87 + dp->val.i32 = (int32_t)gprData[next_gpr++]; 1.88 + } else { 1.89 + dp->val.i32 = (int32_t)*ap++; 1.90 + } 1.91 + break; 1.92 + 1.93 + case nsXPTType::T_I64: 1.94 + if (next_gpr < PARAM_GPR_COUNT) { 1.95 + dp->val.i64 = (int64_t)gprData[next_gpr++]; 1.96 + } else { 1.97 + dp->val.i64 = (int64_t)*ap++; 1.98 + } 1.99 + break; 1.100 + 1.101 + case nsXPTType::T_U8: 1.102 + if (next_gpr < PARAM_GPR_COUNT) { 1.103 + dp->val.u8 = (uint8_t)gprData[next_gpr++]; 1.104 + } else { 1.105 + dp->val.u8 = (uint8_t)*ap++; 1.106 + } 1.107 + break; 1.108 + 1.109 + case nsXPTType::T_U16: 1.110 + if (next_gpr < PARAM_GPR_COUNT) { 1.111 + dp->val.u16 = (uint16_t)gprData[next_gpr++]; 1.112 + } else { 1.113 + dp->val.u16 = (uint16_t)*ap++; 1.114 + } 1.115 + break; 1.116 + 1.117 + case nsXPTType::T_U32: 1.118 + if (next_gpr < PARAM_GPR_COUNT) { 1.119 + dp->val.u32 = (uint32_t)gprData[next_gpr++]; 1.120 + } else { 1.121 + dp->val.u32 = (uint32_t)*ap++; 1.122 + } 1.123 + break; 1.124 + 1.125 + case nsXPTType::T_U64: 1.126 + if (next_gpr < PARAM_GPR_COUNT) { 1.127 + dp->val.u64 = (uint64_t)gprData[next_gpr++]; 1.128 + } else { 1.129 + dp->val.u64 = (uint64_t)*ap++; 1.130 + } 1.131 + break; 1.132 + 1.133 + case nsXPTType::T_FLOAT: 1.134 + if (next_fpr < PARAM_FPR_COUNT) { 1.135 + memcpy(&dp->val.f, &fprData[next_fpr++], sizeof(dp->val.f)); 1.136 + } else { 1.137 + memcpy(&dp->val.f, ap++, sizeof(dp->val.f)); 1.138 + } 1.139 + break; 1.140 + 1.141 + case nsXPTType::T_DOUBLE: 1.142 + if (next_fpr < PARAM_FPR_COUNT) { 1.143 + memcpy(&dp->val.d, &fprData[next_fpr++], sizeof(dp->val.d)); 1.144 + } else { 1.145 + memcpy(&dp->val.d, ap++, sizeof(dp->val.d)); 1.146 + } 1.147 + break; 1.148 + 1.149 + case nsXPTType::T_BOOL: 1.150 + if (next_gpr < PARAM_GPR_COUNT) { 1.151 + dp->val.b = (bool)gprData[next_gpr++]; 1.152 + } else { 1.153 + dp->val.b = (bool)*ap++; 1.154 + } 1.155 + break; 1.156 + 1.157 + case nsXPTType::T_CHAR: 1.158 + if (next_gpr < PARAM_GPR_COUNT) { 1.159 + dp->val.c = (char)gprData[next_gpr++]; 1.160 + } else { 1.161 + dp->val.c = (char)*ap++; 1.162 + } 1.163 + break; 1.164 + 1.165 + case nsXPTType::T_WCHAR: 1.166 + if (next_gpr < PARAM_GPR_COUNT) { 1.167 + dp->val.wc = (wchar_t)gprData[next_gpr++]; 1.168 + } else { 1.169 + dp->val.wc = (wchar_t)*ap++; 1.170 + } 1.171 + break; 1.172 + 1.173 + default: 1.174 + NS_ASSERTION(0, "bad type"); 1.175 + break; 1.176 + } 1.177 + } 1.178 + 1.179 + result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams); 1.180 + 1.181 + if (dispatchParams != paramBuffer) { 1.182 + delete [] dispatchParams; 1.183 + } 1.184 + 1.185 + return result; 1.186 +} 1.187 + 1.188 +// Load w17 with the constant 'n' and branch to SharedStub(). 1.189 +# define STUB_ENTRY(n) \ 1.190 + __asm__ ( \ 1.191 + ".section \".text\" \n\t" \ 1.192 + ".align 2\n\t" \ 1.193 + ".if "#n" < 10 \n\t" \ 1.194 + ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t" \ 1.195 + ".hidden _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t" \ 1.196 + ".type _ZN14nsXPTCStubBase5Stub"#n"Ev,@function \n\n" \ 1.197 + "_ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t" \ 1.198 + ".elseif "#n" < 100 \n\t" \ 1.199 + ".globl _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t" \ 1.200 + ".hidden _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t" \ 1.201 + ".type _ZN14nsXPTCStubBase6Stub"#n"Ev,@function \n\n" \ 1.202 + "_ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t" \ 1.203 + ".elseif "#n" < 1000 \n\t" \ 1.204 + ".globl _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t" \ 1.205 + ".hidden _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t" \ 1.206 + ".type _ZN14nsXPTCStubBase7Stub"#n"Ev,@function \n\n" \ 1.207 + "_ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t" \ 1.208 + ".else \n\t" \ 1.209 + ".err \"stub number "#n" >= 1000 not yet supported\"\n" \ 1.210 + ".endif \n\t" \ 1.211 + "mov w17,#"#n" \n\t" \ 1.212 + "b SharedStub \n" \ 1.213 +); 1.214 + 1.215 +#define SENTINEL_ENTRY(n) \ 1.216 + nsresult nsXPTCStubBase::Sentinel##n() \ 1.217 +{ \ 1.218 + NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \ 1.219 + return NS_ERROR_NOT_IMPLEMENTED; \ 1.220 +} 1.221 + 1.222 +#include "xptcstubsdef.inc"