1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /* Platform specific code to invoke XPCOM methods on native objects */
7
8 #include "xptcprivate.h"
9
10 /* solaris defines __sparc for workshop compilers and
11 linux defines __sparc__ */
12
13 #if !defined(__sparc) && !defined(__sparc__)
14 #error "This code is for Sparc only"
15 #endif
16
17 typedef unsigned nsXPCVariant;
18
19 extern "C" uint32_t
invoke_count_words(uint32_t paramCount,nsXPTCVariant * s)20 invoke_count_words(uint32_t paramCount, nsXPTCVariant* s)
21 {
22 uint32_t result = 0;
23 for(uint32_t i = 0; i < paramCount; i++, s++)
24 {
25 if(s->IsPtrData())
26 {
27 result++;
28 continue;
29 }
30 switch(s->type)
31 {
32 case nsXPTType::T_I8 :
33 case nsXPTType::T_I16 :
34 case nsXPTType::T_I32 :
35 result++;
36 break;
37 case nsXPTType::T_I64 :
38 result+=2;
39 break;
40 case nsXPTType::T_U8 :
41 case nsXPTType::T_U16 :
42 case nsXPTType::T_U32 :
43 result++;
44 break;
45 case nsXPTType::T_U64 :
46 result+=2;
47 break;
48 case nsXPTType::T_FLOAT :
49 result++;
50 break;
51 case nsXPTType::T_DOUBLE :
52 result+=2;
53 break;
54 case nsXPTType::T_BOOL :
55 case nsXPTType::T_CHAR :
56 case nsXPTType::T_WCHAR :
57 result++;
58 break;
59 default:
60 // all the others are plain pointer types
61 result++;
62 break;
63 }
64 }
65 // nuts, I know there's a cooler way of doing this, but it's late
66 // now and it'll probably come to me in the morning.
67 if (result & 0x3) result += 4 - (result & 0x3); // ensure q-word alignment
68 return result;
69 }
70
71 extern "C" uint32_t
invoke_copy_to_stack(uint32_t * d,uint32_t paramCount,nsXPTCVariant * s)72 invoke_copy_to_stack(uint32_t* d, uint32_t paramCount, nsXPTCVariant* s)
73 {
74 /*
75 We need to copy the parameters for this function to locals and use them
76 from there since the parameters occupy the same stack space as the stack
77 we're trying to populate.
78 */
79 uint32_t *l_d = d;
80 nsXPTCVariant *l_s = s;
81 uint32_t l_paramCount = paramCount;
82 uint32_t regCount = 0; // return the number of registers to load from the stack
83
84 typedef struct {
85 uint32_t hi;
86 uint32_t lo;
87 } DU; // have to move 64 bit entities as 32 bit halves since
88 // stack slots are not guaranteed 16 byte aligned
89
90 for(uint32_t i = 0; i < l_paramCount; i++, l_d++, l_s++)
91 {
92 if (regCount < 5) regCount++;
93 if(l_s->IsPtrData())
94 {
95 if(l_s->type == nsXPTType::T_JSVAL)
96 {
97 // On SPARC, we need to pass a pointer to HandleValue
98 *((void**)l_d) = &l_s->ptr;
99 } else
100 {
101 *((void**)l_d) = l_s->ptr;
102 }
103 continue;
104 }
105 switch(l_s->type)
106 {
107 case nsXPTType::T_I8 : *((int32_t*) l_d) = l_s->val.i8; break;
108 case nsXPTType::T_I16 : *((int32_t*) l_d) = l_s->val.i16; break;
109 case nsXPTType::T_I32 : *((int32_t*) l_d) = l_s->val.i32; break;
110 case nsXPTType::T_I64 :
111 case nsXPTType::T_U64 :
112 case nsXPTType::T_DOUBLE : *((uint32_t*) l_d++) = ((DU *)l_s)->hi;
113 if (regCount < 5) regCount++;
114 *((uint32_t*) l_d) = ((DU *)l_s)->lo;
115 break;
116 case nsXPTType::T_U8 : *((uint32_t*) l_d) = l_s->val.u8; break;
117 case nsXPTType::T_U16 : *((uint32_t*) l_d) = l_s->val.u16; break;
118 case nsXPTType::T_U32 : *((uint32_t*) l_d) = l_s->val.u32; break;
119 case nsXPTType::T_FLOAT : *((float*) l_d) = l_s->val.f; break;
120 case nsXPTType::T_BOOL : *((uint32_t*) l_d) = l_s->val.b; break;
121 case nsXPTType::T_CHAR : *((uint32_t*) l_d) = l_s->val.c; break;
122 case nsXPTType::T_WCHAR : *((int32_t*) l_d) = l_s->val.wc; break;
123 default:
124 // all the others are plain pointer types
125 *((void**)l_d) = l_s->val.p;
126 break;
127 }
128 }
129 return regCount;
130 }
131
132