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