1 /* src/vm/jit/sparc64/asmpart.S - Java-C interface functions for Sparc64
3 Copyright (C) 1996-2005, 2006, 2007 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 $Id: asmpart.S 4749 2006-04-11 10:20:18Z twisti $
32 #include "vm/jit/sparc64/md-abi.h"
36 .register %g2,#scratch /* define as scratch */
37 .register %g3,#scratch /* XXX reserve for application */
40 /* export functions ***********************************************************/
42 .global asm_vm_call_method
43 .global asm_vm_call_method_int
44 .global asm_vm_call_method_long
45 .global asm_vm_call_method_float
46 .global asm_vm_call_method_double
47 .global asm_vm_call_method_exception_handler
48 .global asm_vm_call_method_end
50 .global asm_call_jit_compiler
52 .global asm_handle_exception
53 .global asm_handle_nat_exception
55 .global asm_patcher_wrapper
57 .global asm_abstractmethoderror
59 .global asm_criticalsections
60 .global asm_getclassvalues_atomic
62 .global asm_store_fp_state_reg
63 .global asm_load_fp_state_reg
66 /* asm_vm_call_method ******************************************************
68 * This function calls a Java-method (which possibly needs compilation) *
71 * java_objectheader *asm_vm_call_method(methodinfo *m, s4 vmargscount,
73 **************************************************************************/
75 .align 8 /* v9: All data types are aligned to their size */
77 .xword 0 /* catch type all */
78 .xword 0 /* handler pc */
80 .xword 0 /* start pc */
81 .word 1 /* extable size */
82 .word 0 /* ALIGNMENT PADDING */
83 .xword 0 /* line number table start */
84 .xword 0 /* line number table size */
85 .word 0 /* ALIGNMENT PADDING */
90 .word 0 /* frame size */
91 .xword 0 /* method pointer (pointer to name)*/
94 asm_vm_call_method_int:
95 asm_vm_call_method_long:
96 asm_vm_call_method_float:
97 asm_vm_call_method_double:
99 save %sp,-((JITSTACK_CNT+2)*8),%sp
100 add %sp,JITSTACK,%l1 /* right above window save area */
103 /* %i1 not needed after _nocopy -> calculate in branch delay */
105 brlez %i1, calljava_nocopy
107 dec %i1 /* branch delay */
108 ldx [%i2 + offvmargdata],%o0
109 ldd [%i2 + offvmargdata],fa0
110 brlez %i1,calljava_nocopy
112 dec %i1 /* branch delay */
113 ldx [%i2 + (offvmargdata+sizevmarg*1)],%o1
114 ldd [%i2 + (offvmargdata+sizevmarg*1)],fa1
115 brlez %i1,calljava_nocopy
118 ldx [%i2 + (offvmargdata+sizevmarg*2)],%o2
119 ldd [%i2 + (offvmargdata+sizevmarg*2)],fa2
120 brlez %i1,calljava_nocopy
123 ldx [%i2 + (offvmargdata+sizevmarg*3)],%o3
124 ldd [%i2 + (offvmargdata+sizevmarg*3)],fa3
125 brlez %i1,calljava_nocopy
128 ldx [%i2 + (offvmargdata+sizevmarg*4)],%o4
129 ldd [%i2 + (offvmargdata+sizevmarg*4)],fa4
132 brlez %i1, calljava_nocopy
134 sllx %i1,3,%l0 /* remaining args * 8 */
135 sub %sp,%l0,%sp /* allocate more stack space */
136 add %sp,JITSTACK,%l1 /* adjust stack begin pointer */
139 ldx [%i2 + (offvmargdata+sizevmarg*5)],%l0
141 inc sizevmarg,%i2 /* src++ */
142 subcc %i1,1,%i1 /* arg_count-- */
143 bnz %xcc, calljava_copyloop /* use cc from previous instr */
144 inc 8,%l1 /* dst++ (delay) */
148 /* set pv, like a java method does */
149 /* add ra_caller,(asm_vm_call_method - calljava_nocopy + 8),pv_callee */
150 setx asm_vm_call_method,%l0,pv_callee
152 mov %i0,itmp1 /* pass method info pointer via itmp1 */
154 setx asm_call_jit_compiler,%l0,mptr_itmp2 /* fake virtual function call (2 instr) */
155 stx mptr_itmp2,[%l1 + 1*8] /* store function address */
156 mov %l1,mptr_itmp2 /* set method pointer */
158 ldx [1*8 + mptr_itmp2], pv_caller /* method call as in Java */
159 jmpl pv_caller,ra_caller /* call JIT compiler */
162 /* pretend to restore pv */
163 add ra_caller,(asm_vm_call_method - calljava_jit2 + 8),zero
166 mov %o0, %i0 /* pass on the return value */
167 return %i7 + 8 /* implicit window restore */
171 asm_vm_call_method_exception_handler:
173 /* so far this function did not call any c functions */
174 /* but now we need ABI compliant argslots on the stack */
178 call builtin_throw_exception
180 return %i7 + 8 /* implicit window restore */
181 asm_vm_call_method_end:
186 /****************** function asm_call_jit_compiler *****************************
188 * invokes the compiler for untranslated JavaVM methods. *
190 * Register R0 contains a pointer to the method info structure (prepared *
191 * by createcompilerstub). Using the return address in R26 and the *
192 * offset in the LDA instruction or using the value in methodptr R28 the *
193 * patching address for storing the method address can be computed: *
195 * method address was either loaded using *
196 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special ($27) *
197 * M_LDA (REG_PV, REG_RA, low) *
198 * M_LDAH(REG_PV, REG_RA, high) ; optional *
200 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28) *
201 * in the static case the method pointer can be computed using the *
202 * return address and the lda function following the jmp instruction *
204 *******************************************************************************/
206 asm_call_jit_compiler:
208 /* stacksave for regsave(16) + argslots(6) + float args */
209 /* Note: +1 to keep stack 16-byte aligned */
210 save %sp,-((16+6+FLT_ARG_CNT+1)*8),%sp
212 SAVE_FLOAT_ARGUMENT_REGISTERS(22)
214 mov itmp1,%o0 /* pass methodinfo pointer */
215 mov mptr_itmp2,%o1 /* pass method pointer */
216 mov %fp,%o2 /* pass java sp (==fp) */
217 mov ra_callee,%o3 /* pass Java ra */
218 mov %o3,%o4 /* xpc is equal to ra */
219 call jit_asm_compile /* call jit compiler */
222 RESTORE_FLOAT_ARGUMENT_REGISTERS(22)
224 brz %o0,L_asm_call_jit_compiler_exception
227 restore %o0,%g0,pv_caller /* restore the callers window */
228 /* the source o0 references the old window */
229 /* pv_caller references the new window */
232 /* synchronise instruction cache moved somewhere else */
234 jmpl pv_caller,zero /* and call method, the method returns */
235 /* directly to the caller (ra). */
238 L_asm_call_jit_compiler_exception:
239 /* window still open, ra_callee valid, pv_callee undefined */
241 call exceptions_get_and_clear_exception
244 mov %o0,xptr_itmp2 /* get exception */
245 mov ra_callee,xpc_itmp3 /* exception address is address of call */
247 /* restore the window of the calling function */
250 b L_asm_handle_nat_exception
255 /* asm_handle_exception ********************************************************
257 This function handles an exception. It does not use the usual calling
258 conventions. The exception pointer is passed in REG_ITMP2 and the
259 pc from the exception raising position is passed in REG_ITMP3. It searches
260 the local exception table for a handler. If no one is found, it unwinds
261 stacks and continues searching the callers.
263 *******************************************************************************/
266 asm_handle_nat_exception:
267 L_asm_handle_nat_exception: /* required for PIC code */
268 L_asm_handle_exception_stack_loop:
269 /* exception handling assumes that the current java method saved */
270 /* the caller's window, and has a valid pv */
272 /* get ra and pv before saving the window */
277 mov xptr_itmp2,%l0 /* save exception pointer */
278 mov xpc_itmp3,%l1 /* save exception pc */
279 mov zero,%l2 /* save maybe-leaf flag (cleared) */
281 mov %l0,%o0 /* pass xptr */
282 mov %l1,%o1 /* pass xpc */
283 mov %g4,%o2 /* pass PV */
284 mov %fp,%o3 /* pass Java SP */
286 b L_asm_handle_exception_continue
289 asm_handle_exception:
292 /* save bigger stack frame for float args and temps */
293 save %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+CSTACK_CNT)*8),%sp
295 SAVE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT)
296 SAVE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+FLT_ARG_CNT)
298 mov xptr_itmp2,%l0 /* save exception pointer */
299 add zero,1,%l2 /* set maybe-leaf flag */
301 mov %l0,%o0 /* pass xptr */
302 mov xpc_itmp3,%o1 /* pass xpc */
303 mov %g4,%o2 /* pass PV */
304 mov %fp,%o3 /* pass Java SP */
306 L_asm_handle_exception_continue:
307 call exceptions_handle_exception
310 brz %o0,L_asm_handle_exception_not_caught
313 mov %o0,xpc_itmp3 /* move handlerpc into xpc */
314 mov %l0,xptr_itmp2 /* restore exception pointer */
316 brz %l2,L_asm_handle_exception_no_leaf
319 RESTORE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT)
320 RESTORE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+FLT_ARG_CNT)
322 L_asm_handle_exception_no_leaf:
323 /* restore java window and stackframe (ra and pv are in there) */
325 jmpl xpc_itmp3, zero /* jump to the handler */
328 L_asm_handle_exception_not_caught:
329 mov %l0,xptr_itmp2 /* restore xptr */
330 restore /* free our stackframe and window */
331 /* maybe leaf flag gets cleared after branch to _loop */
333 restore /* unwind stack and window */
334 ba L_asm_handle_exception_stack_loop
335 mov ra_caller,xpc_itmp3 /* the new xpc is ra (delay) */
340 /* asm_abstractmethoderror *****************************************************
342 Creates and throws an AbstractMethodError.
344 *******************************************************************************/
346 asm_abstractmethoderror:
347 /* do a window save */
350 mov %fp,%o0 /* pass java sp(==fp) */
351 mov ra_callee,%o1 /* pass exception address */
352 call exceptions_asm_new_abstractmethoderror
355 mov %o0,xptr_itmp2 /* get exception pointer */
356 sub ra_callee,4,xpc_itmp3 /* exception address is ra - 4 */
357 ba L_asm_handle_nat_exception
360 /* XXX: leave the register window open for handle_exception ??? */
362 /* asm_patcher_wrapper *********************************************************
366 Stack layout, when called from patcher stub
367 40 return address into JIT code (patch position)
368 32 pointer to virtual java_objectheader
369 24 machine code (which is patched back later)
370 16 unresolved class/method/field reference
371 8 data segment displacement from load instructions
372 0 patcher function pointer to call
373 -128 WINSAVE REGS (current SP)
375 *******************************************************************************/
379 /* get pv and ra, since the emit code is not passing it on */
380 mov ra_callee,ra_caller
381 mov pv_callee,pv_caller
383 /* create window and stack frame */
384 save %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+CSTACK_CNT+4)*8),%sp
386 SAVE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT)
387 SAVE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+FLT_ARG_CNT)
389 mov itmp1,%l0 /* save itmp1 */
390 mov itmp2,%l1 /* save itmp2 */
392 add %fp,JITSTACK,%o0 /* pass pseudo SP */
393 mov pv_callee,%o1 /* pass PV */
394 mov ra_callee,%o2 /* pass RA (correct for leafs) */
398 RESTORE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT)
399 RESTORE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+FLT_ARG_CNT)
401 mov %l0,itmp1 /* restore itmp1 */
402 mov %l1,itmp2 /* restore itmp2 */
404 brnz %o0,L_asm_patcher_wrapper_exception
407 /* load RA (patch position from patcher data on the stack */
408 ldx [%fp+JITSTACK+5*8],itmp3
410 /* remove window and stack frame (and stack space allocated in the stub code */
411 restore %fp,6*8,%sp /* (source regs refer to old window, rd to new window) */
413 jmpl itmp3,zero /* jump to newly patched code */
416 L_asm_patcher_wrapper_exception:
417 mov %o0,xptr_itmp2 /* get exception */
418 ldx [%fp+JITSTACK+5*8],xpc_itmp3 /* xpc is RA */
419 restore %fp,6*8,%sp /* remove stack frame */
420 ba asm_handle_exception
425 /* asm_store_fp_state_reg **************************************************
427 * This function stores the 64-bit floating point state register to a *
428 * memory location. (which needs to be 8-byte aligned) *
431 * void asm_store_fp_state_reg(u8 *mem); *
433 **************************************************************************/
435 asm_store_fp_state_reg:
437 retl /* return from leaf */
440 /* asm_load_fp_state_reg ***************************************************
442 * This function loades the 64-bit floating point state register from a *
443 * memory location. (which needs to be 8-byte aligned) *
446 * void asm_load_fp_state_reg(u8 *mem); *
448 **************************************************************************/
450 asm_load_fp_state_reg:
452 retl /* return from leaf */
458 asm_getclassvalues_atomic:
461 /* not doing a window save, using the global temporary registers */
462 ldsw [offbaseval+%o0],itmp1
463 ldsw [offdiffval+%o0],itmp2
464 ldsw [offbaseval+%o1],itmp3
466 stw itmp1,[offcast_super_baseval+%o2]
467 stw itmp2,[offcast_super_diffval+%o2]
468 stw itmp3,[offcast_sub_baseval+%o2]
469 jmpl ra_caller+8,zero /* caller's ra, b/c no window save */
475 asm_criticalsections:
476 #if defined(ENABLE_THREADS)
484 /* disable exec-stacks ********************************************************/
486 #if defined(__linux__) && defined(__ELF__)
487 .section .note.GNU-stack,"",%progbits
492 * These are local overrides for various environment variables in Emacs.
493 * Please do not remove this and leave it at the end of the file, where
494 * Emacs will automagically detect them.
495 * ---------------------------------------------------------------------
498 * indent-tabs-mode: t
502 * vim:noexpandtab:sw=4:ts=4: