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 /* line number table start */
83 .quad 0 /* line number table size */
87 .long 0 /* frame size */
88 .quad 0 /* codeinfo pointer */
91 asm_vm_call_method_int:
92 asm_vm_call_method_long:
93 asm_vm_call_method_float:
94 asm_vm_call_method_double:
96 lda sp,-5*8(sp) /* allocate stack space */
97 stq ra,0*8(sp) /* save return address */
98 stq gp,1*8(sp) /* save global pointer */
101 stq a0,4*8(sp) /* save method PV */
103 mov a1,t0 /* address of argument array */
104 mov a2,t1 /* stack argument count */
105 mov sp,s0 /* save stack pointer */
121 beq t1,L_asm_vm_call_method_stack_copy_done
123 negq t1,t2 /* calculate stackframe size (* 8) */
124 s8addq t2,sp,sp /* create stackframe */
125 mov sp,t2 /* temporary stack pointer */
127 L_asm_vm_call_method_stack_copy_loop:
128 ldq t3,12*8(t0) /* load argument */
129 stq t3,0(t2) /* store argument on stack */
131 subq t1,1,t1 /* subtract 1 argument */
132 addq t0,8,t0 /* load address of next argument */
133 addq t2,8,t2 /* increase stack pointer */
135 bgt t1,L_asm_vm_call_method_stack_copy_loop
137 L_asm_vm_call_method_stack_copy_done:
138 lda mptr,4*8(s0) /* get address of PV */
139 ldq pv,0*8(mptr) /* load PV */
141 L_asm_vm_call_method_recompute_pv:
142 lda pv,(asm_vm_call_method - L_asm_vm_call_method_recompute_pv)(ra)
144 mov s0,sp /* restore stack pointer */
146 L_asm_vm_call_method_recompute_return:
147 ldq ra,0*8(sp) /* restore RA */
148 ldq gp,1*8(sp) /* restore global pointer */
151 lda sp,5*8(sp) /* free stack space */
154 asm_vm_call_method_exception_handler:
155 mov s0,sp /* restore stack pointer */
156 ldq gp,1*8(sp) /* restore global pointer */
158 jsr ra,builtin_throw_exception
160 asm_vm_call_method_end:
161 br L_asm_vm_call_method_recompute_return
163 .end asm_vm_call_method
166 /* asm_handle_exception ********************************************************
168 This function handles an exception. It does not use the usual calling
169 conventions. The exception pointer is passed in REG_ITMP1 and the
170 pc from the exception raising position is passed in REG_ITMP2. It searches
171 the local exception table for a handler. If no one is found, it unwinds
172 stacks and continues searching the callers.
174 ATTENTION: itmp3 == gp!
176 *******************************************************************************/
178 .ent asm_handle_nat_exception
180 asm_handle_nat_exception:
181 L_asm_handle_nat_exception: /* required for PIC code */
182 L_asm_handle_exception_stack_loop:
183 lda sp,-6*8(sp) /* keep stack 16-byte aligned */
184 stq xptr,0*8(sp) /* save xptr */
185 stq xpc,1*8(sp) /* save xpc */
186 stq ra,3*8(sp) /* save RA */
187 stq zero,4*8(sp) /* save maybe-leaf flag (cleared) */
189 mov ra,a0 /* pass RA */
191 br ra,L_asm_handle_exception_load_gp
192 L_asm_handle_exception_load_gp:
193 ldgp gp,0(ra) /* load gp */
195 jsr ra,md_codegen_get_pv_from_pc/* get PV from RA */
196 stq v0,2*8(sp) /* save PV */
198 ldq a0,0*8(sp) /* pass xptr */
199 ldq a1,1*8(sp) /* pass xpc */
200 mov v0,a2 /* pass PV */
201 addq sp,6*8,a3 /* pass Java SP */
203 br L_asm_handle_exception_continue
205 .aent asm_handle_exception
207 asm_handle_exception:
208 L_asm_handle_exception: /* required for PIC code */
209 lda sp,-(ARG_CNT+TMP_CNT)*8(sp) /* create maybe-leaf stackframe */
211 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
212 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
214 lda sp,-6*8(sp) /* keep stack 16-byte aligned */
215 stq xptr,0*8(sp) /* save xptr */
216 stq pv,2*8(sp) /* save PV */
217 stq ra,3*8(sp) /* save RA */
218 lda t0,1(zero) /* set maybe-leaf flag */
219 stq t0,4*8(sp) /* save maybe-leaf flag */
221 br ra,L_asm_handle_exception_load_gp_2
222 L_asm_handle_exception_load_gp_2:
223 ldgp gp,0(ra) /* load gp */
225 mov xptr,a0 /* pass xptr */
226 mov xpc,a1 /* pass xpc */
227 mov pv,a2 /* pass PV */
228 lda a3,(ARG_CNT+TMP_CNT+6)*8(sp)/* pass Java SP */
230 L_asm_handle_exception_continue:
231 jsr ra,exceptions_handle_exception
233 beq v0,L_asm_handle_exception_not_catched
235 mov v0,xpc /* move handlerpc into xpc */
236 ldq xptr,0*8(sp) /* restore xptr */
237 ldq pv,2*8(sp) /* restore PV */
238 ldq ra,3*8(sp) /* restore RA */
239 ldq t0,4*8(sp) /* get maybe-leaf flag */
240 lda sp,6*8(sp) /* free stack frame */
242 beq t0,L_asm_handle_exception_no_leaf
244 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
245 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
247 lda sp,(ARG_CNT+TMP_CNT)*8(sp) /* remove maybe-leaf stackframe */
249 L_asm_handle_exception_no_leaf:
250 jmp zero,(xpc) /* jump to the handler */
252 L_asm_handle_exception_not_catched:
253 ldq xptr,0*8(sp) /* restore xptr */
254 ldq pv,2*8(sp) /* restore PV */
255 ldq ra,3*8(sp) /* restore RA */
256 ldq t0,4*8(sp) /* get maybe-leaf flag */
259 beq t0,L_asm_handle_exception_no_leaf_stack
261 lda sp,(ARG_CNT+TMP_CNT)*8(sp) /* remove maybe-leaf stackframe */
262 mov zero,t0 /* clear the maybe-leaf flag */
264 L_asm_handle_exception_no_leaf_stack:
265 ldl t1,FrameSize(pv) /* get frame size */
266 addq t1,sp,t1 /* pointer to save area */
268 ldl t2,IsLeaf(pv) /* is leaf procedure */
269 bne t2,L_asm_handle_exception_no_ra_restore
271 ldq ra,-1*8(t1) /* restore ra */
272 subq t1,8,t1 /* t1-- */
274 L_asm_handle_exception_no_ra_restore:
275 mov ra,xpc /* the new xpc is ra */
276 ldl t2,IntSave(pv) /* t2 = saved int register count */
277 br t3,ex_int1 /* t3 = current pc */
279 lda t3,(ex_int2 - ex_int1)(t3)
280 negl t2,t2 /* negate register count */
281 s4addq t2,t3,t3 /* t2 = IntSave - register count * 4 */
282 jmp zero,(t3) /* jump to save position */
293 s8addq t2,t1,t1 /* t1 = t1 - 8 * register count */
295 ldl t2,FltSave(pv) /* t2 = saved flt register count */
296 br t3,ex_flt1 /* t3 = current pc */
298 lda t3,(ex_flt2 - ex_flt1)(t3)
299 negl t2,t2 /* negate register count */
300 s4addq t2,t3,t3 /* t2 = FltSave - 4 * register count */
301 jmp zero,(t3) /* jump to save position */
313 ldl t1,FrameSize(pv) /* get frame size */
314 addq sp,t1,sp /* unwind stack */
315 br L_asm_handle_exception_stack_loop
317 .end asm_handle_nat_exception
320 /* asm_abstractmethoderror *****************************************************
322 Creates and throws an AbstractMethodError.
324 *******************************************************************************/
326 .ent asm_abstractmethoderror
328 asm_abstractmethoderror:
329 subq sp,2*8,sp /* create stackframe */
330 stq ra,0*8(sp) /* save return address */
331 addq sp,2*8,a0 /* pass java sp */
332 mov ra,a1 /* pass exception address */
333 jsr ra,exceptions_asm_new_abstractmethoderror
334 ldq ra,0*8(sp) /* restore return address */
335 addq sp,2*8,sp /* remove stackframe */
337 mov v0,xptr /* get exception pointer */
338 subq ra,4,xpc /* exception address is ra - 4 */
339 br L_asm_handle_nat_exception
341 .end asm_abstractmethoderror
344 /* asm_compare_and_swap ********************************************************
346 Does an atomic compare and swap. Required for the lock
349 Atomically do the following: Check if the location still contains
350 `oldval`. If so, replace it by `newval` and return `oldval`.
355 long compare_and_swap(volatile long *p, long oldval, long newval);
357 *******************************************************************************/
359 .ent asm_compare_and_swap
361 asm_compare_and_swap:
372 .end asm_compare_and_swap
375 /* asm_memory_barrier **********************************************************
377 A memory barrier for the Java Memory Model.
379 *******************************************************************************/
381 .ent asm_memory_barrier
387 .end asm_memory_barrier
390 /* asm_md_init *****************************************************************
392 Initialize machine dependent stuff.
394 Determines if the byte support instruction set (21164a and higher)
397 *******************************************************************************/
402 .long 0x47e03c20 /* amask 1,v0 */
403 jmp zero,(ra) /* return */
408 /* asm_cacheflush **************************************************************
412 *******************************************************************************/
417 call_pal PAL_imb /* synchronize instruction cache */
423 /* disable exec-stacks ********************************************************/
425 #if defined(__linux__) && defined(__ELF__)
426 .section .note.GNU-stack,"",%progbits
431 * These are local overrides for various environment variables in Emacs.
432 * Please do not remove this and leave it at the end of the file, where
433 * Emacs will automagically detect them.
434 * ---------------------------------------------------------------------
437 * indent-tabs-mode: t
441 * vim:noexpandtab:sw=4:ts=4: