Back to index

lightning-sunbird  0.9+nobinonly
xptcstubs_unixish_x86.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 #include "xptcprivate.h"
00041 #include "xptc_platforms_unixish_x86.h"
00042 
00043 static nsresult
00044 PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, PRUint32* args)
00045 {
00046 #define PARAM_BUFFER_COUNT     16
00047 
00048     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
00049     nsXPTCMiniVariant* dispatchParams = NULL;
00050     nsIInterfaceInfo* iface_info = NULL;
00051     const nsXPTMethodInfo* info;
00052     PRUint8 paramCount;
00053     PRUint8 i;
00054     nsresult result = NS_ERROR_FAILURE;
00055 
00056     NS_ASSERTION(self,"no self");
00057 
00058     self->GetInterfaceInfo(&iface_info);
00059     NS_ASSERTION(iface_info,"no interface info");
00060 
00061     iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
00062     NS_ASSERTION(info,"no interface info");
00063 
00064     paramCount = info->GetParamCount();
00065 
00066     // setup variant array pointer
00067     if(paramCount > PARAM_BUFFER_COUNT)
00068         dispatchParams = new nsXPTCMiniVariant[paramCount];
00069     else
00070         dispatchParams = paramBuffer;
00071     NS_ASSERTION(dispatchParams,"no place for params");
00072 
00073     PRUint32* ap = args;
00074     for(i = 0; i < paramCount; i++, ap++)
00075     {
00076         const nsXPTParamInfo& param = info->GetParam(i);
00077         const nsXPTType& type = param.GetType();
00078         nsXPTCMiniVariant* dp = &dispatchParams[i];
00079 
00080         if(param.IsOut() || !type.IsArithmetic())
00081         {
00082             dp->val.p = (void*) *ap;
00083             continue;
00084         }
00085         // else
00086            dp->val.p = (void*) *ap;
00087         switch(type)
00088         {
00089         case nsXPTType::T_I64    : dp->val.i64 = *((PRInt64*) ap); ap++; break;
00090         case nsXPTType::T_U64    : dp->val.u64 = *((PRUint64*)ap); ap++; break;
00091         case nsXPTType::T_DOUBLE : dp->val.d   = *((double*)  ap); ap++; break;
00092         }
00093     }
00094 
00095     result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
00096 
00097     NS_RELEASE(iface_info);
00098 
00099     if(dispatchParams != paramBuffer)
00100         delete [] dispatchParams;
00101 
00102     return result;
00103 }
00104 
00105 #ifdef __GNUC__         /* Gnu Compiler. */
00106 
00107 #ifdef XP_MACOSX
00108 /* Make sure the stack is 16-byte aligned.  Do that by aligning to 16 bytes and
00109  * then subtracting 4 so the three subsequent pushes result in a 16-byte aligned
00110  * stack. */
00111 #define ALIGN_STACK  \
00112     "addl $0x4, %%esp\n\t" \
00113     "andl $0xfffffff0, %%esp\n\t" \
00114     "subl $0x4, %%esp\n\t"
00115 
00116 #define REGS_TRASHED \
00117        , "%esp"
00118 
00119 #define SAVE_STACK \
00120   unsigned int saved_esp; \
00121   __asm__ __volatile__( \
00122     "movl %%esp, %0\n\t" \
00123     : "=r"(saved_esp));
00124 
00125 #define RESTORE_STACK       \
00126  __asm__ __volatile__( \
00127     "movl %0, %%esp\n\t" \
00128     : \
00129     : "r"(saved_esp));
00130 #else
00131 #define ALIGN_STACK
00132 #define REGS_TRASHED
00133 #define SAVE_STACK
00134 #define RESTORE_STACK
00135 #endif
00136 
00137 #define STUB_ENTRY(n) \
00138 nsresult nsXPTCStubBase::Stub##n() \
00139 { \
00140   register nsresult (*method) (nsXPTCStubBase *, uint32, PRUint32 *) = PrepareAndDispatch; \
00141   int temp0, temp1; \
00142   register nsresult result; \
00143   SAVE_STACK \
00144   __asm__ __volatile__( \
00145     ALIGN_STACK \
00146     "leal   0x0c(%%ebp), %%ecx\n\t"    /* args */ \
00147     "pushl  %%ecx\n\t" \
00148     "pushl  $"#n"\n\t"                 /* method index */ \
00149     "movl   0x08(%%ebp), %%ecx\n\t"    /* this */ \
00150     "pushl  %%ecx\n\t" \
00151     "call   *%%edx\n\t"                /* PrepareAndDispatch */ \
00152     "addl   $12, %%esp" \
00153     : "=a" (result),    /* %0 */ \
00154       "=&c" (temp0),    /* %1 */ \
00155       "=d" (temp1)      /* %2 */ \
00156     : "2" (method)      /* %2 */ \
00157     : "memory" \
00158        REGS_TRASHED \
00159        ); \
00160        RESTORE_STACK \
00161     return result; \
00162 }
00163 
00164 #else
00165 #error "can't find a compiler to use"
00166 #endif /* __GNUC__ */
00167 
00168 #define SENTINEL_ENTRY(n) \
00169 nsresult nsXPTCStubBase::Sentinel##n() \
00170 { \
00171     NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
00172     return NS_ERROR_NOT_IMPLEMENTED; \
00173 }
00174 
00175 #include "xptcstubsdef.inc"