Back to index

lightning-sunbird  0.9+nobinonly
xptcinvoke_linux_m68k.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) 1998
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 /* Platform specific code to invoke XPCOM methods on native objects */
00039 
00040 #include "xptcprivate.h"
00041 
00042 // Remember that these 'words' are 32bit DWORDS
00043 
00044 extern "C" {
00045     static PRUint32
00046     invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
00047     {
00048         PRUint32 result = 0;
00049         for(PRUint32 i = 0; i < paramCount; i++, s++)
00050         {
00051             if(s->IsPtrData())
00052             {
00053                 result++;
00054                 continue;
00055             }
00056             switch(s->type)
00057             {
00058             case nsXPTType::T_I8     :
00059             case nsXPTType::T_I16    :
00060             case nsXPTType::T_I32    :
00061                 result++;
00062                 break;
00063             case nsXPTType::T_I64    :
00064                 result+=2;
00065                 break;
00066             case nsXPTType::T_U8     :
00067             case nsXPTType::T_U16    :
00068             case nsXPTType::T_U32    :
00069                 result++;
00070                 break;
00071             case nsXPTType::T_U64    :
00072                 result+=2;
00073                 break;
00074             case nsXPTType::T_FLOAT  :
00075                 result++;
00076                 break;
00077             case nsXPTType::T_DOUBLE :
00078                 result+=2;
00079                 break;
00080             case nsXPTType::T_BOOL   :
00081             case nsXPTType::T_CHAR   :
00082             case nsXPTType::T_WCHAR  :
00083                 result++;
00084                 break;
00085             default:
00086                 // all the others are plain pointer types
00087                 result++;
00088                 break;
00089             }
00090         }
00091         return result;
00092     }
00093 
00094     void
00095     invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s)
00096     {
00097         for(PRUint32 i = 0; i < paramCount; i++, d++, s++)
00098         {
00099             if(s->IsPtrData())
00100             {
00101                 *((void**)d) = s->ptr;
00102                 continue;
00103             }
00104             switch(s->type)
00105             {
00106             // 8 and 16 bit types should be promoted to 32 bits when copying
00107             // onto the stack.
00108             case nsXPTType::T_I8     : *((PRUint32*)d) = s->val.i8;          break;
00109             case nsXPTType::T_I16    : *((PRUint32*)d) = s->val.i16;         break;
00110             case nsXPTType::T_I32    : *((PRInt32*) d) = s->val.i32;         break;
00111             case nsXPTType::T_I64    : *((PRInt64*) d) = s->val.i64; d++;    break;
00112             case nsXPTType::T_U8     : *((PRUint32*)d) = s->val.u8;          break;
00113             case nsXPTType::T_U16    : *((PRUint32*)d) = s->val.u16;         break;
00114             case nsXPTType::T_U32    : *((PRUint32*)d) = s->val.u32;         break;
00115             case nsXPTType::T_U64    : *((PRUint64*)d) = s->val.u64; d++;    break;
00116             case nsXPTType::T_FLOAT  : *((float*)   d) = s->val.f;           break;
00117             case nsXPTType::T_DOUBLE : *((double*)  d) = s->val.d;   d++;    break;
00118             case nsXPTType::T_BOOL   : *((PRBool*)  d) = s->val.b;           break;
00119             case nsXPTType::T_CHAR   : *((PRUint32*)d) = s->val.c;           break;
00120             case nsXPTType::T_WCHAR  : *((wchar_t*) d) = s->val.wc;          break;
00121 
00122             default:
00123                 // all the others are plain pointer types
00124                 *((void**)d) = s->val.p;
00125                 break;
00126             }
00127         }
00128     }
00129 }
00130 
00131 XPTC_PUBLIC_API(nsresult)
00132 XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
00133                    PRUint32 paramCount, nsXPTCVariant* params)
00134 {
00135     PRUint32 result, n;
00136 
00137     n = invoke_count_words(paramCount, params) * 4;
00138 
00139  __asm__ __volatile__(
00140     "subl  %5, %/sp\n\t"      /* make room for params */
00141     "movl  %/sp, %/a0\n\t"
00142     "movl  %4, %/sp@-\n\t"
00143     "movl  %3, %/sp@-\n\t"
00144     "movl  %/a0, %/sp@-\n\t"
00145     "jbsr  invoke_copy_to_stack\n\t"   /* copy params */
00146     "addl  #12, %/sp\n\t"
00147     "movl  %1, %/a0\n\t"
00148     "movl  %/a0, %/sp@-\n\t"
00149     "movl  %/a0@, %/a0\n\t"
00150     "movl  %2, %/d0\n\t"      /* function index */
00151 #if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 /* G++ V3 ABI */
00152     "movl  %/a0@(%/d0:l:4), %/a0\n\t"
00153 #else /* not V3 */
00154     "movl  %/a0@(8,%/d0:l:4), %/a0\n\t"                
00155 #endif
00156     "jbsr  %/a0@\n\t"         /* safe to not cleanup sp */
00157     "movl  %/d0, %0\n\t"
00158     "addql #4, %/sp\n\t"
00159     "addl  %5, %/sp"
00160     : "=g" (result)         /* %0 */
00161     : "g" (that),           /* %1 */
00162       "g" (methodIndex),    /* %2 */
00163       "g" (paramCount),     /* %3 */
00164       "g" (params),         /* %4 */
00165       "g" (n)               /* %5 */
00166     : "a0", "a1", "d0", "d1", "memory"
00167     );
00168   
00169   return result;
00170 }