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_handle_exception
53 .globl asm_handle_nat_exception
55 .globl asm_abstractmethoderror
57 .globl asm_compare_and_swap
58 .globl asm_memory_barrier
64 /* asm_vm_call_method **********************************************************
66 * This function calls a Java-method (which possibly needs compilation) *
67 * with up to 4 address parameters. *
69 * This functions calls the JIT-compiler which eventually translates the *
70 * method into machine code. *
73 * javaobject_header *asm_calljavafunction (methodinfo *m, *
74 * void *arg1, void *arg2, void *arg3, void *arg4); *
76 *******************************************************************************/
78 .ent asm_vm_call_method
82 .quad 0 /* catch type all */
83 .quad 0 /* handler pc */
85 .quad 0 /* start pc */
86 .long 1 /* extable size */
87 .long 0 /* ALIGNMENT PADDING */
88 .quad 0 /* line number table start */
89 .quad 0 /* line number table size */
90 .long 0 /* ALIGNMENT PADDING */
95 .long 0 /* frame size */
96 .quad 0 /* codeinfo pointer */
99 asm_vm_call_method_int:
100 asm_vm_call_method_long:
101 asm_vm_call_method_float:
102 asm_vm_call_method_double:
104 lda sp,-5*8(sp) /* allocate stack space */
105 stq ra,0*8(sp) /* save return address */
106 stq gp,1*8(sp) /* save global pointer */
109 stq a0,4*8(sp) /* save method PV */
111 mov a1,t0 /* address of argument array */
112 mov a2,t1 /* stack argument count */
113 mov sp,s0 /* save stack pointer */
129 beq t1,L_asm_vm_call_method_stack_copy_done
131 negq t1,t2 /* calculate stackframe size (* 8) */
132 s8addq t2,sp,sp /* create stackframe */
133 mov sp,t2 /* temporary stack pointer */
135 L_asm_vm_call_method_stack_copy_loop:
136 ldq t3,12*8(t0) /* load argument */
137 stq t3,0(t2) /* store argument on stack */
139 subq t1,1,t1 /* subtract 1 argument */
140 addq t0,8,t0 /* load address of next argument */
141 addq t2,8,t2 /* increase stack pointer */
143 bgt t1,L_asm_vm_call_method_stack_copy_loop
145 L_asm_vm_call_method_stack_copy_done:
146 lda mptr,4*8(s0) /* get address of PV */
147 ldq pv,0*8(mptr) /* load PV */
149 L_asm_vm_call_method_recompute_pv:
150 lda pv,(asm_vm_call_method - L_asm_vm_call_method_recompute_pv)(ra)
152 mov s0,sp /* restore stack pointer */
154 L_asm_vm_call_method_recompute_return:
155 ldq ra,0*8(sp) /* restore RA */
156 ldq gp,1*8(sp) /* restore global pointer */
159 lda sp,5*8(sp) /* free stack space */
162 asm_vm_call_method_exception_handler:
163 mov s0,sp /* restore stack pointer */
164 ldq gp,1*8(sp) /* restore global pointer */
166 jsr ra,builtin_throw_exception
168 asm_vm_call_method_end:
169 br L_asm_vm_call_method_recompute_return
171 .end asm_vm_call_method
174 /* asm_handle_exception ********************************************************
176 This function handles an exception. It does not use the usual calling
177 conventions. The exception pointer is passed in REG_ITMP1 and the
178 pc from the exception raising position is passed in REG_ITMP2. It searches
179 the local exception table for a handler. If no one is found, it unwinds
180 stacks and continues searching the callers.
182 ATTENTION: itmp3 == gp!
184 *******************************************************************************/
186 .ent asm_handle_nat_exception
188 asm_handle_nat_exception:
189 L_asm_handle_nat_exception: /* required for PIC code */
190 L_asm_handle_exception_stack_loop:
191 lda sp,-6*8(sp) /* keep stack 16-byte aligned */
192 stq xptr,0*8(sp) /* save xptr */
193 stq xpc,1*8(sp) /* save xpc */
194 stq ra,3*8(sp) /* save RA */
195 stq zero,4*8(sp) /* save maybe-leaf flag (cleared) */
197 mov ra,a0 /* pass RA */
199 br ra,L_asm_handle_exception_load_gp
200 L_asm_handle_exception_load_gp:
201 ldgp gp,0(ra) /* load gp */
203 jsr ra,md_codegen_get_pv_from_pc/* get PV from RA */
204 stq v0,2*8(sp) /* save PV */
206 ldq a0,0*8(sp) /* pass xptr */
207 ldq a1,1*8(sp) /* pass xpc */
208 mov v0,a2 /* pass PV */
209 addq sp,6*8,a3 /* pass Java SP */
211 br L_asm_handle_exception_continue
213 .aent asm_handle_exception
215 asm_handle_exception:
216 L_asm_handle_exception: /* required for PIC code */
217 lda sp,-(ARG_CNT+TMP_CNT)*8(sp) /* create maybe-leaf stackframe */
219 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
220 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
222 lda sp,-6*8(sp) /* keep stack 16-byte aligned */
223 stq xptr,0*8(sp) /* save xptr */
224 stq pv,2*8(sp) /* save PV */
225 stq ra,3*8(sp) /* save RA */
226 lda t0,1(zero) /* set maybe-leaf flag */
227 stq t0,4*8(sp) /* save maybe-leaf flag */
229 br ra,L_asm_handle_exception_load_gp_2
230 L_asm_handle_exception_load_gp_2:
231 ldgp gp,0(ra) /* load gp */
233 mov xptr,a0 /* pass xptr */
234 mov xpc,a1 /* pass xpc */
235 mov pv,a2 /* pass PV */
236 lda a3,(ARG_CNT+TMP_CNT+6)*8(sp)/* pass Java SP */
238 L_asm_handle_exception_continue:
239 jsr ra,exceptions_handle_exception
241 beq v0,L_asm_handle_exception_not_catched
243 mov v0,xpc /* move handlerpc into xpc */
244 ldq xptr,0*8(sp) /* restore xptr */
245 ldq pv,2*8(sp) /* restore PV */
246 ldq ra,3*8(sp) /* restore RA */
247 ldq t0,4*8(sp) /* get maybe-leaf flag */
248 lda sp,6*8(sp) /* free stack frame */
250 beq t0,L_asm_handle_exception_no_leaf
252 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
253 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
255 lda sp,(ARG_CNT+TMP_CNT)*8(sp) /* remove maybe-leaf stackframe */
257 L_asm_handle_exception_no_leaf:
258 jmp zero,(xpc) /* jump to the handler */
260 L_asm_handle_exception_not_catched:
261 ldq xptr,0*8(sp) /* restore xptr */
262 ldq pv,2*8(sp) /* restore PV */
263 ldq ra,3*8(sp) /* restore RA */
264 ldq t0,4*8(sp) /* get maybe-leaf flag */
267 beq t0,L_asm_handle_exception_no_leaf_stack
269 lda sp,(ARG_CNT+TMP_CNT)*8(sp) /* remove maybe-leaf stackframe */
270 mov zero,t0 /* clear the maybe-leaf flag */
272 L_asm_handle_exception_no_leaf_stack:
273 ldl t1,FrameSize(pv) /* get frame size */
274 addq t1,sp,t1 /* pointer to save area */
276 ldl t2,IsLeaf(pv) /* is leaf procedure */
277 bne t2,L_asm_handle_exception_no_ra_restore
279 ldq ra,-1*8(t1) /* restore ra */
280 subq t1,8,t1 /* t1-- */
282 L_asm_handle_exception_no_ra_restore:
283 mov ra,xpc /* the new xpc is ra */
284 ldl t2,IntSave(pv) /* t2 = saved int register count */
285 br t3,ex_int1 /* t3 = current pc */
287 lda t3,(ex_int2 - ex_int1)(t3)
288 negl t2,t2 /* negate register count */
289 s4addq t2,t3,t3 /* t2 = IntSave - register count * 4 */
290 jmp zero,(t3) /* jump to save position */
301 s8addq t2,t1,t1 /* t1 = t1 - 8 * register count */
303 ldl t2,FltSave(pv) /* t2 = saved flt register count */
304 br t3,ex_flt1 /* t3 = current pc */
306 lda t3,(ex_flt2 - ex_flt1)(t3)
307 negl t2,t2 /* negate register count */
308 s4addq t2,t3,t3 /* t2 = FltSave - 4 * register count */
309 jmp zero,(t3) /* jump to save position */
321 ldl t1,FrameSize(pv) /* get frame size */
322 addq sp,t1,sp /* unwind stack */
323 br L_asm_handle_exception_stack_loop
325 .end asm_handle_nat_exception
328 /* asm_abstractmethoderror *****************************************************
330 Creates and throws an AbstractMethodError.
332 *******************************************************************************/
334 .ent asm_abstractmethoderror
336 asm_abstractmethoderror:
337 subq sp,2*8,sp /* create stackframe */
338 stq ra,0*8(sp) /* save return address */
339 addq sp,2*8,a0 /* pass java sp */
340 mov ra,a1 /* pass exception address */
341 jsr ra,exceptions_asm_new_abstractmethoderror
342 ldq ra,0*8(sp) /* restore return address */
343 addq sp,2*8,sp /* remove stackframe */
345 mov v0,xptr /* get exception pointer */
346 subq ra,4,xpc /* exception address is ra - 4 */
347 br L_asm_handle_nat_exception
349 .end asm_abstractmethoderror
352 /* asm_compare_and_swap ********************************************************
354 Does an atomic compare and swap. Required for the lock
357 Atomically do the following: Check if the location still contains
358 `oldval`. If so, replace it by `newval` and return `oldval`.
363 long compare_and_swap(volatile long *p, long oldval, long newval);
365 *******************************************************************************/
367 .ent asm_compare_and_swap
369 asm_compare_and_swap:
380 .end asm_compare_and_swap
383 /* asm_memory_barrier **********************************************************
385 A memory barrier for the Java Memory Model.
387 *******************************************************************************/
389 .ent asm_memory_barrier
395 .end asm_memory_barrier
398 /* asm_md_init *****************************************************************
400 Initialize machine dependent stuff.
402 Determines if the byte support instruction set (21164a and higher)
405 *******************************************************************************/
410 .long 0x47e03c20 /* amask 1,v0 */
411 jmp zero,(ra) /* return */
416 /* asm_cacheflush **************************************************************
420 *******************************************************************************/
425 call_pal PAL_imb /* synchronize instruction cache */
431 /* disable exec-stacks ********************************************************/
433 #if defined(__linux__) && defined(__ELF__)
434 .section .note.GNU-stack,"",%progbits
439 * These are local overrides for various environment variables in Emacs.
440 * Please do not remove this and leave it at the end of the file, where
441 * Emacs will automagically detect them.
442 * ---------------------------------------------------------------------
445 * indent-tabs-mode: t
449 * vim:noexpandtab:sw=4:ts=4: