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"
33 #include "vm/jit/sparc64/offsets.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) *
70 * If the java method is throwing an exception, NULL will be returned.
73 * java_objectheader *asm_vm_call_method(methodinfo *m, s4 vmargscount,
75 **************************************************************************/
77 .align 8 /* v9: All data types are aligned to their size */
79 .xword 0 /* catch type all */
80 .xword 0 /* handler pc */
82 .xword 0 /* start pc */
83 .word 1 /* extable size */
84 .word 0 /* ALIGNMENT PADDING */
85 .xword 0 /* line number table start */
86 .xword 0 /* line number table size */
87 .word 0 /* ALIGNMENT PADDING */
92 .word 0 /* frame size */
93 .xword 0 /* method pointer (pointer to name)*/
96 asm_vm_call_method_int:
97 asm_vm_call_method_long:
98 asm_vm_call_method_float:
99 asm_vm_call_method_double:
101 save %sp,-((JITSTACK_CNT+2)*8),%sp
102 add %sp,JITSTACK,%l1 /* pointer to usable stack */
105 /* i1: ptr to arg array */
106 /* i2: num stackargs */
120 brlez %i2, calljava_nocopy
121 nop /* delay: fill me! */
123 sllx %i2,3,%l0 /* remaining args * 8 */
124 sub %sp,%l0,%sp /* allocate more stack space */
125 add %sp,JITSTACK,%l1 /* adjust stack begin pointer */
127 asm_vm_call_copyloop:
128 ldx [%i1+10*8],%l0 /* load argument from array */
129 stx %l0,[%l1] /* store argument to stack */
131 inc 8,%i1 /* src++ */
132 subcc %i2,1,%i2 /* arg_count-- */
133 bnz %xcc, asm_vm_call_copyloop /* use cc from previous instr */
134 inc 8,%l1 /* dst++ (delay) */
138 /* set pv, like a java method does */
139 setx asm_vm_call_method,%l0,pv_callee
141 stx %i0,[%l1 + 1*8] /* store PV on stack */
142 mov %l1,mptr_itmp2 /* set address of PV (-1*8) */
144 ldx [1*8 + mptr_itmp2], pv_caller /* load PV from stack */
145 jmpl pv_caller,ra_caller /* method call as in Java */
149 /* pretend to restore pv */
150 add ra_caller,(asm_vm_call_method - calljava_jit2 + 8),zero
153 mov %o0, %i0 /* pass on the return value */
154 return %i7 + 8 /* implicit window restore */
158 asm_vm_call_method_exception_handler:
160 /* so far this function did not call any c functions */
161 /* but now we need ABI compliant argslots on the stack */
165 call builtin_throw_exception
167 return %i7 + 8 /* implicit window restore */
168 asm_vm_call_method_end:
169 mov zero,%o0 /* delay: return NULL */
173 /****************** function asm_call_jit_compiler *****************************
175 * invokes the compiler for untranslated JavaVM methods. *
177 * Register R0 contains a pointer to the method info structure (prepared *
178 * by createcompilerstub). Using the return address in R26 and the *
179 * offset in the LDA instruction or using the value in methodptr R28 the *
180 * patching address for storing the method address can be computed: *
182 * method address was either loaded using *
183 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special ($27) *
184 * M_LDA (REG_PV, REG_RA, low) *
185 * M_LDAH(REG_PV, REG_RA, high) ; optional *
187 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28) *
188 * in the static case the method pointer can be computed using the *
189 * return address and the lda function following the jmp instruction *
191 *******************************************************************************/
193 asm_call_jit_compiler:
195 /* stacksave for regsave(16) + argslots(6) + float args */
196 /* Note: +1 to keep stack 16-byte aligned */
197 save %sp,-((16+6+FLT_ARG_CNT+1)*8),%sp
199 SAVE_FLOAT_ARGUMENT_REGISTERS(22)
201 mov itmp1,%o0 /* pass methodinfo pointer */
202 mov mptr_itmp2,%o1 /* pass method pointer */
203 mov %fp,%o2 /* pass java sp (==fp) */
204 mov ra_callee,%o3 /* pass Java ra */
205 mov %o3,%o4 /* xpc is equal to ra */
206 call jit_asm_compile /* call jit compiler */
209 RESTORE_FLOAT_ARGUMENT_REGISTERS(22)
211 brz %o0,L_asm_call_jit_compiler_exception
214 restore %o0,%g0,pv_caller /* restore the callers window */
215 /* the source o0 references the old window */
216 /* pv_caller references the new window */
219 /* synchronise instruction cache moved somewhere else */
221 jmpl pv_caller,zero /* and call method, the method returns */
222 /* directly to the caller (ra). */
225 L_asm_call_jit_compiler_exception:
226 /* window still open, ra_callee valid, pv_callee undefined */
228 call exceptions_get_and_clear_exception
231 mov %o0,xptr_itmp2 /* get exception */
232 mov ra_callee,xpc_itmp3 /* exception address is address of call */
234 /* restore the window of the calling function */
237 b L_asm_handle_nat_exception
242 /* asm_handle_exception ********************************************************
244 This function handles an exception. It does not use the usual calling
245 conventions. The exception pointer is passed in REG_ITMP2 and the
246 pc from the exception raising position is passed in REG_ITMP3. It searches
247 the local exception table for a handler. If no one is found, it unwinds
248 stacks and continues searching the callers.
250 *******************************************************************************/
253 asm_handle_nat_exception:
254 L_asm_handle_nat_exception: /* required for PIC code */
255 L_asm_handle_exception_stack_loop:
256 /* exception handling assumes that the current java method saved */
257 /* the caller's window, and has a valid pv */
259 /* get ra and pv before saving the window */
264 mov xptr_itmp2,%l0 /* save exception pointer */
265 mov xpc_itmp3,%l1 /* save exception pc */
266 mov zero,%l2 /* save maybe-leaf flag (cleared) */
268 mov %l0,%o0 /* pass xptr */
269 mov %l1,%o1 /* pass xpc */
270 mov %g4,%o2 /* pass PV */
271 mov %fp,%o3 /* pass Java SP */
273 b L_asm_handle_exception_continue
276 asm_handle_exception:
279 /* save bigger stack frame for float args and temps */
280 save %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+16+CSTACK_CNT)*8),%sp
282 SAVE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT)
283 SAVE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+FLT_ARG_CNT)
285 mov xptr_itmp2,%l0 /* save exception pointer */
286 add zero,1,%l2 /* set maybe-leaf flag */
288 mov %l0,%o0 /* pass xptr */
289 mov xpc_itmp3,%o1 /* pass xpc */
290 mov %g4,%o2 /* pass PV */
291 mov %fp,%o3 /* pass Java SP */
293 L_asm_handle_exception_continue:
294 call exceptions_handle_exception
297 brz %o0,L_asm_handle_exception_not_caught
300 mov %o0,xpc_itmp3 /* move handlerpc into xpc */
301 mov %l0,xptr_itmp2 /* restore exception pointer */
303 brz %l2,L_asm_handle_exception_no_leaf
306 RESTORE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT)
307 RESTORE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+FLT_ARG_CNT)
309 L_asm_handle_exception_no_leaf:
310 /* restore java window and stackframe (ra and pv are in there) */
312 jmpl xpc_itmp3, zero /* jump to the handler */
315 L_asm_handle_exception_not_caught:
316 mov %l0,xptr_itmp2 /* restore xptr */
317 restore /* free our stackframe and window */
318 /* maybe leaf flag gets cleared after branch to _loop */
320 restore /* unwind stack and window */
321 ba L_asm_handle_exception_stack_loop
322 mov ra_caller,xpc_itmp3 /* the new xpc is ra (delay) */
327 /* asm_abstractmethoderror *****************************************************
329 Creates and throws an AbstractMethodError.
331 *******************************************************************************/
333 asm_abstractmethoderror:
334 /* do a window save */
337 mov %fp,%o0 /* pass java sp(==fp) */
338 mov ra_callee,%o1 /* pass exception address */
339 call exceptions_asm_new_abstractmethoderror
342 mov %o0,xptr_itmp2 /* get exception pointer */
343 sub ra_callee,4,xpc_itmp3 /* exception address is ra - 4 */
344 ba L_asm_handle_nat_exception
347 /* XXX: leave the register window open for handle_exception ??? */
349 /* asm_patcher_wrapper *********************************************************
353 Stack layout, when called from patcher stub
354 40 return address into JIT code (patch position)
355 32 pointer to virtual java_objectheader
356 24 machine code (which is patched back later)
357 16 unresolved class/method/field reference
358 8 data segment displacement from load instructions
359 0 patcher function pointer to call
360 -128 WINSAVE REGS (current SP)
362 *******************************************************************************/
366 /* get pv and ra, since the emit code is not passing it on */
367 mov ra_callee,ra_caller
368 mov pv_callee,pv_caller
370 /* create window and stack frame */
371 save %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+16+CSTACK_CNT+6)*8),%sp
373 SAVE_FLOAT_RETURN_REGISTER(CSTACK_CNT)
374 SAVE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT+1)
375 SAVE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+1+FLT_ARG_CNT)
377 mov itmp1,%l0 /* save itmp1 */
378 mov itmp2,%l1 /* save itmp2 */
380 add %fp,JITSTACK,%o0 /* pass pseudo SP */
381 mov pv_callee,%o1 /* pass PV */
382 mov ra_callee,%o2 /* pass RA (correct for leafs) */
386 RESTORE_FLOAT_RETURN_REGISTER(CSTACK_CNT)
387 RESTORE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT+1)
388 RESTORE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+1+FLT_ARG_CNT)
390 mov %l0,itmp1 /* restore itmp1 */
391 mov %l1,itmp2 /* restore itmp2 */
393 brnz %o0,L_asm_patcher_wrapper_exception
396 /* load RA (patch position from patcher data on the stack */
397 ldx [%fp+JITSTACK+5*8],itmp3
399 /* remove window and stack frame (and stack space allocated in the stub code */
400 restore %fp,6*8,%sp /* (source regs refer to old window, rd to new window) */
402 jmpl itmp3,zero /* jump to newly patched code */
405 L_asm_patcher_wrapper_exception:
406 mov %o0,xptr_itmp2 /* get exception */
407 ldx [%fp+JITSTACK+5*8],xpc_itmp3 /* xpc is RA */
408 restore %fp,6*8,%sp /* remove stack frame */
409 ba asm_handle_exception
414 /* asm_store_fp_state_reg **************************************************
416 * This function stores the 64-bit floating point state register to a *
417 * memory location. (which needs to be 8-byte aligned) *
420 * void asm_store_fp_state_reg(u8 *mem); *
422 **************************************************************************/
424 asm_store_fp_state_reg:
426 retl /* return from leaf */
429 /* asm_load_fp_state_reg ***************************************************
431 * This function loades the 64-bit floating point state register from a *
432 * memory location. (which needs to be 8-byte aligned) *
435 * void asm_load_fp_state_reg(u8 *mem); *
437 **************************************************************************/
439 asm_load_fp_state_reg:
441 retl /* return from leaf */
447 asm_getclassvalues_atomic:
450 /* not doing a window save, using the global temporary registers */
451 ldsw [offbaseval+%o0],itmp1
452 ldsw [offdiffval+%o0],itmp2
453 ldsw [offbaseval+%o1],itmp3
455 stw itmp1,[offcast_super_baseval+%o2]
456 stw itmp2,[offcast_super_diffval+%o2]
457 stw itmp3,[offcast_sub_baseval+%o2]
458 jmpl ra_caller+8,zero /* caller's ra, b/c no window save */
464 asm_criticalsections:
465 #if defined(ENABLE_THREADS)
473 /* disable exec-stacks ********************************************************/
475 #if defined(__linux__) && defined(__ELF__)
476 .section .note.GNU-stack,"",%progbits
481 * These are local overrides for various environment variables in Emacs.
482 * Please do not remove this and leave it at the end of the file, where
483 * Emacs will automagically detect them.
484 * ---------------------------------------------------------------------
487 * indent-tabs-mode: t
491 * vim:noexpandtab:sw=4:ts=4: