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