Back to index

lightning-sunbird  0.9+nobinonly
xptcstubs_os2.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org Code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   John Fairhurst <john_fairhurst@iname.com>
00025  *   Henry Sobotka <sobotka@axess.com> added VAC++ support
00026  *   and fixed emx asm to work with gcc 2.95.2 (Jan. 2000)
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either of the GNU General Public License Version 2 or later (the "GPL"),
00030  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 
00042 /* Implement shared vtbl methods */
00043 
00044 #include "xptcprivate.h"
00045 
00046 #if !defined (__EMX__) && !defined(__IBMCPP__)
00047 #error "This code is only for OS/2"
00048 #endif
00049 
00050 // Procedure in xptcall_vacpp.asm
00051 #ifdef XP_OS2_VACPP
00052 extern nsresult SetEntryFromIndex(int stubidx);
00053 #endif
00054 
00055 #ifdef XP_OS2_VACPP
00056 nsresult
00057 PrepareAndDispatch( nsXPTCStubBase *self, PRUint32 methodIndex,
00058                     PRUint32 *args)
00059 #else
00060 static nsresult
00061 PrepareAndDispatch( nsXPTCStubBase *self, PRUint32 methodIndex,
00062                     PRUint32 *args)
00063 #endif
00064 {
00065 #define PARAM_BUFFER_COUNT     16
00066 
00067     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
00068     nsXPTCMiniVariant* dispatchParams = NULL;
00069     nsIInterfaceInfo* iface_info = NULL;
00070     const nsXPTMethodInfo* info;
00071     PRUint8 paramCount;
00072     PRUint8 i;
00073     nsresult result = NS_ERROR_FAILURE;
00074 
00075     // If anything fails before stackBytesToPop can be set then
00076     // the failure is completely catastrophic!
00077 
00078     NS_ASSERTION(self,"no self");
00079 
00080     self->GetInterfaceInfo(&iface_info);
00081     NS_ASSERTION(iface_info,"no interface info");
00082 
00083     iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
00084     NS_ASSERTION(info,"no interface info");
00085 
00086     paramCount = info->GetParamCount();
00087 
00088 #ifdef XP_OS2_VACPP
00089     /* If paramCount is > 0, write out the EDX pointer to the
00090        space on the stack args[0]. args[-4] is the space on
00091        the stack where it was pushed */
00092     if (paramCount) {
00093         args[0] = args[-4];
00094 
00095         /* If this is the second parameter, or if the first parameter is an
00096            8 byte long long, write out the ECX pointer to the space on the
00097            stack args[1]. args[-3] is the space on the stack where it was
00098            pushed */
00099         nsXPTType type = info->GetParam(0).GetType();
00100         if( paramCount > 1 ||
00101             type == nsXPTType::T_I64 || type == nsXPTType::T_U64 )
00102         {
00103             args[1] = args[-3];
00104         }            
00105     }
00106 #endif
00107 
00108     // setup variant array pointer
00109     if(paramCount > PARAM_BUFFER_COUNT)
00110         dispatchParams = new nsXPTCMiniVariant[paramCount];
00111     else
00112         dispatchParams = paramBuffer;
00113     NS_ASSERTION(dispatchParams,"no place for params");
00114 
00115     PRUint32* ap = args;
00116     for(i = 0; i < paramCount; i++, ap++)
00117     {
00118         const nsXPTParamInfo& param = info->GetParam(i);
00119         const nsXPTType& type = param.GetType();
00120         nsXPTCMiniVariant* dp = &dispatchParams[i];
00121 
00122         if(param.IsOut() || !type.IsArithmetic())
00123         {
00124             dp->val.p = (void*) *ap;
00125             continue;
00126         }
00127         // else
00128         switch(type)
00129         {
00130         case nsXPTType::T_I8     : dp->val.i8  = *((PRInt8*)  ap);       break;
00131         case nsXPTType::T_I16    : dp->val.i16 = *((PRInt16*) ap);       break;
00132         case nsXPTType::T_I32    : dp->val.i32 = *((PRInt32*) ap);       break;
00133         case nsXPTType::T_I64    : dp->val.i64 = *((PRInt64*) ap); ap++; break;
00134         case nsXPTType::T_U8     : dp->val.u8  = *((PRUint8*) ap);       break;
00135         case nsXPTType::T_U16    : dp->val.u16 = *((PRUint16*)ap);       break;
00136         case nsXPTType::T_U32    : dp->val.u32 = *((PRUint32*)ap);       break;
00137         case nsXPTType::T_U64    : dp->val.u64 = *((PRUint64*)ap); ap++; break;
00138         case nsXPTType::T_FLOAT  : dp->val.f   = *((float*)   ap);       break;
00139         case nsXPTType::T_DOUBLE : dp->val.d   = *((double*)  ap); ap++; break;
00140         case nsXPTType::T_BOOL   : dp->val.b   = *((PRBool*)  ap);       break;
00141         case nsXPTType::T_CHAR   : dp->val.c   = *((char*)    ap);       break;
00142         case nsXPTType::T_WCHAR  : dp->val.wc  = *((wchar_t*) ap);       break;
00143         default:
00144             NS_ASSERTION(0, "bad type");
00145             break;
00146         }
00147     }
00148 
00149     result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
00150 
00151     NS_RELEASE(iface_info);
00152 
00153     if(dispatchParams != paramBuffer)
00154         delete [] dispatchParams;
00155 
00156     return result;
00157 }
00158 
00159 #ifdef XP_OS2_VACPP
00160 
00161 #define STUB_ENTRY(n)
00162 
00163 #else
00164 
00165 #define STUB_ENTRY(n) \
00166 nsresult nsXPTCStubBase::Stub##n() \
00167 { \
00168   register nsresult (*method) (nsXPTCStubBase *, PRUint32, PRUint32 *) = PrepareAndDispatch; \
00169   int temp0, temp1; \
00170   register nsresult result; \
00171   __asm__ __volatile__( \
00172     "leal   0x0c(%%ebp), %%ecx\n\t"    /* args */ \
00173     "pushl  %%ecx\n\t" \
00174     "pushl  $"#n"\n\t"                 /* method index */ \
00175     "movl   0x08(%%ebp), %%ecx\n\t"    /* this */ \
00176     "pushl  %%ecx\n\t" \
00177     "call   *%%edx\n\t"                /* PrepareAndDispatch */ \
00178     "addl   $12, %%esp" \
00179     : "=a" (result),    /* %0 */ \
00180       "=&c" (temp0),    /* %1 */ \
00181       "=d" (temp1)      /* %2 */ \
00182     : "2" (method)      /* %2 */ \
00183     : "memory" ); \
00184     return result; \
00185 }
00186 #endif
00187 
00188 #define SENTINEL_ENTRY(n) \
00189 nsresult nsXPTCStubBase::Sentinel##n() \
00190 { \
00191     NS_ASSERTION(0,"nsXPCWrappedJS::Sentinel called"); \
00192     return NS_ERROR_NOT_IMPLEMENTED; \
00193 }
00194 
00195 #include "xptcstubsdef.inc"