* src/vm/jit/arm/emit.c (emit_exception_stubs): Renamed eref to er,
[cacao.git] / src / vm / jit / arm / emit.c
1 /* src/vm/jit/arm/emit.c - Arm 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    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28
29    $Id: emit.c 4398 2006-01-31 23:43:08Z twisti $
30
31 */
32
33
34 #include "config.h"
35
36 #include <assert.h>
37
38 #include "vm/types.h"
39
40 #include "md-abi.h"
41
42 #include "vm/jit/arm/codegen.h"
43
44 #if defined(ENABLE_THREADS)
45 # include "threads/native/lock.h"
46 #endif
47
48 #include "vm/builtin.h"
49 #include "vm/jit/asmpart.h"
50 #include "vm/jit/emit-common.h"
51 #include "vm/jit/jit.h"
52 #include "vm/jit/replace.h"
53
54 #include "toolbox/logging.h" /* XXX for debugging only */
55
56
57 /* emit_load *******************************************************************
58
59    Emits a possible load of an operand.
60
61 *******************************************************************************/
62
63 s4 emit_load(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
64 {
65         codegendata  *cd;
66         s4            disp;
67         s4            reg;
68
69         /* get required compiler data */
70
71         cd = jd->cd;
72
73         if (src->flags & INMEMORY) {
74                 COUNT_SPILLS;
75
76                 disp = src->vv.regoff * 4;
77
78                 if (IS_FLT_DBL_TYPE(src->type)) {
79 #if !defined(ENABLE_SOFTFLOAT)
80                         if (IS_2_WORD_TYPE(src->type))
81                                 M_DLD(tempreg, REG_SP, disp);
82                         else
83                                 M_FLD(tempreg, REG_SP, disp);
84 #else
85                         assert(0);
86 #endif
87                 }
88                 else {
89                         if (IS_2_WORD_TYPE(src->type))
90                                 M_LLD(tempreg, REG_SP, disp);
91                         else
92                                 M_ILD(tempreg, REG_SP, disp);
93                 }
94
95                 reg = tempreg;
96         }
97         else
98                 reg = src->vv.regoff;
99
100         return reg;
101 }
102
103
104 /* emit_load_low ***************************************************************
105
106    Emits a possible load of the low 32-bits of a long source operand.
107
108 *******************************************************************************/
109
110 s4 emit_load_low(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
111 {
112         codegendata  *cd;
113         s4            disp;
114         s4            reg;
115
116         assert(src->type == TYPE_LNG);
117
118         /* get required compiler data */
119
120         cd = jd->cd;
121
122         if (src->flags & INMEMORY) {
123                 COUNT_SPILLS;
124
125                 disp = src->vv.regoff * 4;
126
127 #if defined(__ARMEL__)
128                 M_ILD(tempreg, REG_SP, disp);
129 #else
130                 M_ILD(tempreg, REG_SP, disp + 4);
131 #endif
132
133                 reg = tempreg;
134         }
135         else
136                 reg = GET_LOW_REG(src->vv.regoff);
137
138         return reg;
139 }
140
141
142 /* emit_load_high **************************************************************
143
144    Emits a possible load of the high 32-bits of a long source operand.
145
146 *******************************************************************************/
147
148 s4 emit_load_high(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
149 {
150         codegendata  *cd;
151         s4            disp;
152         s4            reg;
153
154         assert(src->type == TYPE_LNG);
155
156         /* get required compiler data */
157
158         cd = jd->cd;
159
160         if (src->flags & INMEMORY) {
161                 COUNT_SPILLS;
162
163                 disp = src->vv.regoff * 4;
164
165 #if defined(__ARMEL__)
166                 M_ILD(tempreg, REG_SP, disp + 4);
167 #else
168                 M_ILD(tempreg, REG_SP, disp);
169 #endif
170
171                 reg = tempreg;
172         }
173         else
174                 reg = GET_HIGH_REG(src->vv.regoff);
175
176         return reg;
177 }
178
179
180 /* emit_store ******************************************************************
181
182    Emits a possible store to a variable.
183
184 *******************************************************************************/
185
186 void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d)
187 {
188         codegendata  *cd;
189         s4            disp;
190
191         /* get required compiler data */
192
193         cd = jd->cd;
194
195         if (dst->flags & INMEMORY) {
196                 COUNT_SPILLS;
197
198                 disp = dst->vv.regoff * 4;
199
200 #if !defined(ENABLE_SOFTFLOAT)
201                 if (IS_FLT_DBL_TYPE(dst->type)) {
202                         if (IS_2_WORD_TYPE(dst->type))
203                                 M_DST(d, REG_SP, disp);
204                         else
205                                 M_FST(d, REG_SP, disp);
206                 }
207                 else {
208                         if (IS_2_WORD_TYPE(dst->type))
209                                 M_LST(d, REG_SP, disp);
210                         else
211                                 M_IST(d, REG_SP, disp);
212                 }
213 #else
214                 if (IS_2_WORD_TYPE(dst->type))
215                         M_LST(d, REG_SP, disp);
216                 else
217                         M_IST(d, REG_SP, disp);
218 #endif
219         }
220         else if (IS_LNG_TYPE(dst->type)) {
221 #if defined(__ARMEL__)
222                 if (GET_HIGH_REG(dst->vv.regoff) == REG_SPLIT)
223                         M_IST_INTERN(GET_HIGH_REG(d), REG_SP, 0 * 4);
224 #else
225                 if (GET_LOW_REG(dst->vv.regoff) == REG_SPLIT)
226                         M_IST_INTERN(GET_LOW_REG(d), REG_SP, 0 * 4);
227 #endif
228         }
229 }
230
231
232 /* emit_copy *******************************************************************
233
234    XXX
235
236 *******************************************************************************/
237
238 void emit_copy(jitdata *jd, instruction *iptr, varinfo *src, varinfo *dst)
239 {
240         codegendata  *cd;
241         registerdata *rd;
242         s4            s1, d;
243
244         /* get required compiler data */
245
246         cd = jd->cd;
247         rd = jd->rd;
248
249         /* XXX dummy call, removed me!!! */
250         d = codegen_reg_of_var(iptr->opc, dst, REG_ITMP1);
251
252         if ((src->vv.regoff != dst->vv.regoff) ||
253                 ((src->flags ^ dst->flags) & INMEMORY)) {
254
255                 /* If one of the variables resides in memory, we can eliminate
256                    the register move from/to the temporary register with the
257                    order of getting the destination register and the load. */
258
259                 if (IS_INMEMORY(src->flags)) {
260 #if !defined(ENABLE_SOFTFLOAT)
261                         if (IS_FLT_DBL_TYPE(src->type))
262                                 d = codegen_reg_of_var(iptr->opc, dst, REG_FTMP1);
263                         else
264 #endif
265                         {
266                                 if (IS_2_WORD_TYPE(src->type))
267                                         d = codegen_reg_of_var(iptr->opc, dst, REG_ITMP12_PACKED);
268                                 else
269                                         d = codegen_reg_of_var(iptr->opc, dst, REG_ITMP1);
270                         }
271
272                         s1 = emit_load(jd, iptr, src, d);
273                 }
274                 else {
275 #if !defined(ENABLE_SOFTFLOAT)
276                         if (IS_FLT_DBL_TYPE(src->type))
277                                 s1 = emit_load(jd, iptr, src, REG_FTMP1);
278                         else
279 #endif
280                         {
281                                 if (IS_2_WORD_TYPE(src->type))
282                                         s1 = emit_load(jd, iptr, src, REG_ITMP12_PACKED);
283                                 else
284                                         s1 = emit_load(jd, iptr, src, REG_ITMP1);
285                         }
286
287                         d = codegen_reg_of_var(iptr->opc, dst, s1);
288                 }
289
290                 if (s1 != d) {
291 #if !defined(ENABLE_SOFTFLOAT)
292                         if (IS_FLT_DBL_TYPE(src->type)) {
293                                 if (IS_2_WORD_TYPE(src->type))
294                                         M_DMOV(s1, d);
295                                 else
296                                         M_FMOV(s1, d);
297                         }
298                         else {
299                                 if (IS_2_WORD_TYPE(src->type))
300                                         M_LNGMOVE(s1, d);
301                                 else
302                                         /* XXX grrrr, wrong direction! */
303                                         M_MOV(d, s1);
304                         }
305 #else
306                         if (IS_2_WORD_TYPE(src->type))
307                                 M_LNGMOVE(s1, d);
308                         else
309                                 /* XXX grrrr, wrong direction! */
310                                 M_MOV(d, s1);
311 #endif
312                 }
313
314                 emit_store(jd, iptr, dst, d);
315         }
316 }
317
318
319 /* emit_iconst *****************************************************************
320
321    XXX
322
323 *******************************************************************************/
324
325 void emit_iconst(codegendata *cd, s4 d, s4 value)
326 {
327         s4 disp;
328
329         if (IS_IMM(value))
330                 M_MOV_IMM(d, value);
331         else {
332                 disp = dseg_add_s4(cd, value);
333                 M_DSEG_LOAD(d, disp);
334         }
335 }
336
337
338 /* emit_nullpointer_check ******************************************************
339
340    Emit a NullPointerException check.
341
342 *******************************************************************************/
343
344 void emit_nullpointer_check(codegendata *cd, instruction *iptr, s4 reg)
345 {
346         if (INSTRUCTION_MUST_CHECK(iptr)) {
347                 M_TST(reg, reg);
348                 M_BEQ(0);
349                 codegen_add_nullpointerexception_ref(cd);
350         }
351 }
352
353
354 /* emit_arrayindexoutofbounds_check ********************************************
355
356    Emit a ArrayIndexOutOfBoundsException check.
357
358 *******************************************************************************/
359
360 void emit_arrayindexoutofbounds_check(codegendata *cd, instruction *iptr, s4 s1, s4 s2)
361 {
362         if (INSTRUCTION_MUST_CHECK(iptr)) {
363                 M_ILD_INTERN(REG_ITMP3, s1, OFFSET(java_arrayheader, size));
364                 M_CMP(s2, REG_ITMP3);
365                 M_BHS(0);
366                 codegen_add_arrayindexoutofboundsexception_ref(cd, s2);
367         }
368 }
369
370
371 /* emit_exception_stubs ********************************************************
372
373    Generates the code for the exception stubs.
374
375 *******************************************************************************/
376
377 void emit_exception_stubs(jitdata *jd)
378 {
379         codegendata  *cd;
380         registerdata *rd;
381         exceptionref *er;
382         s4            branchmpc;
383         s4            targetmpc;
384         s4            targetdisp;
385         s4            disp;
386
387         /* get required compiler data */
388
389         cd = jd->cd;
390         rd = jd->rd;
391
392         /* generate exception stubs */
393
394         targetdisp = 0;
395
396         for (er = cd->exceptionrefs; er != NULL; er = er->next) {
397                 /* back-patch the branch to this exception code */
398
399                 branchmpc = er->branchpos;
400                 targetmpc = cd->mcodeptr - cd->mcodebase;
401
402                 md_codegen_patch_branch(cd, branchmpc, targetmpc);
403
404                 MCODECHECK(100);
405
406                 /* Check if the exception is an
407                    ArrayIndexOutOfBoundsException.  If so, move index register
408                    into REG_ITMP1. */
409
410                 if (er->reg != -1)
411                         M_MOV(REG_ITMP1, er->reg);
412
413                 /* calcuate exception address */
414
415                 assert((er->branchpos - 4) % 4 == 0);
416                 M_ADD_IMM_EXT_MUL4(REG_ITMP2_XPC, REG_IP, (er->branchpos - 4) / 4);
417
418                 /* move function to call into REG_ITMP3 */
419
420                 disp = dseg_add_functionptr(cd, er->function);
421                 M_DSEG_LOAD(REG_ITMP3, disp);
422
423                 if (targetdisp == 0) {
424                         targetdisp = ((u4 *) cd->mcodeptr) - ((u4 *) cd->mcodebase);
425
426                         M_MOV(rd->argintregs[0], REG_IP);
427                         M_MOV(rd->argintregs[1], REG_SP);
428
429                         if (jd->isleafmethod)
430                                 M_MOV(rd->argintregs[2], REG_LR);
431                         else
432                                 M_LDR(rd->argintregs[2], REG_SP,
433                                           cd->stackframesize * 4 - SIZEOF_VOID_P);
434
435                         M_MOV(rd->argintregs[3], REG_ITMP2_XPC);
436
437                         /* save registers */
438                         /* TODO: we only need to save LR in leaf methods */
439
440                         M_STMFD(BITMASK_ARGS | 1<<REG_IP | 1<<REG_LR, REG_SP);
441
442                         /* move a3 to stack */
443
444                         M_STR_UPDATE(REG_ITMP1, REG_SP, -4);
445
446                         /* do the exception call */
447
448                         M_MOV(REG_LR, REG_PC);
449                         M_MOV(REG_PC, REG_ITMP3);
450
451                         M_ADD_IMM(REG_SP, REG_SP, 4);
452
453                         /* result of stacktrace is our XPTR */
454
455                         M_MOV(REG_ITMP1_XPTR, REG_RESULT);
456
457                         /* restore registers */
458
459                         M_LDMFD(BITMASK_ARGS | 1<<REG_IP | 1<<REG_LR, REG_SP);
460
461                         disp = dseg_add_functionptr(cd, asm_handle_exception);
462                         M_DSEG_LOAD(REG_ITMP3, disp);
463                         M_MOV(REG_PC, REG_ITMP3);
464                 }
465                 else {
466                         disp = (((u4 *) cd->mcodebase) + targetdisp) -
467                                 (((u4 *) cd->mcodeptr) + 2);
468
469                         M_B(disp);
470                 }
471         }
472 }
473
474
475 /* emit_patcher_stubs **********************************************************
476
477    Generates the code for the patcher stubs.
478
479 *******************************************************************************/
480
481 void emit_patcher_stubs(jitdata *jd)
482 {
483         codegendata *cd;
484         patchref    *pref;
485         u4           mcode;
486         u1          *savedmcodeptr;
487         u1          *tmpmcodeptr;
488         s4           targetdisp;
489         s4           disp;
490
491         /* get required compiler data */
492
493         cd = jd->cd;
494
495         /* generate patcher stub call code */
496
497         targetdisp = 0;
498
499         for (pref = cd->patchrefs; pref != NULL; pref = pref->next) {
500                 /* check code segment size */
501
502                 MCODECHECK(100);
503
504                 /* Get machine code which is patched back in later. The
505                    call is 1 instruction word long. */
506
507                 tmpmcodeptr = (u1 *) (cd->mcodebase + pref->branchpos);
508
509                 mcode = *((u4 *) tmpmcodeptr);
510
511                 /* Patch in the call to call the following code (done at
512                    compile time). */
513
514                 savedmcodeptr = cd->mcodeptr;   /* save current mcodeptr              */
515                 cd->mcodeptr  = tmpmcodeptr;    /* set mcodeptr to patch position     */
516
517                 disp = ((u4 *) savedmcodeptr) - (((u4 *) tmpmcodeptr) + 2);
518                 M_B(disp);
519
520                 cd->mcodeptr = savedmcodeptr;   /* restore the current mcodeptr       */
521
522                 /* create stack frame */
523
524                 M_SUB_IMM(REG_SP, REG_SP, 7 * 4);
525
526                 /* save itmp3 onto stack */
527
528                 M_STR_INTERN(REG_ITMP3, REG_SP, 6 * 4);
529
530                 /* calculate return address and move it onto stack */
531                 /* ATTENTION: we can not use BL to branch to patcher stub,        */
532                 /* ATTENTION: because we need to preserve LR for leaf methods     */
533
534                 disp = (s4) (((u4 *) cd->mcodeptr) - (((u4 *) tmpmcodeptr) + 1) + 2);
535
536                 M_SUB_IMM_EXT_MUL4(REG_ITMP3, REG_PC, disp);
537                 M_STR_INTERN(REG_ITMP3, REG_SP, 4 * 4);
538
539                 /* move pointer to java_objectheader onto stack */
540
541 #if defined(ENABLE_THREADS)
542                 /* order reversed because of data segment layout */
543
544                 (void) dseg_add_unique_address(cd, NULL);           /* flcword    */
545                 (void) dseg_add_unique_address(cd, lock_get_initial_lock_word());
546                 disp = dseg_add_unique_address(cd, NULL);           /* vftbl      */
547
548                 M_SUB_IMM_EXT_MUL4(REG_ITMP3, REG_IP, -disp / 4);
549                 M_STR_INTERN(REG_ITMP3, REG_SP, 3 * 4);
550 #else
551                 M_EOR(REG_ITMP3, REG_ITMP3, REG_ITMP3);
552                 M_STR_INTERN(REG_ITMP3, REG_SP, 3 * 4);
553 #endif
554
555                 /* move machine code onto stack */
556
557                 disp = dseg_add_unique_s4(cd, mcode);
558                 M_DSEG_LOAD(REG_ITMP3, disp);
559                 M_STR_INTERN(REG_ITMP3, REG_SP, 2 * 4);
560
561                 /* move class/method/field reference onto stack */
562
563                 disp = dseg_add_unique_address(cd, pref->ref);
564                 M_DSEG_LOAD(REG_ITMP3, disp);
565                 M_STR_INTERN(REG_ITMP3, REG_SP, 1 * 4);
566
567                 /* move data segment displacement onto stack */
568
569                 disp = dseg_add_unique_s4(cd, pref->disp);
570                 M_DSEG_LOAD(REG_ITMP3, disp);
571                 M_STR_INTERN(REG_ITMP3, REG_SP, 5 * 4);
572
573                 /* move patcher function pointer onto stack */
574
575                 disp = dseg_add_functionptr(cd, pref->patcher);
576                 M_DSEG_LOAD(REG_ITMP3, disp);
577                 M_STR_INTERN(REG_ITMP3, REG_SP, 0 * 4);
578
579                 /* finally call the patcher via asm_patcher_wrapper */
580                 /* ATTENTION: don't use REG_IP here, because some patchers need it */
581
582                 if (targetdisp == 0) {
583                         targetdisp = ((u4 *) cd->mcodeptr) - ((u4 *) cd->mcodebase);
584
585                         disp = dseg_add_functionptr(cd, asm_patcher_wrapper);
586                         /*M_DSEG_BRANCH_NOLINK(REG_PC, REG_IP, a);*/
587                         /* TODO: this is only a hack */
588                         M_DSEG_LOAD(REG_ITMP3, disp);
589                         M_MOV(REG_PC, REG_ITMP3);
590                 }
591                 else {
592                         disp = (((u4 *) cd->mcodebase) + targetdisp) -
593                                 (((u4 *) cd->mcodeptr) + 2);
594
595                         M_B(disp);
596                 }
597         }
598 }
599
600
601 /* emit_replacement_stubs ******************************************************
602
603    Generates the code for the replacement stubs.
604
605 *******************************************************************************/
606
607 #if defined(ENABLE_REPLACEMENT)
608 void emit_replacement_stubs(jitdata *jd)
609 {
610         codegendata *cd;
611         codeinfo    *code;
612         rplpoint    *rplp;
613         u1          *savedmcodeptr;
614         s4           disp;
615         s4           i;
616
617         /* get required compiler data */
618
619         cd   = jd->cd;
620         code = jd->code;
621 }
622 #endif /* defined(ENABLE_REPLACEMENT) */
623
624
625 /* emit_verbosecall_enter ******************************************************
626
627    Generates the code for the call trace.
628
629 *******************************************************************************/
630
631 #if !defined(NDEBUG)
632 void emit_verbosecall_enter(jitdata *jd)
633 {
634         methodinfo   *m;
635         codegendata  *cd;
636         registerdata *rd;
637         methoddesc   *md;
638         s4            stackframesize;
639         s4            disp;
640         s4            i, t, s1, s2;
641
642         /* get required compiler data */
643
644         m  = jd->m;
645         cd = jd->cd;
646         rd = jd->rd;
647
648         md = m->parseddesc;
649
650         /* stackframesize is changed below */
651
652         stackframesize = cd->stackframesize;
653
654         /* mark trace code */
655
656         M_NOP;
657
658         /* save argument registers to stack (including LR and IP) */
659         M_STMFD(BITMASK_ARGS | (1<<REG_LR) | (1<<REG_IP), REG_SP);
660         M_SUB_IMM(REG_SP, REG_SP, (2 + 2 + 1) * 4);     /* space for a3, a4 and m */
661
662         stackframesize += 6 + 2 + 2 + 1;
663
664         /* prepare args for tracer */
665
666         i = md->paramcount - 1;
667
668         if (i > 3)
669                 i = 3;
670
671         for (; i >= 0; i--) {
672                 t = md->paramtypes[i].type;
673
674                 /* load argument into register (s1) and make it of TYPE_LNG */
675
676                 if (!md->params[i].inmemory) {
677                         s1 = md->params[i].regoff;
678
679                         if (!IS_2_WORD_TYPE(t)) {
680                                 M_MOV_IMM(REG_ITMP1, 0);
681                                 s1 = PACK_REGS(s1, REG_ITMP1);
682                         }
683                         else {
684                                 SPLIT_OPEN(t, s1, REG_ITMP1);
685                                 SPLIT_LOAD(t, s1, stackframesize);
686                         }
687                 }
688                 else {
689                         s1 = md->params[i].regoff + stackframesize;
690
691                         if (IS_2_WORD_TYPE(t))
692                                 M_LLD(REG_ITMP12_PACKED, REG_SP, s1 * 4);
693                         else
694                                 M_ILD(REG_ITMP1, REG_SP, s1 * 4);
695                 }
696
697                 /* place argument for tracer */
698
699                 if (i < 2) {
700 #if defined(__ARMEL__)
701                         s2 = PACK_REGS(rd->argintregs[i * 2], rd->argintregs[i * 2 + 1]);
702 #else /* defined(__ARMEB__) */
703                         s2 = PACK_REGS(rd->argintregs[i * 2 + 1], rd->argintregs[i * 2]);
704 #endif          
705                         M_LNGMOVE(s1, s2);
706                 }
707                 else {
708                         s2 = (i - 2) * 2;
709                         M_LST(s1, REG_SP, s2 * 4);
710                 }
711         }
712
713         /* prepare methodinfo pointer for tracer */
714
715         disp = dseg_add_address(cd, m);
716         M_DSEG_LOAD(REG_ITMP1, disp);
717         M_STR_INTERN(REG_ITMP1, REG_SP, 16);
718
719         /* call tracer here (we use a long branch) */
720
721         M_LONGBRANCH(builtin_trace_args);
722
723         /* restore argument registers from stack */
724
725         M_ADD_IMM(REG_SP, REG_SP, (2 + 2 + 1) * 4);        /* free argument stack */
726         M_LDMFD(BITMASK_ARGS | (1<<REG_LR) | (1<<REG_IP), REG_SP);
727
728         /* mark trace code */
729
730         M_NOP;
731 }
732 #endif /* !defined(NDEBUG) */
733
734
735 /* emit_verbosecall_exit *******************************************************
736
737    Generates the code for the call trace.
738
739 *******************************************************************************/
740
741 #if !defined(NDEBUG)
742 void emit_verbosecall_exit(jitdata *jd)
743 {
744         methodinfo   *m;
745         codegendata  *cd;
746         registerdata *rd;
747         methoddesc   *md;
748         s4            disp;
749         s4            s1;
750
751         /* get required compiler data */
752
753         m  = jd->m;
754         cd = jd->cd;
755         rd = jd->rd;
756
757         md = m->parseddesc;
758
759         /* mark trace code */
760
761         M_NOP;
762
763         M_STMFD(BITMASK_RESULT | (1<<REG_LR) | (1<<REG_IP), REG_SP);
764         M_SUB_IMM(REG_SP, REG_SP, (1 + 1) * 4);    /* space for d[high reg] and f */
765
766 #if defined(__ARMEL__)
767         s1 = PACK_REGS(rd->argintregs[1], rd->argintregs[2]);
768 #else /* defined(__ARMEB__) */
769         s1 = PACK_REGS(rd->argintregs[2], rd->argintregs[1]);
770 #endif
771
772         switch (md->returntype.type) {
773         case TYPE_ADR:
774         case TYPE_INT:
775                 M_INTMOVE(REG_RESULT, GET_LOW_REG(s1));
776                 M_MOV_IMM(GET_HIGH_REG(s1), 0);
777                 break;
778
779         case TYPE_LNG:
780                 M_LNGMOVE(REG_RESULT_PACKED, s1);
781                 break;
782
783         case TYPE_FLT:
784                 M_IST(REG_RESULT, REG_SP, 1 * 4);
785                 break;
786
787         case TYPE_DBL:
788                 s1 = rd->argintregs[3];
789                 M_INTMOVE(REG_RESULT, s1);
790                 M_IST(REG_RESULT2, REG_SP, 0 * 4);
791                 break;
792         }
793
794         disp = dseg_add_address(cd, m);
795         M_DSEG_LOAD(rd->argintregs[0], disp);
796         M_LONGBRANCH(builtin_displaymethodstop);
797
798         M_ADD_IMM(REG_SP, REG_SP, (1 + 1) * 4);            /* free argument stack */
799         M_LDMFD(BITMASK_RESULT | (1<<REG_LR) | (1<<REG_IP), REG_SP);
800
801         /* mark trace code */
802
803         M_NOP;
804 }
805 #endif /* !defined(NDEBUG) */
806
807
808 /*
809  * These are local overrides for various environment variables in Emacs.
810  * Please do not remove this and leave it at the end of the file, where
811  * Emacs will automagically detect them.
812  * ---------------------------------------------------------------------
813  * Local variables:
814  * mode: c
815  * indent-tabs-mode: t
816  * c-basic-offset: 4
817  * tab-width: 4
818  * End:
819  * vim:noexpandtab:sw=4:ts=4:
820  */