1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcstubs_arm.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,222 @@ 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 +/* Implement shared vtbl methods. */ 1.10 + 1.11 +#include "xptcprivate.h" 1.12 +#include "xptiprivate.h" 1.13 + 1.14 +#if !defined(__arm__) && !(defined(LINUX) || defined(ANDROID)) 1.15 +#error "This code is for Linux ARM only. Please check if it works for you, too.\nDepends strongly on gcc behaviour." 1.16 +#endif 1.17 + 1.18 +/* Specify explicitly a symbol for this function, don't try to guess the c++ mangled symbol. */ 1.19 +static nsresult PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint32_t* args) asm("_PrepareAndDispatch") 1.20 +ATTRIBUTE_USED; 1.21 + 1.22 +#ifdef __ARM_EABI__ 1.23 +#define DOUBLEWORD_ALIGN(p) ((uint32_t *)((((uint32_t)(p)) + 7) & 0xfffffff8)) 1.24 +#else 1.25 +#define DOUBLEWORD_ALIGN(p) (p) 1.26 +#endif 1.27 + 1.28 +// Apple's iOS toolchain is lame and does not support .cfi directives. 1.29 +#ifdef __APPLE__ 1.30 +#define CFI(str) 1.31 +#else 1.32 +#define CFI(str) str 1.33 +#endif 1.34 + 1.35 +static nsresult 1.36 +PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint32_t* args) 1.37 +{ 1.38 +#define PARAM_BUFFER_COUNT 16 1.39 + 1.40 + nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; 1.41 + nsXPTCMiniVariant* dispatchParams = nullptr; 1.42 + const nsXPTMethodInfo* info; 1.43 + uint8_t paramCount; 1.44 + uint8_t i; 1.45 + nsresult result = NS_ERROR_FAILURE; 1.46 + 1.47 + NS_ASSERTION(self,"no self"); 1.48 + 1.49 + self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); 1.50 + paramCount = info->GetParamCount(); 1.51 + 1.52 + // setup variant array pointer 1.53 + if(paramCount > PARAM_BUFFER_COUNT) 1.54 + dispatchParams = new nsXPTCMiniVariant[paramCount]; 1.55 + else 1.56 + dispatchParams = paramBuffer; 1.57 + NS_ASSERTION(dispatchParams,"no place for params"); 1.58 + 1.59 + uint32_t* ap = args; 1.60 + for(i = 0; i < paramCount; i++, ap++) 1.61 + { 1.62 + const nsXPTParamInfo& param = info->GetParam(i); 1.63 + const nsXPTType& type = param.GetType(); 1.64 + nsXPTCMiniVariant* dp = &dispatchParams[i]; 1.65 + 1.66 + if(param.IsOut() || !type.IsArithmetic()) 1.67 + { 1.68 + dp->val.p = (void*) *ap; 1.69 + continue; 1.70 + } 1.71 + // else 1.72 + switch(type) 1.73 + { 1.74 + case nsXPTType::T_I8 : dp->val.i8 = *((int8_t*) ap); break; 1.75 + case nsXPTType::T_I16 : dp->val.i16 = *((int16_t*) ap); break; 1.76 + case nsXPTType::T_I32 : dp->val.i32 = *((int32_t*) ap); break; 1.77 + case nsXPTType::T_I64 : ap = DOUBLEWORD_ALIGN(ap); 1.78 + dp->val.i64 = *((int64_t*) ap); ap++; break; 1.79 + case nsXPTType::T_U8 : dp->val.u8 = *((uint8_t*) ap); break; 1.80 + case nsXPTType::T_U16 : dp->val.u16 = *((uint16_t*)ap); break; 1.81 + case nsXPTType::T_U32 : dp->val.u32 = *((uint32_t*)ap); break; 1.82 + case nsXPTType::T_U64 : ap = DOUBLEWORD_ALIGN(ap); 1.83 + dp->val.u64 = *((uint64_t*)ap); ap++; break; 1.84 + case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break; 1.85 + case nsXPTType::T_DOUBLE : ap = DOUBLEWORD_ALIGN(ap); 1.86 + dp->val.d = *((double*) ap); ap++; break; 1.87 + case nsXPTType::T_BOOL : dp->val.b = *((bool*) ap); break; 1.88 + case nsXPTType::T_CHAR : dp->val.c = *((char*) ap); break; 1.89 + case nsXPTType::T_WCHAR : dp->val.wc = *((wchar_t*) ap); break; 1.90 + default: 1.91 + NS_ERROR("bad type"); 1.92 + break; 1.93 + } 1.94 + } 1.95 + 1.96 + result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams); 1.97 + 1.98 + if(dispatchParams != paramBuffer) 1.99 + delete [] dispatchParams; 1.100 + 1.101 + return result; 1.102 +} 1.103 + 1.104 +/* 1.105 + * This is our shared stub. 1.106 + * 1.107 + * r0 = Self. 1.108 + * 1.109 + * The Rules: 1.110 + * We pass an (undefined) number of arguments into this function. 1.111 + * The first 3 C++ arguments are in r1 - r3, the rest are built 1.112 + * by the calling function on the stack. 1.113 + * 1.114 + * We are allowed to corrupt r0 - r3, ip, and lr. 1.115 + * 1.116 + * Other Info: 1.117 + * We pass the stub number in using `ip'. 1.118 + * 1.119 + * Implementation: 1.120 + * - We save r1 to r3 inclusive onto the stack, which will be 1.121 + * immediately below the caller saved arguments. 1.122 + * - setup r2 (PrepareAndDispatch's args pointer) to point at 1.123 + * the base of all these arguments 1.124 + * - Save LR (for the return address) 1.125 + * - Set r1 (PrepareAndDispatch's methodindex argument) from ip 1.126 + * - r0 is passed through (self) 1.127 + * - Call PrepareAndDispatch 1.128 + * - When the call returns, we return by loading the PC off the 1.129 + * stack, and undoing the stack (one instruction)! 1.130 + * 1.131 + */ 1.132 +__asm__ ("\n" 1.133 + ".text\n" 1.134 + ".align 2\n" 1.135 + "SharedStub:\n" 1.136 + ".fnstart\n" 1.137 + CFI(".cfi_startproc\n") 1.138 + "stmfd sp!, {r1, r2, r3}\n" 1.139 + ".save {r1, r2, r3}\n" 1.140 + CFI(".cfi_def_cfa_offset 12\n") 1.141 + CFI(".cfi_offset r3, -4\n") 1.142 + CFI(".cfi_offset r2, -8\n") 1.143 + CFI(".cfi_offset r1, -12\n") 1.144 + "mov r2, sp\n" 1.145 + "str lr, [sp, #-4]!\n" 1.146 + ".save {lr}\n" 1.147 + CFI(".cfi_def_cfa_offset 16\n") 1.148 + CFI(".cfi_offset lr, -16\n") 1.149 + "mov r1, ip\n" 1.150 + "bl _PrepareAndDispatch\n" 1.151 + "ldr pc, [sp], #16\n" 1.152 + CFI(".cfi_endproc\n") 1.153 + ".fnend"); 1.154 + 1.155 +/* 1.156 + * Create sets of stubs to call the SharedStub. 1.157 + * We don't touch the stack here, nor any registers, other than IP. 1.158 + * IP is defined to be corruptable by a called function, so we are 1.159 + * safe to use it. 1.160 + * 1.161 + * This will work with or without optimisation. 1.162 + */ 1.163 + 1.164 +/* 1.165 + * Note : As G++3 ABI contains the length of the functionname in the 1.166 + * mangled name, it is difficult to get a generic assembler mechanism like 1.167 + * in the G++ 2.95 case. 1.168 + * Create names would be like : 1.169 + * _ZN14nsXPTCStubBase5Stub9Ev 1.170 + * _ZN14nsXPTCStubBase6Stub13Ev 1.171 + * _ZN14nsXPTCStubBase7Stub144Ev 1.172 + * Use the assembler directives to get the names right... 1.173 + */ 1.174 + 1.175 +#define STUB_ENTRY(n) \ 1.176 + __asm__( \ 1.177 + ".section \".text\"\n" \ 1.178 +" .align 2\n" \ 1.179 +" .iflt ("#n" - 10)\n" \ 1.180 +" .globl _ZN14nsXPTCStubBase5Stub"#n"Ev\n" \ 1.181 +" .type _ZN14nsXPTCStubBase5Stub"#n"Ev,#function\n" \ 1.182 +"_ZN14nsXPTCStubBase5Stub"#n"Ev:\n" \ 1.183 +" .else\n" \ 1.184 +" .iflt ("#n" - 100)\n" \ 1.185 +" .globl _ZN14nsXPTCStubBase6Stub"#n"Ev\n" \ 1.186 +" .type _ZN14nsXPTCStubBase6Stub"#n"Ev,#function\n" \ 1.187 +"_ZN14nsXPTCStubBase6Stub"#n"Ev:\n" \ 1.188 +" .else\n" \ 1.189 +" .iflt ("#n" - 1000)\n" \ 1.190 +" .globl _ZN14nsXPTCStubBase7Stub"#n"Ev\n" \ 1.191 +" .type _ZN14nsXPTCStubBase7Stub"#n"Ev,#function\n" \ 1.192 +"_ZN14nsXPTCStubBase7Stub"#n"Ev:\n" \ 1.193 +" .else\n" \ 1.194 +" .err \"stub number "#n"> 1000 not yet supported\"\n" \ 1.195 +" .endif\n" \ 1.196 +" .endif\n" \ 1.197 +" .endif\n" \ 1.198 +" mov ip, #"#n"\n" \ 1.199 +" b SharedStub\n\t"); 1.200 + 1.201 +#if 0 1.202 +/* 1.203 + * This part is left in as comment : this is how the method definition 1.204 + * should look like. 1.205 + */ 1.206 + 1.207 +#define STUB_ENTRY(n) \ 1.208 +nsresult nsXPTCStubBase::Stub##n () \ 1.209 +{ \ 1.210 + __asm__ ( \ 1.211 +" mov ip, #"#n"\n" \ 1.212 +" b SharedStub\n\t"); \ 1.213 + return 0; /* avoid warnings */ \ 1.214 +} 1.215 +#endif 1.216 + 1.217 + 1.218 +#define SENTINEL_ENTRY(n) \ 1.219 +nsresult nsXPTCStubBase::Sentinel##n() \ 1.220 +{ \ 1.221 + NS_ERROR("nsXPTCStubBase::Sentinel called"); \ 1.222 + return NS_ERROR_NOT_IMPLEMENTED; \ 1.223 +} 1.224 + 1.225 +#include "xptcstubsdef.inc"