Back to index

lightning-sunbird  0.9+nobinonly
xptcstubs_arm_openbsd.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Russell King  <rmk@arm.linux.org.uk>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 /* Implement shared vtbl methods. */
00040 
00041 #include "xptcprivate.h"
00042 
00043 /* Specify explicitly a symbol for this function, don't try to guess the c++ mangled symbol.  */
00044 static nsresult PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, PRUint32* args) asm("_PrepareAndDispatch");
00045 
00046 static nsresult
00047 PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, PRUint32* args)
00048 {
00049 #define PARAM_BUFFER_COUNT     16
00050 
00051     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
00052     nsXPTCMiniVariant* dispatchParams = NULL;
00053     nsIInterfaceInfo* iface_info = NULL;
00054     const nsXPTMethodInfo* info;
00055     PRUint8 paramCount;
00056     PRUint8 i;
00057     nsresult result = NS_ERROR_FAILURE;
00058 
00059     NS_ASSERTION(self,"no self");
00060 
00061     self->GetInterfaceInfo(&iface_info);
00062     NS_ASSERTION(iface_info,"no interface info");
00063 
00064     iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
00065     NS_ASSERTION(info,"no interface info");
00066 
00067     paramCount = info->GetParamCount();
00068 
00069     // setup variant array pointer
00070     if(paramCount > PARAM_BUFFER_COUNT)
00071         dispatchParams = new nsXPTCMiniVariant[paramCount];
00072     else
00073         dispatchParams = paramBuffer;
00074     NS_ASSERTION(dispatchParams,"no place for params");
00075 
00076     PRUint32* ap = args;
00077     for(i = 0; i < paramCount; i++, ap++)
00078     {
00079         const nsXPTParamInfo& param = info->GetParam(i);
00080         const nsXPTType& type = param.GetType();
00081         nsXPTCMiniVariant* dp = &dispatchParams[i];
00082 
00083         if(param.IsOut() || !type.IsArithmetic())
00084         {
00085             dp->val.p = (void*) *ap;
00086             continue;
00087         }
00088         // else
00089         switch(type)
00090         {
00091         case nsXPTType::T_I8     : dp->val.i8  = *((PRInt8*)  ap);       break;
00092         case nsXPTType::T_I16    : dp->val.i16 = *((PRInt16*) ap);       break;
00093         case nsXPTType::T_I32    : dp->val.i32 = *((PRInt32*) ap);       break;
00094         case nsXPTType::T_I64    : dp->val.i64 = *((PRInt64*) ap); ap++; break;
00095         case nsXPTType::T_U8     : dp->val.u8  = *((PRUint8*) ap);       break;
00096         case nsXPTType::T_U16    : dp->val.u16 = *((PRUint16*)ap);       break;
00097         case nsXPTType::T_U32    : dp->val.u32 = *((PRUint32*)ap);       break;
00098         case nsXPTType::T_U64    : dp->val.u64 = *((PRUint64*)ap); ap++; break;
00099         case nsXPTType::T_FLOAT  : dp->val.f   = *((float*)   ap);       break;
00100         case nsXPTType::T_DOUBLE : dp->val.d   = *((double*)  ap); ap++; break;
00101         case nsXPTType::T_BOOL   : dp->val.b   = *((PRBool*)  ap);       break;
00102         case nsXPTType::T_CHAR   : dp->val.c   = *((char*)    ap);       break;
00103         case nsXPTType::T_WCHAR  : dp->val.wc  = *((wchar_t*) ap);       break;
00104         default:
00105             NS_ASSERTION(0, "bad type");
00106             break;
00107         }
00108     }
00109 
00110     result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
00111 
00112     NS_RELEASE(iface_info);
00113 
00114     if(dispatchParams != paramBuffer)
00115         delete [] dispatchParams;
00116 
00117     return result;
00118 }
00119 
00120 /*
00121  * This is our shared stub.
00122  *
00123  * r0 = Self.
00124  *
00125  * The Rules:
00126  *   We pass an (undefined) number of arguments into this function.
00127  *   The first 3 C++ arguments are in r1 - r3, the rest are built
00128  *   by the calling function on the stack.
00129  *
00130  *   We are allowed to corrupt r0 - r3, ip, and lr.
00131  *
00132  * Other Info:
00133  *   We pass the stub number in using `ip'.
00134  *
00135  * Implementation:
00136  * - We save r1 to r3 inclusive onto the stack, which will be
00137  *   immediately below the caller saved arguments.
00138  * - setup r2 (PrepareAndDispatch's args pointer) to point at
00139  *   the base of all these arguments
00140  * - Save LR (for the return address)
00141  * - Set r1 (PrepareAndDispatch's methodindex argument) from ip
00142  * - r0 is passed through (self)
00143  * - Call PrepareAndDispatch
00144  * - When the call returns, we return by loading the PC off the
00145  *   stack, and undoing the stack (one instruction)!
00146  *
00147  */
00148 __asm__ ("\n\
00149 SharedStub:                                             \n\
00150        stmfd  sp!, {r1, r2, r3}                         \n\
00151        mov    r2, sp                                    \n\
00152        str    lr, [sp, #-4]!                                   \n\
00153        mov    r1, ip                                    \n\
00154        bl     _PrepareAndDispatch                          \n\
00155        ldr    pc, [sp], #16");
00156 
00157 /*
00158  * Create sets of stubs to call the SharedStub.
00159  * We don't touch the stack here, nor any registers, other than IP.
00160  * IP is defined to be corruptable by a called function, so we are
00161  * safe to use it.
00162  *
00163  * This will work with or without optimisation.
00164  */
00165 #if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 /* G++ V3 ABI */
00166 /*
00167  * Note : As G++3 ABI contains the length of the functionname in the
00168  *  mangled name, it is difficult to get a generic assembler mechanism like
00169  *  in the G++ 2.95 case.
00170  *  Create names would be like :
00171  *    _ZN14nsXPTCStubBase5Stub9Ev
00172  *    _ZN14nsXPTCStubBase6Stub13Ev
00173  *    _ZN14nsXPTCStubBase7Stub144Ev
00174  *  Use the assembler directives to get the names right...
00175  */
00176 
00177 #define STUB_ENTRY(n)                                          \
00178   __asm__(                                              \
00179        ".section \".text\"\n"                                  \
00180 "      .align 2\n"                                      \
00181 "      .iflt ("#n" - 10)\n"                                    \
00182 "      .globl _ZN14nsXPTCStubBase5Stub"#n"Ev\n"         \
00183 "      .type  _ZN14nsXPTCStubBase5Stub"#n"Ev,#function\n"      \
00184 "_ZN14nsXPTCStubBase5Stub"#n"Ev:\n"                            \
00185 "      .else\n"                                                \
00186 "      .iflt  ("#n" - 100)\n"                                  \
00187 "      .globl _ZN14nsXPTCStubBase6Stub"#n"Ev\n"         \
00188 "      .type  _ZN14nsXPTCStubBase6Stub"#n"Ev,#function\n"      \
00189 "_ZN14nsXPTCStubBase6Stub"#n"Ev:\n"                            \
00190 "      .else\n"                                                \
00191 "      .iflt ("#n" - 1000)\n"                                  \
00192 "      .globl _ZN14nsXPTCStubBase7Stub"#n"Ev\n"         \
00193 "      .type  _ZN14nsXPTCStubBase7Stub"#n"Ev,#function\n"      \
00194 "_ZN14nsXPTCStubBase7Stub"#n"Ev:\n"                            \
00195 "      .else\n"                                                \
00196 "      .err \"stub number "#n"> 1000 not yet supported\"\n"    \
00197 "      .endif\n"                                               \
00198 "      .endif\n"                                               \
00199 "      .endif\n"                                               \
00200 "      mov    ip, #"#n"\n"                              \
00201 "      b      SharedStub\n\t");
00202 
00203 #if 0
00204 /*
00205  * This part is left in as comment : this is how the method definition
00206  * should look like.
00207  */
00208 
00209 #define STUB_ENTRY(n)  \
00210 nsresult nsXPTCStubBase::Stub##n ()  \
00211 { \
00212   __asm__ (                         \
00213 "      mov    ip, #"#n"\n"                              \
00214 "      b      SharedStub\n\t");                               \
00215   return 0; /* avoid warnings */                                \
00216 }
00217 #endif
00218 
00219 #else /* G++2.95 ABI */
00220 
00221 #define STUB_ENTRY(n)                                          \
00222   __asm__(                                              \
00223        ".section \".text\"\n"                                  \
00224 "      .align\n"                                        \
00225 "      .globl Stub"#n"__14nsXPTCStubBase\n"                    \
00226 "      .type  Stub"#n"__14nsXPTCStubBase,#function\n\n" \
00227 "Stub"#n"__14nsXPTCStubBase:\n"                                \
00228 "      mov    ip, #"#n"\n"                              \
00229 "      b      SharedStub\n\t");
00230 
00231 #endif
00232 
00233 #define SENTINEL_ENTRY(n) \
00234 nsresult nsXPTCStubBase::Sentinel##n() \
00235 { \
00236     NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
00237     return NS_ERROR_NOT_IMPLEMENTED; \
00238 }
00239 
00240 #include "xptcstubsdef.inc"