Back to index

lightning-sunbird  0.9+nobinonly
xptcinvoke_emx.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) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   John Fairhurst <john_fairhurst@iname.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK *****
00039  *
00040  * This Original Code has been modified by IBM Corporation.
00041  * Modifications made by IBM described herein are
00042  * Copyright (c) International Business Machines
00043  * Corporation, 2000
00044  *
00045  * Modifications to Mozilla code or documentation
00046  * identified per MPL Section 3.3
00047  *
00048  * Date         Modified by     Description of modification
00049  * 03/22/2000  IBM Corp.       Fixed multiple inheritance bug in XPTC_InvokeByIndex to adjust the
00050  *                                     "that" (this) pointer appropriately.
00051  */
00052 
00053 /* Platform specific code to invoke XPCOM methods on native objects */
00054 
00055 // This is 80% copied directly from other platforms; the assembler
00056 // stuff is all my fault, though. (jmf)
00057 
00058 #if !defined(__EMX__)
00059 #error "This code is for OS/2 EMX only"
00060 #endif
00061 
00062 #include "xptcprivate.h"
00063 
00064 // Remember that these 'words' are 32-bit DWORDs
00065 static PRUint32
00066 invoke_count_words( PRUint32 paramCount, nsXPTCVariant* s)
00067 {
00068     PRUint32 result = 0;
00069 
00070     for(PRUint32 i = 0; i < paramCount; i++, s++)
00071     {
00072         if(s->IsPtrData())
00073             result++;
00074 
00075         else {
00076 
00077             switch(s->type)
00078             { 
00079              // 64-bit types
00080              case nsXPTType::T_I64    :
00081              case nsXPTType::T_U64    :
00082              case nsXPTType::T_DOUBLE :
00083                  result+=2;
00084                  break;
00085 
00086              // all others are dwords
00087              default:
00088                  result++;
00089                  break;
00090             }
00091         }
00092     }
00093     return result;
00094 }
00095 
00096 
00097 static void
00098 invoke_copy_to_stack( PRUint32* d, uint32 paramCount, nsXPTCVariant* s)
00099 {
00100     for( PRUint32 i = 0; i < paramCount; i++, d++, s++)
00101     {
00102         if(s->IsPtrData())
00103             *((void**)d) = s->ptr;
00104 
00105         else {
00106 
00107             switch(s->type)
00108             {
00109              case nsXPTType::T_I8     : *((int8*)   d) = s->val.i8;          break;
00110              case nsXPTType::T_I16    : *((int16*)  d) = s->val.i16;         break;
00111              case nsXPTType::T_I32    : *((int32*)  d) = s->val.i32;         break;
00112              case nsXPTType::T_I64    : *((int64*)  d) = s->val.i64; d++;    break;
00113              case nsXPTType::T_U8     : *((uint8*)  d) = s->val.u8;          break;
00114              case nsXPTType::T_U16    : *((uint16*) d) = s->val.u16;         break;
00115              case nsXPTType::T_U32    : *((uint32*) d) = s->val.u32;         break;
00116              case nsXPTType::T_U64    : *((uint64*) d) = s->val.u64; d++;    break;
00117              case nsXPTType::T_FLOAT  : *((float*)  d) = s->val.f;           break;
00118              case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d;   d++;    break;
00119              case nsXPTType::T_BOOL   : *((PRBool*) d) = s->val.b;           break;
00120              case nsXPTType::T_CHAR   : *((char*)   d) = s->val.c;           break;
00121              case nsXPTType::T_WCHAR  : *((wchar_t*)d) = s->val.wc;          break;
00122              default:
00123                 // all the others are plain pointer types
00124                 *((void**)d) = s->val.p;
00125                 break;
00126             }
00127         }
00128     }
00129 }
00130 
00131 
00132 XPTC_PUBLIC_API(nsresult)
00133 XPTC_InvokeByIndex( nsISupports *that, PRUint32 index,
00134                     PRUint32 paramcount, nsXPTCVariant* params)
00135 {
00136    int   ibytes;
00137    void *pStack;
00138    int   result = NS_OK;
00139 
00140    // Find size in bytes necessary for call
00141    ibytes = 4 * invoke_count_words( paramcount, params);
00142 
00143    __asm__ __volatile__(
00144    "movl %1,    %%eax\n"                  /* load |ibytes| into eax */
00145    "subl %%eax, %%esp\n"                      /* make room on stack */
00146    "movl %%esp, %0"                       /* store base in |pStack| */
00147    : "=g" (pStack)   /* %0 */
00148    : "g" (ibytes)    /* %1 */
00149    : "ax", "memory", "sp"
00150    );
00151 
00152    // Fill in that gap in the stack with the params to the method
00153    invoke_copy_to_stack( (PRUint32*) pStack, paramcount, params);
00154 
00155    // push the hidden 'this' parameter, traverse the vtable,
00156    // and then call the method.
00157 
00158    __asm__ __volatile__(
00159    "movl  %2, %%eax\n"                         /* |that| ptr -> eax */
00160    "movl  (%%eax), %%edx\n"                          /* vptr -> edx */
00161    "movl  %3, %%ebx\n"
00162    "shl   $3, %%ebx\n"                      /* 8 bytes per method.. */
00163    "addl  $8, %%ebx\n"              /* ..plus 8 to skip over 1st 8 bytes of vtbl */
00164 
00165    "addl  %%ebx, %%edx\n"                 /* find appropriate vtbl entry */
00166    "movswl (%%edx),%%ecx\n"           /* get possible |that| ptr adjustment value */
00167    "addl  %%ecx, %%eax\n"                 /* adjust the |that| ptr (needed for multiple inheritance) */
00168    "pushl %%eax\n"                            /* enstack the possibly-adjusted |that| */
00169 
00170    "addl  $4, %%edx\n"              /* ..add 4 more to get to the method's entry point */
00171 
00172    "call  (%%edx)\n"                                 /* call method */
00173    "movl  %%eax, %0\n"                       /* save rc in |result| */
00174    "movl  %1, %%ebx\n"                            /* clear up stack */
00175    "addl  $4, %%ebx\n"
00176    "addl  %%ebx, %%esp"
00177    : "=g" (result)     /* %0 */
00178    : "g"  (ibytes),    /* %1 */
00179      "g"  (that),      /* %2 */
00180      "g"  (index)      /* %3 */
00181    : "ax", "bx", "dx", "memory", "sp"
00182    );
00183 
00184    return result;
00185 }