1 /****************************** asmpart.c **************************************
3 * is an assembly language file, but called .c to fake the preprocessor. *
4 * It contains the Java-C interace functions for Alpha processors. *
6 * Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst *
8 * See file COPYRIGHT for information on usage and disclaimer of warranties *
10 * Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at *
11 * Andreas Krall EMAIL: cacao@complang.tuwien.ac.at *
13 * Last Change: 1997/04/26 *
15 *******************************************************************************/
64 /********************* exported functions and variables ***********************/
66 /* .globl has_no_x_instr_set
67 .globl synchronize_caches
68 .globl asm_calljavamethod
69 .globl asm_call_jit_compiler
70 .globl asm_dumpregistersandcall
73 /*************************** imported functions *******************************/
75 /* .globl compiler_compile
78 /*********************** function has_no_x_instr_set ***************************
80 * determines if the byte support instruction set (21164a and higher) *
83 *******************************************************************************/
86 .ident has_no_x_instr_set
90 /* .long 0x47e03c20 ; amask 1,r0
95 jmp zero,(ra) ; return
97 .end has_no_x_instr_set
100 /********************* function synchronize_caches ****************************/
102 .ident synchronize_caches
103 .psect code_sec, code
106 call_pal PAL_imb ; synchronise instruction cache
107 jmp zero,(ra) ; return
109 .end synchronize_caches
113 /********************* function asm_calljavamethod *****************************
115 * This function calls a Java-method (which possibly needs compilation) *
116 * with up to 4 parameters. *
118 * This functions calls the JIT-compiler which eventually translates the *
119 * method into machine code. *
121 * An possibly throwed exception will be returned to the caller as function *
122 * return value, so the java method cannot return a fucntion value (this *
123 * function usually calls 'main' and '<clinit>' which do not return a *
127 * javaobject_header *asm_calljavamethod (methodinfo *m, *
128 * void *arg1, void *arg2, void *arg3, void *arg4); *
130 *******************************************************************************/
132 .ident asm_calljavamethod
133 .psect codesect3, code
134 .external asm_call_jit_compiler
140 lda sp,-24(sp) ; allocate stack space
141 stq ra,0(sp) ; save return address
143 stq r16,16(sp) ; save method pointer for compiler
144 lda r0,16(sp) ; pass pointer to method pointer via r0
146 bis r17,r17,r16 ; pass the remaining parameters
151 la r28,asm_call_jit_compiler ; fake virtual function call
154 stq r28,8(sp) ; store function address
155 bis sp,sp,r28 ; set method pointer
157 ldq pv,8(r28) ; method call as in Java
158 jmp ra,(pv) ; call JIT compiler
160 ldq ra,0(sp) ; restore return address
161 lda sp,24(sp) ; free stack space
163 bis r1,r1,r0 ; pass exception to caller (C)
166 .end asm_calljavamethod
169 /****************** function asm_call_jit_compiler *****************************
171 * invokes the compiler for untranslated JavaVM methods. *
173 * Register R0 contains a pointer to the method info structure (prepared *
174 * by createcompilerstub). Using the return address in R26 and the *
175 * offset in the LDA instruction or using the value in methodptr R28 the *
176 * patching address for storing the method address can be computed: *
178 * method address was either loaded using *
179 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special (r27) *
180 * M_LDA (REG_PV, REG_RA, low) *
181 * M_LDAH(REG_PV, REG_RA, high) ; optional *
183 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interace (r28) *
184 * in the static case the method pointer can be computed using the *
185 * return address and the lda function following the jmp instruction *
187 *******************************************************************************/
190 .ident asm_call_jit_compiler
191 .psect code_sec1, code
192 .external compiler_compile
194 asm_call_jit_compiler::
198 ldl r22,-8(ra) ; load instruction LDQ PV,xxx(ryy)
199 srl r22,16,r22 ; shift right register number ryy
200 and r22,31,r22 ; isolate register number
201 subl r22,28,r22 ; test for REG_METHODPTR
203 ldl r22,0(ra) ; load instruction LDA PV,xxx(RA)
205 sra r22,48,r22 ; isolate offset
206 addq r22,ra,r28 ; compute update address
207 ldl r22,4(ra) ; load instruction LDAH PV,xxx(PV)
208 srl r22,16,r22 ; isolate instruction code
209 lda r22,-0x177b(r22) ; test for LDAH
211 ldl r22,0(ra) ; load instruction LDA PV,xxx(RA)
212 sll r22,16,r22 ; compute high offset
213 addl r22,0,r22 ; sign extend high offset
214 addq r22,r28,r28 ; compute update address
216 lda sp,-14*8(sp) ; reserve stack space
217 stq r16,0*8(sp) ; save all argument registers
218 stq r17,1*8(sp) ; they could be used by method
229 stq r28,12*8(sp) ; save method pointer
230 stq ra,13*8(sp) ; save return address
232 ldq r16,0(r0) ; pass 'methodinfo' pointer to
233 bsr ra,compiler_compile ; compiler
236 call_pal PAL_imb ; synchronise instruction cache
238 ldq r16,0*8(sp) ; load argument registers
250 ldq r28,12*8(sp) ; load method pointer
251 ldq ra,13*8(sp) ; load return address
252 lda sp,14*8(sp) ; deallocate stack area
254 ldl r22,-8(ra) ; load instruction LDQ PV,xxx(ryy)
256 sra r22,48,r22 ; isolate offset
258 addq r22,r28,r22 ; compute update address via method pointer
259 stq r0,0(r22) ; save new method address there
261 bis r0,r0,pv ; load method address into pv
263 jmp zero, (pv) ; and call method. The method returns
264 ; directly to the caller (ra).
266 .end asm_call_jit_compiler
269 /****************** function asm_dumpregistersandcall **************************
271 * This funtion saves all callee saved registers and calls the function *
272 * which is passed as parameter. *
274 * This function is needed by the garbage collector, which needs to access *
275 * all registers which are stored on the stack. Unused registers are *
276 * cleared to avoid intererances with the GC. *
278 * void asm_dumpregistersandcall (functionptr f); *
280 *******************************************************************************/
282 .ident asm_dumpregistersandcall
283 .psect code_sec2, code
284 asm_dumpregistersandcall::
285 lda sp,-16*8(sp) ; allocate stack
286 stq ra,0(sp) ; save return address
288 stq r9,1*8(sp) ; save all callee saved registers
289 stq r10,2*8(sp) ; intialize the remaining registers
304 bis zero,zero,r0 ; intialize the remaining registers
350 bis r16,r16,pv ; load function pointer
351 jmp ra,(pv) ; and call function
353 ldq ra,0(sp) ; load return address
354 lda sp,16*8(sp) ; deallocate stack
355 jmp zero,(ra) ; return