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