* src/vm/jit/powerpc/emit.c (emit_replacement_stubs): Prepared for
[cacao.git] / src / vm / jit / mips / emit.c
1 /* src/vm/jit/mips/emit.c - MIPS code emitter functions
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: Christian Thalinger
28
29    Changes:
30
31    $Id: emitfuncs.c 4398 2006-01-31 23:43:08Z twisti $
32
33 */
34
35
36 #include "config.h"
37
38 #include "vm/types.h"
39
40 #include "md-abi.h"
41
42 #include "vm/jit/mips/codegen.h"
43
44 #if defined(ENABLE_THREADS)
45 # include "threads/native/lock.h"
46 #endif
47
48 #include "vm/exceptions.h"
49 #include "vm/options.h"
50 #include "vm/stringlocal.h" /* XXX for gen_resolvebranch */
51 #include "vm/jit/abi-asm.h"
52 #include "vm/jit/asmpart.h"
53 #include "vm/jit/dseg.h"
54 #include "vm/jit/emit-common.h"
55 #include "vm/jit/jit.h"
56 #include "vm/jit/replace.h"
57
58
59 /* emit_load *******************************************************************
60
61    Emits a possible load of an operand.
62
63 *******************************************************************************/
64
65 s4 emit_load(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
66 {
67         codegendata  *cd;
68         s4            disp;
69         s4            reg;
70
71         /* get required compiler data */
72
73         cd = jd->cd;
74
75         if (src->flags & INMEMORY) {
76                 COUNT_SPILLS;
77
78                 disp = src->vv.regoff * 8;
79
80                 if (IS_FLT_DBL_TYPE(src->type)) {
81                         if (IS_2_WORD_TYPE(src->type))
82                                 M_DLD(tempreg, REG_SP, disp);
83                         else
84                                 M_FLD(tempreg, REG_SP, disp);
85                 }
86                 else
87                         M_LLD(tempreg, REG_SP, disp);
88
89                 reg = tempreg;
90         }
91         else
92                 reg = src->vv.regoff;
93
94         return reg;
95 }
96
97
98 /* emit_store ******************************************************************
99
100    Emits a possible store to variable.
101
102 *******************************************************************************/
103
104 void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d)
105 {
106         codegendata  *cd;
107         s4            disp;
108
109         /* get required compiler data */
110
111         cd = jd->cd;
112
113         if (dst->flags & INMEMORY) {
114                 COUNT_SPILLS;
115
116                 disp = dst->vv.regoff * 8;
117
118                 if (IS_FLT_DBL_TYPE(dst->type)) {
119                         if (IS_2_WORD_TYPE(dst->type))
120                                 M_DST(d, REG_SP, disp);
121                         else
122                                 M_FST(d, REG_SP, disp);
123                 }
124                 else
125                         M_LST(d, REG_SP, disp);
126         }
127 }
128
129
130 /* emit_copy *******************************************************************
131
132    Generates a register/memory to register/memory copy.
133
134 *******************************************************************************/
135
136 void emit_copy(jitdata *jd, instruction *iptr, varinfo *src, varinfo *dst)
137 {
138         codegendata  *cd;
139         s4            s1, d;
140
141         /* get required compiler data */
142
143         cd = jd->cd;
144
145         if ((src->vv.regoff != dst->vv.regoff) ||
146                 ((src->flags ^ dst->flags) & INMEMORY)) {
147
148                 /* If one of the variables resides in memory, we can eliminate
149                    the register move from/to the temporary register with the
150                    order of getting the destination register and the load. */
151
152                 if (IS_INMEMORY(src->flags)) {
153                         d = codegen_reg_of_var(iptr->opc, dst, REG_IFTMP);
154                         s1 = emit_load(jd, iptr, src, d);
155                 }
156                 else {
157                         s1 = emit_load(jd, iptr, src, REG_IFTMP);
158                         d = codegen_reg_of_var(iptr->opc, dst, s1);
159                 }
160
161                 if (s1 != d) {
162                         if (IS_FLT_DBL_TYPE(src->type)) {
163                                 if (IS_2_WORD_TYPE(src->type))
164                                         M_DMOV(s1, d);
165                                 else
166                                         M_FMOV(s1, d);
167                         }
168                         else
169                                 M_MOV(s1, d);
170                 }
171
172                 emit_store(jd, iptr, dst, d);
173         }
174 }
175
176
177 /* emit_iconst *****************************************************************
178
179    XXX
180
181 *******************************************************************************/
182
183 void emit_iconst(codegendata *cd, s4 d, s4 value)
184 {
185         s4 disp;
186
187     if ((value >= -32768) && (value <= 32767))
188         M_IADD_IMM(REG_ZERO, value, d);
189         else if ((value >= 0) && (value <= 0xffff))
190         M_OR_IMM(REG_ZERO, value, d);
191         else {
192         disp = dseg_add_s4(cd, value);
193         M_ILD(d, REG_PV, disp);
194     }
195 }
196
197
198 /* emit_lconst *****************************************************************
199
200    XXX
201
202 *******************************************************************************/
203
204 void emit_lconst(codegendata *cd, s4 d, s8 value)
205 {
206         s4 disp;
207
208         if ((value >= -32768) && (value <= 32767))
209                 M_LADD_IMM(REG_ZERO, value, d);
210         else if ((value >= 0) && (value <= 0xffff))
211                 M_OR_IMM(REG_ZERO, value, d);
212         else {
213                 disp = dseg_add_s8(cd, value);
214                 M_LLD(d, REG_PV, disp);
215         }
216 }
217
218
219 /* emit_arithmetic_check *******************************************************
220
221    Emit an ArithmeticException check.
222
223 *******************************************************************************/
224
225 void emit_arithmetic_check(codegendata *cd, s4 reg)
226 {
227 #if 0
228         M_BEQZ(reg, 0);
229         codegen_add_arithmeticexception_ref(cd);
230         M_NOP;
231 #else
232         M_BNEZ(reg, 6);
233         M_NOP;
234
235         M_LUI(REG_ITMP3, 0);
236         M_OR_IMM(REG_ITMP3, 0, REG_ITMP3);
237         codegen_add_arithmeticexception_ref(cd);
238         M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
239         M_JMP(REG_ITMP3);
240         M_NOP;
241 #endif
242 }
243
244
245 /* emit_arrayindexoutofbounds_check ********************************************
246
247    Emit an ArrayIndexOutOfBoundsException check.
248
249 *******************************************************************************/
250
251 void emit_arrayindexoutofbounds_check(codegendata *cd, s4 s1, s4 s2)
252 {
253         if (checkbounds) {
254                 M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));
255                 M_CMPULT(s2, REG_ITMP3, REG_ITMP3);
256
257 #if 0
258                 M_BEQZ(REG_ITMP3, 0);
259                 codegen_add_arrayindexoutofboundsexception_ref(cd, s2);
260                 M_NOP;
261 #else
262                 M_BNEZ(REG_ITMP3, 6);
263                 M_NOP;
264
265                 M_LUI(REG_ITMP3, 0);
266                 M_OR_IMM(REG_ITMP3, 0, REG_ITMP3);
267                 codegen_add_arrayindexoutofboundsexception_ref(cd, s2);
268                 M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
269                 M_JMP(REG_ITMP3);
270                 M_NOP;
271 #endif
272         }
273 }
274
275
276 /* emit_arraystore_check *******************************************************
277
278    Emit an ArrayStoreException check.
279
280 *******************************************************************************/
281
282 void emit_arraystore_check(codegendata *cd, s4 reg)
283 {
284 #if 0
285         M_BEQZ(reg, 0);
286         codegen_add_arraystoreexception_ref(cd);
287         M_NOP;
288 #else
289         M_BNEZ(reg, 6);
290         M_NOP;
291
292         M_LUI(REG_ITMP3, 0);
293         M_OR_IMM(REG_ITMP3, 0, REG_ITMP3);
294         codegen_add_arraystoreexception_ref(cd);
295         M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
296         M_JMP(REG_ITMP3);
297         M_NOP;
298 #endif
299 }
300
301
302 /* emit_classcast_check ********************************************************
303
304    Emit a ClassCastException check.
305
306 *******************************************************************************/
307
308 void emit_classcast_check(codegendata *cd, s4 condition, s4 reg, s4 s1)
309 {
310 #if 0
311         M_BNEZ(reg, 0);
312         codegen_add_classcastexception_ref(cd, s1);
313         M_NOP;
314 #else
315         switch (condition) {
316         case ICMD_IFEQ:
317                 M_BNEZ(reg, 6);
318                 break;
319
320         case ICMD_IFNE:
321                 M_BEQZ(reg, 6);
322                 break;
323
324         case ICMD_IFLE:
325                 M_BGTZ(reg, 6);
326                 break;
327
328         default:
329                 vm_abort("emit_classcast_check: condition %d not found", condition);
330         }
331
332         M_NOP;
333
334         M_LUI(REG_ITMP3, 0);
335         M_OR_IMM(REG_ITMP3, 0, REG_ITMP3);
336         codegen_add_classcastexception_ref(cd, s1);
337         M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
338         M_JMP(REG_ITMP3);
339         M_NOP;
340 #endif
341 }
342
343
344 /* emit_nullpointer_check ******************************************************
345
346    Emit a NullPointerException check.
347
348 *******************************************************************************/
349
350 void emit_nullpointer_check(codegendata *cd, s4 reg)
351 {
352         if (checknull) {
353 #if 0
354                 M_BEQZ(reg, 0);
355                 codegen_add_nullpointerexception_ref(cd);
356                 M_NOP;
357 #else
358                 M_BNEZ(reg, 6);
359                 M_NOP;
360
361                 M_LUI(REG_ITMP3, 0);
362                 M_OR_IMM(REG_ITMP3, 0, REG_ITMP3);
363                 codegen_add_nullpointerexception_ref(cd);
364                 M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
365                 M_JMP(REG_ITMP3);
366                 M_NOP;
367 #endif
368         }
369 }
370
371
372 /* emit_exception_check ********************************************************
373
374    Emit an Exception check.
375
376 *******************************************************************************/
377
378 void emit_exception_check(codegendata *cd)
379 {
380 #if 0
381         M_BEQZ(REG_RESULT, 0);
382         codegen_add_fillinstacktrace_ref(cd);
383         M_NOP;
384 #else
385         M_BNEZ(REG_RESULT, 6);
386         M_NOP;
387
388         M_LUI(REG_ITMP3, 0);
389         M_OR_IMM(REG_ITMP3, 0, REG_ITMP3);
390         codegen_add_fillinstacktrace_ref(cd);
391         M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
392         M_JMP(REG_ITMP3);
393         M_NOP;
394 #endif
395 }
396
397
398 /* emit_exception_stubs ********************************************************
399
400    Generates the code for the exception stubs.
401
402 *******************************************************************************/
403
404 void emit_exception_stubs(jitdata *jd)
405 {
406         codegendata  *cd;
407         registerdata *rd;
408         exceptionref *er;
409         s4            branchmpc;
410         s4            targetmpc;
411         s4            targetdisp;
412         s4            disp;
413
414         /* get required compiler data */
415
416         cd = jd->cd;
417         rd = jd->rd;
418
419         /* generate exception stubs */
420
421         targetdisp = 0;
422
423         for (er = cd->exceptionrefs; er != NULL; er = er->next) {
424                 /* back-patch the branch to this exception code */
425
426                 branchmpc = er->branchpos;
427                 targetmpc = cd->mcodeptr - cd->mcodebase;
428
429                 md_codegen_patch_branch(cd, branchmpc, targetmpc);
430
431                 MCODECHECK(100);
432
433                 /* Check if the exception is an
434                    ArrayIndexOutOfBoundsException.  If so, move index register
435                    into REG_ITMP1. */
436
437                 if (er->reg != -1)
438                         M_MOV(er->reg, REG_ITMP1);
439
440                 /* calcuate exception address */
441
442                 M_LDA(REG_ITMP2_XPC, REG_PV, er->branchpos - 4);
443
444                 /* move function to call into REG_ITMP3 */
445
446                 disp = dseg_add_functionptr(cd, er->function);
447                 M_ALD(REG_ITMP3, REG_PV, disp);
448
449                 if (targetdisp == 0) {
450                         targetdisp = ((u4 *) cd->mcodeptr) - ((u4 *) cd->mcodebase);
451
452                         M_MOV(REG_PV, REG_A0);
453                         M_MOV(REG_SP, REG_A1);
454
455                         if (jd->isleafmethod)
456                                 M_MOV(REG_RA, REG_A2);
457                         else
458                                 M_ALD(REG_A2, REG_SP, (cd->stackframesize - 1) * 8);
459
460                         M_MOV(REG_ITMP2_XPC, REG_A3);
461                         M_MOV(REG_ITMP1, REG_A4);
462
463                         M_ASUB_IMM(REG_SP, 2 * 8, REG_SP);
464                         M_AST(REG_ITMP2_XPC, REG_SP, 0 * 8);
465
466                         if (jd->isleafmethod)
467                                 M_AST(REG_RA, REG_SP, 1 * 8);
468
469                         M_JSR(REG_RA, REG_ITMP3);
470                         M_NOP;
471                         M_MOV(REG_RESULT, REG_ITMP1_XPTR);
472
473                         if (jd->isleafmethod)
474                                 M_ALD(REG_RA, REG_SP, 1 * 8);
475
476                         M_ALD(REG_ITMP2_XPC, REG_SP, 0 * 8);
477                         M_AADD_IMM(REG_SP, 2 * 8, REG_SP);
478
479                         disp = dseg_add_functionptr(cd, asm_handle_exception);
480                         M_ALD(REG_ITMP3, REG_PV, disp);
481                         M_JMP(REG_ITMP3);
482                         M_NOP;
483                 }
484                 else {
485                         disp = (((u4 *) cd->mcodebase) + targetdisp) -
486                                 (((u4 *) cd->mcodeptr) + 1);
487
488                         M_BR(disp);
489                         M_NOP;
490                 }
491         }
492 }
493
494
495 /* emit_patcher_stubs **********************************************************
496
497    Generates the code for the patcher stubs.
498
499 *******************************************************************************/
500
501 void emit_patcher_stubs(jitdata *jd)
502 {
503         codegendata *cd;
504         patchref    *pr;
505         u4           mcode[5];
506         u1          *savedmcodeptr;
507         u1          *tmpmcodeptr;
508         s4           targetdisp;
509         s4           disp;
510         s4           hi;
511         s4           lo;
512
513         /* get required compiler data */
514
515         cd = jd->cd;
516
517         /* generate code patching stub call code */
518
519         targetdisp = 0;
520
521 /*      for (pr = list_first_unsynced(cd->patchrefs); pr != NULL; */
522 /*               pr = list_next_unsynced(cd->patchrefs, pr)) { */
523         for (pr = cd->patchrefs; pr != NULL; pr = pr->next) {
524                 /* check code segment size */
525
526                 MCODECHECK(100);
527
528                 /* Get machine code which is patched back in later. The
529                    call is 2 instruction words long. */
530
531                 tmpmcodeptr = (u1 *) (cd->mcodebase + pr->branchpos);
532
533                 /* We use 2 loads here as an unaligned 8-byte read on 64-bit
534                    MIPS causes a SIGSEGV and using the same code for both
535                    architectures is much better. */
536
537                 mcode[0] = ((u4 *) tmpmcodeptr)[0];
538                 mcode[1] = ((u4 *) tmpmcodeptr)[1];
539
540                 mcode[2] = ((u4 *) tmpmcodeptr)[2];
541                 mcode[3] = ((u4 *) tmpmcodeptr)[3];
542                 mcode[4] = ((u4 *) tmpmcodeptr)[4];
543
544                 /* Patch in the call to call the following code (done at
545                    compile time). */
546
547                 savedmcodeptr = cd->mcodeptr;   /* save current mcodeptr              */
548                 cd->mcodeptr  = tmpmcodeptr;    /* set mcodeptr to patch position     */
549
550                 disp = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) + 1);
551
552                 if ((disp < (s4) 0xffff8000) || (disp > (s4) 0x00007fff)) {
553                         /* Recalculate the displacement to be relative to PV. */
554
555                         disp = savedmcodeptr - cd->mcodebase;
556
557                         lo = (short) disp;
558                         hi = (short) ((disp - lo) >> 16);
559
560                         M_LUI(REG_ITMP3, hi);
561                         M_OR_IMM(REG_ITMP3, lo, REG_ITMP3);
562                         M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
563                         M_JMP(REG_ITMP3);
564                         M_NOP;
565                 }
566                 else {
567                         M_BR(disp);
568                         M_NOP;
569                         M_NOP;
570                         M_NOP;
571                         M_NOP;
572                 }
573
574                 cd->mcodeptr = savedmcodeptr;   /* restore the current mcodeptr   */
575
576                 /* create stack frame */
577
578                 M_ASUB_IMM(REG_SP, 8 * 8, REG_SP);
579
580                 /* calculate return address and move it onto the stack */
581
582                 M_LDA(REG_ITMP3, REG_PV, pr->branchpos);
583                 M_AST(REG_ITMP3, REG_SP, 7 * 8);
584
585                 /* move pointer to java_objectheader onto stack */
586
587 #if defined(ENABLE_THREADS)
588                 /* create a virtual java_objectheader */
589
590                 (void) dseg_add_unique_address(cd, NULL);                  /* flcword */
591                 (void) dseg_add_unique_address(cd, lock_get_initial_lock_word());
592                 disp = dseg_add_unique_address(cd, NULL);                  /* vftbl   */
593
594                 M_LDA(REG_ITMP3, REG_PV, disp);
595                 M_AST(REG_ITMP3, REG_SP, 6 * 8);
596 #else
597                 /* do nothing */
598 #endif
599
600                 /* move machine code onto stack */
601
602                 disp = dseg_add_s4(cd, mcode[0]);
603                 M_ILD(REG_ITMP3, REG_PV, disp);
604                 M_IST(REG_ITMP3, REG_SP, 3 * 8 + 0);
605
606                 disp = dseg_add_s4(cd, mcode[1]);
607                 M_ILD(REG_ITMP3, REG_PV, disp);
608                 M_IST(REG_ITMP3, REG_SP, 3 * 8 + 4);
609
610                 disp = dseg_add_s4(cd, mcode[2]);
611                 M_ILD(REG_ITMP3, REG_PV, disp);
612                 M_IST(REG_ITMP3, REG_SP, 4 * 8 + 0);
613
614                 disp = dseg_add_s4(cd, mcode[3]);
615                 M_ILD(REG_ITMP3, REG_PV, disp);
616                 M_IST(REG_ITMP3, REG_SP, 4 * 8 + 4);
617
618                 disp = dseg_add_s4(cd, mcode[4]);
619                 M_ILD(REG_ITMP3, REG_PV, disp);
620                 M_IST(REG_ITMP3, REG_SP, 5 * 8 + 0);
621
622                 /* move class/method/field reference onto stack */
623
624                 disp = dseg_add_address(cd, pr->ref);
625                 M_ALD(REG_ITMP3, REG_PV, disp);
626                 M_AST(REG_ITMP3, REG_SP, 2 * 8);
627
628                 /* move data segment displacement onto stack */
629
630                 disp = dseg_add_s4(cd, pr->disp);
631                 M_ILD(REG_ITMP3, REG_PV, disp);
632                 M_IST(REG_ITMP3, REG_SP, 1 * 8);
633
634                 /* move patcher function pointer onto stack */
635
636                 disp = dseg_add_address(cd, pr->patcher);
637                 M_ALD(REG_ITMP3, REG_PV, disp);
638                 M_AST(REG_ITMP3, REG_SP, 0 * 8);
639
640                 if (targetdisp == 0) {
641                         targetdisp = ((u4 *) cd->mcodeptr) - ((u4 *) cd->mcodebase);
642
643                         disp = dseg_add_functionptr(cd, asm_patcher_wrapper);
644                         M_ALD(REG_ITMP3, REG_PV, disp);
645                         M_JMP(REG_ITMP3);
646                         M_NOP;
647                 }
648                 else {
649                         disp = (((u4 *) cd->mcodebase) + targetdisp) -
650                                 (((u4 *) cd->mcodeptr) + 1);
651
652                         M_BR(disp);
653                         M_NOP;
654                 }
655         }
656 }
657
658
659 /* emit_replacement_stubs ******************************************************
660
661    Generates the code for the replacement stubs.
662
663 *******************************************************************************/
664
665 void emit_replacement_stubs(jitdata *jd)
666 {
667         codegendata *cd;
668         codeinfo    *code;
669         rplpoint    *rplp;
670         s4           disp;
671         s4           i;
672 #if !defined(NDEBUG)
673         u1          *savedmcodeptr;
674 #endif
675
676         /* get required compiler data */
677
678         cd   = jd->cd;
679         code = jd->code;
680
681         rplp = code->rplpoints;
682
683         /* store beginning of replacement stubs */
684
685         code->replacementstubs = (u1*) (cd->mcodeptr - cd->mcodebase);
686
687         for (i = 0; i < code->rplpointcount; ++i, ++rplp) {
688                 /* do not generate stubs for non-trappable points */
689
690                 if (rplp->flags & RPLPOINT_FLAG_NOTRAP)
691                         continue;
692
693                 /* check code segment size */
694
695                 MCODECHECK(100);
696
697 #if !defined(NDEBUG)
698                 savedmcodeptr = cd->mcodeptr;
699 #endif
700
701                 /* create stack frame - 16-byte aligned */
702
703                 M_ASUB_IMM(REG_SP, 2 * 8, REG_SP);
704
705                 /* push address of `rplpoint` struct */
706
707                 disp = dseg_add_address(cd, rplp);
708                 M_ALD(REG_ITMP3, REG_PV, disp);
709                 M_AST(REG_ITMP3, REG_SP, 0 * 8);
710
711                 /* jump to replacement function */
712
713                 disp = dseg_add_functionptr(cd, asm_replacement_out);
714                 M_ALD(REG_ITMP3, REG_PV, disp);
715                 M_JMP(REG_ITMP3);
716                 M_NOP; /* delay slot */
717
718                 assert((cd->mcodeptr - savedmcodeptr) == 4*REPLACEMENT_STUB_SIZE);
719         }
720 }
721
722
723 /* emit_verbosecall_enter ******************************************************
724
725    Generates the code for the call trace.
726
727 *******************************************************************************/
728
729 #if !defined(NDEBUG)
730 void emit_verbosecall_enter(jitdata *jd)
731 {
732         methodinfo   *m;
733         codegendata  *cd;
734         registerdata *rd;
735         methoddesc   *md;
736         s4            disp;
737         s4            i, t;
738
739         /* get required compiler data */
740
741         m  = jd->m;
742         cd = jd->cd;
743         rd = jd->rd;
744
745         md = m->parseddesc;
746
747         /* mark trace code */
748
749         M_NOP;
750
751         M_LDA(REG_SP, REG_SP, -(2 + ARG_CNT + TMP_CNT) * 8);
752         M_AST(REG_RA, REG_SP, 1 * 8);
753
754         /* save argument registers */
755
756         for (i = 0; i < INT_ARG_CNT; i++)
757                 M_LST(rd->argintregs[i], REG_SP, (2 + i) * 8);
758
759         for (i = 0; i < FLT_ARG_CNT; i++)
760                 M_DST(rd->argfltregs[i], REG_SP, (2 + INT_ARG_CNT + i) * 8);
761
762         /* save temporary registers for leaf methods */
763
764         if (jd->isleafmethod) {
765                 for (i = 0; i < INT_TMP_CNT; i++)
766                         M_LST(rd->tmpintregs[i], REG_SP, (2 + ARG_CNT + i) * 8);
767
768                 for (i = 0; i < FLT_TMP_CNT; i++)
769                         M_DST(rd->tmpfltregs[i], REG_SP, (2 + ARG_CNT + INT_TMP_CNT + i) * 8);
770         }
771
772         /* load float arguments into integer registers */
773
774         for (i = 0; i < md->paramcount && i < INT_ARG_CNT; i++) {
775                 t = md->paramtypes[i].type;
776
777                 if (IS_FLT_DBL_TYPE(t)) {
778                         if (IS_2_WORD_TYPE(t)) {
779                                 M_DST(rd->argfltregs[i], REG_SP, 0 * 8);
780                                 M_LLD(rd->argintregs[i], REG_SP, 0 * 8);
781                         }
782                         else {
783                                 M_FST(rd->argfltregs[i], REG_SP, 0 * 8);
784                                 M_ILD(rd->argintregs[i], REG_SP, 0 * 8);
785                         }
786                 }
787         }
788
789         disp = dseg_add_address(cd, m);
790         M_ALD(REG_ITMP1, REG_PV, disp);
791         M_AST(REG_ITMP1, REG_SP, 0 * 8);
792         disp = dseg_add_functionptr(cd, builtin_trace_args);
793         M_ALD(REG_ITMP3, REG_PV, disp);
794         M_JSR(REG_RA, REG_ITMP3);
795         M_NOP;
796
797         /* restore argument registers */
798
799         for (i = 0; i < INT_ARG_CNT; i++)
800                 M_LLD(rd->argintregs[i], REG_SP, (2 + i) * 8);
801
802         for (i = 0; i < FLT_ARG_CNT; i++)
803                 M_DLD(rd->argfltregs[i], REG_SP, (2 + INT_ARG_CNT + i) * 8);
804
805         /* restore temporary registers for leaf methods */
806
807         if (jd->isleafmethod) {
808                 for (i = 0; i < INT_TMP_CNT; i++)
809                         M_LLD(rd->tmpintregs[i], REG_SP, (2 + ARG_CNT + i) * 8);
810
811                 for (i = 0; i < FLT_TMP_CNT; i++)
812                         M_DLD(rd->tmpfltregs[i], REG_SP, (2 + ARG_CNT + INT_TMP_CNT + i) * 8);
813         }
814
815         M_ALD(REG_RA, REG_SP, 1 * 8);
816         M_LDA(REG_SP, REG_SP, (2 + ARG_CNT + TMP_CNT) * 8);
817
818         /* mark trace code */
819
820         M_NOP;
821 }
822 #endif /* !defined(NDEBUG) */
823
824
825 /* emit_verbosecall_exit *******************************************************
826
827    Generates the code for the call trace.
828
829 *******************************************************************************/
830
831 #if !defined(NDEBUG)
832 void emit_verbosecall_exit(jitdata *jd)
833 {
834         methodinfo   *m;
835         codegendata  *cd;
836         registerdata *rd;
837         s4            disp;
838
839         /* get required compiler data */
840
841         m  = jd->m;
842         cd = jd->cd;
843         rd = jd->rd;
844
845         /* mark trace code */
846
847         M_NOP;
848
849         M_LDA(REG_SP, REG_SP, -4 * 8);              /* keep stack 16-byte aligned */
850         M_LST(REG_RA, REG_SP, 0 * 8);
851
852         M_LST(REG_RESULT, REG_SP, 1 * 8);
853         M_DST(REG_FRESULT, REG_SP, 2 * 8);
854
855         disp = dseg_add_address(cd, m);
856         M_ALD(rd->argintregs[0], REG_PV, disp);
857
858         M_MOV(REG_RESULT, rd->argintregs[1]);
859         M_DMOV(REG_FRESULT, rd->argfltregs[2]);
860         M_FMOV(REG_FRESULT, rd->argfltregs[3]);
861
862         disp = dseg_add_functionptr(cd, builtin_displaymethodstop);
863         M_ALD(REG_ITMP3, REG_PV, disp);
864         M_JSR(REG_RA, REG_ITMP3);
865         M_NOP;
866
867         M_DLD(REG_FRESULT, REG_SP, 2 * 8);
868         M_LLD(REG_RESULT, REG_SP, 1 * 8);
869
870         M_LLD(REG_RA, REG_SP, 0 * 8);
871         M_LDA(REG_SP, REG_SP, 4 * 8);
872
873         /* mark trace code */
874
875         M_NOP;
876 }
877 #endif /* !defined(NDEBUG) */
878
879
880 /*
881  * These are local overrides for various environment variables in Emacs.
882  * Please do not remove this and leave it at the end of the file, where
883  * Emacs will automagically detect them.
884  * ---------------------------------------------------------------------
885  * Local variables:
886  * mode: c
887  * indent-tabs-mode: t
888  * c-basic-offset: 4
889  * tab-width: 4
890  * End:
891  * vim:noexpandtab:sw=4:ts=4:
892  */