Back to index

lightning-sunbird  0.9+nobinonly
xptcinvoke_linux_s390x.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         case nsXPTType::T_I64    :
00061             if (gpr < 5) gpr++; else overflow++;
00062             break;
00063         case nsXPTType::T_U8     :
00064         case nsXPTType::T_U16    :
00065         case nsXPTType::T_U32    :
00066         case nsXPTType::T_U64    :
00067             if (gpr < 5) gpr++; else overflow++;
00068             break;
00069         case nsXPTType::T_FLOAT  :
00070         case nsXPTType::T_DOUBLE :
00071             if (fpr < 4) fpr++; else overflow++;
00072             break;
00073         case nsXPTType::T_BOOL   :
00074         case nsXPTType::T_CHAR   :
00075         case nsXPTType::T_WCHAR  :
00076             if (gpr < 5) gpr++; else overflow++;
00077             break;
00078         default:
00079             // all the others are plain pointer types
00080             if (gpr < 5) gpr++; else overflow++;
00081             break;
00082         }
00083     }
00084     /* Round up number of overflow words to ensure stack
00085        stays aligned to 8 bytes.  */
00086     return (overflow + 1) & ~1;
00087 }
00088 
00089 static void
00090 invoke_copy_to_stack(PRUint32 paramCount, nsXPTCVariant* s, PRUint64* d_ov, PRUint32 overflow)
00091 {
00092     PRUint64 *d_gpr = d_ov + overflow; 
00093     PRUint64 *d_fpr = (PRUint64 *)(d_gpr + 4);
00094     PRUint32 gpr = 1 /*this*/, fpr = 0;
00095 
00096     for(PRUint32 i = 0; i < paramCount; i++, s++)
00097     {
00098         if(s->IsPtrData())
00099         {
00100             if (gpr < 5) 
00101                 *((void**)d_gpr) = s->ptr, d_gpr++, gpr++;
00102             else
00103                 *((void**)d_ov ) = s->ptr, d_ov++;
00104             continue;
00105         }
00106         switch(s->type)
00107         {
00108         case nsXPTType::T_I8     : 
00109             if (gpr < 5)
00110                 *((PRInt64*) d_gpr) = s->val.i8, d_gpr++, gpr++;
00111             else
00112                 *((PRInt64*) d_ov ) = s->val.i8, d_ov++;
00113             break;
00114         case nsXPTType::T_I16    : 
00115             if (gpr < 5)
00116                 *((PRInt64*) d_gpr) = s->val.i16, d_gpr++, gpr++;
00117             else
00118                 *((PRInt64*) d_ov ) = s->val.i16, d_ov++;
00119             break;
00120         case nsXPTType::T_I32    : 
00121             if (gpr < 5)
00122                 *((PRInt64*) d_gpr) = s->val.i32, d_gpr++, gpr++;
00123             else
00124                 *((PRInt64*) d_ov ) = s->val.i32, d_ov++;
00125             break;
00126         case nsXPTType::T_I64    : 
00127             if (gpr < 5)
00128                 *((PRInt64*) d_gpr) = s->val.i64, d_gpr++, gpr++;
00129             else
00130                 *((PRInt64*) d_ov ) = s->val.i64, d_ov++;
00131             break;
00132         case nsXPTType::T_U8     : 
00133             if (gpr < 5)
00134                 *((PRUint64*) d_gpr) = s->val.u8, d_gpr++, gpr++;
00135             else
00136                 *((PRUint64*) d_ov ) = s->val.u8, d_ov++;
00137             break;
00138         case nsXPTType::T_U16    : 
00139             if (gpr < 5)
00140                 *((PRUint64*)d_gpr) = s->val.u16, d_gpr++, gpr++;
00141             else
00142                 *((PRUint64*)d_ov ) = s->val.u16, d_ov++;
00143             break;
00144         case nsXPTType::T_U32    : 
00145             if (gpr < 5)
00146                 *((PRUint64*)d_gpr) = s->val.u32, d_gpr++, gpr++;
00147             else
00148                 *((PRUint64*)d_ov ) = s->val.u32, d_ov++;
00149             break;
00150         case nsXPTType::T_U64    : 
00151             if (gpr < 5)
00152                 *((PRUint64*)d_gpr) = s->val.u64, d_gpr++, gpr++;
00153             else
00154                 *((PRUint64*)d_ov ) = s->val.u64, d_ov++;
00155             break;
00156         case nsXPTType::T_FLOAT  : 
00157             if (fpr < 4)
00158                 *((float*)   d_fpr)    = s->val.f, d_fpr++, fpr++;
00159             else
00160                 *(((float*)  d_ov )+1) = s->val.f, d_ov++;
00161             break;
00162         case nsXPTType::T_DOUBLE : 
00163             if (fpr < 4)
00164                 *((double*)  d_fpr) = s->val.d, d_fpr++, fpr++;
00165             else
00166                 *((double*)  d_ov ) = s->val.d, d_ov++;
00167             break;
00168         case nsXPTType::T_BOOL   : 
00169             if (gpr < 5)
00170                 *((PRUint64*)d_gpr) = s->val.b, d_gpr++, gpr++;
00171             else
00172                 *((PRUint64*)d_ov ) = s->val.b, d_ov++;
00173             break;
00174         case nsXPTType::T_CHAR   : 
00175             if (gpr < 5)
00176                 *((PRUint64*)d_gpr) = s->val.c, d_gpr++, gpr++;
00177             else
00178                 *((PRUint64*)d_ov ) = s->val.c, d_ov++;
00179             break;
00180         case nsXPTType::T_WCHAR  : 
00181             if (gpr < 5)
00182                 *((PRUint64*)d_gpr) = s->val.wc, d_gpr++, gpr++;
00183             else
00184                 *((PRUint64*)d_ov ) = s->val.wc, d_ov++;
00185             break;
00186         default:
00187             // all the others are plain pointer types
00188             if (gpr < 5) 
00189                 *((void**)   d_gpr) = s->val.p, d_gpr++, gpr++;
00190             else
00191                 *((void**)   d_ov ) = s->val.p, d_ov++;
00192             break;
00193         }
00194     }
00195 }
00196 
00197 XPTC_PUBLIC_API(nsresult)
00198 XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
00199                    PRUint32 paramCount, nsXPTCVariant* params)
00200 {
00201     PRUint64 *vtable = *(PRUint64 **)that;
00202 #if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 /* G++ V3 ABI */
00203     PRUint64 method = vtable[methodIndex];
00204 #else /* not G++ V3 ABI  */
00205     PRUint64 method = vtable[methodIndex + 2];
00206 #endif /* G++ V3 ABI */
00207     PRUint64 overflow = invoke_count_words (paramCount, params);
00208     PRUint64 result;
00209 
00210     __asm__ __volatile__
00211     (
00212         "lgr    7,15\n\t"
00213         "aghi   7,-64\n\t"
00214 
00215         "lgr    3,%3\n\t"
00216         "sllg   3,3,3\n\t"
00217         "lcgr   3,3\n\t"
00218         "lg     2,0(15)\n\t"
00219         "la     15,0(3,7)\n\t"
00220         "stg    2,0(15)\n\t"
00221 
00222         "lgr    2,%1\n\t"
00223         "lgr    3,%2\n\t"
00224         "la     4,160(15)\n\t"
00225         "lgr    5,%3\n\t"
00226         "basr   14,%4\n\t"
00227 
00228         "lgr    2,%5\n\t"
00229         "ld     0,192(7)\n\t"
00230         "ld     2,200(7)\n\t"
00231         "ld     4,208(7)\n\t"
00232         "ld     6,216(7)\n\t"
00233         "lmg    3,6,160(7)\n\t"
00234         "basr   14,%6\n\t"
00235 
00236         "la     15,64(7)\n\t"
00237 
00238         "lgr    %0,2\n\t"
00239         : "=r" (result)
00240         : "r" ((PRUint64)paramCount),
00241           "r" (params),
00242           "r" (overflow),
00243           "a" (invoke_copy_to_stack),
00244           "a" (that),
00245           "a" (method)
00246         : "2", "3", "4", "5", "6", "7", "14", "cc", "memory",
00247          "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7"
00248     );
00249   
00250     return result;
00251 }