1 /* -*- mode: asm; tab-width: 4 -*- */
2 /****************************** asmpart.c **************************************
4 * is an assembly language file, but called .c to fake the preprocessor. *
5 * It contains the Java-C interface functions for Alpha processors. *
7 * Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst *
9 * See file COPYRIGHT for information on usage and disclaimer of warranties *
11 * Authors: Andreas Krall EMAIL: cacao@complang.tuwien.ac.at *
12 * Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at *
14 * Last Change: 1998/11/01 *
16 *******************************************************************************/
25 /********************* exported functions and variables ***********************/
27 .globl has_no_x_instr_set
28 .globl synchronize_caches
29 .globl asm_calljavamethod
30 .globl asm_calljavafunction
31 .globl asm_call_jit_compiler
32 .globl asm_dumpregistersandcall
33 .globl asm_handle_exception
34 .globl asm_handle_nat_exception
35 .globl asm_builtin_checkcast
36 .globl asm_builtin_checkarraycast
37 .globl asm_builtin_anewarray
38 .globl asm_builtin_aastore
39 .globl asm_builtin_monitorenter
40 .globl asm_builtin_monitorexit
41 .globl asm_builtin_idiv
42 .globl asm_builtin_irem
43 .globl asm_builtin_ldiv
44 .globl asm_builtin_lrem
45 .globl asm_perform_threadswitch
46 .globl asm_initialize_thread_stack
47 .globl asm_switchstackandcall
48 .globl asm_getcallingmethod
50 /*************************** imported variables *******************************/
55 /*************************** imported functions *******************************/
58 .globl builtin_monitorexit
59 .globl builtin_throw_exception
60 .globl builtin_trace_exception
61 .globl class_java_lang_Object
64 /*********************** function has_no_x_instr_set ***************************
66 * determines if the byte support instruction set (21164a and higher) *
69 *******************************************************************************/
73 /* .long 0x47e03c20 /* amask 1,v0 */
75 /* jmp zero,(ra) /* return */
79 /********************* function synchronize_caches ****************************/
83 /* call_pal PAL_imb /* synchronise instruction cache */
84 /* jmp zero,(ra) /* return */
88 /********************* function asm_calljavamethod *****************************
90 * This function calls a Java-method (which possibly needs compilation) *
91 * with up to 4 parameters. *
93 * This functions calls the JIT-compiler which eventually translates the *
94 * method into machine code. *
96 * An possibly throwed exception will be returned to the caller as function *
97 * return value, so the java method cannot return a fucntion value (this *
98 * function usually calls 'main' and '<clinit>' which do not return a *
102 * javaobject_header *asm_calljavamethod (methodinfo *m, *
103 * void *arg1, void *arg2, void *arg3, void *arg4); *
105 *******************************************************************************/
107 #define MethodPointer -8
108 #define FrameSize -12
113 #define ExTableSize -32
114 #define ExTableStart -32
116 #define ExEntrySize -32
119 #define ExHandlerPC -24
120 #define ExCatchType -32
123 .ascii "calljavamethod\0\0"
127 .quad 0 /* catch type all */
128 /* .quad calljava_xhandler /* handler pc */
129 /* .quad calljava_xhandler /* end pc */
130 /* .quad asm_calljavamethod /* start pc */
131 .long 1 /* extable size */
132 .long 0 /* fltsave */
133 .long 0 /* intsave */
136 .long 32 /* frame size */
137 .quad 0 /* method pointer (pointer to name) */
141 pushl %ebp /* allocate stack space */
144 subl $32,%esp /* pass the remaining parameters */
147 movl %edx,28(%esp) /* convert parms to 8 byte */
163 movl 8(%ebp),%eax /* move function pointer to %eax */
165 /* pushl %ebp /* save %ebp, cause it's a tmp reg */
167 call asm_call_jit_compiler /* call JIT compiler */
169 /* popl %ebp /* restore %ebp, changed in java code */
172 /* lda pv,-64(ra) /* asm_calljavamethod-calljava_jit !!!!!*/
176 addl $32,%esp /* free stack space */
178 /* ldl v0,newcompiler /* load newcompiler flag */
179 movl newcompiler, %eax /* load newcompiler flag */
180 /* subq v0,1,v0 /* negate for clearing v0 */
181 subl $1,%eax /* negate for clearing v0 */
182 /* beq v0,calljava_ret /* if newcompiler skip ex copying */
183 cmpl $0,%eax /* if newcompiler skip ex copying */
185 /* mov $1,v0 /* pass exception to caller (C) */
186 movl $1, %eax /* pass exception to caller (C) */
193 /* ldq gp,24(sp) /* restore global pointer */
196 /* jsr ra,builtin_throw_exception */
197 call builtin_throw_exception
198 /* ldq ra,0(sp) /* restore return address */
199 /* lda sp,32(sp) /* free stack space */
205 /********************* function asm_calljavafunction ***************************
207 * This function calls a Java-method (which possibly needs compilation) *
208 * with up to 4 address parameters. *
210 * This functions calls the JIT-compiler which eventually translates the *
211 * method into machine code. *
214 * javaobject_header *asm_calljavamethod (methodinfo *m, *
215 * void *arg1, void *arg2, void *arg3, void *arg4); *
217 *******************************************************************************/
220 .ascii "calljavafunction\0\0"
224 .quad 0 /* catch type all */
225 /* .quad calljava_xhandler2 /* handler pc */
226 /* .quad calljava_xhandler2 /* end pc */
227 /* .quad asm_calljavafunction /* start pc */
228 .long 1 /* extable size */
229 .long 0 /* fltsave */
230 .long 0 /* intsave */
233 .long 32 /* frame size */
234 .quad 0 /* method pointer (pointer to name) */
236 asm_calljavafunction:
237 pushl %ebp /* allocate stack space */
240 subl $32,%esp /* pass the remaining parameters */
243 movl %edx,28(%esp) /* convert parms to 8 byte */
259 movl 8(%ebp),%eax /* move function pointer to %eax */
261 /* pushl %ebp /* save %ebp, cause it's a tmp reg */
263 call asm_call_jit_compiler /* call JIT compiler */
265 /* popl %ebp /* restore %ebp, changed in java code */
268 /* lda pv,-64(ra) /* asm_calljavamethod-calljava_jit !!!!!*/
271 addl $32,%esp /* free stack space */
279 /* ldq gp,24(sp) /* restore global pointer */
282 /* jsr ra,builtin_throw_exception */
283 call builtin_throw_exception
284 /* ldq ra,0(sp) /* restore return address */
285 /* lda sp,32(sp) /* free stack space */
291 /****************** function asm_call_jit_compiler *****************************
293 * invokes the compiler for untranslated JavaVM methods. *
295 * Register R0 contains a pointer to the method info structure (prepared *
296 * by createcompilerstub). Using the return address in R26 and the *
297 * offset in the LDA instruction or using the value in methodptr R28 the *
298 * patching address for storing the method address can be computed: *
300 * method address was either loaded using *
302 * i386_mov_imm_reg(a, REG_ITMP2) ; invokestatic/special *
303 * i386_call_reg(REG_ITMP2) *
307 * i386_mov_membase_reg(REG_SP, 0, REG_ITMP2) ; invokevirtual/interface *
308 * i386_mov_membase_reg(REG_ITMP2, OFFSET(, vftbl), REG_ITMP3) *
309 * i386_mov_membase_reg(REG_ITMP3, OFFSET(vftbl, table[0]) + \ *
310 * sizeof(methodptr) * m->vftblindex, REG_ITMP1) *
311 * i386_call_reg(REG_ITMP1) *
313 * in the static case the method pointer can be computed using the *
314 * return address and the lda function following the jmp instruction *
316 *******************************************************************************/
319 asm_call_jit_compiler:
324 pushl %eax /* push methodpointer on stack */
328 movl 4(%ebp),%edx /* get return address */
329 movb -1(%edx),%bl /* get function code */
330 cmpb $0xd2,%bl /* called with `call *REG_ITMP2' (%edx)? */
333 subl $6,%edx /* calculate address of immediate */
334 movl %eax,(%edx) /* and now save the new pointer */
337 jmp *%eax /* ...and now call the new method */
341 /****************** function asm_dumpregistersandcall **************************
343 * This funtion saves all callee saved registers and calls the function *
344 * which is passed as parameter. *
346 * This function is needed by the garbage collector, which needs to access *
347 * all registers which are stored on the stack. Unused registers are *
348 * cleared to avoid interferances with the GC. *
350 * void asm_dumpregistersandcall (functionptr f); *
352 *******************************************************************************/
354 asm_dumpregistersandcall:
355 pushl %ebp /* build stack frame */
358 movl 8(%ebp),%eax /* load function pointer */
359 call *%eax /* call function */
365 /********************* function asm_handle_exception ***************************
367 * This function handles an exception. It does not use the usual calling *
368 * conventions. The exception pointer is passed in REG_ITMP1 and the *
369 * pc from the exception raising position is passed in REG_ITMP2. It searches *
370 * the local exception table for a handler. If no one is found, it unwinds *
371 * stacks and continues searching the callers. *
373 * void asm_handle_exception (exceptionptr, exceptionpc); *
375 *******************************************************************************/
377 asm_handle_nat_exception:
378 asm_handle_exception:
384 /********************* function asm_builtin_monitorenter ***********************
386 * Does null check and calls monitorenter or throws an exception *
388 *******************************************************************************/
390 asm_builtin_monitorenter:
391 jmp builtin_monitorenter
394 /********************* function asm_builtin_monitorexit ************************
396 * Does null check and calls monitorexit or throws an exception *
398 *******************************************************************************/
400 asm_builtin_monitorexit:
401 jmp builtin_monitorexit
404 /************************ function asm_builtin_idiv ****************************
406 * Does null check and calls idiv or throws an exception *
408 *******************************************************************************/
414 /************************ function asm_builtin_ldiv ****************************
416 * Does null check and calls ldiv or throws an exception *
418 *******************************************************************************/
424 /************************ function asm_builtin_irem ****************************
426 * Does null check and calls irem or throws an exception *
428 *******************************************************************************/
434 /************************ function asm_builtin_lrem ****************************
436 * Does null check and calls lrem or throws an exception *
438 *******************************************************************************/
444 /*********************** function new_builtin_checkcast ************************
446 * Does the cast check and eventually throws an exception *
448 *******************************************************************************/
450 asm_builtin_checkcast:
456 /******************* function asm_builtin_checkarraycast ***********************
458 * Does the cast check and eventually throws an exception *
460 *******************************************************************************/
462 asm_builtin_checkarraycast:
463 subl $8,%esp /* build stack frame (2 * 4 bytes) */
471 call builtin_checkarraycast
477 /******************* function asm_builtin_anewarray ****************************
479 * Does the cast check and eventually throws an exception *
481 *******************************************************************************/
483 asm_builtin_anewarray:
484 subl $8,%esp /* build stack frame (2 * 4 bytes) */
492 call builtin_anewarray
498 /******************* function asm_builtin_aastore ******************************
500 * Does the cast check and eventually throws an exception *
502 *******************************************************************************/
505 subl $12,%esp /* build stack frame (3 * 4 bytes) */
522 /******************* function asm_initialize_thread_stack **********************
524 * initialized a thread stack *
526 *******************************************************************************/
528 asm_initialize_thread_stack:
534 /******************* function asm_perform_threadswitch *************************
536 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
538 * performs a threadswitch *
540 *******************************************************************************/
542 asm_perform_threadswitch:
548 /********************* function asm_switchstackandcall *************************
550 * void asm_switchstackandcall (void *stack, void *func, void **stacktopsave); *
552 * Switches to a new stack, calls a function and switches back. *
553 * a0 new stack pointer *
554 * a1 function pointer *
555 * a2 pointer to variable where stack top should be stored *
557 *******************************************************************************/
559 asm_switchstackandcall:
565 /********************* function asm_getcallingmethod ***************************
567 * classinfo *asm_getcallingmethodclass (); *
569 * goes back stack frames to get the calling method *
575 *******************************************************************************/
577 asm_getcallingmethod: