1 /* src/vm/jit/alpha/asmpart.S - Java-C interface functions for alpha
3 Copyright (C) 1996-2005, 2006, 2007, 2008 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
61 /* asm_vm_call_method **********************************************************
63 * This function calls a Java-method (which possibly needs compilation) *
64 * with up to 4 address parameters. *
66 * This functions calls the JIT-compiler which eventually translates the *
67 * method into machine code. *
70 * javaobject_header *asm_calljavafunction (methodinfo *m, *
71 * void *arg1, void *arg2, void *arg3, void *arg4); *
73 *******************************************************************************/
75 .ent asm_vm_call_method
82 .long 0 /* frame size */
83 .quad 0 /* codeinfo pointer */
86 asm_vm_call_method_int:
87 asm_vm_call_method_long:
88 asm_vm_call_method_float:
89 asm_vm_call_method_double:
91 lda sp,-5*8(sp) /* allocate stack space */
92 stq ra,0*8(sp) /* save return address */
93 stq gp,1*8(sp) /* save global pointer */
96 stq a0,4*8(sp) /* save method PV */
98 mov a1,t0 /* address of argument array */
99 mov a2,t1 /* stack argument count */
100 mov sp,s0 /* save stack pointer */
116 beq t1,L_asm_vm_call_method_stack_copy_done
118 negq t1,t2 /* calculate stackframe size (* 8) */
119 s8addq t2,sp,sp /* create stackframe */
120 mov sp,t2 /* temporary stack pointer */
122 L_asm_vm_call_method_stack_copy_loop:
123 ldq t3,12*8(t0) /* load argument */
124 stq t3,0(t2) /* store argument on stack */
126 subq t1,1,t1 /* subtract 1 argument */
127 addq t0,8,t0 /* load address of next argument */
128 addq t2,8,t2 /* increase stack pointer */
130 bgt t1,L_asm_vm_call_method_stack_copy_loop
132 L_asm_vm_call_method_stack_copy_done:
133 lda mptr,4*8(s0) /* get address of PV */
134 ldq pv,0*8(mptr) /* load PV */
136 L_asm_vm_call_method_recompute_pv:
137 lda pv,(asm_vm_call_method - L_asm_vm_call_method_recompute_pv)(ra)
139 L_asm_vm_call_method_recompute_return:
140 mov s0,sp /* restore stack pointer */
142 ldq ra,0*8(sp) /* restore RA */
143 ldq gp,1*8(sp) /* restore global pointer */
146 lda sp,5*8(sp) /* free stack space */
149 asm_vm_call_method_exception_handler:
150 mov s0,sp /* restore stack pointer */
151 ldq gp,1*8(sp) /* restore global pointer */
153 jsr ra,builtin_throw_exception
155 asm_vm_call_method_end:
156 br L_asm_vm_call_method_recompute_return
158 .end asm_vm_call_method
161 /* asm_handle_exception ********************************************************
163 This function handles an exception. It does not use the usual calling
164 conventions. The exception pointer is passed in REG_ITMP1 and the
165 pc from the exception raising position is passed in REG_ITMP2. It searches
166 the local exception table for a handler. If no one is found, it unwinds
167 stacks and continues searching the callers.
169 ATTENTION: itmp3 == gp!
171 *******************************************************************************/
173 .ent asm_handle_nat_exception
175 asm_handle_nat_exception:
176 L_asm_handle_nat_exception: /* required for PIC code */
177 L_asm_handle_exception_stack_loop:
178 lda sp,-6*8(sp) /* keep stack 16-byte aligned */
179 stq xptr,0*8(sp) /* save xptr */
180 stq xpc,1*8(sp) /* save xpc */
181 stq ra,3*8(sp) /* save RA */
182 stq zero,4*8(sp) /* save maybe-leaf flag (cleared) */
184 mov ra,a0 /* pass RA */
186 br ra,L_asm_handle_exception_load_gp
187 L_asm_handle_exception_load_gp:
188 ldgp gp,0(ra) /* load gp */
190 jsr ra,md_asm_codegen_get_pv_from_pc /* get PV from RA */
191 stq v0,2*8(sp) /* save PV */
193 ldq a0,0*8(sp) /* pass xptr */
194 ldq a1,1*8(sp) /* pass xpc */
195 mov v0,a2 /* pass PV */
196 addq sp,6*8,a3 /* pass Java SP */
198 br L_asm_handle_exception_continue
200 .aent asm_handle_exception
202 asm_handle_exception:
203 L_asm_handle_exception: /* required for PIC code */
204 lda sp,-(ARG_CNT+TMP_CNT)*8(sp) /* create maybe-leaf stackframe */
206 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
207 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
209 lda sp,-6*8(sp) /* keep stack 16-byte aligned */
210 stq xptr,0*8(sp) /* save xptr */
211 stq pv,2*8(sp) /* save PV */
212 stq ra,3*8(sp) /* save RA */
213 lda t0,1(zero) /* set maybe-leaf flag */
214 stq t0,4*8(sp) /* save maybe-leaf flag */
216 br ra,L_asm_handle_exception_load_gp_2
217 L_asm_handle_exception_load_gp_2:
218 ldgp gp,0(ra) /* load gp */
220 mov xptr,a0 /* pass xptr */
221 mov xpc,a1 /* pass xpc */
222 mov pv,a2 /* pass PV */
223 lda a3,(ARG_CNT+TMP_CNT+6)*8(sp)/* pass Java SP */
225 L_asm_handle_exception_continue:
226 jsr ra,exceptions_handle_exception
228 beq v0,L_asm_handle_exception_not_catched
230 mov v0,xpc /* move handlerpc into xpc */
231 ldq xptr,0*8(sp) /* restore xptr */
232 ldq pv,2*8(sp) /* restore PV */
233 ldq ra,3*8(sp) /* restore RA */
234 ldq t0,4*8(sp) /* get maybe-leaf flag */
235 lda sp,6*8(sp) /* free stack frame */
237 beq t0,L_asm_handle_exception_no_leaf
239 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
240 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
242 lda sp,(ARG_CNT+TMP_CNT)*8(sp) /* remove maybe-leaf stackframe */
244 L_asm_handle_exception_no_leaf:
245 jmp zero,(xpc) /* jump to the handler */
247 L_asm_handle_exception_not_catched:
248 ldq xptr,0*8(sp) /* restore xptr */
249 ldq pv,2*8(sp) /* restore PV */
250 ldq ra,3*8(sp) /* restore RA */
251 ldq t0,4*8(sp) /* get maybe-leaf flag */
254 beq t0,L_asm_handle_exception_no_leaf_stack
256 lda sp,(ARG_CNT+TMP_CNT)*8(sp) /* remove maybe-leaf stackframe */
257 mov zero,t0 /* clear the maybe-leaf flag */
259 L_asm_handle_exception_no_leaf_stack:
260 ldl t1,FrameSize(pv) /* get frame size */
261 addq t1,sp,t1 /* pointer to save area */
263 ldl t2,IsLeaf(pv) /* is leaf procedure */
264 bne t2,L_asm_handle_exception_no_ra_restore
266 ldq ra,-1*8(t1) /* restore ra */
267 subq t1,8,t1 /* t1-- */
269 L_asm_handle_exception_no_ra_restore:
270 mov ra,xpc /* the new xpc is ra */
271 ldl t2,IntSave(pv) /* t2 = saved int register count */
272 br t3,ex_int1 /* t3 = current pc */
274 lda t3,(ex_int2 - ex_int1)(t3)
275 negl t2,t2 /* negate register count */
276 s4addq t2,t3,t3 /* t2 = IntSave - register count * 4 */
277 jmp zero,(t3) /* jump to save position */
288 s8addq t2,t1,t1 /* t1 = t1 - 8 * register count */
290 ldl t2,FltSave(pv) /* t2 = saved flt register count */
291 br t3,ex_flt1 /* t3 = current pc */
293 lda t3,(ex_flt2 - ex_flt1)(t3)
294 negl t2,t2 /* negate register count */
295 s4addq t2,t3,t3 /* t2 = FltSave - 4 * register count */
296 jmp zero,(t3) /* jump to save position */
308 ldl t1,FrameSize(pv) /* get frame size */
309 addq sp,t1,sp /* unwind stack */
310 br L_asm_handle_exception_stack_loop
312 .end asm_handle_nat_exception
315 /* asm_abstractmethoderror *****************************************************
317 Creates and throws an AbstractMethodError.
319 *******************************************************************************/
321 .ent asm_abstractmethoderror
323 asm_abstractmethoderror:
324 subq sp,2*8,sp /* create stackframe */
325 stq ra,0*8(sp) /* save return address */
326 addq sp,2*8,a0 /* pass java sp */
327 mov ra,a1 /* pass exception address */
328 jsr ra,exceptions_asm_new_abstractmethoderror
329 ldq ra,0*8(sp) /* restore return address */
330 addq sp,2*8,sp /* remove stackframe */
332 mov v0,xptr /* get exception pointer */
333 subq ra,4,xpc /* exception address is ra - 4 */
334 br L_asm_handle_nat_exception
336 .end asm_abstractmethoderror
339 /* asm_md_init *****************************************************************
341 Initialize machine dependent stuff.
343 Determines if the byte support instruction set (21164a and higher)
346 *******************************************************************************/
351 .long 0x47e03c20 /* amask 1,v0 */
352 jmp zero,(ra) /* return */
357 /* asm_cacheflush **************************************************************
361 *******************************************************************************/
366 call_pal PAL_imb /* synchronize instruction cache */
372 /* disable exec-stacks ********************************************************/
374 #if defined(__linux__) && defined(__ELF__)
375 .section .note.GNU-stack,"",%progbits
380 * These are local overrides for various environment variables in Emacs.
381 * Please do not remove this and leave it at the end of the file, where
382 * Emacs will automagically detect them.
383 * ---------------------------------------------------------------------
386 * indent-tabs-mode: t
390 * vim:noexpandtab:sw=4:ts=4: