xa51, work in progress
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 29 Jan 2002 18:05:45 +0000 (18:05 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 29 Jan 2002 18:05:45 +0000 (18:05 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1856 4a8a32a2-be11-0410-ad9d-d568d2c75423

as/xa51/xa_asm.y
as/xa51/xa_main.c
device/examples/xa51/Makefile
sim/ucsim/packages.mk [deleted file]
sim/ucsim/xa.src/glob.cc
sim/ucsim/xa.src/glob.h
sim/ucsim/xa.src/inst.cc
sim/ucsim/xa.src/xa.cc
src/xa51/gen.c
src/xa51/main.c

index 7872da4ef8e7ffab112bc1cfab12a6a7c3ec89d1..4b87ea3f109abf8f7bb1419e8cc2a2a37f540fa1 100644 (file)
@@ -84,7 +84,7 @@ line:          linesymbol ':' linenosym {
                }
 
 linenosym:     directive EOL {
-                       if (p3) out(op, $1);
+                       if (p3) out(op, $1);
                        $$ = $1;
                }
              | instruction EOL {
@@ -138,7 +138,7 @@ directive:     '.' ORG expr {
                         $$ = 0;
                 }
             | bitsymbol BITDEF expr {
-                       if (p1) {
+                       if (p1) {
                                 build_sym_list(symbol_name);
                                 mk_bit(symbol_name);
                         }
@@ -184,6 +184,10 @@ directive:     '.' ORG expr {
                        /* ignore global symbol declaration */
                        $$ = 0;
                }
+            | '.' GLOBL bit {
+                       /* ignore bit symbol declaration */
+                       $$ = 0;
+               }
             | '.' DS expr {
                        /* todo: if CSEG, emit some filler bytes */
                        $$ = $3;
index d0a0832d2b3df50cf4928d085fe02e554b593495..91c70944865e0317f3d4396041260291d38d6014 100644 (file)
@@ -232,8 +232,8 @@ void print_symbol_table()
 #else
     if (p->issfr) {
       fprintf (sym_fp, "%-5s", "SFR");
-    } else if (p->isbit) {
-      fprintf (sym_fp, "%-5s", "BIT");
+    } else if (p->isbit && !p->area) {
+      fprintf (sym_fp, "%-5s", "SBIT");
     } else {
       fprintf (sym_fp, "%-5s", areaToString(p->area));
     }
@@ -326,17 +326,19 @@ void out(int *byte_list, int num)
        if (num > 0) fprintf(list_fp, "%06X: ", MEM_POS);
        else fprintf(list_fp, "\t");
 
-       for (i=0; i<num; i++) {
-               hexout(byte_list[i], MEM_POS + i, 0);
-               if (!first && (i % 4) == 0) fprintf(list_fp, "\t");
-               fprintf(list_fp, "%02X", byte_list[i]);
-               if ((i+1) % 4 == 0) {
-                       if (first) fprintf(list_fp, "\t%s\n", last_line_text);
-                       else fprintf(list_fp, "\n");
-                       first = 0;
-               } else {
-                       if (i<num-1) fprintf(list_fp, " ");
-               }
+       if (current_area==AREA_CSEG || current_area==AREA_XINIT) {
+         for (i=0; i<num; i++) {
+           hexout(byte_list[i], MEM_POS + i, 0);
+           if (!first && (i % 4) == 0) fprintf(list_fp, "\t");
+           fprintf(list_fp, "%02X", byte_list[i]);
+           if ((i+1) % 4 == 0) {
+             if (first) fprintf(list_fp, "\t%s\n", last_line_text);
+             else fprintf(list_fp, "\n");
+             first = 0;
+           } else {
+             if (i<num-1) fprintf(list_fp, " ");
+           }
+         }
        }
        if (first) {
                if (num < 3) fprintf(list_fp, "\t");
index 877df36bd9de25c166ba729ab99b313178388155..521cea29b1dff9ee76163278e65832455b8d5021 100644 (file)
@@ -1,16 +1,16 @@
 CC = sdcc
 
-#CFLAGS=
-#MFLAGS=
+CFLAGS= -Wa-s -V
+MFLAGS= -mxa51
 #LFLAGS=
 
 all: hello.hex
 
 
 hello.hex: hello.c
-       $(CC) -mxa51 hello.c
+       $(CC) $(CFLAGS) $(MFLAGS) hello.c
 
 clean:
        rm -f core *~ \#* *.asm *.cdb *.rel *.hex *.ihx *.lst *.map \
-               *.xa *.rst *.sym *.lnk *.lib *.bin *.dump*
+               *.xa *.rst *.sym *.lnk *.lib *.bin *.dump* *.log
 
diff --git a/sim/ucsim/packages.mk b/sim/ucsim/packages.mk
deleted file mode 100644 (file)
index 06285d6..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-enable_51      = yes
-enable_avr     = yes
-enable_z80     = yes
-enable_xa      = yes
-
-ifeq ($(enable_51),yes)
-S51            = s51.src
-else
-S51            =
-endif
-
-ifeq ($(enable_avr),yes)
-SAVR           = avr.src
-else
-SAVR           =
-endif
-
-ifeq ($(enable_z80),yes)
-SZ80           = z80.src
-else
-SZ80           =
-endif
-
-ifeq ($(enable_xa),yes)
-XA             = xa.src
-else
-XA             =
-endif
-
-PKGS           = cmd.src sim.src gui.src $(S51) $(SAVR) $(SZ80) $(XA) doc
index 784f88ec83efb92b18b389a5724a4a7a3160dd84..527e29541a99ee1bfebcd922a627aaddaf177d07 100644 (file)
@@ -78,6 +78,7 @@ char *op_mnemonic_str[] = {
 "CALL",
 "RET",
 "Bcc",
+"BEQ",
 "JB",
 "JNB",
 "CJNE",
@@ -102,7 +103,7 @@ struct xa_dis_entry disass_xa[]= {
  {0xff00,0xffff,' ',1,NOP, NO_OPERANDS     }, //  BRPT  1 1 1 1 1 1 1 1
 
  {0x0840,0xfffc,' ',3,ANL, C_BIT           }, //  ANL C, bit                 0 0 0 0 1 0 0 0  0 1 0 0 0 0 b b
- {0x0850,0xfffc,' ',3,ANL, NOTC_BIT        }, //  ANL C, /bit                0 0 0 0 1 0 0 0  0 1 0 1 0 0 b b
+ {0x0850,0xfffc,' ',3,ANL, C_NOTBIT        }, //  ANL C, /bit                0 0 0 0 1 0 0 0  0 1 0 1 0 0 b b
  {0x0850,0xfffc,' ',3,ASL, REG_REG         }, //  ASL Rd, Rs                 1 1 0 0 S S 0 1  d d d d s s s s
  {0x900c,0xf70f,' ',2,CPL, REG_ALONE       }, //  CPL Rd                     1 0 0 1 S 0 0 0  d d d d 1 0 1 0
  {0xe708,0xff00,' ',2,DIV_w, REG_REG       }, //  DIV.w Rd, Rs               1 1 1 0 0 1 1 1  d d d d s s s s
@@ -342,7 +343,12 @@ struct xa_dis_entry disass_xa[]= {
  {0x9607,0xff8f,' ',4,XOR, DIRECT_DATA8    },  // XOR direct, #data8         1 0 0 1 0 1 1 0  0 b b b 0 1 1 1
  {0x9e07,0xff8f,' ',5,XOR, DIRECT_DATA16   },  // XOR direct, #data16        1 0 0 1 0 1 1 0  0 b b b 0 1 1 1
 
-  { 0x0000,   0x00,   0, 1, BAD_OPCODE, REG_REG}
+ {0xc500,0xff00,' ',3,CALL, REL16          },  // CALL rel16                 1 1 0 0 0 1 0 1  rel16
+ {0xc600,0xfff8,' ',2,CALL, IREG_ALONE     },  // CALL [Rs]                  1 1 0 0 0 1 1 0  0 0 0 0 0 s s s
+
+ {0xf300,0xff00,' ',2,BEQ, REL8            },  // BEQ rel8                   1 1 1 1 0 0 1 1  rel8
+
+ {0x0000,0x0000,  0,1,BAD_OPCODE, REG_REG}
 };
 
 
index 16b9e3f793239e2526141e9dd7c39306ad58b339..b8a4284e6c26b36d206286bb80219b81a2d98212 100644 (file)
@@ -91,6 +91,7 @@ JMP,
 CALL,
 RET,
 Bcc,
+BEQ,
 JB,
 JNB,
 CJNE,
@@ -136,7 +137,7 @@ enum op_operands {
 // odd-ball ones
   NO_OPERANDS,  // for NOP
   C_BIT,
-  NOTC_BIT,
+  C_NOTBIT,
   REG_DATA4,
   IREG_DATA4,
   IREGINC_DATA4,
@@ -145,9 +146,13 @@ enum op_operands {
   DIRECT_DATA4,
 
   REG_ALONE,
+  IREG_ALONE,
   ADDR24,
   REG_REL8,
-  DIRECT_REL8
+  DIRECT_REL8,
+
+  REL8,
+  REL16,
 };
 
 // table of dissassembled instructions
index 984871bb61a2045085c202453fe2e03577daac2e..218ec440eec5399277e130653ca4fba0ee2f7750 100644 (file)
@@ -66,7 +66,9 @@ cl_xa::inst_ADD(uint code)
 {
   int operands = code >> 16;  // kludgy, param info
 
+#undef FUNC1
 #define FUNC1 add1
+#undef FUNC2
 #define FUNC2 add2
 #include "inst_gen.cc"
 
@@ -78,7 +80,9 @@ cl_xa::inst_ADDC(uint code)
 {
   int operands = code >> 16;  // kludgy, param info
 
+#undef FUNC1
 #define FUNC1 addc1
+#undef FUNC2
 #define FUNC2 addc2
 #include "inst_gen.cc"
 
index d9865e58b2dca0cf5b5a4e635e85ad0bd8978b4d..67c3f671aa024dc950ceace31cab4d70d553a53d 100644 (file)
@@ -402,16 +402,16 @@ cl_xa::disass(t_addr addr, char *sep)
       immed_offset += 4;
     break;
     case DIRECT_DATA8 :
-      sprintf(parm_str, "#%04d 0x%02x",
-              ((code & 0x3) << 8) | get_mem(MEM_ROM, addr+immed_offset),
-              get_mem(MEM_ROM, addr+immed_offset+1) );
+      sprintf(parm_str, "0x%03x,#0x%02x",
+              ((code & 0x0070) << 4) | get_mem(MEM_ROM, addr+immed_offset),
+              get_mem(MEM_ROM, addr+immed_offset+1));
       immed_offset += 3;
     break;
     case DIRECT_DATA16 :
-      sprintf(parm_str, "#%04d 0x%04x",
-              ((code & 0x3) << 8) | get_mem(MEM_ROM, addr+immed_offset),
-              (short)((get_mem(MEM_ROM, addr+immed_offset+2)) |
-                     (get_mem(MEM_ROM, addr+immed_offset+1)<<8)) );
+      sprintf(parm_str, "%0x03x,#0x%04x",
+              ((code & 0x0070) << 4) | get_mem(MEM_ROM, addr+immed_offset),
+              get_mem(MEM_ROM, addr+immed_offset+2) +
+             (get_mem(MEM_ROM, addr+immed_offset+1)<<8));
       immed_offset += 3;
     break;
 
@@ -445,6 +445,10 @@ cl_xa::disass(t_addr addr, char *sep)
       sprintf(parm_str, "%s",
               reg_strs[((code >> 4) & 0xf)] );
     break;
+    case IREG_ALONE :
+      sprintf(parm_str, "[%s]",
+              reg_strs[((code >> 4) & 0xf)] );
+    break;
     case ADDR24 :
       strcpy(parm_str, "ADDR24");
     break;
@@ -454,6 +458,19 @@ cl_xa::disass(t_addr addr, char *sep)
     case DIRECT_REL8 :
       strcpy(parm_str, "DIRECT_REL8");
     break;
+
+    case REL8 :
+      //strcpy(parm_str, "REL8");
+      sprintf(parm_str, "0x%04x",
+             (get_mem(MEM_ROM, addr+1)*2+addr+len)&0xfffe);
+    break;
+    case REL16 :
+      //strcpy(parm_str, "REL16");
+      sprintf(parm_str, "0x%04x",
+             (((get_mem(MEM_ROM, addr+1)<<8) |
+             get_mem(MEM_ROM, addr+2))*2+addr+len)&0xfffe);
+    break;
+
     default:
       strcpy(parm_str, "???");
     break;
index 9d525df19f0a9901fa63cb6316d2cf230eed87f0..74f0947db8789e2193907fd299c81439e7fe1dc3 100755 (executable)
@@ -446,7 +446,7 @@ bool aopIsPtr(operand *op) {
   }
 }
       
-char *opRegName(operand *op, int offset, char *opName) {
+char *opRegName(operand *op, int offset, char *opName, bool decorate) {
 
   if (IS_SYMOP(op)) {
     if (OP_SYMBOL(op)->onStack) {
@@ -471,17 +471,21 @@ char *opRegName(operand *op, int offset, char *opName) {
       }
       // fall through
     case V_CHAR:
-      sprintf (opName, "#0x%02x", SPEC_CVAL(OP_VALUE(op)->type).v_int);
+      sprintf (opName, "#%s0x%02x", decorate?"(char)":"", 
+              SPEC_CVAL(OP_VALUE(op)->type).v_int);
       break;
     case V_INT:
       if (SPEC_LONG(OP_VALUE(op)->type)) {
-       sprintf (opName, "#0x%02lx", SPEC_CVAL(OP_VALUE(op)->type).v_long);
+       sprintf (opName, "#%s0x%02lx", decorate?"(long)":"",
+                SPEC_CVAL(OP_VALUE(op)->type).v_long);
       } else {
-       sprintf (opName, "#0x%02x", SPEC_CVAL(OP_VALUE(op)->type).v_int);
+       sprintf (opName, "#%s0x%02x", decorate?"(int)":"",
+                SPEC_CVAL(OP_VALUE(op)->type).v_int);
       }
       break;
     case V_FLOAT:
-      sprintf (opName, "#%f", SPEC_CVAL(OP_VALUE(op)->type).v_float);
+      sprintf (opName, "#%s%f", decorate?"(float)":"",
+              SPEC_CVAL(OP_VALUE(op)->type).v_float);
       break;
     default: 
       bailOut("opRegName: unexpected noun");
@@ -553,7 +557,7 @@ char * printOp (operand *op) {
     strcat (line, "unknown");
     return line;
   } else if (IS_VALOP(op)) {
-    opRegName(op, 0, line);
+    opRegName(op, 0, line, 1);
   } else if (IS_TYPOP(op)) {
     sprintf (line, "[");
     if (isPtr) {
@@ -694,10 +698,43 @@ static void genUminus (iCode * ic) {
 }
 
 /*-----------------------------------------------------------------*/
-/* genIpush - genrate code for pushing this gets a little complex  */
+/* genIpush - generate code for pushing                            */
 /*-----------------------------------------------------------------*/
 static void genIpush (iCode * ic) {
+  operand *left=IC_LEFT(ic);
+
   printIc ("genIpush", ic, 0,1,0);
+  aopOp(left,FALSE,FALSE);
+  if (AOP_TYPE(left)==AOP_LIT) {
+    switch (AOP_SIZE(left)) 
+      {
+      case 1:
+       emitcode ("mov", "r1l,%s", AOP_NAME(left)[0]);
+       emitcode ("push", "r1l");
+       return;
+      case 2:
+       emitcode ("mov", "r1,%s", AOP_NAME(left)[0]);
+       emitcode ("push", "r1");
+       return;
+      case 3:
+       emitcode ("mov", "r1l,%s", AOP_NAME(left)[1]);
+       emitcode ("push", "r1l");
+       emitcode ("mov", "r1,%s", AOP_NAME(left)[0]);
+       emitcode ("push", "r1");
+       return;
+      case 4:
+       emitcode ("mov", "r1,%s", AOP_NAME(left)[1]);
+       emitcode ("push", "r1");
+       emitcode ("mov", "r1,%s", AOP_NAME(left)[0]);
+       emitcode ("push", "r1");
+       return;
+      }
+  } else {
+    if (AOP_SIZE(left)>2) {
+      emitcode ("push", "%s", AOP_NAME(left)[1]);
+    }
+    emitcode ("push", "%s", AOP_NAME(left)[0]);
+  }
 }
 
 /*-----------------------------------------------------------------*/
@@ -711,8 +748,37 @@ static void genIpop (iCode * ic) {
 /* genCall - generates a call statement                            */
 /*-----------------------------------------------------------------*/
 static void genCall (iCode * ic) {
-  emitcode (";", "genCall %s result=%s", OP_SYMBOL(IC_LEFT(ic))->name,
+  operand *result=IC_RESULT(ic);
+
+  emitcode (";", "genCall(%d) %s result=%s", ic->lineno,
+           OP_SYMBOL(IC_LEFT(ic))->name,
            printOp (IC_RESULT(ic)));
+  emitcode ("call", "%s", OP_SYMBOL(IC_LEFT(ic))->rname);
+
+  /* if we need to assign a result value */
+  if (IS_ITEMP (IC_RESULT(ic)) &&
+      OP_SYMBOL (IC_RESULT (ic))->nRegs) {
+    aopOp(result,FALSE,FALSE);
+    switch (AOP_SIZE(result))
+      {
+      case 1:
+       emitcode ("mov", "%s,r0l", AOP_NAME(result)[0]);
+       return;
+      case 2:
+       emitcode ("mov", "%s,r0", AOP_NAME(result)[0]);
+       return;
+      case 3:
+       // generic pointer
+       emitcode ("mov", "%s,r1l", AOP_NAME(result)[1]);
+       emitcode ("mov", "%s,r0", AOP_NAME(result)[0]);
+       return;
+      case 4:
+       emitcode ("mov", "%s,r1", AOP_NAME(result)[1]);
+       emitcode ("mov", "%s,r0", AOP_NAME(result)[0]);
+       return;
+      }
+    bailOut("genCall");
+  }
 }
 
 /*-----------------------------------------------------------------*/
@@ -987,14 +1053,6 @@ static iCode *hasInc (operand *op, iCode *ic, int osize) {
   while (lic) {
     /* if operand of the form op = op + <sizeof *op> */
     if (lic->op == '+') {
-      fprintf (stderr, "isOperandEqual(IC_LEFT(lic),op):%d\n",
-              isOperandEqual(IC_LEFT(lic),op));
-      fprintf (stderr, "isOperandEqual(IC_RESULT(lic),op):%d\n",
-              isOperandEqual(IC_RESULT(lic),op));
-      fprintf (stderr, "isOperandLiteral(IC_RIGHT(lic)):%d\n",
-              isOperandLiteral(IC_RIGHT(lic)));
-      fprintf (stderr, "operandLitValue(IC_RIGHT(lic)) %f %d\n",
-              operandLitValue(IC_RIGHT(lic)), isize);
       if (isOperandEqual(IC_LEFT(lic),op) &&
          //isOperandEqual(IC_RESULT(lic),op) && 
          isOperandLiteral(IC_RIGHT(lic)) &&
index 03aa0cb5af0bf95994efa11f5a984f9c34ae771a..03c72ef30505de72d3f577507518e6c7e9818df7 100755 (executable)
@@ -136,18 +136,24 @@ static void _xa51_genXINIT (FILE * of) {
 static void
 _xa51_genAssemblerPreamble (FILE * of)
 {
+  symbol *mainExists=newSymbol("main", 0);
+  mainExists->block=0;
+
   fprintf (of, "_errno\tsfr\t0x00; to keep the fp-lib's happy for now\n\n");
-  fprintf (of, "\t.area CSEG\t(CODE)\n");
-  fprintf (of, "__interrupt_vect:\n");
-  fprintf (of, "\t.dw\t0x8f00\n");
-  fprintf (of, "\t.dw\t__sdcc_gsinit_startup\n");
-  fprintf (of, "\n");
-  fprintf (of, "__sdcc_gsinit_startup:\n");
-  fprintf (of, "\tmov\tr7,#0x%04x\n", options.stack_loc);
-  fprintf (of, "\tcall\t_external_startup\n");
-  _xa51_genXINIT(of);
-  fprintf (of, "\tcall\t_main\n");
-  fprintf (of, "\treset\t;main should not return\n");
+
+  if ((mainExists=findSymWithLevel(SymbolTab, mainExists))) {
+    fprintf (of, "\t.area CSEG\t(CODE)\n");
+    fprintf (of, "__interrupt_vect:\n");
+    fprintf (of, "\t.dw\t0x8f00\n");
+    fprintf (of, "\t.dw\t__sdcc_gsinit_startup\n");
+    fprintf (of, "\n");
+    fprintf (of, "__sdcc_gsinit_startup:\n");
+    fprintf (of, "\tmov\tr7,#0x%04x\n", options.stack_loc);
+    fprintf (of, "\tcall\t_external_startup\n");
+    _xa51_genXINIT(of);
+    fprintf (of, "\tcall\t_main\n");
+    fprintf (of, "\treset\t;main should not return\n");
+  }
 }
 
 /* dummy linker for now */