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