changeset 383:9a3d897d58fd

ARM continue...
author kono
date Tue, 20 Jul 2004 12:23:03 +0900
parents 832e1f6bba82
children 5fc059f1947d
files Changes Makefile mc-code-arm.c mc-parse.h
diffstat 4 files changed, 81 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Mon Jul 19 16:30:11 2004 +0900
+++ b/Changes	Tue Jul 20 12:23:03 2004 +0900
@@ -5879,3 +5879,10 @@
 
 なかなか終らないね。GBAとLinux Zaurus と両方だからな。
 (やっぱ ARM に手をつけたのは失敗でした)
+
+alloca の引数が定数の場合をやってないね。
+
+まだ、先長そう。でも、やりたかったんだから、仕方ない。
+
+浮動小数点レジスタ一つっての嘘だな。レジスタは使うたびに、
+毎回セーブするみたいね。
--- a/Makefile	Mon Jul 19 16:30:11 2004 +0900
+++ b/Makefile	Tue Jul 20 12:23:03 2004 +0900
@@ -35,6 +35,9 @@
 mc-mips : mc-code-mips.o $(COMPLIB) $(CONVERTER)
 	$(CC) -g mc-code-mips.o $(COMPLIB) $(CONVERTER) -o $@
 
+mc-arm : mc-code-arm.o $(COMPLIB) $(CONVERTER)
+	$(CC) -g mc-code-arm.o $(COMPLIB) $(CONVERTER) -o $@
+
 conv/conv.h: conv_func.tbl conv_func.pl
 	perl conv_func.pl
 conv/convdef.h: conv_func.tbl conv_func.pl
--- a/mc-code-arm.c	Mon Jul 19 16:30:11 2004 +0900
+++ b/mc-code-arm.c	Tue Jul 20 12:23:03 2004 +0900
@@ -12,17 +12,9 @@
 
 int arch_mode = UseFPP; 
 
-char **l_include_path[];
-
-char *l_include_path_zaurus[] = {
+char *l_include_path[]={
     "/Developer/Zaurus-X-gcc/opt/Embedix/tools/arm-linux/include",
-    0
-};
-
-char *l_include_path_gba[] = {
-    "/Developer/Zaurus-X-gcc/opt/Embedix/tools/arm-linux/include",
-    0
-};
+    0};
 
 int data_alignment = 0;
 
@@ -39,11 +31,15 @@
 static void shift(char *op, int creg,int reg);
 static int struct_push(int e4,int t,int arg);
 static void register_usage(char *s);
+static void code_add(int reg,int offset,int r);
+static void const_list_table();
+static char * cstore(int sz);
+static void code_int_lib(char *lib,int reg,int oreg); 
+static void code_float_lib(char *opc,int oreg,int in_reg,int e1);
+static void code_double_lib(char *opc,int oreg,int in_reg,int e1);
 
 static int creg;
-
 static int output_mode = TEXT_EMIT_MODE;
-
 static int cprestore_label;
 static int fmask_label;
 static int fmask_offset_label;
@@ -161,7 +157,7 @@
 static char *reg_name[] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 
     "r8", "r9", "sl", "lr", "ip", "fp", "sp", "pc",
-    "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7";
+    "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7"
 }; 
 
 #define register_name(i)  reg_name[i]
@@ -283,7 +279,7 @@
 static unsigned int code_fmask();
 static int code_fmask_offset();
 
-static void jcond(int l, char cond);
+static void jcond(int l, int cond);
 
 #define ARG_LVAR_OFFSET 0x10000000
 
@@ -1030,7 +1026,7 @@
 void
 gexpr_init(void)
 {
-    const_list();
+    const_list_table();
     while(reg_sp > 0) {
 	error(-1);
 	free_register(reg_stack[--reg_sp]);
@@ -1211,9 +1207,9 @@
 }
 
 static void
-const_list()
-{
-    int p,next,lb;
+const_list_table()
+{
+    int p,lb;
     if (control) {
 	lb = fwdlabel();
 	jmp(lb);
@@ -1231,7 +1227,7 @@
     if (lb) {
 	fwddef(lb);
     }
-    free_glist3_a(pconst_list);
+    free_glist3_a(prev_const_list);
     prev_const_list=const_list;
     prev_const_list_label=const_list_label;
     const_list = 0;
@@ -1245,7 +1241,7 @@
     static int inst_count;
     if ((inst_count+=count)>CONST_TBL_COUNT) {
 	inst_count = 0;
-	const_list();
+	const_list_table();
     }
 }
 
@@ -1315,11 +1311,11 @@
 {
     int sign,p1,p2,p3;
     sign = make_const(c,&p1,&p2,&p3,mode);
-    return (*p1&&!*p2&&!*p3)?sign:0;
-}
-
-
-static void 
+    return (p1&&!p2&&!p3)?sign:0;
+}
+
+
+extern void 
 code_const(int e2,int reg)
 {
     char *crn,*add,*mov;
@@ -1331,9 +1327,9 @@
     if ((s=make_const(e2,&p1,&p2,&p3,0))) {
 	add = s>0?"add":"sub";
 	mov = s>0?"mov":"mvn";
-	if (p1) printf("\t%s\t%s, %s, #%d\n",mov,crn,rrn,p1);
-	if (p2) printf("\t%s\t%s, %s, #%d\n",add,crn,rrn,p2);
-	if (p3) printf("\t%s\t%s, %s, #%d\n",add,crn,rrn,p3);
+	if (p1) printf("\t%s\t%s, #%d\n",mov,crn,p1);
+	if (p2) printf("\t%s\t%s, %s, #%d\n",add,crn,crn,p2);
+	if (p3) printf("\t%s\t%s, %s, #%d\n",add,crn,crn,p3);
     } else {
 	disp = search_const(CONST,e2,&label);
 	printf("\tldr\t%s, .L%d+%d\n",crn,label,disp);
@@ -1374,7 +1370,7 @@
 	printf("\t%s\t%s, [%s, #%d]%s\n",ld,crn,rrn,offset,cext);
     } else {
 	code_add(reg,offset,r);
-	printf("\t%s\t%s, [%s, #0]%s\n",ldcrn,crn,cext);
+	printf("\t%s\t%s, [%s, #0]%s\n",ld,crn,crn,cext);
     }
 }
 
@@ -1398,7 +1394,6 @@
 #define cload(sz,sign) \
     (sz==1?"ldrb":sz==SIZE_OF_SHORT?(sign?"ldrsh":"ldrh"):"ldr")
 
-#define cstore(sz) (sz==1?"strb":sz==SIZE_OF_SHORT?"strh":"str")
 
 #define cext(sign,sz,reg)
 
@@ -1425,7 +1420,7 @@
 void
 code_crgvar(int e1,int reg,int sign,int sz){
     use_int(reg);
-    code_ld(cload(sz,sign),reg,cadr(e1),get_ptr_cache((NMTBL*)caddr(e1))
+    code_ld(cload(sz,sign),reg,cadr(e1),get_ptr_cache((NMTBL*)caddr(e1)),
 	sz==1?"  @ zero_extendqisi2":"");
     cext(sign,sz,reg);
 }
@@ -1496,7 +1491,7 @@
     int lb,disp;
     use_int(reg);
     disp = search_const(LABEL,label,&lb);
-    printf("\tldr\t%s, .L%d+%d\n",crn,lb,disp);
+    printf("\tldr\t%s, .L%d+%d\n",register_name(reg),lb,disp);
     return;
 }
 
@@ -1530,8 +1525,8 @@
     int xreg;
     if (car(e2)==REGISTER) {
 	use_int(reg);
-	code_add(dir,cadr(e2));
-	if (cadr(reg)!=e2)
+	code_add(reg,dir,cadr(e2));
+	if (reg!=cadr(e2))
 	    code_register(cadr(e2),reg);
 	return;
     } 
@@ -1547,7 +1542,7 @@
     }
     code_ld(cload(sz,sign),reg,0,xreg,sz==1?"  @ zero_extendqisi2":"");
     code_add(reg,dir,reg);
-    code_ldf(cstore(sz),reg,0,xreg,sz==SIZE_OF_SHORT?"  @ movhi":"");
+    code_ldf(cstore(sz),drn,0,xreg,sz==SIZE_OF_SHORT?"  @ movhi":"");
 }
 
 
@@ -1558,7 +1553,7 @@
     if (car(e2)==REGISTER) {
 	use_int(reg);
 	code_register(cadr(e2),reg);
-	code_add(dir,reg);
+	code_add(reg,dir,reg);
 	return;
     } 
     g_expr(e2);
@@ -1575,7 +1570,7 @@
     }
     code_ld(cload(sz,sign),reg,0,xreg,sz==1?"  @ zero_extendqisi2":"");
     code_add(nreg,dir,reg);
-    code_ldf(cstore(sz),nreg,0,xreg,sz==SIZE_OF_SHORT?"  @ movhi":"");
+    code_ldf(cstore(sz),nrn,0,xreg,sz==SIZE_OF_SHORT?"  @ movhi":"");
 
     free_register(nreg);
 }
@@ -1610,8 +1605,8 @@
 
 void
 code_bool(int e1,int reg) {
-    char *xrn;
-    int e2,e3;
+
+
     if (rexpr_bool(e1, reg)) return;
 #if 0
     b_expr(e1,1,e2=fwdlabel(),1);  /* including > < ... */
@@ -1663,7 +1658,7 @@
 void
 code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) {
     use_int(reg);
-    code_ld(cload(sz,0),reg,cadr(e1),xreg,get_ptr_cache((NMTBL*)caddr(e1)),
+    code_ld(cload(sz,0),reg,cadr(e1),get_ptr_cache((NMTBL*)caddr(e1)),
 	sz==1?"  @ zero_extendqisi2":"");
     cext(0,sz,r);
     printf("\tcmp\t%s, #0\n",register_name(reg));
@@ -1785,8 +1780,8 @@
 	}
 	clear_ptr_cache();
 	code_save_stacks();
-	code_code_register(from,0);
-	code_code_register(to,1);
+	code_register(from,0);
+	code_register(to,1);
 	code_const(length,2);
         /* overrap must be allowed */
 	printf("\tbl %s\n",memmove);
@@ -1871,7 +1866,7 @@
 	    free_register(freg);
 	    if (mode) {
 		printf("\t%s %s,%s\n",
-		    arch_mode&UseFPP?"mvfd":mov",
+		    arch_mode&UseFPP?"mvfd":"mov",
 		    fregister_name(reg),fregister_name(freg));
 	    }
 	}
@@ -2462,7 +2457,7 @@
     g = get_register();
     crn = register_name(reg);
     grn = register_name(g);
-    printf("\trsb\tsp, %s, sp,%s\n",crn);
+    printf("\trsb\tsp, %s, sp, %s\n",crn, grn);
     printf("\tmov\t%s, sp\n",crn);
     free_register(g);
 }
@@ -2497,7 +2492,7 @@
     max_reg_var = REG_VAR_BASE-REG_VAR_MIN;
     max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN;
     use_int(e2);
-    printf("\tmov\tpc, %s @ indirect jump\n",s); // ?!
+    printf("\tmov\tpc, %s @ indirect jump\n",register_name(e2)); // ?!
     control=0;
 }
 
@@ -2531,7 +2526,7 @@
     if (!is_int_reg(creg)) error(-1);
     xreg = creg;
     use_float(d,reg);
-    code_ldf(d?"ldfd":"ldfs,reg,offset,xreg,"");
+    code_ldf(d?"ldfd":"ldfs",register_name(reg),offset,xreg,"");
     return d?DOUBLE:FLOAT;
 }
 #endif
@@ -2617,7 +2612,7 @@
 static char *
 cstore(int sz)
 {
-    swithc(sz) {
+    switch(sz) {
     case 1: return "strb";
     case SIZE_OF_SHORT: return "strh";
     default: return "str";
@@ -2628,7 +2623,7 @@
 code_assign_gvar(int e2,int creg,int byte) {
     use_int(creg);
     code_ldf(cstore(byte),register_name(creg),cadr(e2),
-        get_ptr_cache((NMTBL*)caddr(e2)),byte==SIZE_OF_SHORT?" @ movhi");
+        get_ptr_cache((NMTBL*)caddr(e2)),byte==SIZE_OF_SHORT?" @ movhi":"");
 }
 
 void
@@ -2756,19 +2751,14 @@
     case UMUL:
 	printf("\tmul %s,%s,%s\n",crn,crn,orn);
 	break;
-    case DIV: case UDIV: case MOD: case UMOD:
-        bl      __modsi3
-        bl      __udivsi3
-        bl      __umodsi3
-
-        printf("\t%s $0,%s,%s\n",(op==UDIV||op==UMOD)?"divu":"div",crn,orn);
-        printf("\t%s %s\n",(op==MOD||op==UMOD)?"mfhi":"mflo",crn);
-        printf("\t.set    noreorder\n");
-        printf("\tbeql    %s,$0,1f\n",orn);
-        printf("\tbreak   7\n");
-        printf("1:\n");
-        printf("\t.set    reorder\n");
-        break;
+    case DIV:
+	code_int_lib("__divsi3",creg,oreg); break;
+    case UDIV:
+	code_int_lib("__udivsi3",creg,oreg); break;
+    case MOD:
+	code_int_lib("__modsi3",creg,oreg); break;
+    case UMOD:
+	code_int_lib("__umodsi3",creg,oreg); break;
     default:
 	error(-1);
     }
@@ -2784,7 +2774,7 @@
     switch(op) {
     case MUL: case UMUL: case DIV: case UDIV:
 	return ilog(v);
-    case ADD: case SUB;
+    case ADD: case SUB:
 	return 1;
     case LSHIFT: case ULSHIFT: case RSHIFT: case URSHIFT:
 	return 0<v&&v<=32;
@@ -2909,10 +2899,10 @@
 static void
 pcond(int op, int r2,int r1,int r0,int cond,int l1,int mode)
 {
-    int t;
     char *rn2;
     char *rn1;
     char *rn0;
+    char *cc,*ncc;
 
     rn1 =		register_name(r1);
     rn2 =		register_name(r2);
@@ -2979,10 +2969,10 @@
 #define CMP_C1T (-1)
 
 static void
-jcond(int l, int reg,char cond,int reg)
+jcond(int l, int cond)
 {       
     if (chk) return;
-    printf("\tb%s\t%\t.L%d\n",cond?"ne":"eq",l);
+    printf("\tb%s\t.L%d\n",cond?"ne":"eq",l);
 }
 
 void
@@ -3004,15 +2994,15 @@
 code_register_save(int reg_save,int freg_save,int disp)
 {
     int i;
+    printf("\tstmfd\tsp!, {");
     for (i=reg_var_num(0);i>reg_var_num(reg_save);i--) {
-	printf("\tstr\t%s, [sp, #%d]\n",register_name(i),
-	    r1_offset_label,-disp);
+	    printf(", %s",register_name(i));
 	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);
-	disp -= SIZE_OF_FLOAT;
+    printf("fp, ip, lr, pc}\n");
+    if (freg_save>0) {
+	printf("\tsfmfd\tf4, %d, [sp]!\n",freg_save);
+	disp -= SIZE_OF_DOUBLE*freg_save;
     }
     return disp;
 }
@@ -3021,16 +3011,16 @@
 code_register_restore(int reg_save,int freg_save,int disp)
 {
     int i;
+    if (freg_save>0) {
+	printf("\tlfm\tf4, %d, [fp, #%d]!\n",freg_save);
+	disp -= SIZE_OF_DOUBLE*freg_save;
+    }
+    printf("\tldmea\tfp, {");
     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("%s, ",register_name(i));
 	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);
-	disp -= SIZE_OF_FLOAT;
-    }
+    printf("fp, sp, pc}\n");
     return disp;
 }
 
@@ -3047,7 +3037,6 @@
 #ifdef DOT_SIZE
     printf("\t.type\t%s,@function\n",name);
 #endif
-    printf(".ent %s\n",name);
     printf("%s:\n",name);
     printf("\t.frame $fp,$L_%d,$31\n",r1_offset_label=fwdlabel());
     printf("\t.mask  $L_%d,$L_%d\n",mask_label=fwdlabel(),
@@ -3095,7 +3084,6 @@
 
     if (stmode!=STATIC)
 	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.mask  $L_%d,$L_%d\n",mask_label=fwdlabel(),
@@ -3434,8 +3422,8 @@
 {
     NMTBL *n;
     int init;
-    const_list();
-    free_glist3_a(pconst_list); pconst_list = 0;
+    const_list_table();
+    free_glist3_a(prev_const_list); prev_const_list = 0;
 
     init=0;
     /* static local variables */
--- a/mc-parse.h	Mon Jul 19 16:30:11 2004 +0900
+++ b/mc-parse.h	Tue Jul 20 12:23:03 2004 +0900
@@ -61,6 +61,7 @@
 /* used in mc-switch */
 
 extern void free_glist3(int e1);
+extern void free_glist3_a(int e1);
 extern int csvalue1;
 extern int blabel,dlabel;