* src/vm/jit/alpha/asmpart.S (asm_compare_and_swap): Changed comment.
[cacao.git] / src / vm / jit / alpha / asmpart.S
1 /* src/vm/jit/alpha/asmpart.S - Java-C interface functions for alpha
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    $Id: asmpart.S 7253 2007-01-29 21:37:00Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include "vm/jit/alpha/md-abi.h"
33 #include "vm/jit/alpha/md-asm.h"
34 #include "vm/jit/alpha/offsets.h"
35
36 #include "vm/jit/abi-asm.h"
37 #include "vm/jit/methodheader.h"
38
39
40         .text
41         .set    noat
42         .set    noreorder
43
44
45 /* export functions ***********************************************************/
46
47         .globl asm_vm_call_method
48         .globl asm_vm_call_method_int
49         .globl asm_vm_call_method_long
50         .globl asm_vm_call_method_float
51         .globl asm_vm_call_method_double
52         .globl asm_vm_call_method_exception_handler
53
54         .globl asm_call_jit_compiler
55
56         .globl asm_handle_exception
57         .globl asm_handle_nat_exception
58
59         .globl asm_abstractmethoderror
60
61         .globl asm_patcher_wrapper
62
63 #if defined(ENABLE_REPLACEMENT)
64         .globl asm_replacement_out
65         .globl asm_replacement_in
66 #endif
67
68         .globl asm_compare_and_swap
69         .globl asm_memory_barrier
70
71         .globl asm_criticalsections
72         .globl asm_getclassvalues_atomic
73
74         .globl asm_md_init
75         .globl asm_cacheflush
76
77
78 /* asm_vm_call_method **********************************************************
79 *                                                                              *
80 *   This function calls a Java-method (which possibly needs compilation)       *
81 *   with up to 4 address parameters.                                           *
82 *                                                                              *
83 *   This functions calls the JIT-compiler which eventually translates the      *
84 *   method into machine code.                                                  *
85 *                                                                              *
86 *   C-prototype:                                                               *
87 *    javaobject_header *asm_calljavafunction (methodinfo *m,                   *
88 *         void *arg1, void *arg2, void *arg3, void *arg4);                     *
89 *                                                                              *
90 *******************************************************************************/
91
92         .ent    asm_vm_call_method
93
94         .align  3
95
96         .quad   0                           /* catch type all                     */
97         .quad   0                           /* handler pc                         */
98         .quad   0                           /* end pc                             */
99         .quad   0                           /* start pc                           */
100         .long   1                           /* extable size                       */
101         .long   0                           /* ALIGNMENT PADDING                  */
102         .quad   0                           /* line number table start            */
103         .quad   0                           /* line number table size             */
104         .long   0                           /* ALIGNMENT PADDING                  */
105         .long   0                           /* fltsave                            */
106         .long   1                           /* intsave                            */
107         .long   0                           /* isleaf                             */
108         .long   0                           /* IsSync                             */
109         .long   0                           /* frame size                         */
110         .quad   0                           /* codeinfo pointer                   */
111
112 asm_vm_call_method:
113 asm_vm_call_method_int:
114 asm_vm_call_method_long:
115 asm_vm_call_method_float:
116 asm_vm_call_method_double:
117         ldgp    gp,0(pv)
118         lda     sp,-5*8(sp)               /* allocate stack space                 */
119         stq     ra,0*8(sp)                /* save return address                  */
120         stq     gp,1*8(sp)                /* save global pointer                  */
121         stq     s6,3*8(sp)
122
123         stq     a0,4*8(sp)                /* save method pointer for compiler     */
124
125         mov     a2,t0                     /* pointer to arg block                 */
126         mov     a1,s6                     /* arg count                            */
127
128         ble     s6,calljava_argsloaded
129         lda     s6,-1(s6)
130         ldq     a0,offvmargdata(t0)
131         ldt     $f16,offvmargdata(t0)
132         ble     s6,calljava_argsloaded
133
134         lda     s6,-1(s6)
135         ldq     a1,offvmargdata+sizevmarg*1(t0)
136         ldt     $f17,offvmargdata+sizevmarg*1(t0)
137         ble     s6,calljava_argsloaded
138
139         lda     s6,-1(s6)
140         ldq     a2,offvmargdata+sizevmarg*2(t0)
141         ldt     $f18,offvmargdata+sizevmarg*2(t0)
142         ble     s6,calljava_argsloaded
143
144         lda     s6,-1(s6)
145         ldq     a3,offvmargdata+sizevmarg*3(t0)
146         ldt     $f19,offvmargdata+sizevmarg*3(t0)
147         ble     s6,calljava_argsloaded
148
149         lda     s6,-1(s6)
150         ldq     a4,offvmargdata+sizevmarg*4(t0)
151         ldt     $f20,offvmargdata+sizevmarg*4(t0)
152         ble     s6,calljava_argsloaded
153
154         lda     s6,-1(s6)
155         ldq     a5,offvmargdata+sizevmarg*5(t0)
156         ldt     $f21,offvmargdata+sizevmarg*5(t0)
157 calljava_argsloaded:
158         mov     sp,t4
159         ble     s6,calljava_nocopy
160         negq    s6,t1
161         s8addq  t1,sp,sp
162         s8addq  t1,t4,t2
163
164 calljava_copyloop:
165         ldq     t3,offvmargdata+sizevmarg*6(t0)
166         stq     t3,0(t2)
167         lda     t1,1(t1)
168         lda     t0,sizevmarg(t0)
169         lda     t2,8(t2)
170         bne     t1,calljava_copyloop
171
172 calljava_nocopy:
173         ldq     itmp1,4*8(t4)             /* pass method pointer via itmp1        */
174
175         lda     mptr,asm_call_jit_compiler/* fake virtual function call (2 instr) */
176         stq     mptr,2*8(t4)              /* store function address               */
177         lda     mptr,1*8(t4)              /* set method pointer                   */
178
179         ldq     pv,1*8(mptr)              /* method call as in Java               */
180         jmp     ra,(pv)                   /* call JIT compiler                    */
181 calljava_jit2:
182         lda     pv,(asm_vm_call_method - calljava_jit2)(ra)
183
184         s8addq  s6,sp,sp
185 calljava_return2:
186         ldq     ra,0*8(sp)                /* restore return address               */
187         ldq     gp,1*8(sp)                /* restore global pointer               */
188         ldq     s6,3*8(sp)
189         lda     sp,5*8(sp)                /* free stack space                     */
190
191 calljava_ret2:
192         jmp     zero,(ra)
193
194 asm_vm_call_method_exception_handler:
195         s8addq  s6,sp,sp
196         ldq     gp,1*8(sp)                /* restore global pointer               */
197         mov     itmp1,a0
198         jsr     ra,builtin_throw_exception
199         ldq     ra,0*8(sp)                /* restore return address               */
200         ldq     s6,3*8(sp)
201         lda     sp,5*8(sp)                /* free stack space                     */
202         jmp     zero,(ra)
203
204         .end    asm_vm_call_method
205
206
207 /* asm_call_jit_compiler *******************************************************
208
209    Invokes the compiler for untranslated Java methods.
210
211 *******************************************************************************/
212
213         .ent    asm_call_jit_compiler
214
215 asm_call_jit_compiler:
216         ldgp    gp,0(pv)
217         lda     sp,-(ARG_CNT+2)*8(sp) /* +2: keep stack 16-byte aligned           */
218
219         stq     ra,0*8(sp)            /* save return address                      */
220
221         SAVE_ARGUMENT_REGISTERS(1)    /* save 6 int/6 float argument registers    */
222
223         mov     itmp1,a0              /* pass methodinfo pointer                  */
224         mov     mptr,a1               /* pass method pointer                      */
225         lda     a2,(ARG_CNT+2)*8(sp)  /* pass java sp                             */
226         mov     ra,a3
227         jsr     ra,jit_asm_compile    /* call jit compiler                        */
228         mov     v0,pv
229
230         ldq     ra,0*8(sp)            /* load return address                      */
231
232         RESTORE_ARGUMENT_REGISTERS(1) /* restore 6 int/6 float argument registers */
233
234         lda     sp,(ARG_CNT+2)*8(sp)  /* remove stack frame                       */
235
236         beq     pv,L_asm_call_jit_compiler_exception
237
238         jmp     zero,(pv)             /* and call method, the method returns      */
239                                       /* directly to the caller (ra).             */
240
241 L_asm_call_jit_compiler_exception:
242         subq    sp,2*8,sp
243         stq     ra,0*8(sp)            /* save return address (xpc)                */
244         jsr     ra,exceptions_get_and_clear_exception
245         ldq     ra,0*8(sp)            /* restore return address (xpc)             */
246         addq    sp,2*8,sp
247
248         mov     v0,xptr               /* get exception                            */
249         subq    ra,4,xpc              /* exception address is ra - 4              */
250         br      L_asm_handle_nat_exception
251
252         .end    asm_call_jit_compiler
253
254
255 /* asm_handle_exception ********************************************************
256
257    This function handles an exception. It does not use the usual calling
258    conventions. The exception pointer is passed in REG_ITMP1 and the
259    pc from the exception raising position is passed in REG_ITMP2. It searches
260    the local exception table for a handler. If no one is found, it unwinds
261    stacks and continues searching the callers.
262
263    ATTENTION: itmp3 == gp!
264
265 *******************************************************************************/
266
267         .ent    asm_handle_nat_exception
268
269 asm_handle_nat_exception:
270 L_asm_handle_nat_exception:       /* required for PIC code                    */
271 L_asm_handle_exception_stack_loop:
272         lda     sp,-6*8(sp)                 /* keep stack 16-byte aligned         */
273         stq     xptr,0*8(sp)                /* save xptr                          */
274         stq     xpc,1*8(sp)                 /* save xpc                           */
275         stq     ra,3*8(sp)                  /* save RA                            */
276         stq     zero,4*8(sp)                /* save maybe-leaf flag (cleared)     */
277
278         mov     ra,a0                       /* pass RA                            */
279
280         br      ra,L_asm_handle_exception_load_gp
281 L_asm_handle_exception_load_gp:
282         ldgp    gp,0(ra)                    /* load gp                            */
283
284         jsr     ra,md_codegen_get_pv_from_pc/* get PV from RA                     */
285         stq     v0,2*8(sp)                  /* save PV                            */
286
287         ldq     a0,0*8(sp)                  /* pass xptr                          */
288         ldq     a1,1*8(sp)                  /* pass xpc                           */
289         mov     v0,a2                       /* pass PV                            */
290         addq    sp,6*8,a3                   /* pass Java SP                       */
291
292         br      L_asm_handle_exception_continue
293
294         .aent    asm_handle_exception
295
296 asm_handle_exception:
297 L_asm_handle_exception:                 /* required for PIC code              */
298         lda     sp,-(ARG_CNT+TMP_CNT)*8(sp) /* create maybe-leaf stackframe       */
299
300         SAVE_ARGUMENT_REGISTERS(0)          /* we save arg and temp registers in  */
301         SAVE_TEMPORARY_REGISTERS(ARG_CNT)   /* case this is a leaf method         */
302
303         lda     sp,-6*8(sp)                 /* keep stack 16-byte aligned         */
304         stq     xptr,0*8(sp)                /* save xptr                          */
305         stq     pv,2*8(sp)                  /* save PV                            */
306         stq     ra,3*8(sp)                  /* save RA                            */
307         lda     t0,1(zero)                  /* set maybe-leaf flag                */
308         stq     t0,4*8(sp)                  /* save maybe-leaf flag               */
309
310         br      ra,L_asm_handle_exception_load_gp_2
311 L_asm_handle_exception_load_gp_2:
312         ldgp    gp,0(ra)                    /* load gp                            */
313
314         mov     xptr,a0                     /* pass xptr                          */
315         mov     xpc,a1                      /* pass xpc                           */
316         mov     pv,a2                       /* pass PV                            */
317         lda     a3,(ARG_CNT+TMP_CNT+6)*8(sp)/* pass Java SP                       */
318
319 L_asm_handle_exception_continue:
320         jsr     ra,exceptions_handle_exception
321
322         beq     v0,L_asm_handle_exception_not_catched
323
324         mov     v0,xpc                      /* move handlerpc into xpc            */
325         ldq     xptr,0*8(sp)                /* restore xptr                       */
326         ldq     pv,2*8(sp)                  /* restore PV                         */
327         ldq     ra,3*8(sp)                  /* restore RA                         */
328         ldq     t0,4*8(sp)                  /* get maybe-leaf flag                */
329         lda     sp,6*8(sp)                  /* free stack frame                   */
330
331         beq     t0,L_asm_handle_exception_no_leaf
332
333         RESTORE_ARGUMENT_REGISTERS(0)       /* if this is a leaf method, we have  */
334         RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers  */
335         
336         lda     sp,(ARG_CNT+TMP_CNT)*8(sp)  /* remove maybe-leaf stackframe       */
337
338 L_asm_handle_exception_no_leaf:
339         jmp     zero,(xpc)                  /* jump to the handler                */
340
341 L_asm_handle_exception_not_catched:
342         ldq     xptr,0*8(sp)                /* restore xptr                       */
343         ldq     pv,2*8(sp)                  /* restore PV                         */
344         ldq     ra,3*8(sp)                  /* restore RA                         */
345         ldq     t0,4*8(sp)                  /* get maybe-leaf flag                */
346         lda     sp,6*8(sp)
347
348         beq     t0,L_asm_handle_exception_no_leaf_stack
349
350         lda     sp,(ARG_CNT+TMP_CNT)*8(sp)  /* remove maybe-leaf stackframe       */
351         mov     zero,t0                     /* clear the maybe-leaf flag          */
352
353 L_asm_handle_exception_no_leaf_stack:
354         ldl     t1,FrameSize(pv)            /* get frame size                     */
355         addq    t1,sp,t1                    /* pointer to save area               */
356
357         ldl     t2,IsLeaf(pv)               /* is leaf procedure                  */
358         bne     t2,L_asm_handle_exception_no_ra_restore
359
360         ldq     ra,-1*8(t1)                 /* restore ra                         */
361         subq    t1,8,t1                     /* t1--                               */
362
363 L_asm_handle_exception_no_ra_restore:
364         mov     ra,xpc                      /* the new xpc is ra                  */
365         ldl     t2,IntSave(pv)              /* t2 = saved int register count      */
366         br      t3,ex_int1                  /* t3 = current pc                    */
367 ex_int1:
368         lda     t3,(ex_int2 - ex_int1)(t3)
369         negl    t2,t2                       /* negate register count              */
370         s4addq  t2,t3,t3                    /* t2 = IntSave - register count * 4  */
371         jmp     zero,(t3)                   /* jump to save position              */
372
373         ldq     s0,-7*8(t1)
374         ldq     s1,-6*8(t1)
375         ldq     s2,-5*8(t1)
376         ldq     s3,-4*8(t1)
377         ldq     s4,-3*8(t1)
378         ldq     s5,-2*8(t1)
379         ldq     s6,-1*8(t1)
380
381 ex_int2:
382         s8addq  t2,t1,t1                    /* t1 = t1 - 8 * register count       */
383
384         ldl     t2,FltSave(pv)              /* t2 = saved flt register count      */
385         br      t3,ex_flt1                  /* t3 = current pc                    */
386 ex_flt1:
387         lda     t3,(ex_flt2 - ex_flt1)(t3)
388         negl    t2,t2                       /* negate register count              */
389         s4addq  t2,t3,t3                    /* t2 = FltSave - 4 * register count  */
390         jmp     zero,(t3)                   /* jump to save position              */
391
392         ldt     fs0,-8*8(t1)
393         ldt     fs1,-7*8(t1)
394         ldt     fs2,-6*8(t1)
395         ldt     fs3,-5*8(t1)
396         ldt     fs4,-4*8(t1)
397         ldt     fs5,-3*8(t1)
398         ldt     fs6,-2*8(t1)
399         ldt     fs7,-1*8(t1)
400
401 ex_flt2:
402         ldl     t1,FrameSize(pv)            /* get frame size                     */
403         addq    sp,t1,sp                    /* unwind stack                       */
404         br      L_asm_handle_exception_stack_loop
405
406         .end    asm_handle_nat_exception
407
408
409 /* asm_abstractmethoderror *****************************************************
410
411    Creates and throws an AbstractMethodError.
412
413 *******************************************************************************/
414
415         .ent    asm_abstractmethoderror
416
417 asm_abstractmethoderror:
418         subq    sp,2*8,sp                   /* create stackframe                  */
419         stq     ra,0*8(sp)                  /* save return address                */
420         addq    sp,2*8,a0                   /* pass java sp                       */
421         mov     ra,a1                       /* pass exception address             */
422         jsr     ra,exceptions_asm_new_abstractmethoderror
423         ldq     ra,0*8(sp)                  /* restore return address             */
424         addq    sp,2*8,sp                   /* remove stackframe                  */
425
426         mov     v0,xptr                     /* get exception pointer              */
427         subq    ra,4,xpc                    /* exception address is ra - 4        */
428         br      L_asm_handle_nat_exception
429
430         .end    asm_abstractmethoderror
431
432
433 /* asm_patcher_wrapper *********************************************************
434
435    XXX
436
437    Stack layout:
438      40   return address into JIT code (patch position)
439      32   pointer to virtual java_objectheader
440      24   machine code (which is patched back later)
441      16   unresolved class/method/field reference
442       8   data segment displacement from load instructions
443       0   patcher function pointer to call (pv afterwards)
444
445    ATTENTION: itmp3 == gp! But we don't need gp do call the patcher function.
446
447 *******************************************************************************/
448                 
449         .ent    asm_patcher_wrapper
450
451 asm_patcher_wrapper:
452         lda     sp,-((2+12+27+4)*8)(sp) /* create stack frame                     */
453
454         SAVE_RETURN_REGISTERS(0)      /* save 1 int/1 float return registers      */
455         SAVE_ARGUMENT_REGISTERS(2)    /* save 6 int/6 float argument registers    */
456         SAVE_TEMPORARY_REGISTERS(14)  /* save 11 int/16 float temporary registers */
457
458         stq     itmp1,(2+12+27+0)*8(sp) /* save itmp1                             */
459         stq     itmp2,(2+12+27+1)*8(sp) /* save itmp2                             */
460         stq     ra,(2+12+27+2)*8(sp)  /* save method return address (for leafs)   */
461         stq     pv,(2+12+27+3)*8(sp)  /* save pv of calling java function         */
462
463         br      ra,L_asm_patcher_wrapper_load_gp
464 L_asm_patcher_wrapper_load_gp:
465         ldgp    gp,0(ra)              /* load gp (it's not set correctly in jit)  */
466
467         lda     a0,(2+12+27+4)*8(sp)  /* pass SP of patcher stub                  */
468         mov     pv,a1                 /* pass PV                                  */
469         ldq     a2,(2+12+27+2)*8(sp)  /* pass RA (correct for leafs)              */
470         jsr     ra,patcher_wrapper
471         ldgp    gp,0(ra)
472         stq     v0,(0+2+12+27+4)*8(sp) /* save return value                       */
473
474         RESTORE_RETURN_REGISTERS(0)   /* restore 1 int/1 float return registers   */
475         RESTORE_ARGUMENT_REGISTERS(2) /* restore 6 int/6 float argument registers */
476         RESTORE_TEMPORARY_REGISTERS(14) /* restore 11 integer temporary registers */
477
478         ldq     itmp1,(2+12+27+0)*8(sp) /* restore itmp1                          */
479         ldq     itmp2,(2+12+27+1)*8(sp) /* restore itmp2                          */
480         ldq     ra,(2+12+27+2)*8(sp)  /* restore method return address (for leafs)*/
481         ldq     pv,(2+12+27+3)*8(sp)  /* restore pv of calling java function      */
482
483         ldq     itmp3,(0+2+12+27+4)*8(sp) /* get return value                     */
484         bne     itmp3,L_asm_patcher_wrapper_exception
485
486         ldq     itmp3,(5+2+12+27+4)*8(sp) /* get RA to JIT                        */
487         lda     sp,(6+2+12+27+4)*8(sp) /* remove stack frame                      */
488
489         jmp     zero,(itmp3)          /* jump to new patched code                 */
490
491 L_asm_patcher_wrapper_exception:
492         mov     itmp3,xptr            /* get exception                            */
493         ldq     xpc,(5+2+12+27+4)*8(sp) /* RA is xpc                              */
494         lda     sp,(6+2+12+27+4)*8(sp) /* remove stack frame                      */
495         br      L_asm_handle_exception
496
497         .end    asm_patcher_wrapper
498
499                 
500 #if defined(ENABLE_REPLACEMENT)
501
502 /* asm_replacement_out *********************************************************
503
504    This code is jumped to from the replacement-out stubs that are executed
505    when a thread reaches an activated replacement point.
506
507    The purpose of asm_replacement_out is to read out the parts of the
508    execution state that cannot be accessed from C code, store this state,
509    and then call the C function replace_me.
510
511    Stack layout:
512      16                 start of stack inside method to replace
513       0   rplpoint *    info on the replacement point that was reached
514
515    NOTE: itmp3 has been clobbered by the replacement-out stub!
516
517 *******************************************************************************/
518
519 /* some room to accomodate changes of the stack frame size during replacement */
520         /* XXX we should find a cleaner solution here */
521 #define REPLACEMENT_ROOM  512
522
523 #define REPLACEMENT_STACK_OFFSET ((sizeexecutionstate + REPLACEMENT_ROOM + 0xf) & ~0xf)
524
525         .ent asm_replacement_out
526
527 asm_replacement_out:
528     /* create stack frame */
529         lda     sp,-(REPLACEMENT_STACK_OFFSET)(sp)
530
531         /* save registers in execution state */
532         stq     $0 ,( 0*8+offes_intregs)(sp)
533         stq     $1 ,( 1*8+offes_intregs)(sp)
534         stq     $2 ,( 2*8+offes_intregs)(sp)
535         stq     $3 ,( 3*8+offes_intregs)(sp)
536         stq     $4 ,( 4*8+offes_intregs)(sp)
537         stq     $5 ,( 5*8+offes_intregs)(sp)
538         stq     $6 ,( 6*8+offes_intregs)(sp)
539         stq     $7 ,( 7*8+offes_intregs)(sp)
540         stq     $8 ,( 8*8+offes_intregs)(sp)
541         stq     $9 ,( 9*8+offes_intregs)(sp)
542         stq     $10,(10*8+offes_intregs)(sp)
543         stq     $11,(11*8+offes_intregs)(sp)
544         stq     $12,(12*8+offes_intregs)(sp)
545         stq     $13,(13*8+offes_intregs)(sp)
546         stq     $14,(14*8+offes_intregs)(sp)
547         stq     $15,(15*8+offes_intregs)(sp)
548         stq     $16,(16*8+offes_intregs)(sp)
549         stq     $17,(17*8+offes_intregs)(sp)
550         stq     $18,(18*8+offes_intregs)(sp)
551         stq     $19,(19*8+offes_intregs)(sp)
552         stq     $20,(20*8+offes_intregs)(sp)
553         stq     $21,(21*8+offes_intregs)(sp)
554         stq     $22,(22*8+offes_intregs)(sp)
555         stq     $23,(23*8+offes_intregs)(sp)
556         stq     $24,(24*8+offes_intregs)(sp)
557         stq     $25,(25*8+offes_intregs)(sp)
558         stq     $26,(26*8+offes_intregs)(sp)
559         stq     $27,(27*8+offes_intregs)(sp)
560         stq     $28,(28*8+offes_intregs)(sp)
561         stq     $29,(29*8+offes_intregs)(sp)
562         stq     $30,(30*8+offes_intregs)(sp)
563         stq     $31,(31*8+offes_intregs)(sp)
564         
565         stt     $f0 ,( 0*8+offes_fltregs)(sp)
566         stt     $f1 ,( 1*8+offes_fltregs)(sp)
567         stt     $f2 ,( 2*8+offes_fltregs)(sp)
568         stt     $f3 ,( 3*8+offes_fltregs)(sp)
569         stt     $f4 ,( 4*8+offes_fltregs)(sp)
570         stt     $f5 ,( 5*8+offes_fltregs)(sp)
571         stt     $f6 ,( 6*8+offes_fltregs)(sp)
572         stt     $f7 ,( 7*8+offes_fltregs)(sp)
573         stt     $f8 ,( 8*8+offes_fltregs)(sp)
574         stt     $f9 ,( 9*8+offes_fltregs)(sp)
575         stt     $f10,(10*8+offes_fltregs)(sp)
576         stt     $f11,(11*8+offes_fltregs)(sp)
577         stt     $f12,(12*8+offes_fltregs)(sp)
578         stt     $f13,(13*8+offes_fltregs)(sp)
579         stt     $f14,(14*8+offes_fltregs)(sp)
580         stt     $f15,(15*8+offes_fltregs)(sp)
581         stt     $f16,(16*8+offes_fltregs)(sp)
582         stt     $f17,(17*8+offes_fltregs)(sp)
583         stt     $f18,(18*8+offes_fltregs)(sp)
584         stt     $f19,(19*8+offes_fltregs)(sp)
585         stt     $f20,(20*8+offes_fltregs)(sp)
586         stt     $f21,(21*8+offes_fltregs)(sp)
587         stt     $f22,(22*8+offes_fltregs)(sp)
588         stt     $f23,(23*8+offes_fltregs)(sp)
589         stt     $f24,(24*8+offes_fltregs)(sp)
590         stt     $f25,(25*8+offes_fltregs)(sp)
591         stt     $f26,(26*8+offes_fltregs)(sp)
592         stt     $f27,(27*8+offes_fltregs)(sp)
593         stt     $f28,(28*8+offes_fltregs)(sp)
594         stt     $f29,(29*8+offes_fltregs)(sp)
595         stt     $f30,(30*8+offes_fltregs)(sp)
596         stt     $f31,(31*8+offes_fltregs)(sp)
597         
598         /* calculate sp of method */
599         lda     itmp1,(REPLACEMENT_STACK_OFFSET + 2*8)(sp)
600         stq     itmp1,(offes_sp)(sp)
601
602         br      ra,L_asm_replacement_out_load_gp
603 L_asm_replacement_out_load_gp:
604         ldgp    gp,0(ra)                    /* load gp                            */
605
606         /* store pv */
607         stq     pv,(offes_pv)(sp)
608
609         /* call replace_me */
610         ldq     a0,-(2*8)(itmp1)            /* arg0: rplpoint *                   */
611     mov     sp,a1                       /* arg1: execution state              */
612     jmp     zero,replace_me             /* call C function replace_me         */
613     jmp     zero,abort                  /* NEVER REACHED                      */
614
615         .end asm_replacement_out
616
617 /* asm_replacement_in **********************************************************
618
619    This code writes the given execution state and jumps to the replacement
620    code.
621
622    This function never returns!
623
624    NOTE: itmp3 is not restored!
625
626    C prototype:
627       void asm_replacement_in(executionstate *es, replace_safestack_t *st);
628
629 *******************************************************************************/
630
631         .ent asm_replacement_in
632         
633 asm_replacement_in:
634         /* a0 == executionstate *es */
635
636         /* get arguments */
637         mov     a1,s1                       /* replace_safestack_t *st            */
638         mov     a0,s2                       /* executionstate *es == safe stack   */
639
640         /* switch to the safe stack */
641         mov     s2,sp
642
643         /* call replace_build_execution_state(st) */
644         mov             s1,a0
645         jsr             ra,replace_build_execution_state
646
647         /* set new sp */
648         ldq             sp,(offes_sp)(s2)
649
650         /* build stack frame */
651         lda     sp,(-sizeexecutionstate)(sp)
652
653         /* call replace_free_safestack(st,& of allocated executionstate_t) */
654         mov             sp,a1 /* tmpes */
655         mov             s1,a0 /* st    */
656         jsr             ra,replace_free_safestack
657
658         /* set new pv */
659         ldq     pv,(offes_pv)(sp)
660         
661         /* copy registers from execution state */
662         ldq     $0 ,( 0*8+offes_intregs)(sp)
663         ldq     $1 ,( 1*8+offes_intregs)(sp)
664         ldq     $2 ,( 2*8+offes_intregs)(sp)
665         ldq     $3 ,( 3*8+offes_intregs)(sp)
666         ldq     $4 ,( 4*8+offes_intregs)(sp)
667         ldq     $5 ,( 5*8+offes_intregs)(sp)
668         ldq     $6 ,( 6*8+offes_intregs)(sp)
669         ldq     $7 ,( 7*8+offes_intregs)(sp)
670         ldq     $8 ,( 8*8+offes_intregs)(sp)
671         ldq     $9 ,( 9*8+offes_intregs)(sp)
672         ldq     $10,(10*8+offes_intregs)(sp)
673         ldq     $11,(11*8+offes_intregs)(sp)
674         ldq     $12,(12*8+offes_intregs)(sp)
675         ldq     $13,(13*8+offes_intregs)(sp)
676         ldq     $14,(14*8+offes_intregs)(sp)
677         ldq     $15,(15*8+offes_intregs)(sp)
678         ldq     a0, (16*8+offes_intregs)(sp)
679         ldq     $17,(17*8+offes_intregs)(sp)
680         ldq     $18,(18*8+offes_intregs)(sp)
681         ldq     $19,(19*8+offes_intregs)(sp)
682         ldq     $20,(20*8+offes_intregs)(sp)
683         ldq     $21,(21*8+offes_intregs)(sp)
684         ldq     $22,(22*8+offes_intregs)(sp)
685         ldq     $23,(23*8+offes_intregs)(sp)
686         ldq     $24,(24*8+offes_intregs)(sp)
687         ldq     $25,(25*8+offes_intregs)(sp)
688         ldq     $26,(26*8+offes_intregs)(sp)
689         /* $27 is pv                    */
690         ldq     $28,(28*8+offes_intregs)(sp)
691         ldq     $29,(29*8+offes_intregs)(sp)
692         /* $30 is sp                      */
693         /* $31 is zero                    */
694         
695         ldt     $f0 ,( 0*8+offes_fltregs)(sp)
696         ldt     $f1 ,( 1*8+offes_fltregs)(sp)
697         ldt     $f2 ,( 2*8+offes_fltregs)(sp)
698         ldt     $f3 ,( 3*8+offes_fltregs)(sp)
699         ldt     $f4 ,( 4*8+offes_fltregs)(sp)
700         ldt     $f5 ,( 5*8+offes_fltregs)(sp)
701         ldt     $f6 ,( 6*8+offes_fltregs)(sp)
702         ldt     $f7 ,( 7*8+offes_fltregs)(sp)
703         ldt     $f8 ,( 8*8+offes_fltregs)(sp)
704         ldt     $f9 ,( 9*8+offes_fltregs)(sp)
705         ldt     $f10,(10*8+offes_fltregs)(sp)
706         ldt     $f11,(11*8+offes_fltregs)(sp)
707         ldt     $f12,(12*8+offes_fltregs)(sp)
708         ldt     $f13,(13*8+offes_fltregs)(sp)
709         ldt     $f14,(14*8+offes_fltregs)(sp)
710         ldt     $f15,(15*8+offes_fltregs)(sp)
711         ldt     $f16,(16*8+offes_fltregs)(sp)
712         ldt     $f17,(17*8+offes_fltregs)(sp)
713         ldt     $f18,(18*8+offes_fltregs)(sp)
714         ldt     $f19,(19*8+offes_fltregs)(sp)
715         ldt     $f20,(20*8+offes_fltregs)(sp)
716         ldt     $f21,(21*8+offes_fltregs)(sp)
717         ldt     $f22,(22*8+offes_fltregs)(sp)
718         ldt     $f23,(23*8+offes_fltregs)(sp)
719         ldt     $f24,(24*8+offes_fltregs)(sp)
720         ldt     $f25,(25*8+offes_fltregs)(sp)
721         ldt     $f26,(26*8+offes_fltregs)(sp)
722         ldt     $f27,(27*8+offes_fltregs)(sp)
723         ldt     $f28,(28*8+offes_fltregs)(sp)
724         ldt     $f29,(29*8+offes_fltregs)(sp)
725         ldt     $f30,(30*8+offes_fltregs)(sp)
726         ldt     $f31,(31*8+offes_fltregs)(sp)
727
728         /* load new pc */
729
730         ldq     itmp3,offes_pc(sp)
731
732         /* remove stack frame */
733
734         lda             sp,(sizeexecutionstate)(sp)
735
736         /* jump to new code */
737
738         jmp     zero,(itmp3)
739
740         .end asm_replacement_in
741
742 #endif /* defined(ENABLE_REPLACEMENT) */
743
744
745 /* asm_compare_and_swap ********************************************************
746
747    Does an atomic compare and swap.  Required for the lock
748    implementation.
749
750    Atomically do the following: Check if the location still contains
751    `oldval`. If so, replace it by `newval` and return `oldval`.
752
753    RETURN VALUE:
754        the old value at *p
755
756    long compare_and_swap(volatile long *p, long oldval, long newval);
757
758 *******************************************************************************/
759
760         .ent    asm_compare_and_swap
761
762 asm_compare_and_swap:
763 1:
764         ldq_l   v0,0(a0)
765         cmpeq   v0,a1,t0
766         beq     t0,2f
767         mov     a2,t0
768         stq_c   t0,0(a0)
769         beq     t0,1b
770 2:
771         jmp     zero,(ra)
772
773         .end    asm_compare_and_swap
774
775
776 /* asm_memory_barrier **********************************************************
777
778    A memory barrier for the Java Memory Model.
779
780 *******************************************************************************/
781
782         .ent    asm_memory_barrier
783
784 asm_memory_barrier:
785         mb
786         jmp     zero,(ra)
787
788         .end    asm_memory_barrier
789
790
791         .ent    asm_getclassvalues_atomic
792
793 asm_getclassvalues_atomic:
794 _crit_restart:
795 _crit_begin:
796         ldl     t0,offbaseval(a0)
797         ldl     t1,offdiffval(a0)
798         ldl     t2,offbaseval(a1)
799 _crit_end:
800         stl     t0,offcast_super_baseval(a2)
801         stl     t1,offcast_super_diffval(a2)
802         stl     t2,offcast_sub_baseval(a2)
803         jmp     zero,(ra)
804
805         .end    asm_getclassvalues_atomic
806
807
808     .data
809
810 asm_criticalsections:
811 #if defined(ENABLE_THREADS)
812     .quad   _crit_begin
813     .quad   _crit_end
814     .quad   _crit_restart
815 #endif
816     .quad   0
817
818
819 /* asm_md_init *****************************************************************
820
821    Initialize machine dependent stuff.
822
823    Determines if the byte support instruction set (21164a and higher)
824    is available.
825
826 *******************************************************************************/
827
828         .ent    asm_md_init
829
830 asm_md_init:
831         .long   0x47e03c20                  /* amask   1,v0                       */
832         jmp     zero,(ra)                   /* return                             */
833
834         .end    asm_md_init
835
836
837 /* asm_cacheflush **************************************************************
838
839    XXX
840
841 *******************************************************************************/
842
843         .ent    asm_cacheflush
844
845 asm_cacheflush:
846         call_pal PAL_imb              /* synchronize instruction cache            */
847         jmp     zero,(ra)
848
849         .end    asm_cacheflush
850
851
852 /* Disable exec-stacks, required for Gentoo ***********************************/
853
854 #if defined(__GCC__) && defined(__ELF__)
855         .section .note.GNU-stack,"",@progbits
856 #endif
857
858
859 /*
860  * These are local overrides for various environment variables in Emacs.
861  * Please do not remove this and leave it at the end of the file, where
862  * Emacs will automagically detect them.
863  * ---------------------------------------------------------------------
864  * Local variables:
865  * mode: asm
866  * indent-tabs-mode: t
867  * c-basic-offset: 4
868  * tab-width: 4
869  * End:
870  * vim:noexpandtab:sw=4:ts=4:
871  */