changeset 100:a9e6f2a2946f

Wrote all code for PowerPC and no compile error. Let's fix all bugs...
author kono
date Fri, 14 Mar 2003 22:47:13 +0900
parents 53899975154c
children 05f197a4573a
files Changes mc-code-powerpc.c
diffstat 2 files changed, 103 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Fri Mar 14 21:33:03 2003 +0900
+++ b/Changes	Fri Mar 14 22:47:13 2003 +0900
@@ -2153,3 +2153,29 @@
 仕組みで割り振る必要がある。ってことは、get_input_register_var
 が要るってこと?
 
+
+0x9001a544 <saveFP+4>:  stfd    f15,-136(r1)
+0x9001a548 <saveFP+8>:  stfd    f16,-128(r1)
+0x9001a54c <saveFP+12>: stfd    f17,-120(r1)
+0x9001a550 <saveFP+16>: stfd    f18,-112(r1)
+0x9001a554 <saveFP+20>: stfd    f19,-104(r1)
+0x9001a558 <saveFP+24>: stfd    f20,-96(r1)
+0x9001a55c <saveFP+28>: stfd    f21,-88(r1)
+0x9001a560 <saveFP+32>: stfd    f22,-80(r1)
+0x9001a564 <saveFP+36>: stfd    f23,-72(r1)
+0x9001a568 <saveFP+40>: stfd    f24,-64(r1)
+0x9001a56c <saveFP+44>: stfd    f25,-56(r1)
+0x9001a570 <saveFP+48>: stfd    f26,-48(r1)
+0x9001a574 <saveFP+52>: stfd    f27,-40(r1)
+0x9001a578 <saveFP+56>: stfd    f28,-32(r1)
+0x9001a57c <saveFP+60>: stfd    f29,-24(r1)
+0x9001a580 <saveFP+64>: stfd    f30,-16(r1)
+0x9001a584 <saveFP+68>: stfd    f31,-8(r1)
+0x9001a588 <saveFP+72>: stw     r0,8(r1)
+0x9001a58c <saveFP+76>: blr
+
+なのか。ということは、
+      f%d に対して、"saveFP+%d",68-(31-f)*4
+かな?
+
+
--- a/mc-code-powerpc.c	Fri Mar 14 21:33:03 2003 +0900
+++ b/mc-code-powerpc.c	Fri Mar 14 22:47:13 2003 +0900
@@ -78,6 +78,9 @@
 #define MIN_TMP_FREG 1
 #define MAX_TMP_FREG 12
 
+#define RET_REGISTER 3
+#define RET_DREGISTER 1
+
 int MAX_REGISTER=30;             /* PowerPCのレジスタを10個まで使う*/
 int MAX_FREGISTER=30;
 #define  REAL_MAX_REGISTER 32    /* PowerPCのレジスタが32ということ*/
@@ -429,7 +432,7 @@
     return xreg;
 }
 
-static char *code_base;
+static int code_base;
 
 #define MAX_PTR_CACHE 10
 
@@ -497,9 +500,9 @@
 	    r=creg; /* this can't happen */
     }
     rrn = register_name(r);
-    printf("\taddis %s,r31,ha16(L_%s$non_lazy_ptr-%s)\n",
+    printf("\taddis %s,r31,ha16(L_%s$non_lazy_ptr-_%d)\n",
 	     rrn,(char *)g,code_base);
-    printf("\tlzw %s,lo16(L_%s$non_lazy_ptr-%s)(%s)\n",
+    printf("\tlzw %s,lo16(L_%s$non_lazy_ptr-_%d)(%s)\n",
 	     rrn,(char *)g,code_base,rrn);
     return r;
 }
@@ -764,8 +767,8 @@
 void
 code_return() {
     char *crn = register_name(creg);
-    printf("\taddis %s,r31,ha16(_%d-%s)\n",crn,retcont,code_base);
-    printf("\tla %s,lo16(_%d-%s)(%s)\n",crn,retcont,code_base,crn);
+    printf("\taddis %s,r31,ha16(_%d-_%d)\n",crn,retcont,code_base);
+    printf("\tla %s,lo16(_%d-_%d)(%s)\n",crn,retcont,code_base,crn);
 }
 
 
@@ -890,8 +893,8 @@
     } else {
 	text_mode();
     }
-    printf("\taddis %s,r31,ha16(_%d-%s)\n",crn,lb,code_base);
-    printf("\tla %s,lo16(_%d-%s)(%s)\n",crn,lb,code_base,crn);
+    printf("\taddis %s,r31,ha16(_%d-_%d)\n",crn,lb,code_base);
+    printf("\tla %s,lo16(_%d-_%d)(%s)\n",crn,lb,code_base,crn);
 }
 
 #define MAX_COPY_LEN 20
@@ -1356,24 +1359,27 @@
     printf("## %s",s);
 }
 
+static int code_begin;
 
 void
 code_enter(char *name)
 {
-    printf("\t.align 4\n");
+    if (output_mode!=TEXT_EMIT_MODE) 
+	text_mode();
+    else
+	printf("\t.align 4\n");
     if (stmode!=STATIC)
 	printf(".globl %s\n",name);
     printf("\t.type\t%s,@function\n",name);
     printf("%s:\n",name);
+    code_disp_label=fwdlabel();
+    printf("\tla r30,-_%d(r1)\n",code_disp_label);
 }
 
 
 void
 code_enter1(int args)
 {
-    code_disp_label=fwdlabel();
-    printf("\tlea _%d(%%ebp),%%esp\n",code_disp_label);
-
     printf("## args %d disp %d code_arg_offset=%d code_disp_offset=%d\n",args,disp,code_arg_offset,code_disp_offset); 
 }
 
@@ -1383,53 +1389,88 @@
     disp&= -size_of_int;
     printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset);
     printf("_%d:\n",labelno);
-    printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
+    printf("\t.size\t_%s,_%d-_%d\n",name,labelno,code_begin);
     local_table();
     labelno++;
     free_all_register();
 }
 
+static int code_setup;
+
 void
 enter(char *name)
 {
-    printf("\t.align 2\n");
+    if (output_mode!=TEXT_EMIT_MODE) 
+	text_mode();
+    else
+	printf("\t.align 4\n");
     if (stmode!=STATIC)
 	printf(".globl %s\n",name);
+    printf("\t.type\t%s,@function\n",name);
     printf("%s:\n",name);
-    printf("\t.type\t%s,@function\n",name);
-    printf("\tpushl %%ebp\n");
-    printf("\tmovl %%esp,%%ebp\n");
-    printf("\tpushl %%ebx\n");
-    printf("\tpushl %%esi\n");
-    printf("\tpushl %%edi\n");
+    code_setup=fwdlabel();
+    printf("\tmflr r0\n");
+    printf("\tbl _%d\n",code_setup);
+    code_base=fwdlabel();
+    printf("\tmr r30,r1\n");
+    printf("\tmflr r31\n");
 }
 
 void
 enter1()
 {
-    func_disp_label=fwdlabel();
-    printf("\tlea _%d(%%ebp),%%esp\n",func_disp_label); 
-    /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */
+}
+
+int
+reg_save_offset()
+{
+    return (REG_VAR_BASE-max_reg_var)*size_of_int+
+           (FREG_VAR_BASE-max_freg_var)*size_of_double+
+	    20;
 }
 
 void
 leave(int control, char *name)
 {
-    if (retcont) {
-	if (control)
-	    jmp(retlabel);
-	fwddef(retcont);
+    if (control) {
+	if (regv[creg] && creg!=RET_REGISTER)
+	    printf("\tmr r%d,r%d\n",RET_REGISTER,creg);
+	if (fregv[freg] && freg!=RET_DREGISTER)
+	    printf("\tfmr f%d,f%d\n",RET_DREGISTER,freg);
     }
+    if (retcont) fwddef(retcont);
     fwddef(retlabel);
-    disp &= -size_of_int;
+    printf("\tlwz r1,0(r1)\n");
+    if (FREG_VAR_BASE-max_freg_var>0) {
+	if (REG_VAR_BASE-max_reg_var>0)
+	    printf("\tlmw r%d,-%d(r1)\n",
+			REG_VAR_BASE-max_reg_var,reg_save_offset());
+	printf("\tb restFP+%d ; restore f%d-f31\n",
+			68-(31-FREG_VAR_BASE-max_freg_var)*4,
+			FREG_VAR_BASE-max_freg_var);
+    } else {
+	printf("\tlwz r0,8(r1)\n");
+	printf("\tmtlr r0\n");
+	if (REG_VAR_BASE-max_reg_var>0)
+	    printf("\tlmw r%d,-%d(r1)\n",
+			REG_VAR_BASE-max_reg_var,reg_save_offset());
+	printf("\tblr\n");
+    }
 
-    printf("\tlea %d(%%ebp),%%esp\n",disp_offset);
-    printf("\tpopl %%edi\n");
-    printf("\tpopl %%esi\n");
-    printf("\tpopl %%ebx\n");
-    printf("\tleave\n");
-    printf("\tret\n");
-    printf("\t.set _%d,%d\n",func_disp_label,disp+disp_offset);
+    disp &= -size_of_int;
+    fwddef(code_setup);
+    fwddef(code_base);
+    if (REG_VAR_BASE-max_reg_var>0)
+	printf("\tstmw r%d,-%d(r1)\n",
+			REG_VAR_BASE-max_reg_var,reg_save_offset());
+    printf("\tstwu r1,-%d(r1)\n",disp+disp_offset);
+    if (FREG_VAR_BASE-max_freg_var>0)
+	printf("\tb saveFP+%d ; save f%d-f31\n",
+			68-(31-FREG_VAR_BASE-max_freg_var)*4,
+			FREG_VAR_BASE-max_freg_var);
+    else
+	printf("\tblr\n");
+
     printf("_%d:\n",labelno);
     printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
     local_table();
@@ -1764,8 +1805,8 @@
     } else {
 	text_mode();
     }
-    printf("\taddis %s,r31,ha16(_%d-%s)\n",rrn,lb,code_base);
-    printf("\tla %s,lo16(_%d-%s)(%s)\n",rrn,lb,code_base,rrn);
+    printf("\taddis %s,r31,ha16(_%d-_%d)\n",rrn,lb,code_base);
+    printf("\tla %s,lo16(_%d-_%d)(%s)\n",rrn,lb,code_base,rrn);
     printf("\tlfd %s,(%s)\n",frn,rrn);
     free_register(r);
 }