Back to index

lightning-sunbird  0.9+nobinonly
xptcinvoke_ppc_linux.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  *   Franz.Sirl-kernel@lauterbach.com (Franz Sirl)
00024  *   beard@netscape.com (Patrick Beard)
00025  *   waterson@netscape.com (Chris Waterson)
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 // Platform specific code to invoke XPCOM methods on native objects
00042 
00043 // The purpose of XPTC_InvokeByIndex() is to map a platform
00044 // indepenpent call to the platform ABI. To do that,
00045 // XPTC_InvokeByIndex() has to determine the method to call via vtable
00046 // access. The parameters for the method are read from the
00047 // nsXPTCVariant* and prepared for th native ABI.  For the Linux/PPC
00048 // ABI this means that the first 8 integral and floating point
00049 // parameters are passed in registers.
00050 
00051 #include "xptcprivate.h"
00052 
00053 // 8 integral parameters are passed in registers
00054 #define GPR_COUNT     8
00055 
00056 // 8 floating point parameters are passed in registers, floats are
00057 // promoted to doubles when passed in registers
00058 #define FPR_COUNT     8
00059 
00060 extern "C" PRUint32
00061 invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
00062 {
00063   return PRUint32(((paramCount * 2) + 3) & ~3);
00064 }
00065 
00066 extern "C" void
00067 invoke_copy_to_stack(PRUint32* d,
00068                      PRUint32 paramCount,
00069                      nsXPTCVariant* s, 
00070                      PRUint32* gpregs,
00071                      double* fpregs)
00072 {
00073     PRUint32 gpr = 1; // skip one GP reg for 'that'
00074     PRUint32 fpr = 0;
00075     PRUint32 tempu32;
00076     PRUint64 tempu64;
00077     
00078     for(uint32 i = 0; i < paramCount; i++, s++) {
00079         if(s->IsPtrData())
00080             tempu32 = (PRUint32) s->ptr;
00081         else {
00082             switch(s->type) {
00083             case nsXPTType::T_FLOAT:                                  break;
00084             case nsXPTType::T_DOUBLE:                                 break;
00085             case nsXPTType::T_I8:     tempu32 = s->val.i8;            break;
00086             case nsXPTType::T_I16:    tempu32 = s->val.i16;           break;
00087             case nsXPTType::T_I32:    tempu32 = s->val.i32;           break;
00088             case nsXPTType::T_I64:    tempu64 = s->val.i64;           break;
00089             case nsXPTType::T_U8:     tempu32 = s->val.u8;            break;
00090             case nsXPTType::T_U16:    tempu32 = s->val.u16;           break;
00091             case nsXPTType::T_U32:    tempu32 = s->val.u32;           break;
00092             case nsXPTType::T_U64:    tempu64 = s->val.u64;           break;
00093             case nsXPTType::T_BOOL:   tempu32 = s->val.b;             break;
00094             case nsXPTType::T_CHAR:   tempu32 = s->val.c;             break;
00095             case nsXPTType::T_WCHAR:  tempu32 = s->val.wc;            break;
00096             default:                  tempu32 = (PRUint32) s->val.p;  break;
00097             }
00098         }
00099 
00100         if (!s->IsPtrData() && s->type == nsXPTType::T_DOUBLE) {
00101             if (fpr < FPR_COUNT)
00102                 fpregs[fpr++]    = s->val.d;
00103             else {
00104                 if ((PRUint32) d & 4) d++; // doubles are 8-byte aligned on stack
00105                 *((double*) d) = s->val.d;
00106                 d += 2;
00107             }
00108         }
00109         else if (!s->IsPtrData() && s->type == nsXPTType::T_FLOAT) {
00110             if (fpr < FPR_COUNT)
00111                 fpregs[fpr++]   = s->val.f; // if passed in registers, floats are promoted to doubles
00112             else
00113                 *((float*) d++) = s->val.f;
00114         }
00115         else if (!s->IsPtrData() && (s->type == nsXPTType::T_I64
00116                                      || s->type == nsXPTType::T_U64)) {
00117             if ((gpr + 1) < GPR_COUNT) {
00118                 if (gpr & 1) gpr++; // longlongs are aligned in odd/even register pairs, eg. r5/r6
00119                 *((PRUint64*) &gpregs[gpr]) = tempu64;
00120                 gpr += 2;
00121             }
00122             else {
00123                 if ((PRUint32) d & 4) d++; // longlongs are 8-byte aligned on stack
00124                 *((PRUint64*) d)            = tempu64;
00125                 d += 2;
00126             }
00127         }
00128         else {
00129             if (gpr < GPR_COUNT)
00130                 gpregs[gpr++] = tempu32;
00131             else
00132                 *d++          = tempu32;
00133         }
00134         
00135     }
00136 }
00137 
00138 extern "C"
00139 XPTC_PUBLIC_API(nsresult)
00140 XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
00141                    PRUint32 paramCount, nsXPTCVariant* params);