X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=gesamt_ppc%2Fchelper.c;h=2e736ea421618c08867b07b598b27cfdbbf2d615;hb=HEAD;hp=84ef5bac03d3f6215bc5a3758a2782aec2163058;hpb=5f61ae4fe282ab07b5a81722497893c767bdb058;p=uebersetzerbau-ss10.git diff --git a/gesamt_ppc/chelper.c b/gesamt_ppc/chelper.c index 84ef5ba..2e736ea 100644 --- a/gesamt_ppc/chelper.c +++ b/gesamt_ppc/chelper.c @@ -23,7 +23,10 @@ void func_header(char *s, int vars, int parms, int call) need_stack = (vars || parms) && call; if(need_stack) { - printf("\tenter $%d, $0\n", 8*(vars + parms + 2 /* fuer rax und r10 */)); + /* save the link register */ + printf("\tmflr 0; stw 0,-8(1)\n"); + /* create the stack */ + printf("\tstwu 1, -80(1)\n"); } } @@ -34,8 +37,12 @@ char *get_func_name(void) void func_footer(void) { - if(need_stack) - printf("\tleave\n"); + if(need_stack) { + /* remove stack frame */ + printf("\taddi 1,1,80\n"); + /* restore link register */ + printf("\tlwz 0,-8(1); mtlr 0\n"); + } printf("\tblr\n\n\n"); } @@ -43,14 +50,21 @@ void move(char *src, char *dst) { if(src == (char*) NULL) return; if(strcmp(src,dst) != 0) { - printf("\tmr %s, %s\n", dst, src); + printf("\tmr %s,%s\n", dst, src); } } void moveimm(long imm, char *dst) { - /* TODO: 32 bits... */ - printf("\taddi %s,0,%d\n", dst, imm); + if((imm > 65536-1) || (imm < -65536)) { + /* high word */ + printf("\tlis %s,%d@ha\n", dst, imm); + /* low word */ + printf("\taddi %s,%s,%d@l\n", dst, dst, imm); + } else { + /* just low word */ + printf("\tli %s,%d@l\n", dst, imm); + } } char *next_reg(char *s, int params) @@ -77,7 +91,7 @@ char *reg_64to8l(char *s) char *param_reg(int num) { - char *regs[] = {"3", "4", "5", "6", "7", "8", "9"}; + char *regs[] = {"3", "4", "5", "6", "7", "8", "9", "10"}; return regs[num]; }