Mercurial > hg > CbC > old > device
changeset 376:d81e1be4036f lvar-offset-done
frame offset fix MIPS
author | kono |
---|---|
date | Mon, 12 Jul 2004 12:37:18 +0900 |
parents | 91849fdeea60 |
children | b23568be1155 |
files | Changes mc-code-mips.c |
diffstat | 2 files changed, 38 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Mon Jul 12 07:33:23 2004 +0900 +++ b/Changes Mon Jul 12 12:37:18 2004 +0900 @@ -5778,3 +5778,6 @@ うーん、やっぱり、難しいよな... 何故か、printf が local variable を壊してしまう。 + +はぁ。大変なのはPowerPCだけで、MIPSとia32 は、そのまま動くというのが +わかりました。
--- a/mc-code-mips.c Mon Jul 12 07:33:23 2004 +0900 +++ b/mc-code-mips.c Mon Jul 12 12:37:18 2004 +0900 @@ -1,4 +1,4 @@ -/* Micro-C Code Generation Part for Power PC (Mac OS X) */ +/* Micro-C Code Generation Part for MIPS (ps2linux) */ /* $Id$ */ @@ -316,13 +316,13 @@ <-------r1_offset------------------------------> - <------------lvar_offset-------> + <--lvar_offset--> <-arg_offset-> r+ +-----------+----+---------------+----------+-------------+----+ callee arg xxx register save local caller arg xxx ($r31)($fp) reg_save disp max_func_args*SIZE_OF_INT lvar>0 lvar<0 lvar>0x1000 0000 - prev $sp=$fp $sp=$fp + prev $fp prev $sp $fp $sp */ #define arg_offset 8 @@ -355,7 +355,7 @@ lvar_offsetv += round16(r1_offsetv)-r1_offsetv; r1_offsetv = round16(r1_offsetv); -#if 0 +#if 1 printf("# vars= %d, regs= %d/%d, args= %d, extra= %d\n", round16(-disp), max_reg_var+2, @@ -390,7 +390,7 @@ fprintf(asi,"$L_%d=%d\n",cprestore_label , round16((max_func_args>2?max_func_args:2)*SIZE_OF_INT)); fprintf(asi,"$L_%d=%d\n",r1_offset_label,r1_offsetv); - fprintf(asi,"$L_%d=%d\n",lvar_offset_label,lvar_offsetv); + fprintf(asi,"$L_%d=%d\n",lvar_offset_label,r1_offsetv-lvar_offsetv); return r1_offsetv; } @@ -404,11 +404,11 @@ } else printf("%d($fp)\n",CODE_LVAR(l)); } else if (l<0) { /* local variable */ - printf("%d+$L_%d($fp)\n",FUNC_LVAR(l),lvar_offset_label); + printf("%d($fp)\n",FUNC_LVAR(l)); } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ printf("%d($sp)\n",CALLER_ARG(l-ARG_LVAR_OFFSET)); } else { /* callee's arguments */ - printf("%d+$L_%d($fp)\n",CALLEE_ARG(l),r1_offset_label); + printf("%d+$L_%d($fp)\n",CALLEE_ARG(l),lvar_offset_label); } } @@ -422,14 +422,14 @@ } else printf("\taddu\t%s,$fp,%d\n",register_name(creg),CODE_LVAR(l)); } else if (l<0) { /* local variable */ - printf("\taddu\t%s,$fp,%d+$L_%d\n",register_name(creg), - FUNC_LVAR(l),lvar_offset_label); + printf("\taddu\t%s,$fp,%d\n",register_name(creg), + FUNC_LVAR(l)); } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ printf("\taddu\t%s,$sp,%d\n", register_name(creg),CALLER_ARG(l-ARG_LVAR_OFFSET)); } else { /* callee's arguments */ printf("\taddu\t%s,$fp,%d+$L_%d\n", - register_name(creg),CALLEE_ARG(l),r1_offset_label); + register_name(creg),CALLEE_ARG(l),lvar_offset_label); } } @@ -1402,8 +1402,12 @@ printf("\tlw %s,0($fp)\n",register_name(creg)); #else use_int(creg); +#if 0 printf("\taddu %s,",register_name(creg)); printf("$fp,%d+$L_%d\n",FUNC_LVAR(0),lvar_offset_label); +#else + printf("\tmove %s,$fp\n",register_name(creg)); +#endif #endif } @@ -2282,8 +2286,10 @@ void code_fix_frame_pointer(int offset) { +#if 0 printf("\tla $fp,"); printf("%d+$L_%d($sp)\n",FUNC_LVAR(0),lvar_offset_label); +#endif } // MIPS $25 (=$jp) contains calling function address. @@ -2932,13 +2938,13 @@ { int i; for (i=reg_var_num(0);i>reg_var_num(reg_save);i--) { - printf("\tsw %s,$L_%d-%d($sp)\n",register_name(i), - r1_offset_label,-disp); + printf("\tsw %s,-%d($13)\n",register_name(i), + -disp); disp -= SIZE_OF_INT; } for (i=freg_var_num(0);i>freg_var_num(freg_save);i--) { - printf("\ts.s %s,$L_%d-%d($sp)\n",register_name(i), - r1_offset_label,-disp); + printf("\ts.s %s,-%d($13)\n",register_name(i), + -disp); disp -= SIZE_OF_FLOAT; } return disp; @@ -2949,13 +2955,13 @@ { int i; for (i=reg_var_num(0);i>reg_var_num(reg_save);i--) { - printf("\tlw %s,$L_%d-%d($sp)\n",register_name(i), - r1_offset_label,-disp); + printf("\tlw %s,-%d($13)\n",register_name(i), + -disp); disp -= SIZE_OF_INT; } for (i=freg_var_num(0);i>freg_var_num(freg_save);i--) { - printf("\tl.s %s,$L_%d-%d($sp)\n",register_name(i), - r1_offset_label,-disp); + printf("\tl.s %s,-%d($13)\n",register_name(i), + -disp); disp -= SIZE_OF_FLOAT; } return disp; @@ -3054,7 +3060,7 @@ printf("\t.globl\t%s\n",name); printf(".ent %s\n",name); printf("%s:\n",name); - printf("\t.frame $fp,$L_%d,$31\n",r1_offset_label=fwdlabel()); + printf("\t.frame $sp,$L_%d,$31\n",r1_offset_label=fwdlabel()); printf("\t.mask $L_%d,$L_%d\n",mask_label=fwdlabel(), mask_offset_label=fwdlabel()); printf("\t.fmask $L_%d,$L_%d\n",fmask_label=fwdlabel(), @@ -3062,13 +3068,14 @@ printf("\t.set noreorder\n"); printf("\t.cpload $25\n"); printf("\t.set reorder\n"); + printf("\tmove $13,$sp\n"); printf("\tsubu $sp,$sp,$L_%d\n",r1_offset_label); printf("\t.cprestore $L_%d\n",cprestore_label=fwdlabel()); - printf("\tsw $31,$L_%d-%d($sp)\n",r1_offset_label,arg_offset); - printf("\tsw $fp,$L_%d-%d($sp)\n",r1_offset_label,arg_offset+SIZE_OF_INT); + printf("\tsw $31,-%d($13)\n",arg_offset); + printf("\tsw $fp,-%d($13)\n",arg_offset+SIZE_OF_INT); printf("\tj $L_%d\n",register_save_label=fwdlabel()); register_save_return_label = backdef(); - printf("\tmove $fp,$sp\n"); + printf("\tsubu $fp,$13,$L_%d\n",lvar_offset_label); } void @@ -3117,10 +3124,12 @@ } #if R1SAVE #else +#if 0 printf("\tsubu $fp,"); printf("$fp,%d+$L_%d\n",FUNC_LVAR(0),lvar_offset_label); // printf("\tj $L_%d\n",retcont1); #endif +#endif } fwddef(retlabel); // if (retcont) { @@ -3129,12 +3138,12 @@ r1_offsetv = code_offset_set(fnptr); - printf("\tmove $sp,$fp\n"); - printf("\tlw $31,$L_%d-%d($sp)\n",r1_offset_label,arg_offset); - printf("\tlw $fp,$L_%d-%d($sp)\n",r1_offset_label,arg_offset+SIZE_OF_INT); + printf("\taddu $13,$fp,$L_%d\n",lvar_offset_label); + printf("\tlw $31,-%d($13)\n",arg_offset); + printf("\tlw $fp,-%d($13)\n",arg_offset+SIZE_OF_INT); if (max_reg_var+max_freg_var) code_register_restore(max_reg_var,max_freg_var,-arg_offset-SIZE_OF_INT*2); - printf("\taddu $sp,$sp,%d\n",r1_offsetv); + printf("\tmove $sp,$13\n"); printf("\tj $31\n"); // leave part end