1 /* src/vm/jit/sparc64/asmpart.S - Java-C interface functions for Sparc
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Andreas Krall
33 $Id: asmpart.S 4749 2006-04-11 10:20:18Z twisti $
42 .register %g2,#scratch /* define as scratch */
43 .register %g3,#scratch /* XXX reserve for application */
46 /* export functions ***********************************************************/
48 .global asm_vm_call_method
49 .global asm_vm_call_method_int
50 .global asm_vm_call_method_long
51 .global asm_vm_call_method_float
52 .global asm_vm_call_method_double
53 .global asm_vm_call_method_exception_handler
55 .global asm_call_jit_compiler
57 .global asm_handle_exception
58 .global asm_handle_nat_exception
61 .global asm_abstractmethoderror
63 .global asm_criticalsections
64 .global asm_getclassvalues_atomic
67 /* asm_vm_call_method ******************************************************
69 * This function calls a Java-method (which possibly needs compilation) *
72 * java_objectheader *asm_vm_call_method(methodinfo *m, s4 vmargscount,
74 **************************************************************************/
76 .align 8 /* v9: All data types are aligned to their size */
78 .xword 0 /* catch type all */
79 .xword 0 /* handler pc */
81 .xword 0 /* start pc */
82 .word 1 /* extable size */
83 .word 0 /* ALIGNMENT PADDING */
84 .xword 0 /* line number table start */
85 .xword 0 /* line number table size */
86 .word 0 /* ALIGNMENT PADDING */
91 .word 0 /* frame size */
92 .xword 0 /* method pointer (pointer to name)*/
95 asm_vm_call_method_int:
96 asm_vm_call_method_long:
97 asm_vm_call_method_float:
98 asm_vm_call_method_double:
100 save %sp, -144, %sp /* 16 reg-save + 2 */
103 /* todo: copy fp registers */
105 brlez %i1, calljava_argsloaded
107 ldx [%i2 + offvmargdata], %o0
108 brlez %i1, calljava_argsloaded
111 ldx [%i2 + (offvmargdata+sizevmarg*1)], %o1
112 brlez %i1, calljava_argsloaded
115 ldx [%i2 + (offvmargdata+sizevmarg*2)], %o2
116 brlez %i1, calljava_argsloaded
119 ldx [%i2 + (offvmargdata+sizevmarg*3)], %o3
120 brlez %i1, calljava_argsloaded
123 ldx [%i2 + (offvmargdata+sizevmarg*4)], %o4
125 /* todo: use more out registers ? */
128 /* todo: stack frame layout!! */
130 brlez %i1, calljava_nocopy
131 sllx %i1, 3, %l0 /* remaining args * 8 */
132 mov %sp, %l1 /* right above window save area */
133 sub %sp, %l0, %sp /* allocate more stack space */
136 ldx [%i2 + (offvmargdata+sizevmarg*5)], %l0
138 inc sizevmarg, %i2 /* src++ */
139 inc 8, %l1 /* dst++ */
140 dec %i1 /* arg_count-- */
141 bnz %xcc, calljava_copyloop
145 mov %i0,itmp1 /* pass method info pointer via itmp1 */
147 setx asm_call_jit_compiler,%l0,mptr_itmp2 /* fake virtual function call (2 instr) */
148 stx mptr_itmp2,[%sp + 2047 + 17*8] /* store function address */
149 add %sp,2047 + 16*8,mptr_itmp2 /* set method pointer */
151 ldx [1*8 + mptr_itmp2], pv_caller /* method call as in Java */
152 jmpl pv_caller,ra_caller /* call JIT compiler */
155 /* pretend to restore pv */
156 add ra_caller,(asm_vm_call_method - calljava_jit2 + 8),pv_callee
159 mov %o0, %i0 /* pass on the return value */
160 return %i7 + 8 /* implicit window restore */
164 asm_vm_call_method_exception_handler:
166 call builtin_throw_exception
167 return %i7 + 8 /* implicit window restore */
172 /****************** function asm_call_jit_compiler *****************************
174 * invokes the compiler for untranslated JavaVM methods. *
176 * Register R0 contains a pointer to the method info structure (prepared *
177 * by createcompilerstub). Using the return address in R26 and the *
178 * offset in the LDA instruction or using the value in methodptr R28 the *
179 * patching address for storing the method address can be computed: *
181 * method address was either loaded using *
182 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special ($27) *
183 * M_LDA (REG_PV, REG_RA, low) *
184 * M_LDAH(REG_PV, REG_RA, high) ; optional *
186 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28) *
187 * in the static case the method pointer can be computed using the *
188 * return address and the lda function following the jmp instruction *
190 *******************************************************************************/
192 asm_call_jit_compiler:
194 save %sp,-160,%sp /* regsave + 4 slots for float args */
196 SAVE_FLOAT_ARGUMENT_REGISTERS(16)
198 mov itmp1,%o0 /* pass methodinfo pointer */
199 mov mptr_itmp2,%o1 /* pass method pointer */
200 mov %fp,%o2 /* pass java sp (==fp) */
201 mov ra_callee,%o3 /* pass Java ra */
202 mov %o3,%o4 /* xpc is equal to ra */
203 call jit_asm_compile /* call jit compiler */
206 RESTORE_FLOAT_ARGUMENT_REGISTERS(16)
208 restore %o0,%g0,pv_caller /* restore the callers window */
209 /* the source o0 references the old window */
210 /* pv_caller references the new window */
214 brz pv_caller,L_asm_call_jit_compiler_exception
216 /* synchronise instruction cache moved somewhere else */
218 jmpl pv_caller,zero /* and call method, the method returns */
219 /* directly to the caller (ra). */
221 L_asm_call_jit_compiler_exception:
222 /* no need to do a save, only ra needs to be preserved */
224 /* we save ra in one of the application globals */
225 mov ra_caller,xpc_itmp3 /* save return address (xpc) */
227 call exceptions_get_and_clear_exception
229 mov xpc_itmp3,ra_caller /* restore return address (xpc) */
231 mov %o0,xptr_itmp2 /* get exception */
232 sub ra_caller,4,xpc_itmp3 /* exception address is ra - 4 */
233 ba L_asm_handle_nat_exception
237 /* asm_handle_exception ********************************************************
239 This function handles an exception. It does not use the usual calling
240 conventions. The exception pointer is passed in REG_ITMP2 and the
241 pc from the exception raising position is passed in REG_ITMP3. It searches
242 the local exception table for a handler. If no one is found, it unwinds
243 stacks and continues searching the callers.
245 *******************************************************************************/
248 asm_handle_nat_exception:
249 L_asm_handle_nat_exception: /* required for PIC code */
250 asm_handle_exception:
257 /* asm_abstractmethoderror *****************************************************
259 Creates and throws an AbstractMethodError.
261 *******************************************************************************/
263 asm_abstractmethoderror:
264 /* do a window save */
267 mov %fp,%o0 /* pass java sp(==fp) */
268 mov ra_callee,%o1 /* pass exception address */
269 call exceptions_asm_new_abstractmethoderror
271 mov %o0,xptr_itmp2 /* get exception pointer */
272 sub ra_callee,4,xpc_itmp3 /* exception address is ra - 4 */
273 ba L_asm_handle_nat_exception
275 /* XXX: leave the register window open for handle_exception ??? */
277 asm_getclassvalues_atomic:
280 /* not doing a window save, using the global temporary registers */
281 ldsw [offbaseval+%o0],itmp1
282 ldsw [offdiffval+%o0],itmp2
283 ldsw [offbaseval+%o1],itmp3
285 stw itmp1,[offcast_super_baseval+%o2]
286 stw itmp2,[offcast_super_diffval+%o2]
287 stw itmp3,[offcast_sub_baseval+%o2]
288 jmpl ra_caller,zero /* caller's ra, b/c no window save */
290 .end asm_getclassvalues_atomic
295 asm_criticalsections:
296 #if defined(ENABLE_THREADS)