Back to index

lightning-sunbird  0.9+nobinonly
xptcstubs_nto_arm.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 #if !defined(__QNXNTO__) || !defined(__arm__)
00044 #error "This code is for Neutrino ARM only. Please check if it works for you, too.\nDepends strongly on gcc behaviour."
00045 #endif
00046 
00047 /* Specify explicitly a symbol for this function, don't try to guess the c++ mangled symbol.  */
00048 static nsresult PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, PRUint32* args) asm("_PrepareAndDispatch");
00049 
00050 static nsresult
00051 PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, PRUint32* args)
00052 {
00053 #define PARAM_BUFFER_COUNT     16
00054 
00055     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
00056     nsXPTCMiniVariant* dispatchParams = NULL;
00057     nsIInterfaceInfo* iface_info = NULL;
00058     const nsXPTMethodInfo* info;
00059     PRUint8 paramCount;
00060     PRUint8 i;
00061     nsresult result = NS_ERROR_FAILURE;
00062 
00063     NS_ASSERTION(self,"no self");
00064 
00065     self->GetInterfaceInfo(&iface_info);
00066     NS_ASSERTION(iface_info,"no interface info");
00067 
00068     iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
00069     NS_ASSERTION(info,"no interface info");
00070 
00071     paramCount = info->GetParamCount();
00072 
00073     // setup variant array pointer
00074     if(paramCount > PARAM_BUFFER_COUNT)
00075         dispatchParams = new nsXPTCMiniVariant[paramCount];
00076     else
00077         dispatchParams = paramBuffer;
00078     NS_ASSERTION(dispatchParams,"no place for params");
00079 
00080     PRUint32* ap = args;
00081     for(i = 0; i < paramCount; i++, ap++)
00082     {
00083         const nsXPTParamInfo& param = info->GetParam(i);
00084         const nsXPTType& type = param.GetType();
00085         nsXPTCMiniVariant* dp = &dispatchParams[i];
00086 
00087         if(param.IsOut() || !type.IsArithmetic())
00088         {
00089             dp->val.p = (void*) *ap;
00090             continue;
00091         }
00092         // else
00093         switch(type)
00094         {
00095         case nsXPTType::T_I8     : dp->val.i8  = *((PRInt8*)  ap);       break;
00096         case nsXPTType::T_I16    : dp->val.i16 = *((PRInt16*) ap);       break;
00097         case nsXPTType::T_I32    : dp->val.i32 = *((PRInt32*) ap);       break;
00098         case nsXPTType::T_I64    : dp->val.i64 = *((PRInt64*) ap); ap++; break;
00099         case nsXPTType::T_U8     : dp->val.u8  = *((PRUint8*) ap);       break;
00100         case nsXPTType::T_U16    : dp->val.u16 = *((PRUint16*)ap);       break;
00101         case nsXPTType::T_U32    : dp->val.u32 = *((PRUint32*)ap);       break;
00102         case nsXPTType::T_U64    : dp->val.u64 = *((PRUint64*)ap); ap++; break;
00103         case nsXPTType::T_FLOAT  : dp->val.f   = *((float*)   ap);       break;
00104         case nsXPTType::T_DOUBLE : dp->val.d   = *((double*)  ap); ap++; break;
00105         case nsXPTType::T_BOOL   : dp->val.b   = *((PRBool*)  ap);       break;
00106         case nsXPTType::T_CHAR   : dp->val.c   = *((char*)    ap);       break;
00107         case nsXPTType::T_WCHAR  : dp->val.wc  = *((wchar_t*) ap);       break;
00108         default:
00109             NS_ASSERTION(0, "bad type");
00110             break;
00111         }
00112     }
00113 
00114     result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
00115 
00116     NS_RELEASE(iface_info);
00117 
00118     if(dispatchParams != paramBuffer)
00119         delete [] dispatchParams;
00120 
00121     return result;
00122 }
00123 
00124 /*
00125  * This is our shared stub.
00126  *
00127  * r0 = Self.
00128  *
00129  * The Rules:
00130  *   We pass an (undefined) number of arguments into this function.
00131  *   The first 3 C++ arguments are in r1 - r3, the rest are built
00132  *   by the calling function on the stack.
00133  *
00134  *   We are allowed to corrupt r0 - r3, ip, and lr.
00135  *
00136  * Other Info:
00137  *   We pass the stub number in using `ip'.
00138  *
00139  * Implementation:
00140  * - We save r1 to r3 inclusive onto the stack, which will be
00141  *   immediately below the caller saved arguments.
00142  * - setup r2 (PrepareAndDispatch's args pointer) to point at
00143  *   the base of all these arguments
00144  * - Save LR (for the return address)
00145  * - Set r1 (PrepareAndDispatch's methodindex argument) from ip
00146  * - r0 is passed through (self)
00147  * - Call PrepareAndDispatch
00148  * - When the call returns, we return by loading the PC off the
00149  *   stack, and undoing the stack (one instruction)!
00150  *
00151  */
00152 __asm__ ("\n\
00153 SharedStub:                                             \n\
00154        stmfd  sp!, {r1, r2, r3}                         \n\
00155        mov    r2, sp                                    \n\
00156        str    lr, [sp, #-4]!                                   \n\
00157        mov    r1, ip                                    \n\
00158        bl     _PrepareAndDispatch                          \n\
00159        ldr    pc, [sp], #16");
00160 
00161 /*
00162  * Create sets of stubs to call the SharedStub.
00163  * We don't touch the stack here, nor any registers, other than IP.
00164  * IP is defined to be corruptable by a called function, so we are
00165  * safe to use it.
00166  *
00167  * This will work with or without optimisation.
00168  */
00169 #if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 /* G++ V3 ABI */
00170 /*
00171  * Note : As G++3 ABI contains the length of the functionname in the
00172  *  mangled name, it is difficult to get a generic assembler mechanism like
00173  *  in the G++ 2.95 case.
00174  *  Create names would be like :
00175  *    _ZN14nsXPTCStubBase5Stub9Ev
00176  *    _ZN14nsXPTCStubBase6Stub13Ev
00177  *    _ZN14nsXPTCStubBase7Stub144Ev
00178  *  Use the assembler directives to get the names right...
00179  */
00180 
00181 #define STUB_ENTRY(n)                                          \
00182   __asm__(                                              \
00183        ".section \".text\"\n"                                  \
00184 "      .align 2\n"                                      \
00185 "      .iflt ("#n" - 10)\n"                                    \
00186 "      .globl _ZN14nsXPTCStubBase5Stub"#n"Ev\n"         \
00187 "      .type  _ZN14nsXPTCStubBase5Stub"#n"Ev,#function\n"      \
00188 "_ZN14nsXPTCStubBase5Stub"#n"Ev:\n"                            \
00189 "      .else\n"                                                \
00190 "      .iflt  ("#n" - 100)\n"                                  \
00191 "      .globl _ZN14nsXPTCStubBase6Stub"#n"Ev\n"         \
00192 "      .type  _ZN14nsXPTCStubBase6Stub"#n"Ev,#function\n"      \
00193 "_ZN14nsXPTCStubBase6Stub"#n"Ev:\n"                            \
00194 "      .else\n"                                                \
00195 "      .iflt ("#n" - 1000)\n"                                  \
00196 "      .globl _ZN14nsXPTCStubBase7Stub"#n"Ev\n"         \
00197 "      .type  _ZN14nsXPTCStubBase7Stub"#n"Ev,#function\n"      \
00198 "_ZN14nsXPTCStubBase7Stub"#n"Ev:\n"                            \
00199 "      .else\n"                                                \
00200 "      .err \"stub number "#n"> 1000 not yet supported\"\n"    \
00201 "      .endif\n"                                               \
00202 "      .endif\n"                                               \
00203 "      .endif\n"                                               \
00204 "      mov    ip, #"#n"\n"                              \
00205 "      b      SharedStub\n\t");
00206 
00207 #if 0
00208 /*
00209  * This part is left in as comment : this is how the method definition
00210  * should look like.
00211  */
00212 
00213 #define STUB_ENTRY(n)  \
00214 nsresult nsXPTCStubBase::Stub##n ()  \
00215 { \
00216   __asm__ (                         \
00217 "      mov    ip, #"#n"\n"                              \
00218 "      b      SharedStub\n\t");                               \
00219   return 0; /* avoid warnings */                                \
00220 }
00221 #endif
00222 
00223 #else /* G++2.95 ABI */
00224 
00225 #define STUB_ENTRY(n)                                          \
00226   __asm__(                                              \
00227        ".section \".text\"\n"                                  \
00228 "      .align\n"                                        \
00229 "      .globl Stub"#n"__14nsXPTCStubBase\n"                    \
00230 "      .type  Stub"#n"__14nsXPTCStubBase,#function\n\n" \
00231 "Stub"#n"__14nsXPTCStubBase:\n"                                \
00232 "      mov    ip, #"#n"\n"                              \
00233 "      b      SharedStub\n\t");
00234 
00235 #endif
00236 
00237 #define SENTINEL_ENTRY(n) \
00238 nsresult nsXPTCStubBase::Sentinel##n() \
00239 { \
00240     NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
00241     return NS_ERROR_NOT_IMPLEMENTED; \
00242 }
00243 
00244 #include "xptcstubsdef.inc"