1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_sparc_netbsd.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,131 @@ 1.4 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* Platform specific code to invoke XPCOM methods on native objects */ 1.10 + 1.11 +#include "xptcprivate.h" 1.12 + 1.13 +/* solaris defines __sparc for workshop compilers and 1.14 + linux defines __sparc__ */ 1.15 + 1.16 +#if !defined(__sparc) && !defined(__sparc__) 1.17 +#error "This code is for Sparc only" 1.18 +#endif 1.19 + 1.20 +typedef unsigned nsXPCVariant; 1.21 + 1.22 +extern "C" uint32_t 1.23 +invoke_count_words(uint32_t paramCount, nsXPTCVariant* s) 1.24 +{ 1.25 + uint32_t result = 0; 1.26 + for(uint32_t i = 0; i < paramCount; i++, s++) 1.27 + { 1.28 + if(s->IsPtrData()) 1.29 + { 1.30 + result++; 1.31 + continue; 1.32 + } 1.33 + switch(s->type) 1.34 + { 1.35 + case nsXPTType::T_I8 : 1.36 + case nsXPTType::T_I16 : 1.37 + case nsXPTType::T_I32 : 1.38 + result++; 1.39 + break; 1.40 + case nsXPTType::T_I64 : 1.41 + result+=2; 1.42 + break; 1.43 + case nsXPTType::T_U8 : 1.44 + case nsXPTType::T_U16 : 1.45 + case nsXPTType::T_U32 : 1.46 + result++; 1.47 + break; 1.48 + case nsXPTType::T_U64 : 1.49 + result+=2; 1.50 + break; 1.51 + case nsXPTType::T_FLOAT : 1.52 + result++; 1.53 + break; 1.54 + case nsXPTType::T_DOUBLE : 1.55 + result+=2; 1.56 + break; 1.57 + case nsXPTType::T_BOOL : 1.58 + case nsXPTType::T_CHAR : 1.59 + case nsXPTType::T_WCHAR : 1.60 + result++; 1.61 + break; 1.62 + default: 1.63 + // all the others are plain pointer types 1.64 + result++; 1.65 + break; 1.66 + } 1.67 + } 1.68 + // nuts, I know there's a cooler way of doing this, but it's late 1.69 + // now and it'll probably come to me in the morning. 1.70 + if (result & 0x3) result += 4 - (result & 0x3); // ensure q-word alignment 1.71 + return result; 1.72 +} 1.73 + 1.74 +extern "C" uint32_t 1.75 +invoke_copy_to_stack(uint32_t* d, uint32_t paramCount, nsXPTCVariant* s) 1.76 +{ 1.77 +/* 1.78 + We need to copy the parameters for this function to locals and use them 1.79 + from there since the parameters occupy the same stack space as the stack 1.80 + we're trying to populate. 1.81 +*/ 1.82 + uint32_t *l_d = d; 1.83 + nsXPTCVariant *l_s = s; 1.84 + uint32_t l_paramCount = paramCount; 1.85 + uint32_t regCount = 0; // return the number of registers to load from the stack 1.86 + 1.87 + typedef struct { 1.88 + uint32_t hi; 1.89 + uint32_t lo; 1.90 + } DU; // have to move 64 bit entities as 32 bit halves since 1.91 + // stack slots are not guaranteed 16 byte aligned 1.92 + 1.93 + for(uint32_t i = 0; i < l_paramCount; i++, l_d++, l_s++) 1.94 + { 1.95 + if (regCount < 5) regCount++; 1.96 + if(l_s->IsPtrData()) 1.97 + { 1.98 + if(l_s->type == nsXPTType::T_JSVAL) 1.99 + { 1.100 + // On SPARC, we need to pass a pointer to HandleValue 1.101 + *((void**)l_d) = &l_s->ptr; 1.102 + } else 1.103 + { 1.104 + *((void**)l_d) = l_s->ptr; 1.105 + } 1.106 + continue; 1.107 + } 1.108 + switch(l_s->type) 1.109 + { 1.110 + case nsXPTType::T_I8 : *((int32_t*) l_d) = l_s->val.i8; break; 1.111 + case nsXPTType::T_I16 : *((int32_t*) l_d) = l_s->val.i16; break; 1.112 + case nsXPTType::T_I32 : *((int32_t*) l_d) = l_s->val.i32; break; 1.113 + case nsXPTType::T_I64 : 1.114 + case nsXPTType::T_U64 : 1.115 + case nsXPTType::T_DOUBLE : *((uint32_t*) l_d++) = ((DU *)l_s)->hi; 1.116 + if (regCount < 5) regCount++; 1.117 + *((uint32_t*) l_d) = ((DU *)l_s)->lo; 1.118 + break; 1.119 + case nsXPTType::T_U8 : *((uint32_t*) l_d) = l_s->val.u8; break; 1.120 + case nsXPTType::T_U16 : *((uint32_t*) l_d) = l_s->val.u16; break; 1.121 + case nsXPTType::T_U32 : *((uint32_t*) l_d) = l_s->val.u32; break; 1.122 + case nsXPTType::T_FLOAT : *((float*) l_d) = l_s->val.f; break; 1.123 + case nsXPTType::T_BOOL : *((uint32_t*) l_d) = l_s->val.b; break; 1.124 + case nsXPTType::T_CHAR : *((uint32_t*) l_d) = l_s->val.c; break; 1.125 + case nsXPTType::T_WCHAR : *((int32_t*) l_d) = l_s->val.wc; break; 1.126 + default: 1.127 + // all the others are plain pointer types 1.128 + *((void**)l_d) = l_s->val.p; 1.129 + break; 1.130 + } 1.131 + } 1.132 + return regCount; 1.133 +} 1.134 +