Mercurial > hg > CbC > old > device
changeset 283:230a3b98b843 mips-done
MIPS jump work.
author | kono |
---|---|
date | Mon, 24 May 2004 13:21:22 +0900 |
parents | d61cf7a9b469 |
children | ec1a68133f6a |
files | Changes mc-code-mips.c mc-code-powerpc.c |
diffstat | 3 files changed, 74 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Mon May 24 07:37:42 2004 +0900 +++ b/Changes Mon May 24 13:21:22 2004 +0900 @@ -4529,3 +4529,13 @@ args: 0 263785888 4200109 2712942 0 : 0 0 Segmentation fault ま、いろいろあるね。 + + +0x401180 <main1+16>: sw $gp,16($sp) + +0x401298 <main+56>: jalr $t9 +0x40129c <main+60>: nop +0x4012a0 <main+64>: lw $gp,16($s8) + +この一貫しないのやめてよ.... $sp!=$fp にすると、$gp がずれて +しまう。call の前に $fp=$sp にするという手もあるが....
--- a/mc-code-mips.c Mon May 24 07:37:42 2004 +0900 +++ b/mc-code-mips.c Mon May 24 13:21:22 2004 +0900 @@ -296,8 +296,9 @@ $2,$3 return value. (dpcmp return value on $2) $0 special register $4-$7 input register - r22-r29 saved register variable (input register for code segement) - $31 stack pointer + r18-r24 saved register variable (input register for code segement) + $25 jump register + $31 stack pointer $fp frame pointer $f0 return value etc. @@ -307,7 +308,7 @@ code segment stack frame * gotoを呼び出した関数のr1 ! r1(goto前のr1) - # * r30 <---r1_offset---------> r1 + # * $fp <---r1_offset---------> $sp r+ +----------+--+----------+----------------+-----------+----------+----+ cousin arg xx reg save !callee arg !code local caller arg xx ($fp)r20-r29 lvar>0 lvar<0 lvar>0x1000 000 @@ -400,13 +401,13 @@ { if (fnptr->sc==CODE) { if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("%d($fp)\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); + printf("%d($sp)\n",CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); } 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); } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("%d($fp)\n",CALLER_ARG(l-ARG_LVAR_OFFSET)); + 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); } @@ -417,7 +418,7 @@ { if (fnptr->sc==CODE) { if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("\taddu\t%s,$fp,%d\n", + printf("\taddu\t%s,$sp,%d\n", register_name(creg),CODE_CALLER_ARG(l-ARG_LVAR_OFFSET)); } else printf("\taddu\t%s,$fp,%d\n",register_name(creg),CODE_LVAR(l)); @@ -425,7 +426,7 @@ printf("\taddu\t%s,$fp,%d+$L_%d\n",register_name(creg), FUNC_LVAR(l),lvar_offset_label); } else if (l>=ARG_LVAR_OFFSET) { /* caller's arguments */ - printf("\taddu\t%s,$fp,%d\n", + 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", @@ -1307,18 +1308,18 @@ printf("\tla %s,$L_%d\n",crn,retcont); } -#define R1SAVE 1 +#define R1SAVE 0 void code_environment(int creg) { /* save frame pointer */ +#if R1SAVE use_int(creg); -#if R1SAVE printf("\tlw %s,0($fp)\n",register_name(creg)); #else - int l = 0; + use_int(creg); printf("\taddu %s,",register_name(creg)); - printf("$fp,%d+$L_%d\n",FUNC_LVAR,lvar_offset_label); + printf("$fp,%d+$L_%d\n",FUNC_LVAR(0),lvar_offset_label); #endif } @@ -1964,6 +1965,30 @@ } } +static void +code_call(int e2,NMTBL *fn,int jmp) +{ + char *jrn; + if (fnptr->sc==CODE) { + if (car(e2) == FNAME) { + printf("\tla\t$25,%s\n",fn->nm); + } else { + jrn = register_name(cadr(jmp)); + printf("\tmove\t$25,%s\n",jrn); + } + printf("\tjalr\t$25\n"); + printf("\tlw\t$gp,$L_%d($sp)\n",cprestore_label); + } else { + if (car(e2) == FNAME) { + printf("\tjal\t%s\n",fn->nm); + } else { + jrn = register_name(cadr(jmp)); + printf("\tmove $25,%s\n",jrn); + printf("\tjal\t$31,$25\n"); + } + } +} + int function(int e1) { @@ -1973,7 +1998,6 @@ int reg_arg_list=0,ret_type,special_lvar; NMTBL *fn = 0; int jmp = 0; - char *jrn; int complex_; int pnargs,preg_arg,pfreg_arg; int stargs; @@ -2132,13 +2156,7 @@ g_expr_u(car(arg_assign)); } clear_ptr_cache(); - if (car(e2) == FNAME) { - printf("\tjal\t%s\n",fn->nm); - } else { - jrn = register_name(cadr(jmp)); - printf("\tmove $25,%s\n",jrn); - printf("\tjal\t$31,$25\n"); - } + code_call(e2,fn,jmp); for(;reg_arg_list;reg_arg_list=cadr(reg_arg_list)) { arg = car(reg_arg_list); if (car(arg)==REGISTER||car(arg)==DREGISTER||car(arg)==FREGISTER @@ -2178,6 +2196,9 @@ printf("%d+$L_%d($sp)\n",FUNC_LVAR(0),lvar_offset_label); } +// MIPS $25 (=$jp) contains calling function address. +// It is used in cpload $25 to get global address table $gp. + void code_jmp(char *s) { // jump to continuation means use all register variable @@ -2185,8 +2206,8 @@ max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN; printf("\tla $25,%s\n",s); printf("\tj\t$25\n"); -} - + control=0; +} void code_indirect_jmp(int e2) { @@ -2194,7 +2215,9 @@ max_reg_var = REG_VAR_BASE-REG_VAR_MIN; max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN; use_int(e2); - printf("\tj %s\n",register_name(e2)); + printf("\tmove $25,%s\n",register_name(e2)); + printf("\tj\t$25\n"); + control=0; } int @@ -2884,9 +2907,9 @@ printf("\t.set noreorder\n"); printf("\t.cpload $25\n"); printf("\t.set reorder\n"); - printf("\tsubu $sp,$sp,$L_%d\n",r1_offset_label); + printf("\tsubu $sp,$fp,$L_%d\n",r1_offset_label); printf("\t.cprestore $L_%d\n",cprestore_label=fwdlabel()); - printf("\tmove $fp,$sp\n"); + // printf("\tmove $fp,$sp\n"); lvar_offset_label = fwdlabel(); max_func_args = 0; } @@ -2967,10 +2990,10 @@ retcont1 = fwdlabel(); fwddef(retcont); if (cadr(fnptr->ty)==FLOAT) { - if (freg!=RET_FREGISTER) - printf("\tmov.s %s,%s\n",register_name(RET_FREGISTER), - register_name(freg)); + creg = freg = cadr(get_input_dregister_var(0,0,1,0)); + set_freg(RET_FREGISTER,1); } else if (cadr(fnptr->ty)==DOUBLE) { + creg = lreg = cadr(get_input_dregister_var(0,0,1,1)); set_dreg(RET_DREGISTER,1); } else if (cadr(fnptr->ty)>0&&( car(cadr(fnptr->ty))==STRUCT || @@ -2981,15 +3004,21 @@ printf("\tlw $3,(%d)($fp)\n",(my_func_args-1)*SIZE_OF_INT); emit_copy(6,3,sz,0,1,1); } else if (cadr(fnptr->ty)!=VOID) { + creg = ireg = cadr(get_input_register_var(0,0,1)); if (creg!=RET_REGISTER) - printf("\tmove $3,%s\n",register_name(creg)); + set_ireg(RET_REGISTER,1); } - printf("\tj $L_%d\n",retcont1); +#if R1SAVE +#else + printf("\tsubu $fp,"); + printf("$fp,%d+$L_%d\n",FUNC_LVAR(0),lvar_offset_label); + // printf("\tj $L_%d\n",retcont1); +#endif } fwddef(retlabel); - if (retcont) { - fwddef(retcont1); - } + // if (retcont) { +// fwddef(retcont1); + // } r1_offsetv = code_offset_set(fnptr); @@ -3791,7 +3820,7 @@ use_float(d,reg); if (regv_l(lreg)==edx || regv_h(lreg)==edx) { edx0 = get_register(); if(!edx0) error(-1); - printf("# dassop\n\tmr %s,%s\n",register_name(edx0),register_name(edx)); + printf("# dassop\n\tmove %s,%s\n",register_name(edx0),register_name(edx)); edx = edx0; } lload(edx,reg,0);
--- a/mc-code-powerpc.c Mon May 24 07:37:42 2004 +0900 +++ b/mc-code-powerpc.c Mon May 24 13:21:22 2004 +0900 @@ -2123,6 +2123,7 @@ max_reg_var = REG_VAR_BASE-REG_VAR_MIN; max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN; printf("\tb L_%s$stub\n",s); + control=0; } @@ -2133,6 +2134,7 @@ use_int(e2); printf("\tmtctr %s\n",register_name(e2)); printf("\tbctr\n"); + control=0; } int