1 /* src/vm/jit/s390/asmpart.S - Java-C interface functions for s390
3 Copyright (C) 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 8352 2007-08-19 18:32:59Z pm $
32 #include "vm/jit/s390/arch.h"
33 #include "vm/jit/s390/md-abi.h"
34 #include "vm/jit/s390/md-asm.h"
36 #include "vm/jit/abi-asm.h"
37 #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_replacement_out
60 .globl asm_replacement_in
62 .globl asm_builtin_f2i
63 .globl asm_builtin_f2l
64 .globl asm_builtin_d2i
65 .globl asm_builtin_d2l
68 asm_abstractmethoderror:
83 /* Generates a PIC call.
85 * func: function to call
86 * tag: tag unique for this call to generate a label
87 * tmp: one temporary register needed for calculation
89 * The offset table used is located at the bottom of this file.
91 * Note: destroys r12/itmp2. r12 MUST contain GOT for PIC calls!
93 #define CALL_PIC(func, tag) \
94 bras %r14, L_bras_##tag; /* get PC */ \
96 l %r12, L_offsets - L_bras_##tag (%r14); /* load offset to PLT */ \
97 la %r12, L_offsets - L_bras_##tag (%r12, %r14); /* load PLT address */ \
98 l %r14, L_offset_##func - L_bras_##tag (%r14); /* load offset to func */ \
99 bas %r14, 0(%r14, %r12);
101 /********************* function asm_calljavafunction ***************************
103 * This function calls a Java-method (which possibly needs compilation) *
104 * with up to 4 address parameters. *
106 * This functions calls the JIT-compiler which eventually translates the *
107 * method into machine code. *
110 * javaobject_header *asm_calljavamethod (methodinfo *m, *
111 * void *arg1, void *arg2, void *arg3, void *arg4); *
113 *******************************************************************************/
115 .long 0 /* catch type all */
116 .long 0 /* exception handler pc */
118 .long 0 /* start pc */
119 .long 1 /* extable size */
120 .long 0 /* line number table start */
121 .long 0 /* line number table size */
122 .long 0 /* fltsave */
123 .long 0 /* intsave */
126 .long 0 /* frame size */
127 .long 0 /* codeinfo pointer */
130 asm_vm_call_method_int:
131 asm_vm_call_method_long:
132 asm_vm_call_method_float:
133 asm_vm_call_method_double:
135 ahi sp, -8*4 /* allocate stack frame */
138 /* a1: data structure */
139 /* a2: number of stack arguments */
141 st s0, 0*4(sp) /* store used calle saved registers */
144 st mptr, 3*4(sp) /* mptr/itmp2 is callee saved in terms of C abi */
146 st a4, 5*4(sp) /* a4 is callee saved in terms of C abi */
149 lr s0, a1 /* data structure */
150 lr %r0, a2 /* number of stack arguments */
152 l a0, 0*8+4(s0) /* big endian */
161 lr s1, sp /* backup stack pointer */
163 ltr %r0, %r0 /* are there any stack arguments ? */
164 je L_asm_vm_call_method_stack_copy_done
165 lr %r1, %r0 /* copy number of stack arguments */
166 sll %r1, 3 /* calculate stackframe size */
167 sr sp, %r1 /* allocate stack frame */
168 lr %r1, sp /* temporary stack pointer */
170 L_asm_vm_call_method_stack_copy_loop:
172 mvc 0(8, %r1), 7*8(s0) /* copy argument */
173 ahi %r1, 8 /* increase sp */
174 ahi s0, 8 /* set address of next argument */
175 ahi %r0, -1 /* substract 1 argument */
176 jh L_asm_vm_call_method_stack_copy_loop
178 L_asm_vm_call_method_stack_copy_done:
180 la mptr, 2*4(s1) /* load method pointer */
181 l pv, 0(mptr) /* load procedure vector from method pointer */
182 basr ra, pv /* call method */
183 lr sp, s1 /* restore stack pointer */
185 L_asm_vm_call_method_return:
187 l s0, 0*4(sp) /* restore used callee saved registers */
194 ahi sp, 8*4 /* remove stackframe */
198 asm_vm_call_method_exception_handler:
202 CALL_PIC(builtin_throw_exception, avcmeh)
205 j L_asm_vm_call_method_return
207 asm_vm_call_method_end:
210 /****************** function asm_call_jit_compiler *****************************
212 * invokes the compiler for untranslated JavaVM methods. *
214 * itmp1: methodinfo pointer *
215 * itmp2: method pointer *
217 *******************************************************************************/
221 argument registers: arguments (like in JIT)
223 arguments on stack (like in JIT)
224 ------------------------------------------------------------- <- SP on entry
226 saved return address \
227 stored volatile (in terms of C ABI) floag argument registers |
228 96 stored volatile (in terms of C ABI) integer argument registers | ACJC_STACKFRAME
229 0 - 96 register save area (C ABI) /
230 -------------------------------------------------- <- SP for jit_asm_compile
233 /* This is called from a compiler stub.
234 * Arguments are already in registers and the stack is setup like in CACAO.
237 asm_call_jit_compiler:
238 L_asm_call_jit_compiler:
240 # define ACJC_STACKFRAME (4 + (4 * 4) + (2 * 8) + 96 + 4)
242 ahi sp,-ACJC_STACKFRAME /* allocate stack space */
244 stm %r2,%r5,96(sp) /* store volatile int arg regs */
245 std %f0,96+16(sp) /* store volatile float arg regs */
247 st %r14,96+32(sp) /* store return address */
251 lr a0,itmp1 /* pass methodinfo pointer */
252 lr a1,itmp2 /* pass method pointer */
253 la a2,ACJC_STACKFRAME(sp) /* pass java sp */
254 la a3,0(%r14) /* pass return address, make sure bit 32 is 0 */
256 CALL_PIC(jit_asm_compile, acjc)
258 lr pv, v0 /* save return value */
260 lm %r2,%r5,96(sp) /* restore volatile int arg regs */
261 ld %f0,96+16(sp) /* restore volatile float arg regs */
262 ld %f2,96+24(sp) /* restore volatile float arg regs */
265 je L_asm_call_jit_compiler_exception
267 l %r14,96+32(sp) /* restore return address */
268 ahi sp, ACJC_STACKFRAME /* remove stack frame */
270 jit_code_entry: /* label to set breakpoint on */
271 br pv /* call the method, it will return to the caller */
274 L_asm_call_jit_compiler_exception:
276 CALL_PIC(exceptions_get_and_clear_exception, acjce)
279 l xpc,96+32(sp) /* restore return address */
280 ahi sp, ACJC_STACKFRAME /* remove stack frame */
281 j L_asm_handle_nat_exception
284 /* asm_handle_exception ********************************************************
286 * This function handles an exception. It does not use the usual calling *
287 * conventions. The exception pointer is passed in REG_ITMP1 and the *
288 * pc from the exception raising position is passed in REG_ITMP2. It searches *
289 * the local exception table for a handler. If no one is found, it unwinds *
290 * stacks and continues searching the callers. *
292 *******************************************************************************/
294 asm_handle_nat_exception:
295 L_asm_handle_nat_exception:
296 /* TODO really nothing here ? */
297 asm_handle_exception:
298 L_asm_handle_exception:
300 /* a wrapper for md_handle_exception */
302 # define STACKFRAMESIZE (96 + (16 * 4) + (16 * 8) + (4 * 4))
304 # define FREGS (96 + (16 * 4))
305 # define OUT (96 + (16 * 4) + (16 * 8))
307 ahi sp, -STACKFRAMESIZE /* allocate stack frame containing the arrays */
309 /* store special registers to array */
311 st xptr, REGS+(1*4)(sp)
312 st xpc, REGS+(12*4)(sp)
313 st pv, REGS+(13*4)(sp)
314 la itmp3, STACKFRAMESIZE(sp)
315 st itmp3, REGS+(15*4)(sp)
317 /* store temporary and argument registers */
319 stm a0, a4, REGS+(2*4)(sp)
320 std %f0, FREGS+(0*8)(sp)
321 std %f1, FREGS+(1*8)(sp)
322 std %f2, FREGS+(2*8)(sp)
323 std %f3, FREGS+(3*8)(sp)
324 std %f5, FREGS+(5*8)(sp)
325 std %f7, FREGS+(7*8)(sp)
326 std %f8, FREGS+(8*8)(sp)
327 std %f9, FREGS+(9*8)(sp)
328 std %f10, FREGS+(10*8)(sp)
329 std %f11, FREGS+(11*8)(sp)
330 std %f12, FREGS+(12*8)(sp)
331 std %f13, FREGS+(13*8)(sp)
332 std %f14, FREGS+(14*8)(sp)
333 std %f15, FREGS+(15*8)(sp)
335 /* call md_handle_exception */
341 CALL_PIC(md_handle_exception, ahe)
343 l itmp3, OUT+(2*4)(sp) /* out[2] contains maybe leaf flag */
347 L_restore_temporary_and_argument:
349 /* if we are maybe leaf,
350 * we have to restore argument and temporary registers
353 lm a0, a4, REGS+(2*4)(sp)
354 ld %f0, FREGS+(0*8)(sp)
355 ld %f1, FREGS+(1*8)(sp)
356 ld %f2, FREGS+(2*8)(sp)
357 ld %f3, FREGS+(3*8)(sp)
358 ld %f5, FREGS+(5*8)(sp)
359 ld %f7, FREGS+(7*8)(sp)
360 ld %f8, FREGS+(8*8)(sp)
361 ld %f9, FREGS+(9*8)(sp)
362 ld %f10, FREGS+(10*8)(sp)
363 ld %f11, FREGS+(11*8)(sp)
364 ld %f12, FREGS+(12*8)(sp)
365 ld %f13, FREGS+(13*8)(sp)
366 ld %f14, FREGS+(14*8)(sp)
367 ld %f15, FREGS+(15*8)(sp)
373 /* if we are not a maybe leaf,
374 * we have to restore callee saved registers of the callee
377 l itmp3, OUT+(0*4)(sp) /* out[0] contains IntSav */
381 l s4, REGS+(11*4)(sp)
385 l s3, REGS+(10*4)(sp)
401 /* restore callee saved float registers */
403 l itmp3, OUT+(1*4)(sp) /* out[1] contains FltSav */
407 ld %f6, FREGS+(6*8)(sp)
411 ld %f4, FREGS+(4*8)(sp)
417 /* write new values for special registers */
419 l xptr, REGS+(1*4)(sp)
420 l xpc, REGS+(12*4)(sp)
421 l pv, REGS+(13*4)(sp)
422 l sp, REGS+(15*4)(sp)
424 br xpc /* jump to handler */
426 # undef STACKFRAMESIZE
433 /* asm_abstractmethoderror *****************************************************
435 Creates and throws an AbstractMethodError.
437 *******************************************************************************/
439 asm_abstractmethoderror:
440 mov sp,a0 /* pass java sp */
442 mov 0*8(sp),a1 /* pass exception address */
444 call exceptions_asm_new_abstractmethoderror@PLT
445 /* exception pointer is return value */
446 pop xpc /* get exception address */
447 sub $3,xpc /* exception address is ra - 3 */
448 jmp L_asm_handle_exception
452 /* Offset table for PIC calls, see CALL_PIC */
455 .long _GLOBAL_OFFSET_TABLE_ - L_offsets
456 L_offset_builtin_throw_exception:
457 .long builtin_throw_exception@PLTOFF
458 L_offset_jit_asm_compile:
459 .long jit_asm_compile@PLTOFF
460 L_offset_exceptions_get_and_clear_exception:
461 .long exceptions_get_and_clear_exception@PLTOFF
462 L_offset_md_handle_exception:
463 .long md_handle_exception@PLTOFF
467 * These are local overrides for various environment variables in Emacs.
468 * Please do not remove this and leave it at the end of the file, where
469 * Emacs will automagically detect them.
470 * ---------------------------------------------------------------------
473 * indent-tabs-mode: t
477 * vim:noexpandtab:sw=4:ts=4: