Back to index

lightning-sunbird  0.9+nobinonly
xptcinvoke_linux_s390.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  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 /* Platform specific code to invoke XPCOM methods on native objects */
00040 
00041 #include "xptcprivate.h"
00042 
00043 
00044 static PRUint32
00045 invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
00046 {
00047     PRUint32 overflow = 0, gpr = 1 /*this*/, fpr = 0;
00048     for(PRUint32 i = 0; i < paramCount; i++, s++)
00049     {
00050         if(s->IsPtrData())
00051         {
00052             if (gpr < 5) gpr++; else overflow++;
00053             continue;
00054         }
00055         switch(s->type)
00056         {
00057         case nsXPTType::T_I8     :
00058         case nsXPTType::T_I16    :
00059         case nsXPTType::T_I32    :
00060             if (gpr < 5) gpr++; else overflow++;
00061             break;
00062         case nsXPTType::T_I64    :
00063             if (gpr < 4) gpr+=2; else gpr=5, overflow+=2;
00064             break;
00065         case nsXPTType::T_U8     :
00066         case nsXPTType::T_U16    :
00067         case nsXPTType::T_U32    :
00068             if (gpr < 5) gpr++; else overflow++;
00069             break;
00070         case nsXPTType::T_U64    :
00071             if (gpr < 4) gpr+=2; else gpr=5, overflow+=2;
00072             break;
00073         case nsXPTType::T_FLOAT  :
00074             if (fpr < 2) fpr++; else overflow++;
00075             break;
00076         case nsXPTType::T_DOUBLE :
00077             if (fpr < 2) fpr++; else overflow+=2;
00078             break;
00079         case nsXPTType::T_BOOL   :
00080         case nsXPTType::T_CHAR   :
00081         case nsXPTType::T_WCHAR  :
00082             if (gpr < 5) gpr++; else overflow++;
00083             break;
00084         default:
00085             // all the others are plain pointer types
00086             if (gpr < 5) gpr++; else overflow++;
00087             break;
00088         }
00089     }
00090     /* Round up number of overflow words to ensure stack
00091        stays aligned to 8 bytes.  */
00092     return (overflow + 1) & ~1;
00093 }
00094 
00095 static void
00096 invoke_copy_to_stack(PRUint32 paramCount, nsXPTCVariant* s, PRUint32* d_ov, PRUint32 overflow)
00097 {
00098     PRUint32 *d_gpr = d_ov + overflow; 
00099     PRUint64 *d_fpr = (PRUint64 *)(d_gpr + 4);
00100     PRUint32 gpr = 1 /*this*/, fpr = 0;
00101 
00102     for(PRUint32 i = 0; i < paramCount; i++, s++)
00103     {
00104         if(s->IsPtrData())
00105         {
00106             if (gpr < 5) 
00107                 *((void**)d_gpr) = s->ptr, d_gpr++, gpr++;
00108             else
00109                 *((void**)d_ov ) = s->ptr, d_ov++;
00110             continue;
00111         }
00112         switch(s->type)
00113         {
00114         case nsXPTType::T_I8     : 
00115             if (gpr < 5)
00116                 *((PRInt32*) d_gpr) = s->val.i8, d_gpr++, gpr++;
00117             else
00118                 *((PRInt32*) d_ov ) = s->val.i8, d_ov++;
00119             break;
00120         case nsXPTType::T_I16    : 
00121             if (gpr < 5)
00122                 *((PRInt32*) d_gpr) = s->val.i16, d_gpr++, gpr++;
00123             else
00124                 *((PRInt32*) d_ov ) = s->val.i16, d_ov++;
00125             break;
00126         case nsXPTType::T_I32    : 
00127             if (gpr < 5)
00128                 *((PRInt32*) d_gpr) = s->val.i32, d_gpr++, gpr++;
00129             else
00130                 *((PRInt32*) d_ov ) = s->val.i32, d_ov++;
00131             break;
00132         case nsXPTType::T_I64    : 
00133             if (gpr < 4)
00134                 *((PRInt64*) d_gpr) = s->val.i64, d_gpr+=2, gpr+=2;
00135             else
00136                 *((PRInt64*) d_ov ) = s->val.i64, d_ov+=2, gpr=5;
00137             break;
00138         case nsXPTType::T_U8     : 
00139             if (gpr < 5)
00140                 *((PRUint32*) d_gpr) = s->val.u8, d_gpr++, gpr++;
00141             else
00142                 *((PRUint32*) d_ov ) = s->val.u8, d_ov++;
00143             break;
00144         case nsXPTType::T_U16    : 
00145             if (gpr < 5)
00146                 *((PRUint32*)d_gpr) = s->val.u16, d_gpr++, gpr++;
00147             else
00148                 *((PRUint32*)d_ov ) = s->val.u16, d_ov++;
00149             break;
00150         case nsXPTType::T_U32    : 
00151             if (gpr < 5)
00152                 *((PRUint32*)d_gpr) = s->val.u32, d_gpr++, gpr++;
00153             else
00154                 *((PRUint32*)d_ov ) = s->val.u32, d_ov++;
00155             break;
00156         case nsXPTType::T_U64    : 
00157             if (gpr < 4)
00158                 *((PRUint64*)d_gpr) = s->val.u64, d_gpr+=2, gpr+=2;
00159             else
00160                 *((PRUint64*)d_ov ) = s->val.u64, d_ov+=2, gpr=5;
00161             break;
00162         case nsXPTType::T_FLOAT  : 
00163             if (fpr < 2)
00164                 *((float*)   d_fpr) = s->val.f, d_fpr++, fpr++;
00165             else
00166                 *((float*)   d_ov ) = s->val.f, d_ov++;
00167             break;
00168         case nsXPTType::T_DOUBLE : 
00169             if (fpr < 2)
00170                 *((double*)  d_fpr) = s->val.d, d_fpr++, fpr++;
00171             else
00172                 *((double*)  d_ov ) = s->val.d, d_ov+=2;
00173             break;
00174         case nsXPTType::T_BOOL   : 
00175             if (gpr < 5)
00176                 *((PRUint32*)d_gpr) = s->val.b, d_gpr++, gpr++;
00177             else
00178                 *((PRUint32*)d_ov ) = s->val.b, d_ov++;
00179             break;
00180         case nsXPTType::T_CHAR   : 
00181             if (gpr < 5)
00182                 *((PRUint32*)d_gpr) = s->val.c, d_gpr++, gpr++;
00183             else
00184                 *((PRUint32*)d_ov ) = s->val.c, d_ov++;
00185             break;
00186         case nsXPTType::T_WCHAR  : 
00187             if (gpr < 5)
00188                 *((PRUint32*)d_gpr) = s->val.wc, d_gpr++, gpr++;
00189             else
00190                 *((PRUint32*)d_ov ) = s->val.wc, d_ov++;
00191             break;
00192         default:
00193             // all the others are plain pointer types
00194             if (gpr < 5) 
00195                 *((void**)   d_gpr) = s->val.p, d_gpr++, gpr++;
00196             else
00197                 *((void**)   d_ov ) = s->val.p, d_ov++;
00198             break;
00199         }
00200     }
00201 }
00202 
00203 XPTC_PUBLIC_API(nsresult)
00204 XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
00205                    PRUint32 paramCount, nsXPTCVariant* params)
00206 {
00207     PRUint32 *vtable = *(PRUint32 **)that;
00208 #if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 /* G++ V3 ABI */
00209     PRUint32 method = vtable[methodIndex];
00210 #else /* not G++ V3 ABI  */
00211     PRUint32 method = vtable[methodIndex + 2];
00212 #endif /* G++ V3 ABI */ 
00213     PRUint32 overflow = invoke_count_words (paramCount, params);
00214     PRUint32 result;
00215 
00216     __asm__ __volatile__
00217     (
00218         "lr    7,15\n\t"
00219         "ahi   7,-32\n\t"
00220 
00221         "lr    3,%3\n\t"
00222         "sll   3,2\n\t"
00223         "lcr   3,3\n\t"
00224         "l     2,0(15)\n\t"
00225         "la    15,0(3,7)\n\t"
00226         "st    2,0(15)\n\t"
00227 
00228         "lr    2,%1\n\t"
00229         "lr    3,%2\n\t"
00230         "la    4,96(15)\n\t"
00231         "lr    5,%3\n\t"
00232         "basr  14,%4\n\t"
00233 
00234         "lr    2,%5\n\t"
00235         "ld    0,112(7)\n\t"
00236         "ld    2,120(7)\n\t"
00237         "lm    3,6,96(7)\n\t"
00238         "basr  14,%6\n\t"
00239 
00240         "la    15,32(7)\n\t"
00241 
00242         "lr    %0,2\n\t"
00243         : "=r" (result)
00244         : "r" (paramCount),
00245           "r" (params),
00246           "r" (overflow),
00247           "a" (invoke_copy_to_stack),
00248           "a" (that),
00249           "a" (method)
00250         : "2", "3", "4", "5", "6", "7", "14", "cc", "memory", "%f0", "%f2"
00251     );
00252   
00253     return result;
00254 }