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
30 #include "vm/jit/s390/arch.h"
31 #include "vm/jit/s390/md-abi.h"
32 #include "vm/jit/s390/md-asm.h"
34 #include "vm/jit/abi-asm.h"
35 #include "vm/jit/methodheader.h"
40 /* export functions ***********************************************************/
42 .globl asm_vm_call_method
43 .globl asm_vm_call_method_int
44 .globl asm_vm_call_method_long
45 .globl asm_vm_call_method_float
46 .globl asm_vm_call_method_double
47 .globl asm_vm_call_method_exception_handler
48 .globl asm_vm_call_method_end
50 .globl asm_call_jit_compiler
52 .globl asm_handle_exception
53 .globl asm_handle_nat_exception
55 .globl asm_abstractmethoderror
57 .globl asm_builtin_f2i
58 .globl asm_builtin_f2l
59 .globl asm_builtin_d2i
60 .globl asm_builtin_d2l
63 asm_abstractmethoderror:
74 /* Generates a PIC call.
76 * func: function to call
77 * tag: tag unique for this call to generate a label
78 * tmp: one temporary register needed for calculation
80 * The offset table used is located at the bottom of this file.
82 * Note: destroys r12. r12 MUST contain GOT for PIC calls!
84 #define CALL_PIC(func, tag) \
85 bras %r14, L_bras_##tag; /* get PC */ \
87 l %r12, L_offsets - L_bras_##tag (%r14); /* load offset to PLT */ \
88 la %r12, L_offsets - L_bras_##tag (%r12, %r14); /* load PLT address */ \
89 l %r14, L_offset_##func - L_bras_##tag (%r14); /* load offset to func */ \
90 bas %r14, 0(%r14, %r12);
92 /********************* function asm_calljavafunction ***************************
94 * This function calls a Java-method (which possibly needs compilation) *
95 * with up to 4 address parameters. *
97 * This functions calls the JIT-compiler which eventually translates the *
98 * method into machine code. *
101 * javaobject_header *asm_calljavamethod (methodinfo *m, *
102 * void *arg1, void *arg2, void *arg3, void *arg4); *
104 *******************************************************************************/
106 .long 0 /* fltsave */
107 .long 0 /* intsave */
109 .long 0 /* frame size */
110 .long 0 /* codeinfo pointer */
113 asm_vm_call_method_int:
114 asm_vm_call_method_long:
115 asm_vm_call_method_float:
116 asm_vm_call_method_double:
118 ahi sp, -8*4 /* allocate stack frame */
121 /* a1: data structure */
122 /* a2: number of stack arguments */
124 st s0, 0*4(sp) /* store used calle saved registers */
127 st %r12, 3*4(sp) /* %r12 is callee saved, we'll need it as GOT */
129 st a4, 5*4(sp) /* a4 is callee saved in terms of C abi */
130 std ftmp1, 6*4(sp) /* ftmp1 and ftmp2 are callees saved in terms of C abi */
134 lr s0, a1 /* data structure */
135 lr %r0, a2 /* number of stack arguments */
137 l a0, 0*8+4(s0) /* big endian */
146 lr s1, sp /* backup stack pointer */
148 ltr %r0, %r0 /* are there any stack arguments ? */
149 je L_asm_vm_call_method_stack_copy_done
150 lr %r1, %r0 /* copy number of stack arguments */
151 sll %r1, 3 /* calculate stackframe size */
152 sr sp, %r1 /* allocate stack frame */
153 lr %r1, sp /* temporary stack pointer */
155 L_asm_vm_call_method_stack_copy_loop:
157 mvc 0(8, %r1), 7*8(s0) /* copy argument */
158 ahi %r1, 8 /* increase sp */
159 ahi s0, 8 /* set address of next argument */
160 ahi %r0, -1 /* substract 1 argument */
161 jh L_asm_vm_call_method_stack_copy_loop
163 L_asm_vm_call_method_stack_copy_done:
165 la mptr, 2*4(s1) /* load method pointer */
166 l pv, 0(mptr) /* load procedure vector from method pointer */
167 basr ra, pv /* call method */
168 lr sp, s1 /* restore stack pointer */
170 L_asm_vm_call_method_return:
172 l s0, 0*4(sp) /* restore used callee saved registers */
181 ahi sp, 8*4 /* remove stackframe */
185 asm_vm_call_method_exception_handler:
189 CALL_PIC(builtin_throw_exception, avcmeh)
192 j L_asm_vm_call_method_return
194 asm_vm_call_method_end:
197 /****************** function asm_call_jit_compiler *****************************
199 * invokes the compiler for untranslated JavaVM methods. *
201 * itmp3: methodinfo pointer *
202 * itmp1: method pointer *
204 *******************************************************************************/
208 argument registers: arguments (like in JIT)
210 arguments on stack (like in JIT)
211 ------------------------------------------------------------- <- SP on entry
213 saved return address \
214 stored volatile (in terms of C ABI) floag argument registers |
215 96 stored volatile (in terms of C ABI) integer argument registers | ACJC_STACKFRAME
216 0 - 96 register save area (C ABI) /
217 -------------------------------------------------- <- SP for jit_asm_compile
220 /* This is called from a compiler stub.
221 * Arguments are already in registers and the stack is setup like in CACAO.
224 asm_call_jit_compiler:
225 L_asm_call_jit_compiler:
227 # define ACJC_STACKFRAME ((2 * 4) + (4 * 4) + (2 * 8) + 96)
229 ahi sp,-ACJC_STACKFRAME /* allocate stack space */
231 stm %r2,%r5,96(sp) /* store volatile int arg regs */
232 std %f0,96+16(sp) /* store volatile float arg regs */
234 st %r12,96+32(sp) /* store %r12, used as GOT pointer */
235 st %r14,96+36(sp) /* store return address */
239 lr a0,itmp3 /* pass methodinfo pointer */
240 lr a1,mptr /* pass method pointer */
241 la a2,ACJC_STACKFRAME(sp) /* pass java sp */
242 la a3,0(%r14) /* pass return address, make sure bit 32 is 0 */
244 CALL_PIC(jit_asm_compile, acjc)
246 lr pv, v0 /* save return value */
248 lm %r2,%r5,96(sp) /* restore volatile int arg regs */
249 ld %f0,96+16(sp) /* restore volatile float arg regs */
250 ld %f2,96+24(sp) /* restore volatile float arg regs */
253 je L_asm_call_jit_compiler_exception
255 l %r12,96+32(sp) /* restore %r12 */
256 l %r14,96+36(sp) /* restore return address */
257 ahi sp, ACJC_STACKFRAME /* remove stack frame */
259 jit_code_entry: /* label to set breakpoint on */
260 br pv /* call the method, it will return to the caller */
263 L_asm_call_jit_compiler_exception:
265 CALL_PIC(exceptions_get_and_clear_exception, acjce)
268 l xpc,96+36(sp) /* restore return address */
269 l %r12,96+32(sp) /* restore %r12 */
270 ahi sp, ACJC_STACKFRAME /* remove stack frame */
271 j L_asm_handle_nat_exception
274 /* asm_handle_exception ********************************************************
276 * This function handles an exception. It does not use the usual calling *
277 * conventions. The exception pointer is passed in REG_ITMP1 and the *
278 * pc from the exception raising position is passed in REG_ITMP2. It searches *
279 * the local exception table for a handler. If no one is found, it unwinds *
280 * stacks and continues searching the callers. *
282 *******************************************************************************/
284 asm_handle_nat_exception:
285 L_asm_handle_nat_exception:
286 /* TODO really nothing here ? */
287 asm_handle_exception:
288 L_asm_handle_exception:
290 /* a wrapper for md_handle_exception */
292 # define STACKFRAMESIZE (96 + (16 * 4) + (16 * 8) + (4 * 4))
294 # define FREGS (96 + (16 * 4))
295 # define OUT (96 + (16 * 4) + (16 * 8))
297 ahi sp, -STACKFRAMESIZE /* allocate stack frame containing the arrays */
299 /* store special registers to array */
301 st xptr, REGS+(0*4)(sp)
302 st xpc, REGS+(1*4)(sp)
303 st pv, REGS+(13*4)(sp)
304 la itmp3, STACKFRAMESIZE(sp)
305 st itmp3, REGS+(15*4)(sp)
307 /* store temporary and argument registers */
309 stm a0, a4, REGS+(2*4)(sp)
310 std %f0, FREGS+(0*8)(sp)
311 std %f1, FREGS+(1*8)(sp)
312 std %f2, FREGS+(2*8)(sp)
313 std %f3, FREGS+(3*8)(sp)
314 std %f5, FREGS+(5*8)(sp)
315 std %f7, FREGS+(7*8)(sp)
316 std %f8, FREGS+(8*8)(sp)
317 std %f9, FREGS+(9*8)(sp)
318 std %f10, FREGS+(10*8)(sp)
319 std %f11, FREGS+(11*8)(sp)
320 std %f12, FREGS+(12*8)(sp)
321 std %f13, FREGS+(13*8)(sp)
322 std %f14, FREGS+(14*8)(sp)
323 std %f15, FREGS+(15*8)(sp)
325 /* store %r12 used as GOT */
327 st %r12, REGS+(12*4)(sp)
329 /* call md_handle_exception */
335 CALL_PIC(md_handle_exception, ahe)
339 l %r12, REGS+(12*4)(sp)
341 l itmp3, OUT+(2*4)(sp) /* out[2] contains maybe leaf flag */
345 L_restore_temporary_and_argument:
347 /* if we are maybe leaf,
348 * we have to restore argument and temporary registers
351 lm a0, a4, REGS+(2*4)(sp)
352 ld %f0, FREGS+(0*8)(sp)
353 ld %f1, FREGS+(1*8)(sp)
354 ld %f2, FREGS+(2*8)(sp)
355 ld %f3, FREGS+(3*8)(sp)
356 ld %f5, FREGS+(5*8)(sp)
357 ld %f7, FREGS+(7*8)(sp)
358 ld %f8, FREGS+(8*8)(sp)
359 ld %f9, FREGS+(9*8)(sp)
360 ld %f10, FREGS+(10*8)(sp)
361 ld %f11, FREGS+(11*8)(sp)
362 ld %f12, FREGS+(12*8)(sp)
363 ld %f13, FREGS+(13*8)(sp)
364 ld %f14, FREGS+(14*8)(sp)
365 ld %f15, FREGS+(15*8)(sp)
371 /* if we are not a maybe leaf,
372 * we have to restore callee saved registers of the callee
375 l itmp3, OUT+(0*4)(sp) /* out[0] contains IntSav */
379 l s5, REGS+(12*4)(sp)
383 l s4, REGS+(11*4)(sp)
387 l s3, REGS+(10*4)(sp)
403 /* restore callee saved float registers */
405 /* there are currently none */
411 /* write new values for special registers */
413 l xptr, REGS+(0*4)(sp)
414 l xpc, REGS+(1*4)(sp)
415 l pv, REGS+(13*4)(sp)
416 l sp, REGS+(15*4)(sp)
418 br xpc /* jump to handler */
420 # undef STACKFRAMESIZE
427 /* asm_abstractmethoderror *****************************************************
429 Creates and throws an AbstractMethodError.
431 *******************************************************************************/
433 asm_abstractmethoderror:
434 mov sp,a0 /* pass java sp */
436 mov 0*8(sp),a1 /* pass exception address */
438 call exceptions_asm_new_abstractmethoderror@PLT
439 /* exception pointer is return value */
440 pop xpc /* get exception address */
441 sub $3,xpc /* exception address is ra - 3 */
442 jmp L_asm_handle_exception
446 /* Offset table for PIC calls, see CALL_PIC */
449 .long _GLOBAL_OFFSET_TABLE_ - L_offsets
450 L_offset_builtin_throw_exception:
451 .long builtin_throw_exception@PLTOFF
452 L_offset_jit_asm_compile:
453 .long jit_asm_compile@PLTOFF
454 L_offset_exceptions_get_and_clear_exception:
455 .long exceptions_get_and_clear_exception@PLTOFF
456 L_offset_md_handle_exception:
457 .long md_handle_exception@PLTOFF
461 * These are local overrides for various environment variables in Emacs.
462 * Please do not remove this and leave it at the end of the file, where
463 * Emacs will automagically detect them.
464 * ---------------------------------------------------------------------
467 * indent-tabs-mode: t
471 * vim:noexpandtab:sw=4:ts=4: