Back to index

lightning-sunbird  0.9+nobinonly
xptcstubs_gcc_x86_unix.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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /* Implement shared vtbl methods. */
00039 
00040 #ifdef __GNUC__         /* Gnu Compiler. */
00041 
00042 #include "xptcprivate.h"
00043 #include "xptc_platforms_unixish_x86.h"
00044 #include "xptc_gcc_x86_unix.h"
00045 
00046 extern "C" {
00047 static nsresult ATTRIBUTE_USED
00048 __attribute__ ((regparm (3)))
00049 PrepareAndDispatch(uint32 methodIndex, nsXPTCStubBase* self, PRUint32* args)
00050 {
00051 #define PARAM_BUFFER_COUNT     16
00052 
00053     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
00054     nsXPTCMiniVariant* dispatchParams = NULL;
00055     nsIInterfaceInfo* iface_info = NULL;
00056     const nsXPTMethodInfo* info;
00057     PRUint8 paramCount;
00058     PRUint8 i;
00059     nsresult result = NS_ERROR_FAILURE;
00060 
00061     NS_ASSERTION(self,"no self");
00062 
00063     self->GetInterfaceInfo(&iface_info);
00064     NS_ASSERTION(iface_info,"no interface info");
00065 
00066     iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
00067     NS_ASSERTION(info,"no interface info");
00068 
00069     paramCount = info->GetParamCount();
00070 
00071     // setup variant array pointer
00072     if(paramCount > PARAM_BUFFER_COUNT)
00073         dispatchParams = new nsXPTCMiniVariant[paramCount];
00074     else
00075         dispatchParams = paramBuffer;
00076     NS_ASSERTION(dispatchParams,"no place for params");
00077 
00078     PRUint32* ap = args;
00079     for(i = 0; i < paramCount; i++, ap++)
00080     {
00081         const nsXPTParamInfo& param = info->GetParam(i);
00082         const nsXPTType& type = param.GetType();
00083         nsXPTCMiniVariant* dp = &dispatchParams[i];
00084 
00085         if(param.IsOut() || !type.IsArithmetic())
00086         {
00087             dp->val.p = (void*) *ap;
00088             continue;
00089         }
00090         // else
00091            dp->val.p = (void*) *ap;
00092         switch(type)
00093         {
00094         case nsXPTType::T_I64    : dp->val.i64 = *((PRInt64*) ap); ap++; break;
00095         case nsXPTType::T_U64    : dp->val.u64 = *((PRUint64*)ap); ap++; break;
00096         case nsXPTType::T_DOUBLE : dp->val.d   = *((double*)  ap); ap++; break;
00097         }
00098     }
00099 
00100     result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
00101 
00102     NS_RELEASE(iface_info);
00103 
00104     if(dispatchParams != paramBuffer)
00105         delete [] dispatchParams;
00106 
00107     return result;
00108 }
00109 } // extern "C"
00110 
00111 // NOTE! See xptc_gcc_x86_unix.h for the reason this function exists.
00112 #if (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ == 0))
00113 PRUint32
00114 xptc_PrepareAndDispatch_keeper (void)
00115 {
00116     PRUint32 dummy1;
00117     nsresult ATTRIBUTE_USED __attribute__ ((regparm (3))) (*dummy2)
00118         (uint32, nsXPTCStubBase *, PRUint32*) = PrepareAndDispatch;
00119 // dummy2 references PrepareAndDispatch, now "use" it
00120     __asm__ __volatile__ (
00121         ""
00122         : "=&a" (dummy1)
00123         : "g"   (dummy2)
00124     );
00125     return dummy1 & 0xF0F00000;
00126 }
00127 #endif
00128 
00129 #if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 /* G++ V3 ABI */
00130 // gcc3 mangling tends to insert the length of the method name
00131 #define STUB_ENTRY(n) \
00132 asm(".text\n\t" \
00133     ".align   2\n\t" \
00134     ".if      " #n " < 10\n\t" \
00135     ".globl   " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
00136     ".type    " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase5Stub" #n "Ev,@function\n" \
00137     SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase5Stub" #n "Ev:\n\t" \
00138     ".elseif  " #n " < 100\n\t" \
00139     ".globl   " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
00140     ".type    " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase6Stub" #n "Ev,@function\n" \
00141     SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase6Stub" #n "Ev:\n\t" \
00142     ".elseif    " #n " < 1000\n\t" \
00143     ".globl     " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
00144     ".type      " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase7Stub" #n "Ev,@function\n" \
00145     SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase7Stub" #n "Ev:\n\t" \
00146     ".else\n\t" \
00147     ".err     \"stub number " #n " >= 1000 not yet supported\"\n\t" \
00148     ".endif\n\t" \
00149     "movl     $" #n ", %eax\n\t" \
00150     "jmp      " SYMBOL_UNDERSCORE "SharedStub\n\t" \
00151     ".if      " #n " < 10\n\t" \
00152     ".size    " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase5Stub" #n "Ev,.-" SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
00153     ".elseif  " #n " < 100\n\t" \
00154     ".size    " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase6Stub" #n "Ev,.-" SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
00155     ".else\n\t" \
00156     ".size    " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase7Stub" #n "Ev,.-" SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
00157     ".endif");
00158 #else
00159 #define STUB_ENTRY(n) \
00160 asm(".text\n\t" \
00161     ".align   2\n\t" \
00162     ".globl   " SYMBOL_UNDERSCORE "Stub" #n "__14nsXPTCStubBase\n\t" \
00163     ".type    " SYMBOL_UNDERSCORE "Stub" #n "__14nsXPTCStubBase,@function\n" \
00164     SYMBOL_UNDERSCORE "Stub" #n "__14nsXPTCStubBase:\n\t" \
00165     "movl     $" #n ", %eax\n\t" \
00166     "jmp      " SYMBOL_UNDERSCORE "SharedStub\n\t" \
00167     ".size    " SYMBOL_UNDERSCORE "Stub" #n "__14nsXPTCStubBase,.-" SYMBOL_UNDERSCORE "Stub" #n "__14nsXPTCStubBase");
00168 #endif
00169 
00170 // static nsresult SharedStub(PRUint32 methodIndex) __attribute__((regparm(1)))
00171 asm(".text\n\t"
00172     ".align   2\n\t"
00173     ".type    " SYMBOL_UNDERSCORE "SharedStub,@function\n\t"
00174     SYMBOL_UNDERSCORE "SharedStub:\n\t"
00175     "leal     0x08(%esp), %ecx\n\t"
00176     "movl     0x04(%esp), %edx\n\t"
00177     "jmp      " SYMBOL_UNDERSCORE "PrepareAndDispatch\n\t"
00178     ".size    " SYMBOL_UNDERSCORE "SharedStub,.-" SYMBOL_UNDERSCORE "SharedStub");
00179 
00180 #define SENTINEL_ENTRY(n) \
00181 nsresult nsXPTCStubBase::Sentinel##n() \
00182 { \
00183     NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
00184     return NS_ERROR_NOT_IMPLEMENTED; \
00185 }
00186 
00187 #include "xptcstubsdef.inc"
00188 
00189 void
00190 xptc_dummy()
00191 {
00192 }
00193 
00194 #else
00195 #error "can't find a compiler to use"
00196 #endif /* __GNUC__ */