b418863715f9990a633bfdf9ed9a27ca5b51ce9a
[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, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: emit.c 4398 2006-01-31 23:43:08Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33
34 #include "vm/types.h"
35
36 #include "vm/jit/mips/codegen.h"
37 #include "vm/jit/mips/md-abi.h"
38
39 #include "mm/memory.h"
40
41 #include "threads/lock-common.h"
42
43 #include "vm/builtin.h"
44 #include "vm/exceptions.h"
45 #include "vm/stringlocal.h" /* XXX for gen_resolvebranch */
46
47 #include "vm/jit/abi.h"
48 #include "vm/jit/abi-asm.h"
49 #include "vm/jit/asmpart.h"
50 #include "vm/jit/dseg.h"
51 #include "vm/jit/emit-common.h"
52 #include "vm/jit/jit.h"
53 #include "vm/jit/patcher-common.h"
54 #include "vm/jit/replace.h"
55
56 #include "vmcore/options.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;
79
80                 switch (src->type) {
81 #if SIZEOF_VOID_P == 8
82                 case TYPE_INT:
83                 case TYPE_LNG:
84                 case TYPE_ADR:
85                         M_LLD(tempreg, REG_SP, disp);
86                         break;
87 #else
88                 case TYPE_INT:
89                 case TYPE_ADR:
90                         M_ILD(tempreg, REG_SP, disp);
91                         break;
92                 case TYPE_LNG:
93                         M_LLD(tempreg, REG_SP, disp);
94                         break;
95 #endif
96                 case TYPE_FLT:
97                         M_FLD(tempreg, REG_SP, disp);
98                         break;
99                 case TYPE_DBL:
100                         M_DLD(tempreg, REG_SP, disp);
101                         break;
102                 default:
103                         vm_abort("emit_load: unknown type %d", src->type);
104                 }
105
106                 reg = tempreg;
107         }
108         else
109                 reg = src->vv.regoff;
110
111         return reg;
112 }
113
114
115 /* emit_load_low ***************************************************************
116
117    Emits a possible load of the low 32-bits of an operand.
118
119 *******************************************************************************/
120
121 #if SIZEOF_VOID_P == 4
122 s4 emit_load_low(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
123 {
124         codegendata  *cd;
125         s4            disp;
126         s4            reg;
127
128         assert(src->type == TYPE_LNG);
129
130         /* get required compiler data */
131
132         cd = jd->cd;
133
134         if (src->flags & INMEMORY) {
135                 COUNT_SPILLS;
136
137                 disp = src->vv.regoff;
138
139 #if WORDS_BIGENDIAN == 1
140                 M_ILD(tempreg, REG_SP, disp + 4);
141 #else
142                 M_ILD(tempreg, REG_SP, disp);
143 #endif
144
145                 reg = tempreg;
146         }
147         else
148                 reg = GET_LOW_REG(src->vv.regoff);
149
150         return reg;
151 }
152 #endif /* SIZEOF_VOID_P == 4 */
153
154
155 /* emit_load_high **************************************************************
156
157    Emits a possible load of the high 32-bits of an operand.
158
159 *******************************************************************************/
160
161 #if SIZEOF_VOID_P == 4
162 s4 emit_load_high(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
163 {
164         codegendata  *cd;
165         s4            disp;
166         s4            reg;
167
168         assert(src->type == TYPE_LNG);
169
170         /* get required compiler data */
171
172         cd = jd->cd;
173
174         if (src->flags & INMEMORY) {
175                 COUNT_SPILLS;
176
177                 disp = src->vv.regoff;
178
179 #if WORDS_BIGENDIAN == 1
180                 M_ILD(tempreg, REG_SP, disp);
181 #else
182                 M_ILD(tempreg, REG_SP, disp + 4);
183 #endif
184
185                 reg = tempreg;
186         }
187         else
188                 reg = GET_HIGH_REG(src->vv.regoff);
189
190         return reg;
191 }
192 #endif /* SIZEOF_VOID_P == 4 */
193
194
195 /* emit_store ******************************************************************
196
197    Emits a possible store to variable.
198
199 *******************************************************************************/
200
201 void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d)
202 {
203         codegendata  *cd;
204         s4            disp;
205
206         /* get required compiler data */
207
208         cd = jd->cd;
209
210         if (dst->flags & INMEMORY) {
211                 COUNT_SPILLS;
212
213                 disp = dst->vv.regoff;
214
215                 switch (dst->type) {
216 #if SIZEOF_VOID_P == 8
217                 case TYPE_INT:
218                 case TYPE_LNG:
219                 case TYPE_ADR:
220                         M_LST(d, REG_SP, disp);
221                         break;
222 #else
223                 case TYPE_INT:
224                 case TYPE_ADR:
225                         M_IST(d, REG_SP, disp);
226                         break;
227                 case TYPE_LNG:
228                         M_LST(d, REG_SP, disp);
229                         break;
230 #endif
231                 case TYPE_FLT:
232                         M_FST(d, REG_SP, disp);
233                         break;
234                 case TYPE_DBL:
235                         M_DST(d, REG_SP, disp);
236                         break;
237                 default:
238                         vm_abort("emit_store: unknown type %d", dst->type);
239                 }
240         }
241 }
242
243
244 /* emit_copy *******************************************************************
245
246    Generates a register/memory to register/memory copy.
247
248 *******************************************************************************/
249
250 void emit_copy(jitdata *jd, instruction *iptr)
251 {
252         codegendata *cd;
253         varinfo     *src;
254         varinfo     *dst;
255         s4           s1, d;
256
257         /* get required compiler data */
258
259         cd = jd->cd;
260
261         /* get source and destination variables */
262
263         src = VAROP(iptr->s1);
264         dst = VAROP(iptr->dst);
265
266         if ((src->vv.regoff != dst->vv.regoff) ||
267                 ((src->flags ^ dst->flags) & INMEMORY)) {
268
269                 if ((src->type == TYPE_RET) || (dst->type == TYPE_RET)) {
270                         /* emit nothing, as the value won't be used anyway */
271                         return;
272                 }
273
274                 /* If one of the variables resides in memory, we can eliminate
275                    the register move from/to the temporary register with the
276                    order of getting the destination register and the load. */
277
278                 if (IS_INMEMORY(src->flags)) {
279 #if SIZEOF_VOID_P == 4
280                         if (IS_2_WORD_TYPE(src->type))
281                                 d = codegen_reg_of_var(iptr->opc, dst, REG_ITMP12_PACKED);
282                         else
283 #endif
284                                 d = codegen_reg_of_var(iptr->opc, dst, REG_IFTMP);
285                         s1 = emit_load(jd, iptr, src, d);
286                 }
287                 else {
288                         s1 = emit_load(jd, iptr, src, REG_IFTMP);
289 #if SIZEOF_VOID_P == 4
290                         if (IS_2_WORD_TYPE(src->type))
291                                 d = codegen_reg_of_var(iptr->opc, dst, REG_ITMP12_PACKED);
292                         else
293 #endif
294                                 d = codegen_reg_of_var(iptr->opc, dst, s1);
295                 }
296
297                 if (s1 != d) {
298                         switch (dst->type) {
299 #if SIZEOF_VOID_P == 8
300                         case TYPE_INT:
301                         case TYPE_LNG:
302                         case TYPE_ADR:
303                                 M_MOV(s1, d);
304                                 break;
305 #else
306                         case TYPE_INT:
307                         case TYPE_ADR:
308                                 M_MOV(s1, d);
309                                 break;
310                         case TYPE_LNG:
311                                 M_LNGMOVE(s1, d);
312                                 break;
313 #endif
314                         case TYPE_FLT:
315                                 M_FMOV(s1, d);
316                                 break;
317                         case TYPE_DBL:
318                                 M_DMOV(s1, d);
319                                 break;
320                         default:
321                                 vm_abort("emit_copy: unknown type %d", dst->type);
322                         }
323                 }
324
325                 emit_store(jd, iptr, dst, d);
326         }
327 }
328
329
330 /* emit_iconst *****************************************************************
331
332    XXX
333
334 *******************************************************************************/
335
336 void emit_iconst(codegendata *cd, s4 d, s4 value)
337 {
338         s4 disp;
339
340     if ((value >= -32768) && (value <= 32767))
341         M_IADD_IMM(REG_ZERO, value, d);
342         else if ((value >= 0) && (value <= 0xffff))
343         M_OR_IMM(REG_ZERO, value, d);
344         else {
345         disp = dseg_add_s4(cd, value);
346         M_ILD(d, REG_PV, disp);
347     }
348 }
349
350
351 /* emit_lconst *****************************************************************
352
353    XXX
354
355 *******************************************************************************/
356
357 void emit_lconst(codegendata *cd, s4 d, s8 value)
358 {
359         s4 disp;
360
361 #if SIZEOF_VOID_P == 8
362         if ((value >= -32768) && (value <= 32767))
363                 M_LADD_IMM(REG_ZERO, value, d);
364         else if ((value >= 0) && (value <= 0xffff))
365                 M_OR_IMM(REG_ZERO, value, d);
366         else {
367                 disp = dseg_add_s8(cd, value);
368                 M_LLD(d, REG_PV, disp);
369         }
370 #else
371         disp = dseg_add_s8(cd, value);
372         M_LLD(d, REG_PV, disp);
373 #endif
374 }
375
376
377 /* emit_branch *****************************************************************
378
379    Emits the code for conditional and unconditional branchs.
380
381    NOTE: The reg argument may contain two packed registers.
382
383 *******************************************************************************/
384
385 void emit_branch(codegendata *cd, s4 disp, s4 condition, s4 reg, u4 opt)
386 {
387         s4 checkdisp;
388         s4 branchdisp;
389
390         /* calculate the different displacements */
391
392         checkdisp  = (disp - 4);
393         branchdisp = (disp - 4) >> 2;
394
395         /* check which branch to generate */
396
397         if (condition == BRANCH_UNCONDITIONAL) {
398                 /* check displacement for overflow */
399
400                 if ((checkdisp < (s4) 0xffff8000) || (checkdisp > (s4) 0x00007fff)) {
401                         /* if the long-branches flag isn't set yet, do it */
402
403                         if (!CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
404                                 cd->flags |= (CODEGENDATA_FLAG_ERROR |
405                                                           CODEGENDATA_FLAG_LONGBRANCHES);
406                         }
407
408                         vm_abort("emit_branch: emit unconditional long-branch code");
409                 }
410                 else {
411                         M_BR(branchdisp);
412                         M_NOP;
413                 }
414         }
415         else {
416                 /* and displacement for overflow */
417
418                 if ((checkdisp < (s4) 0xffff8000) || (checkdisp > (s4) 0x00007fff)) {
419                         /* if the long-branches flag isn't set yet, do it */
420
421                         if (!CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
422                                 cd->flags |= (CODEGENDATA_FLAG_ERROR |
423                                                           CODEGENDATA_FLAG_LONGBRANCHES);
424                         }
425
426                         switch (condition) {
427                         case BRANCH_EQ:
428                                 M_BNE(GET_HIGH_REG(reg), GET_LOW_REG(reg), 5);
429                                 break;
430                         case BRANCH_NE:
431                                 M_BEQ(GET_HIGH_REG(reg), GET_LOW_REG(reg), 5);
432                                 break;
433                         case BRANCH_LT:
434                                 M_BGEZ(reg, 5);
435                                 break;
436                         case BRANCH_GE:
437                                 M_BLTZ(reg, 5);
438                                 break;
439                         case BRANCH_GT:
440                                 M_BLEZ(reg, 5);
441                                 break;
442                         case BRANCH_LE:
443                                 M_BGTZ(reg, 5);
444                                 break;
445                         default:
446                                 vm_abort("emit_branch: unknown condition %d", condition);
447                         }
448
449                         /* The actual branch code which is over-jumped (NOTE: we
450                            don't use a branch delay slot here). */
451
452                         M_LUI(REG_ITMP3, branchdisp >> 16);
453                         M_OR_IMM(REG_ITMP3, branchdisp, REG_ITMP3);
454                         M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
455                         M_JMP(REG_ITMP3);
456                         M_NOP;
457
458                 }
459                 else {
460                         switch (condition) {
461                         case BRANCH_EQ:
462                                 M_BEQ(GET_HIGH_REG(reg), GET_LOW_REG(reg), branchdisp);
463                                 break;
464                         case BRANCH_NE:
465                                 M_BNE(GET_HIGH_REG(reg), GET_LOW_REG(reg), branchdisp);
466                                 break;
467                         case BRANCH_LT:
468                                 M_BLTZ(reg, branchdisp);
469                                 break;
470                         case BRANCH_GE:
471                                 M_BGEZ(reg, branchdisp);
472                                 break;
473                         case BRANCH_GT:
474                                 M_BGTZ(reg, branchdisp);
475                                 break;
476                         case BRANCH_LE:
477                                 M_BLEZ(reg, branchdisp);
478                                 break;
479                         default:
480                                 vm_abort("emit_branch: unknown condition %d", condition);
481                         }
482
483                         /* branch delay */
484                         M_NOP;
485                 }
486         }
487 }
488
489
490 /* emit_arithmetic_check *******************************************************
491
492    Emit an ArithmeticException check.
493
494 *******************************************************************************/
495
496 void emit_arithmetic_check(codegendata *cd, instruction *iptr, s4 reg)
497 {
498         if (INSTRUCTION_MUST_CHECK(iptr)) {
499                 M_BNEZ(reg, 2);
500                 M_NOP;
501                 M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_ARITHMETIC);
502         }
503 }
504
505
506 /* emit_arrayindexoutofbounds_check ********************************************
507
508    Emit an ArrayIndexOutOfBoundsException check.
509
510 *******************************************************************************/
511
512 void emit_arrayindexoutofbounds_check(codegendata *cd, instruction *iptr, s4 s1, s4 s2)
513 {
514         if (INSTRUCTION_MUST_CHECK(iptr)) {
515                 M_ILD_INTERN(REG_ITMP3, s1, OFFSET(java_array_t, size));
516                 M_CMPULT(s2, REG_ITMP3, REG_ITMP3);
517                 M_BNEZ(REG_ITMP3, 2);
518                 M_NOP;
519                 M_ALD_INTERN(s2, REG_ZERO, EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS);
520         }
521 }
522
523
524 /* emit_classcast_check ********************************************************
525
526    Emit a ClassCastException check.
527
528 *******************************************************************************/
529
530 void emit_classcast_check(codegendata *cd, instruction *iptr, s4 condition, s4 reg, s4 s1)
531 {
532         if (INSTRUCTION_MUST_CHECK(iptr)) {
533                 switch (condition) {
534                 case ICMD_IFEQ:
535                         M_BNEZ(reg, 2);
536                         break;
537
538                 case ICMD_IFNE:
539                         M_BEQZ(reg, 2);
540                         break;
541
542                 case ICMD_IFLE:
543                         M_BGTZ(reg, 2);
544                         break;
545
546                 default:
547                         vm_abort("emit_classcast_check: unknown condition %d", condition);
548                 }
549
550                 M_NOP;
551                 M_ALD_INTERN(s1, REG_ZERO, EXCEPTION_HARDWARE_CLASSCAST);
552         }
553 }
554
555
556 /* emit_nullpointer_check ******************************************************
557
558    Emit a NullPointerException check.
559
560 *******************************************************************************/
561
562 void emit_nullpointer_check(codegendata *cd, instruction *iptr, s4 reg)
563 {
564         if (INSTRUCTION_MUST_CHECK(iptr)) {
565                 M_BNEZ(reg, 2);
566                 M_NOP;
567                 M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_NULLPOINTER);
568         }
569 }
570
571
572 /* emit_exception_check ********************************************************
573
574    Emit an Exception check.
575
576 *******************************************************************************/
577
578 void emit_exception_check(codegendata *cd, instruction *iptr)
579 {
580         if (INSTRUCTION_MUST_CHECK(iptr)) {
581                 M_BNEZ(REG_RESULT, 2);
582                 M_NOP;
583                 M_ALD_INTERN(REG_RESULT, REG_ZERO, EXCEPTION_HARDWARE_EXCEPTION);
584         }
585 }
586
587
588 /* emit_trap *******************************************************************
589
590    Emit a trap instruction and return the original machine code.
591
592 *******************************************************************************/
593
594 uint32_t emit_trap(codegendata *cd)
595 {
596         uint32_t mcode;
597
598         /* Get machine code which is patched back in later. The
599            trap is 1 instruction word long. */
600
601         mcode = *((u4 *) cd->mcodeptr);
602
603         M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_PATCHER);
604
605         return mcode;
606 }
607
608
609 /* emit_verbosecall_enter ******************************************************
610
611    Generates the code for the call trace.
612
613 *******************************************************************************/
614
615 #if !defined(NDEBUG)
616 void emit_verbosecall_enter(jitdata *jd)
617 {
618         methodinfo   *m;
619         codegendata  *cd;
620         registerdata *rd;
621         methoddesc   *md;
622         s4            disp;
623         s4            i, j, t;
624
625         /* get required compiler data */
626
627         m  = jd->m;
628         cd = jd->cd;
629         rd = jd->rd;
630
631         md = m->parseddesc;
632
633         /* mark trace code */
634
635         M_NOP;
636
637         M_LDA(REG_SP, REG_SP, -(PA_SIZE + (2 + ARG_CNT + TMP_CNT) * 8));
638         M_AST(REG_RA, REG_SP, PA_SIZE + 1 * 8);
639
640         /* save argument registers (we store the registers as address
641            types, so it's correct for MIPS32 too) */
642
643         for (i = 0; i < INT_ARG_CNT; i++)
644                 M_AST(abi_registers_integer_argument[i], REG_SP, PA_SIZE + (2 + i) * 8);
645
646         for (i = 0; i < FLT_ARG_CNT; i++)
647                 M_DST(abi_registers_float_argument[i], REG_SP, PA_SIZE + (2 + INT_ARG_CNT + i) * 8);
648
649         /* save temporary registers for leaf methods */
650
651         if (jd->isleafmethod) {
652                 for (i = 0; i < INT_TMP_CNT; i++)
653                         M_AST(rd->tmpintregs[i], REG_SP, PA_SIZE + (2 + ARG_CNT + i) * 8);
654
655                 for (i = 0; i < FLT_TMP_CNT; i++)
656                         M_DST(rd->tmpfltregs[i], REG_SP, PA_SIZE + (2 + ARG_CNT + INT_TMP_CNT + i) * 8);
657         }
658
659         /* Load float arguments into integer registers.  MIPS32 has less
660            float argument registers than integer ones, we need to check
661            that. */
662
663         for (i = 0; i < md->paramcount && i < INT_ARG_CNT && i < FLT_ARG_CNT; i++) {
664                 t = md->paramtypes[i].type;
665
666                 if (IS_FLT_DBL_TYPE(t)) {
667                         if (IS_2_WORD_TYPE(t)) {
668                                 M_DST(abi_registers_float_argument[i], REG_SP, 0 * 8);
669                                 M_LLD(abi_registers_integer_argument[i], REG_SP, 0 * 8);
670                         }
671                         else {
672                                 M_FST(abi_registers_float_argument[i], REG_SP, 0 * 8);
673                                 M_ILD(abi_registers_integer_argument[i], REG_SP, 0 * 8);
674                         }
675                 }
676         }
677
678 #if SIZEOF_VOID_P == 4
679                 for (i = 0, j = 0; i < md->paramcount && i < TRACE_ARGS_NUM; i++) {
680                         t = md->paramtypes[i].type;
681
682                         if (IS_INT_LNG_TYPE(t)) {
683                                 if (IS_2_WORD_TYPE(t)) {
684                                         M_ILD(abi_registers_integer_argument[j], REG_SP, PA_SIZE + (2 + i) * 8);
685                                         M_ILD(abi_registers_integer_argument[j + 1], REG_SP, PA_SIZE + (2 + i) * 8 + 4);
686                                 }
687                                 else {
688 # if WORDS_BIGENDIAN == 1
689                                         M_MOV(REG_ZERO, abi_registers_integer_argument[j]);
690                                         M_ILD(abi_registers_integer_argument[j + 1], REG_SP, PA_SIZE + (2 + i) * 8);
691 # else
692                                         M_ILD(abi_registers_integer_argument[j], REG_SP, PA_SIZE + (2 + i) * 8);
693                                         M_MOV(REG_ZERO, abi_registers_integer_argument[j + 1]);
694 # endif
695                                 }
696                                 j += 2;
697                         }
698                 }
699 #endif
700
701         disp = dseg_add_address(cd, m);
702         M_ALD(REG_ITMP1, REG_PV, disp);
703         M_AST(REG_ITMP1, REG_SP, PA_SIZE + 0 * 8);
704         disp = dseg_add_functionptr(cd, builtin_verbosecall_enter);
705         M_ALD(REG_ITMP3, REG_PV, disp);
706         M_JSR(REG_RA, REG_ITMP3);
707         M_NOP;
708
709         /* restore argument registers */
710
711         for (i = 0; i < INT_ARG_CNT; i++)
712                 M_ALD(abi_registers_integer_argument[i], REG_SP, PA_SIZE + (2 + i) * 8);
713
714         for (i = 0; i < FLT_ARG_CNT; i++)
715                 M_DLD(abi_registers_float_argument[i], REG_SP, PA_SIZE + (2 + INT_ARG_CNT + i) * 8);
716
717         /* restore temporary registers for leaf methods */
718
719         if (jd->isleafmethod) {
720                 for (i = 0; i < INT_TMP_CNT; i++)
721                         M_ALD(rd->tmpintregs[i], REG_SP, PA_SIZE + (2 + ARG_CNT + i) * 8);
722
723                 for (i = 0; i < FLT_TMP_CNT; i++)
724                         M_DLD(rd->tmpfltregs[i], REG_SP, PA_SIZE + (2 + ARG_CNT + INT_TMP_CNT + i) * 8);
725         }
726
727         M_ALD(REG_RA, REG_SP, PA_SIZE + 1 * 8);
728         M_LDA(REG_SP, REG_SP, PA_SIZE + (2 + ARG_CNT + TMP_CNT) * 8);
729
730         /* mark trace code */
731
732         M_NOP;
733 }
734 #endif /* !defined(NDEBUG) */
735
736
737 /* emit_verbosecall_exit *******************************************************
738
739    Generates the code for the call trace.
740
741    void builtin_verbosecall_exit(s8 l, double d, float f, methodinfo *m);
742
743 *******************************************************************************/
744
745 #if !defined(NDEBUG)
746 void emit_verbosecall_exit(jitdata *jd)
747 {
748         methodinfo   *m;
749         codegendata  *cd;
750         registerdata *rd;
751         methoddesc   *md;
752         s4            disp;
753
754         /* get required compiler data */
755
756         m  = jd->m;
757         cd = jd->cd;
758         rd = jd->rd;
759
760         md = m->parseddesc;
761
762         /* mark trace code */
763
764         M_NOP;
765
766 #if SIZEOF_VOID_P == 8
767         M_ASUB_IMM(REG_SP, 4 * 8, REG_SP);          /* keep stack 16-byte aligned */
768         M_AST(REG_RA, REG_SP, 0 * 8);
769
770         M_LST(REG_RESULT, REG_SP, 1 * 8);
771         M_DST(REG_FRESULT, REG_SP, 2 * 8);
772
773         M_MOV(REG_RESULT, REG_A0);
774         M_DMOV(REG_FRESULT, REG_FA1);
775         M_FMOV(REG_FRESULT, REG_FA2);
776
777         disp = dseg_add_address(cd, m);
778         M_ALD(REG_A4, REG_PV, disp);
779 #else
780         M_ASUB_IMM(REG_SP, (8*4 + 4 * 8), REG_SP);
781         M_AST(REG_RA, REG_SP, 8*4 + 0 * 8);
782
783         M_LST(REG_RESULT_PACKED, REG_SP, 8*4 + 1 * 8);
784         M_DST(REG_FRESULT, REG_SP, 8*4 + 2 * 8);
785
786         switch (md->returntype.type) {
787         case TYPE_LNG:
788                 M_LNGMOVE(REG_RESULT_PACKED, REG_A0_A1_PACKED);
789                 break;
790
791         default:
792 # if WORDS_BIGENDIAN == 1
793                 M_MOV(REG_ZERO, REG_A0);
794                 M_MOV(REG_RESULT, REG_A1);
795 # else
796                 M_MOV(REG_RESULT, REG_A0);
797                 M_MOV(REG_ZERO, REG_A1);
798 # endif
799         }
800
801         M_LLD(REG_A2_A3_PACKED, REG_SP, 8*4 + 2 * 8);
802         M_FST(REG_FRESULT, REG_SP, 4*4 + 0 * 4);
803
804         disp = dseg_add_address(cd, m);
805         M_ALD(REG_ITMP1, REG_PV, disp);
806         M_AST(REG_ITMP1, REG_SP, 4*4 + 1 * 4);
807 #endif
808
809         disp = dseg_add_functionptr(cd, builtin_verbosecall_exit);
810         M_ALD(REG_ITMP3, REG_PV, disp);
811         M_JSR(REG_RA, REG_ITMP3);
812         M_NOP;
813
814 #if SIZEOF_VOID_P == 8
815         M_DLD(REG_FRESULT, REG_SP, 2 * 8);
816         M_LLD(REG_RESULT, REG_SP, 1 * 8);
817
818         M_ALD(REG_RA, REG_SP, 0 * 8);
819         M_AADD_IMM(REG_SP, 4 * 8, REG_SP);
820 #else
821         M_DLD(REG_FRESULT, REG_SP, 8*4 + 2 * 8);
822         M_LLD(REG_RESULT_PACKED, REG_SP, 8*4 + 1 * 8);
823
824         M_ALD(REG_RA, REG_SP, 8*4 + 0 * 8);
825         M_AADD_IMM(REG_SP, 8*4 + 4 * 8, REG_SP);
826 #endif
827
828         /* mark trace code */
829
830         M_NOP;
831 }
832 #endif /* !defined(NDEBUG) */
833
834
835 /*
836  * These are local overrides for various environment variables in Emacs.
837  * Please do not remove this and leave it at the end of the file, where
838  * Emacs will automagically detect them.
839  * ---------------------------------------------------------------------
840  * Local variables:
841  * mode: c
842  * indent-tabs-mode: t
843  * c-basic-offset: 4
844  * tab-width: 4
845  * End:
846  * vim:noexpandtab:sw=4:ts=4:
847  */