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