Back to index

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