1*d2748020SPedro Giffuni !\**************************************************************
2*d2748020SPedro Giffuni ! *
3*d2748020SPedro Giffuni ! * Licensed to the Apache Software Foundation (ASF) under one
4*d2748020SPedro Giffuni ! * or more contributor license agreements.  See the NOTICE file
5*d2748020SPedro Giffuni ! * distributed with this work for additional information
6*d2748020SPedro Giffuni ! * regarding copyright ownership.  The ASF licenses this file
7*d2748020SPedro Giffuni ! * to you under the Apache License, Version 2.0 (the
8*d2748020SPedro Giffuni ! * "License"); you may not use this file except in compliance
9*d2748020SPedro Giffuni ! * with the License.  You may obtain a copy of the License at
10*d2748020SPedro Giffuni ! *
11*d2748020SPedro Giffuni ! *   http://www.apache.org/licenses/LICENSE-2.0
12*d2748020SPedro Giffuni ! *
13*d2748020SPedro Giffuni ! * Unless required by applicable law or agreed to in writing,
14*d2748020SPedro Giffuni ! * software distributed under the License is distributed on an
15*d2748020SPedro Giffuni ! * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d2748020SPedro Giffuni ! * KIND, either express or implied.  See the License for the
17*d2748020SPedro Giffuni ! * specific language governing permissions and limitations
18*d2748020SPedro Giffuni ! * under the License.
19*d2748020SPedro Giffuni ! *
20*d2748020SPedro Giffuni ! *************************************************************/
21b5da552cSAndrew Rist 
22cdf0e10cSrcweir .global privateSnippetExecutor
23cdf0e10cSrcweir .type privateSnippetExecutor,2
24cdf0e10cSrcweir privateSnippetExecutor:
25cdf0e10cSrcweir 		! save %sp, -96, %sp  already done in code snippet
26cdf0e10cSrcweir 		st %i0, [%fp+68]
27cdf0e10cSrcweir 		st %i1, [%fp+72]
28cdf0e10cSrcweir 		st %i2, [%fp+76]
29cdf0e10cSrcweir 		st %i3, [%fp+80]
30cdf0e10cSrcweir 		st %i4, [%fp+84]
31cdf0e10cSrcweir 		st %i5, [%fp+88]
32cdf0e10cSrcweir 		! %o0: functionIndex, stored by code snippet
33cdf0e10cSrcweir 		! %o1: vtableOffset, stored by code snippet
34cdf0e10cSrcweir 		call cpp_vtable_call
35cdf0e10cSrcweir 		add %fp, 68, %o2
36cdf0e10cSrcweir .privateSnippetExecutorExceptionPosition:
37cdf0e10cSrcweir 		subcc %o0, 11, %g0
38cdf0e10cSrcweir 		be .double
39cdf0e10cSrcweir 		subcc %o0, 10, %g0
40cdf0e10cSrcweir 		be .float
41cdf0e10cSrcweir 		ld [%fp+72], %i0
42cdf0e10cSrcweir 		ld [%fp+76], %i1
43cdf0e10cSrcweir 		ret
44cdf0e10cSrcweir 		restore
45cdf0e10cSrcweir .double:
46cdf0e10cSrcweir 		ldd [%fp+72], %f0
47cdf0e10cSrcweir 		ret
48cdf0e10cSrcweir 		restore
49cdf0e10cSrcweir .float:
50cdf0e10cSrcweir 		ld [%fp+72], %f0
51cdf0e10cSrcweir 		ret
52cdf0e10cSrcweir 		restore
53cdf0e10cSrcweir .size privateSnippetExecutor,(.-privateSnippetExecutor)
54cdf0e10cSrcweir .align 8
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
57cdf0e10cSrcweir .global callVirtualMethod
58cdf0e10cSrcweir .type callVirtualMethod,2
59cdf0e10cSrcweir callVirtualMethod:
60cdf0e10cSrcweir 		! allocate FIRST stack to have own local registers
61cdf0e10cSrcweir 		sethi		 %hi(-96), %g1
62cdf0e10cSrcweir 		or		 %g1, %lo(-96), %g1
63cdf0e10cSrcweir 		subcc		 %g1, %o5, %g1
64cdf0e10cSrcweir 		subcc		 %g1, %o5, %g1
65cdf0e10cSrcweir 		subcc		 %g1, %o5, %g1
66cdf0e10cSrcweir 		subcc		 %g1, %o5, %g1
67cdf0e10cSrcweir 		save		%sp, %g1, %sp
68cdf0e10cSrcweir 		! copy stack longs if necessary
69cdf0e10cSrcweir 		subcc		%i5, 6, %l5
70cdf0e10cSrcweir 		ble		.copyRegisters
71cdf0e10cSrcweir 		nop
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 		! prepare source location
74cdf0e10cSrcweir 		add		%i4, 24, %l4
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 		! prepare real stack
77cdf0e10cSrcweir 		add		%sp, 92, %l3
78cdf0e10cSrcweir 
79cdf0e10cSrcweir .copyLong:
80cdf0e10cSrcweir 		ld		[%l4+0], %l0
81cdf0e10cSrcweir 		st		%l0, [%l3]
82cdf0e10cSrcweir 		add		%l4, 4, %l4
83cdf0e10cSrcweir 		add		%l3, 4, %l3
84cdf0e10cSrcweir 		deccc		%l5
85cdf0e10cSrcweir 		bne		.copyLong
86cdf0e10cSrcweir 		nop
87cdf0e10cSrcweir .copyRegisters:
88cdf0e10cSrcweir 		mov		%i5, %l5
89cdf0e10cSrcweir 		mov		%i4, %l4
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 		ld		[%l4], %o0
92cdf0e10cSrcweir 		add		%l4, 4, %l4
93cdf0e10cSrcweir 		deccc		%l5
94cdf0e10cSrcweir 		ble		.doCall
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		ld		[%l4], %o1
97cdf0e10cSrcweir 		add		%l4, 4, %l4
98cdf0e10cSrcweir 		deccc		%l5
99cdf0e10cSrcweir 		ble		.doCall
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 		ld		[%l4], %o2
102cdf0e10cSrcweir 		add		%l4, 4, %l4
103cdf0e10cSrcweir 		deccc		%l5
104cdf0e10cSrcweir 		ble		.doCall
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 		ld			[%l4], %o3
107cdf0e10cSrcweir 		add		%l4, 4, %l4
108cdf0e10cSrcweir 		deccc		%l5
109cdf0e10cSrcweir 		ble		.doCall
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 		ld			[%l4], %o4
112cdf0e10cSrcweir 		add		%l4, 4, %l4
113cdf0e10cSrcweir 		deccc		%l5
114cdf0e10cSrcweir 		ble		.doCall
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		ld			[%l4], %o5
117cdf0e10cSrcweir 		add		%l4, 4, %l4
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 		! prepare complex return pointer
120cdf0e10cSrcweir 		st			%i2, [%sp+64]
121cdf0e10cSrcweir .doCall:
122cdf0e10cSrcweir 		! get virtual table entry
123cdf0e10cSrcweir 		mov		%i1, %l1
124cdf0e10cSrcweir 		add		%l1, 2, %l1
125cdf0e10cSrcweir 		sll		%l1, 2, %l1
126cdf0e10cSrcweir 		ld			[%i0], %l3
127cdf0e10cSrcweir 		add		%l3, %l1, %l1
128cdf0e10cSrcweir 		ld			[%l1], %l0
129cdf0e10cSrcweir 		jmpl		%l0,%o7
130cdf0e10cSrcweir 		nop
131cdf0e10cSrcweir .callVirtualMethodExceptionPosition:
132cdf0e10cSrcweir 		! handle returns
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 		!byte types
135cdf0e10cSrcweir 		subcc %i3, 2, %l3		! typelib_TypeClass_BOOLEAN
136cdf0e10cSrcweir 		be .handleByte
137cdf0e10cSrcweir 		subcc %i3, 3, %l3		! typelib_TypeClass_BYTE
138cdf0e10cSrcweir 		be .handleByte
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 		! half word types
141cdf0e10cSrcweir 		subcc %i3, 4, %l3		! typelib_TypeClass_SHORT
142cdf0e10cSrcweir 		be .handleShort
143cdf0e10cSrcweir 		subcc %i3, 5, %l3		! typelib_TypeClass_UNSIGNED_SHORT
144cdf0e10cSrcweir 		be .handleShort
145cdf0e10cSrcweir 		subcc %i3, 1, %l3		! typelib_TypeClass_CHAR (sal_Unicode==sal_uInt16)
146cdf0e10cSrcweir 		be .handleShort
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 		! word types
149cdf0e10cSrcweir 		subcc %i3, 6, %l3		! typelib_TypeClass_LONG
150cdf0e10cSrcweir 		be .handleWord
151cdf0e10cSrcweir 		subcc %i3, 7, %l3		! typelib_TypeClass_UNSIGNED_LONG
152cdf0e10cSrcweir 		be .handleWord
153cdf0e10cSrcweir 		subcc %i3, 15, %l3	! typelib_TypeClass_ENUM
154cdf0e10cSrcweir 		be .handleWord
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		! double word types
157cdf0e10cSrcweir 		subcc %i3, 8, %l3		! typelib_TypeClass_HYPER
158cdf0e10cSrcweir 		be .handleDoubleWord
159cdf0e10cSrcweir 		subcc %i3, 9, %l3		! typelib_TypeClass_UNSIGNED_HYPER
160cdf0e10cSrcweir 		be .handleDoubleWord
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 		! float
163cdf0e10cSrcweir 		subcc %i3, 10, %l3	! typelib_TypeClass_FLOAT
164cdf0e10cSrcweir 		be .handleFloat
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 		! double
167cdf0e10cSrcweir 		subcc %i3, 11, %l3	! typelib_TypeClass_DOUBLE
168cdf0e10cSrcweir 		be .handleDouble
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 		! default: return void
171cdf0e10cSrcweir 		nop					! empty prefetch
172cdf0e10cSrcweir 		ba .doRestore
173cdf0e10cSrcweir 		nop
174cdf0e10cSrcweir .handleByte:
175cdf0e10cSrcweir 		stb %o0, [%i2]
176cdf0e10cSrcweir 		ba .doRestore
177cdf0e10cSrcweir 		nop
178cdf0e10cSrcweir .handleShort:
179cdf0e10cSrcweir 		sth %o0, [%i2]
180cdf0e10cSrcweir 		ba .doRestore
181cdf0e10cSrcweir 		nop
182cdf0e10cSrcweir .handleWord:
183cdf0e10cSrcweir 		st %o0, [%i2]
184cdf0e10cSrcweir 		ba .doRestore
185cdf0e10cSrcweir 		nop
186cdf0e10cSrcweir .handleDoubleWord:
187cdf0e10cSrcweir 		st %o0, [%i2]
188cdf0e10cSrcweir 		st %o1, [%i2+4]
189cdf0e10cSrcweir 		ba .doRestore
190cdf0e10cSrcweir 		nop
191cdf0e10cSrcweir .handleFloat:
192cdf0e10cSrcweir 		st %f0, [%i2]
193cdf0e10cSrcweir 		ba .doRestore
194cdf0e10cSrcweir 		nop
195cdf0e10cSrcweir .handleDouble:
196cdf0e10cSrcweir 		std %f0, [%fp-8]
197cdf0e10cSrcweir 		ldd [%fp-8], %o0
198cdf0e10cSrcweir 		st %o0, [%i2]
199cdf0e10cSrcweir 		st %o1, [%i2+4]
200cdf0e10cSrcweir 		ba .doRestore
201cdf0e10cSrcweir 		nop
202cdf0e10cSrcweir .doRestore:
203cdf0e10cSrcweir 		ret
204cdf0e10cSrcweir 		restore	! stack frame for own locals
205cdf0e10cSrcweir .size callVirtualMethod,(.-callVirtualMethod)
206cdf0e10cSrcweir .align 8
207cdf0e10cSrcweir 
208cdf0e10cSrcweir .rethrow_handler:
209cdf0e10cSrcweir 		call	__1cG__CrunMex_rethrow_q6F_v_
210cdf0e10cSrcweir 		nop
211cdf0e10cSrcweir 
212cdf0e10cSrcweir .section	".exception_ranges",#alloc
213cdf0e10cSrcweir .word		%r_disp32(.privateSnippetExecutorExceptionPosition)
214cdf0e10cSrcweir .word		0
215cdf0e10cSrcweir .word		.rethrow_handler-.privateSnippetExecutorExceptionPosition
216cdf0e10cSrcweir .word		0,0
217cdf0e10cSrcweir .word		%r_disp32(.callVirtualMethodExceptionPosition)
218cdf0e10cSrcweir .word		0
219cdf0e10cSrcweir .word		.rethrow_handler-.callVirtualMethodExceptionPosition
220cdf0e10cSrcweir .word		0,0
221