1 /* src/vm/jit/alpha/asmpart.S - Java-C interface functions for alpha
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
30 #include "vm/jit/alpha/md-abi.h"
31 #include "vm/jit/alpha/md-asm.h"
33 #include "vm/jit/abi-asm.h"
34 #include "vm/jit/methodheader.h"
42 /* export functions ***********************************************************/
44 .globl asm_vm_call_method
45 .globl asm_vm_call_method_int
46 .globl asm_vm_call_method_long
47 .globl asm_vm_call_method_float
48 .globl asm_vm_call_method_double
49 .globl asm_vm_call_method_exception_handler
50 .globl asm_vm_call_method_end
52 .globl asm_call_jit_compiler
54 .globl asm_handle_exception
55 .globl asm_handle_nat_exception
57 .globl asm_abstractmethoderror
59 .globl asm_compare_and_swap
60 .globl asm_memory_barrier
66 /* asm_vm_call_method **********************************************************
68 * This function calls a Java-method (which possibly needs compilation) *
69 * with up to 4 address parameters. *
71 * This functions calls the JIT-compiler which eventually translates the *
72 * method into machine code. *
75 * javaobject_header *asm_calljavafunction (methodinfo *m, *
76 * void *arg1, void *arg2, void *arg3, void *arg4); *
78 *******************************************************************************/
80 .ent asm_vm_call_method
84 .quad 0 /* catch type all */
85 .quad 0 /* handler pc */
87 .quad 0 /* start pc */
88 .long 1 /* extable size */
89 .long 0 /* ALIGNMENT PADDING */
90 .quad 0 /* line number table start */
91 .quad 0 /* line number table size */
92 .long 0 /* ALIGNMENT PADDING */
97 .long 0 /* frame size */
98 .quad 0 /* codeinfo pointer */
101 asm_vm_call_method_int:
102 asm_vm_call_method_long:
103 asm_vm_call_method_float:
104 asm_vm_call_method_double:
106 lda sp,-5*8(sp) /* allocate stack space */
107 stq ra,0*8(sp) /* save return address */
108 stq gp,1*8(sp) /* save global pointer */
111 stq a0,4*8(sp) /* save method PV */
113 mov a1,t0 /* address of argument array */
114 mov a2,t1 /* stack argument count */
115 mov sp,s0 /* save stack pointer */
131 beq t1,L_asm_vm_call_method_stack_copy_done
133 negq t1,t2 /* calculate stackframe size (* 8) */
134 s8addq t2,sp,sp /* create stackframe */
135 mov sp,t2 /* temporary stack pointer */
137 L_asm_vm_call_method_stack_copy_loop:
138 ldq t3,12*8(t0) /* load argument */
139 stq t3,0(t2) /* store argument on stack */
141 subq t1,1,t1 /* subtract 1 argument */
142 addq t0,8,t0 /* load address of next argument */
143 addq t2,8,t2 /* increase stack pointer */
145 bgt t1,L_asm_vm_call_method_stack_copy_loop
147 L_asm_vm_call_method_stack_copy_done:
148 lda mptr,4*8(s0) /* get address of PV */
149 ldq pv,0*8(mptr) /* load PV */
151 L_asm_vm_call_method_recompute_pv:
152 lda pv,(asm_vm_call_method - L_asm_vm_call_method_recompute_pv)(ra)
154 mov s0,sp /* restore stack pointer */
156 L_asm_vm_call_method_recompute_return:
157 ldq ra,0*8(sp) /* restore RA */
158 ldq gp,1*8(sp) /* restore global pointer */
161 lda sp,5*8(sp) /* free stack space */
164 asm_vm_call_method_exception_handler:
165 mov s0,sp /* restore stack pointer */
166 ldq gp,1*8(sp) /* restore global pointer */
168 jsr ra,builtin_throw_exception
170 asm_vm_call_method_end:
171 br L_asm_vm_call_method_recompute_return
173 .end asm_vm_call_method
176 /* asm_call_jit_compiler *******************************************************
178 Invokes the compiler for untranslated Java methods.
180 *******************************************************************************/
182 .ent asm_call_jit_compiler
184 asm_call_jit_compiler:
186 lda sp,-(ARG_CNT+2)*8(sp) /* +2: keep stack 16-byte aligned */
188 stq ra,0*8(sp) /* save return address */
190 SAVE_ARGUMENT_REGISTERS(1) /* save 6 int/6 float argument registers */
192 mov itmp1,a0 /* pass methodinfo pointer */
193 mov mptr,a1 /* pass method pointer */
194 lda a2,(ARG_CNT+2)*8(sp) /* pass java sp */
196 jsr ra,jit_asm_compile /* call jit compiler */
199 ldq ra,0*8(sp) /* load return address */
201 RESTORE_ARGUMENT_REGISTERS(1) /* restore 6 int/6 float argument registers */
203 lda sp,(ARG_CNT+2)*8(sp) /* remove stack frame */
205 beq pv,L_asm_call_jit_compiler_exception
207 jmp zero,(pv) /* and call method, the method returns */
208 /* directly to the caller (ra). */
210 L_asm_call_jit_compiler_exception:
212 stq ra,0*8(sp) /* save return address (xpc) */
213 jsr ra,exceptions_get_and_clear_exception
214 ldq ra,0*8(sp) /* restore return address (xpc) */
217 mov v0,xptr /* get exception */
218 subq ra,4,xpc /* exception address is ra - 4 */
219 br L_asm_handle_nat_exception
221 .end asm_call_jit_compiler
224 /* asm_handle_exception ********************************************************
226 This function handles an exception. It does not use the usual calling
227 conventions. The exception pointer is passed in REG_ITMP1 and the
228 pc from the exception raising position is passed in REG_ITMP2. It searches
229 the local exception table for a handler. If no one is found, it unwinds
230 stacks and continues searching the callers.
232 ATTENTION: itmp3 == gp!
234 *******************************************************************************/
236 .ent asm_handle_nat_exception
238 asm_handle_nat_exception:
239 L_asm_handle_nat_exception: /* required for PIC code */
240 L_asm_handle_exception_stack_loop:
241 lda sp,-6*8(sp) /* keep stack 16-byte aligned */
242 stq xptr,0*8(sp) /* save xptr */
243 stq xpc,1*8(sp) /* save xpc */
244 stq ra,3*8(sp) /* save RA */
245 stq zero,4*8(sp) /* save maybe-leaf flag (cleared) */
247 mov ra,a0 /* pass RA */
249 br ra,L_asm_handle_exception_load_gp
250 L_asm_handle_exception_load_gp:
251 ldgp gp,0(ra) /* load gp */
253 jsr ra,md_codegen_get_pv_from_pc/* get PV from RA */
254 stq v0,2*8(sp) /* save PV */
256 ldq a0,0*8(sp) /* pass xptr */
257 ldq a1,1*8(sp) /* pass xpc */
258 mov v0,a2 /* pass PV */
259 addq sp,6*8,a3 /* pass Java SP */
261 br L_asm_handle_exception_continue
263 .aent asm_handle_exception
265 asm_handle_exception:
266 L_asm_handle_exception: /* required for PIC code */
267 lda sp,-(ARG_CNT+TMP_CNT)*8(sp) /* create maybe-leaf stackframe */
269 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
270 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
272 lda sp,-6*8(sp) /* keep stack 16-byte aligned */
273 stq xptr,0*8(sp) /* save xptr */
274 stq pv,2*8(sp) /* save PV */
275 stq ra,3*8(sp) /* save RA */
276 lda t0,1(zero) /* set maybe-leaf flag */
277 stq t0,4*8(sp) /* save maybe-leaf flag */
279 br ra,L_asm_handle_exception_load_gp_2
280 L_asm_handle_exception_load_gp_2:
281 ldgp gp,0(ra) /* load gp */
283 mov xptr,a0 /* pass xptr */
284 mov xpc,a1 /* pass xpc */
285 mov pv,a2 /* pass PV */
286 lda a3,(ARG_CNT+TMP_CNT+6)*8(sp)/* pass Java SP */
288 L_asm_handle_exception_continue:
289 jsr ra,exceptions_handle_exception
291 beq v0,L_asm_handle_exception_not_catched
293 mov v0,xpc /* move handlerpc into xpc */
294 ldq xptr,0*8(sp) /* restore xptr */
295 ldq pv,2*8(sp) /* restore PV */
296 ldq ra,3*8(sp) /* restore RA */
297 ldq t0,4*8(sp) /* get maybe-leaf flag */
298 lda sp,6*8(sp) /* free stack frame */
300 beq t0,L_asm_handle_exception_no_leaf
302 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
303 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
305 lda sp,(ARG_CNT+TMP_CNT)*8(sp) /* remove maybe-leaf stackframe */
307 L_asm_handle_exception_no_leaf:
308 jmp zero,(xpc) /* jump to the handler */
310 L_asm_handle_exception_not_catched:
311 ldq xptr,0*8(sp) /* restore xptr */
312 ldq pv,2*8(sp) /* restore PV */
313 ldq ra,3*8(sp) /* restore RA */
314 ldq t0,4*8(sp) /* get maybe-leaf flag */
317 beq t0,L_asm_handle_exception_no_leaf_stack
319 lda sp,(ARG_CNT+TMP_CNT)*8(sp) /* remove maybe-leaf stackframe */
320 mov zero,t0 /* clear the maybe-leaf flag */
322 L_asm_handle_exception_no_leaf_stack:
323 ldl t1,FrameSize(pv) /* get frame size */
324 addq t1,sp,t1 /* pointer to save area */
326 ldl t2,IsLeaf(pv) /* is leaf procedure */
327 bne t2,L_asm_handle_exception_no_ra_restore
329 ldq ra,-1*8(t1) /* restore ra */
330 subq t1,8,t1 /* t1-- */
332 L_asm_handle_exception_no_ra_restore:
333 mov ra,xpc /* the new xpc is ra */
334 ldl t2,IntSave(pv) /* t2 = saved int register count */
335 br t3,ex_int1 /* t3 = current pc */
337 lda t3,(ex_int2 - ex_int1)(t3)
338 negl t2,t2 /* negate register count */
339 s4addq t2,t3,t3 /* t2 = IntSave - register count * 4 */
340 jmp zero,(t3) /* jump to save position */
351 s8addq t2,t1,t1 /* t1 = t1 - 8 * register count */
353 ldl t2,FltSave(pv) /* t2 = saved flt register count */
354 br t3,ex_flt1 /* t3 = current pc */
356 lda t3,(ex_flt2 - ex_flt1)(t3)
357 negl t2,t2 /* negate register count */
358 s4addq t2,t3,t3 /* t2 = FltSave - 4 * register count */
359 jmp zero,(t3) /* jump to save position */
371 ldl t1,FrameSize(pv) /* get frame size */
372 addq sp,t1,sp /* unwind stack */
373 br L_asm_handle_exception_stack_loop
375 .end asm_handle_nat_exception
378 /* asm_abstractmethoderror *****************************************************
380 Creates and throws an AbstractMethodError.
382 *******************************************************************************/
384 .ent asm_abstractmethoderror
386 asm_abstractmethoderror:
387 subq sp,2*8,sp /* create stackframe */
388 stq ra,0*8(sp) /* save return address */
389 addq sp,2*8,a0 /* pass java sp */
390 mov ra,a1 /* pass exception address */
391 jsr ra,exceptions_asm_new_abstractmethoderror
392 ldq ra,0*8(sp) /* restore return address */
393 addq sp,2*8,sp /* remove stackframe */
395 mov v0,xptr /* get exception pointer */
396 subq ra,4,xpc /* exception address is ra - 4 */
397 br L_asm_handle_nat_exception
399 .end asm_abstractmethoderror
402 /* asm_compare_and_swap ********************************************************
404 Does an atomic compare and swap. Required for the lock
407 Atomically do the following: Check if the location still contains
408 `oldval`. If so, replace it by `newval` and return `oldval`.
413 long compare_and_swap(volatile long *p, long oldval, long newval);
415 *******************************************************************************/
417 .ent asm_compare_and_swap
419 asm_compare_and_swap:
430 .end asm_compare_and_swap
433 /* asm_memory_barrier **********************************************************
435 A memory barrier for the Java Memory Model.
437 *******************************************************************************/
439 .ent asm_memory_barrier
445 .end asm_memory_barrier
448 /* asm_md_init *****************************************************************
450 Initialize machine dependent stuff.
452 Determines if the byte support instruction set (21164a and higher)
455 *******************************************************************************/
460 .long 0x47e03c20 /* amask 1,v0 */
461 jmp zero,(ra) /* return */
466 /* asm_cacheflush **************************************************************
470 *******************************************************************************/
475 call_pal PAL_imb /* synchronize instruction cache */
481 /* disable exec-stacks ********************************************************/
483 #if defined(__linux__) && defined(__ELF__)
484 .section .note.GNU-stack,"",%progbits
489 * These are local overrides for various environment variables in Emacs.
490 * Please do not remove this and leave it at the end of the file, where
491 * Emacs will automagically detect them.
492 * ---------------------------------------------------------------------
495 * indent-tabs-mode: t
499 * vim:noexpandtab:sw=4:ts=4: