last ci before completely rewrite ralloc.c
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 18 Feb 2002 14:21:12 +0000 (14:21 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 18 Feb 2002 14:21:12 +0000 (14:21 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1936 4a8a32a2-be11-0410-ad9d-d568d2c75423

as/xa51/xa_link.c
as/xa51/xa_main.c
as/xa51/xa_rasm.y
device/examples/xa51/hello.c
src/xa51/gen.c
src/xa51/main.c

index f6d708eb0361448266cb3fadd7071fff97b9794d..f9a81c75625b672db32ec99eff87e7d3fcfb75b3 100644 (file)
@@ -14,7 +14,9 @@
 
 /* This is a cheap hack. The xa51 has a couple of ways to scramble
    relocation info into it's opcode that the standard linker can't
-   handle. No hash or qsort yet.
+   handle, not to mention word allignment. 
+
+   No hash or qsort yet.
 
    The relocatable format looks like the known one, BUT ISN'T.
 
@@ -50,13 +52,17 @@ enum {
   GSINIT=1,
   CSEG,
   XINIT,
-  GSFINAL, // here goes the final output
+
+  // here goes the final output and should be used by the assembler
+  GSFINAL,
 
   // these are only for storage
   BSEG,
   DSEG,
   XSEG,
   XISEG,
+
+  // that's all
   MAX_SEGMENTS
 };
 
@@ -455,7 +461,6 @@ void readModule(char *module, int isLib) {
       }
     currentLine++;
   }
-  // that's all for now, thanks for watching */
   fclose (relModule);
 }
 
@@ -595,8 +600,9 @@ int relocate() {
          int rel8 = symbol->address-(reference->pc & ~1);
          if (rel8<-256 || rel8>256) {
            fprintf (stderr,
-                    "rel8 target for %s is out of range in module %s\n",
-                    reference->name, reference->module->name);
+                    "rel8 target for %s is out of range in module %s:%d\n",
+                    reference->name, reference->module->name, 
+                    reference->lineno);
            fatalErrors++;
          }
          gsfinalImage[reference->address]=rel8/2;
@@ -606,8 +612,9 @@ int relocate() {
          int rel16 = symbol->address-(reference->pc & ~1);
          if (rel16<-65536 || rel16>65534) {
            fprintf (stderr, 
-                    "rel16 target for %s is out of range in module %s\n",
-                    reference->name, reference->module->name);
+                    "rel16 target for %s is out of range in module %s:%d\n",
+                    reference->name, reference->module->name,
+                    reference->lineno);
            fatalErrors++;
          }
          gsfinalImage[reference->address]=(rel16/2)>>8;
@@ -667,7 +674,6 @@ int scanLibraries(int unresolved) {
   for (nlp=0; nlp<nlibPaths; nlp++) {
     for (nlf=0; nlf<nlibFiles; nlf++) {
       sprintf (libFiles, "%s/%s.lib", libraryPaths[nlp], libraryFiles[nlf]);
-      //fprintf (stderr, "  %s\n", libFiles);
       if ((lfs=fopen(libFiles,"r"))==NULL) {
        continue;
       }
@@ -675,15 +681,13 @@ int scanLibraries(int unresolved) {
        // remove trailing \n
        line[strlen(line)-1]='\0';
        sprintf (libFile, "%s/%s", libraryPaths[nlp], line);
-       //fprintf (stderr, "    %s\n", libFile);
-       if ((lf=fopen(libFile,"r"))==0) {
+       if ((lf=fopen(libFile,"r"))==NULL) {
          continue;
        }
        while (fgets(line, 132, lf)) {
          int dummy; // we need this to get the right count of the next sscanf
          if (sscanf(line, "S %[^ ] Def%04x", symName, &dummy)==2) {
            if (isUnresolved(symName, 1)) {
-             //fprintf (stderr, "%s:%s\n", libFile, symName);
              readModule(libFile,1);
              if (resolved++ == unresolved) {
                // we are done
@@ -792,7 +796,6 @@ int main(int argc, char **argv) {
   addToDefs("s_XISEG", 0, 0);
   addToDefs("l_XISEG", segments[XISEG]._size, 1);
 
-#if 1
   // mark the resolved references
   resolve();
 
@@ -816,7 +819,6 @@ int main(int argc, char **argv) {
   if (unresolved==0) {
     writeModule(outFileName);
   }
-#endif
 
   // the modules
   fprintf (mapOut, "Modules:\n");
index 63152a6216633444a29a76fac3a8e1f8527ca352..345ca7e4ec44498a524c0ff0e3430715f88149c7 100644 (file)
@@ -286,15 +286,15 @@ void print_symbol_table()
     fprintf(sym_fp, " Line %d\n", p->line_def);
 #else
     if (p->issfr) {
-      fprintf (sym_fp, "%-5s", "SFR");
+      fprintf (sym_fp, "%-7s", "SFR");
     } else if (p->isbit && !p->area) {
-      fprintf (sym_fp, "%-5s", "SBIT");
+      fprintf (sym_fp, "%-7s", "SBIT");
     } else if (p->mode=='=') {
-      fprintf (sym_fp,"ABS");
+      fprintf (sym_fp,"ABS    ");
     } else if (!p->isdef) {
-      fprintf (sym_fp,"EXTRN");
+      fprintf (sym_fp,"EXTRN  ");
     } else {
-      fprintf (sym_fp, "%-5s", areaToString(p->area));
+      fprintf (sym_fp, "%-7s", areaToString(p->area));
     }
     fprintf (sym_fp, " 0x%04x (%5d)", p->value, p->value);
     fprintf (sym_fp, " %s", p->isdef ? "D" : "-");
@@ -384,6 +384,17 @@ struct symbol *is_ref(char *thename) {
   return NULL;
 }
 
+int is_abs(char *thename) {
+  struct symbol *p;
+  p = sym_list;
+  while (p != NULL) {
+    if (strcasecmp(thename, p->name)==0) 
+      return p->mode == '=';
+    p = p->next;
+  }
+  return 0;
+}
+
 /* this routine is used to dump a group of bytes to the output */
 /* it is responsible for generating the list file and sending */
 /* the bytes one at a time to the object code generator */
index c99078e2c8f74b00d4dff47031b65333803cac31..5db815552d37a9f1d65034bca43aeb941e173e6c 100755 (executable)
@@ -167,7 +167,9 @@ line:          linesymbol ':' linenosym {
                        MEM_POS += $3;
                }
              | linenosym {
-                       MEM_POS += $1;
+                        if (!is_abs(symbol_name)) {
+                         MEM_POS += $1;
+                       }
                }
 
 linenosym:     directive EOL {
index 224327fccc8b6c264244ccd10cfb26a598719762..db0f05b7fec5f5ece1cd6f09ec6fb4ed506ea61d 100755 (executable)
@@ -9,8 +9,8 @@ extern bit be;
 extern code ce;
 extern data de;
 extern xdata xe;
-xdata at 0x1234 abs;
 extern xdata xee;
+xdata at 0x1234 abs;
 
 void main(void) {
   puts ("Hello world.\n\r");
index 2ce675329ec7837f960900daa215d9692ad2c4c1..25dcc5dc550166b7925540f42bca22a943695e41 100755 (executable)
@@ -205,23 +205,23 @@ static asmop *aopForSym(symbol *sym,
       switch (size) 
        {
        case 1:
-         emitcode ("mov.b", "r0l,[%s]", getStackOffset(sym->stack));
+         emitcode ("mov.b", "r0l,[%s] ;aopForSym:stack:1", getStackOffset(sym->stack));
          sprintf (aop->name[0], "r0l");
          return aop;
        case 2:
-         emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack));
+         emitcode ("mov.w", "r0,[%s] ;aopForSym:stack:2", getStackOffset(sym->stack));
          sprintf (aop->name[0], "r0");
          return aop;
        case 3:
-         emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack));
+         emitcode ("mov.w", "r0,[%s] ;aopForSym:stack:3", getStackOffset(sym->stack));
          sprintf (aop->name[0], "r0");
-         emitcode ("mov.b", "r1l,[%s]", getStackOffset(sym->stack+2));
+         emitcode ("mov.b", "r1l,[%s] ;aopForSym:stack:3", getStackOffset(sym->stack+2));
          sprintf (aop->name[1], "r1l");
          return aop;
        case 4:
-         emitcode ("mov.w", "r0,[%s]", getStackOffset(sym->stack));
+         emitcode ("mov.w", "r0,[%s] ;aopForSym:stack:4", getStackOffset(sym->stack));
          sprintf (aop->name[0], "r0");
-         emitcode ("mov.w", "r1,[%s]", getStackOffset(sym->stack+2));
+         emitcode ("mov.w", "r1,[%s] ;aopForSym:stack:4", getStackOffset(sym->stack+2));
          sprintf (aop->name[1], "r1");
          return aop;
        }
@@ -949,7 +949,7 @@ static void genPlus (iCode * ic) {
   aopOp(left, !aopIsPtr(result), !aopIsDir(result));
   aopOp(right, !aopIsPtr(result), !aopIsDir(result));
 
-  // special case for * = * + char, needs a closer look
+  // special case for "* = * + char", needs a closer look
   // heck, this shouldn't have come here but bug-223113 does
   if (size==3 && AOP_SIZE(right)==1) {
     emitcode ("mov", "r1l,%s", AOP_NAME(right)[0]);
@@ -960,7 +960,7 @@ static void genPlus (iCode * ic) {
     return;
   }
 
-  // special case for (whatever)* = (whatever)** + char, needs a closer look
+  // special case for "xdata * = xdata * + char", needs a closer look
   // heck, this shouldn't have come here but bug-441448 does
   if (size==2 && AOP_SIZE(right)==1) {
     emitcode ("mov", "r1l,%s", AOP_NAME(right)[0]);
@@ -996,9 +996,62 @@ static void genPlus (iCode * ic) {
 /* genMinus - generates code for subtraction                       */
 /*-----------------------------------------------------------------*/
 static void genMinus (iCode * ic) {
+  operand *result=IC_RESULT(ic), *left=IC_LEFT(ic), *right=IC_RIGHT(ic);
+  int size;
+  char *instr;
+
   printIc (0, "genMinus", ic, 1,1,1);
-}
 
+  size=aopOp(result, TRUE, TRUE);
+
+  /* if left is a literal, then exchange them */
+  if (IS_LITERAL(operandType(left))) {
+    operand *tmp = right;
+    right = left;
+    left = tmp;
+  }
+    
+  if (aopIsBit(result)) {
+    if (IS_LITERAL(operandType(right))) {
+      if (operandLitValue(right)) {
+       emitcode ("clr", AOP_NAME(result)[0]);
+       return;
+      }
+      aopOp(left, TRUE, TRUE);
+      emitcode ("mov", "%s,%s", AOP_NAME(result)[0], toBoolean(left));
+      return;
+    }
+    bailOut("genPlus: unfinished genPlus bit");
+  }
+  
+  if (isOperandEqual(result,left)) {
+    left->aop=result->aop;
+  } else {
+    aopOp(left, !aopIsPtr(result), !aopIsDir(result));
+  }
+  aopOp(right, !aopIsPtr(result), !aopIsDir(result));
+
+  if (size>1) {
+    instr="sub.w";
+  } else {
+    instr="sub.b";
+  }
+  if (!aopEqual(result->aop, left->aop, 0)) {
+    emitcode ("mov", "%s,%s", AOP_NAME(result)[0], AOP_NAME(left)[0]);
+  }
+  emitcode (instr, "%s,%s", AOP_NAME(result)[0], AOP_NAME(right)[0]);
+  if (size>2) {
+    if (!aopEqual(result->aop, left->aop, 1)) {
+      emitcode ("mov", "%s,%s", AOP_NAME(result)[1], AOP_NAME(left)[1]);
+    }
+    if (size==3) {
+      // generic pointer
+    } else {
+      emitcode ("subb.w", "%s,%s", AOP_NAME(result)[1], AOP_NAME(right)[1]);
+    }
+  }
+  return;
+}
 
 /*-----------------------------------------------------------------*/
 /* genMult - generates code for multiplication                     */
index 8875d3e7b964b4c88d0985e0afca507e54c1dda1..eb2c944f840bafa853e95454d38ec796d67b461d 100755 (executable)
@@ -149,7 +149,7 @@ _xa51_genAssemblerPreamble (FILE * of)
     fprintf (of, "\t.dw\t__sdcc_gsinit_startup\n");
     fprintf (of, "\n");
     fprintf (of, "__sdcc_gsinit_startup:\n");
-    //fprintf (of, ";\tmov.b\t_SCR,#0x01\t; page zero mode\n");
+    fprintf (of, ";\tmov.b\t_SCR,#0x01\t; page zero mode\n");
     fprintf (of, "\t.db 0x96,0x48,0x40,0x01\n");
     fprintf (of, "\tmov\tr7,#0x%04x\n", options.stack_loc);
     fprintf (of, "\tcall\t_external_startup\n");