Fixed several tiny bugs.
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 10 May 2002 21:53:41 +0000 (21:53 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 10 May 2002 21:53:41 +0000 (21:53 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2014 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/device.c
src/pic/device.h
src/pic/main.c
src/pic/ralloc.c

index db4e2b3967662fd3febad90683557db8f05e42c1..4e92fed441fcfbcbd18e69367a11657880b1752e 100644 (file)
@@ -152,6 +152,12 @@ static int num_of_supported_PICS = sizeof(Pics)/sizeof(PIC_device);
 static PIC_device *pic=NULL;
 
 AssignedMemory *finalMapping=NULL;
+
+#define CONFIG_WORD_ADDRESS 0x2007
+#define DEFAULT_CONFIG_WORD 0x3fff
+
+static unsigned int config_word = DEFAULT_CONFIG_WORD;
+
 /*-----------------------------------------------------------------*
  *
  * void addMem(memRange *ranges,int type)
@@ -264,6 +270,7 @@ void dump_cblock(FILE *of)
 {
   int start=-1;
   int addr=0;
+  int bank_base;
 
   //dump_map();   /* display the register map */
 
@@ -276,9 +283,17 @@ void dump_cblock(FILE *of)
     } else {
       if(start>=0) {
 
+       /* clear the lower 7-bits of the start address of the first
+        * variable declared in this bank. The upper bits for the mid
+        * range pics are the bank select bits.
+        */
+
+       bank_base = start & 0xfff8;
+
        /* The bank number printed in the cblock comment tacitly
         * assumes that the first register in the contiguous group
         * of registers represents the bank for the whole group */
+
        fprintf(of,"  cblock  0X%04X\t; Bank %d\n",start,finalMapping[start].bank);
 
        for( ; start < addr; start++) {
@@ -288,7 +303,7 @@ void dump_cblock(FILE *of)
            /* If this register is aliased in multiple banks, then
             * mangle the variable name with the alias address: */
            if(finalMapping[start].alias & start)
-             fprintf(of,"_%x",finalMapping[start].alias);
+             fprintf(of,"_%x",bank_base);
 
            if(finalMapping[start].instance)
              fprintf(of,"_%d",finalMapping[start].instance);
@@ -567,3 +582,36 @@ void assignRelocatableRegisters(set *regset, int used)
 
 }
 
+
+/*-----------------------------------------------------------------*
+ *  void assignConfigWordValue(int address, int value)
+ *
+ * All midrange PICs have one config word at address 0x2007.
+ * This routine will assign a value to that address.
+ *
+ *-----------------------------------------------------------------*/
+
+void assignConfigWordValue(int address, int value)
+{
+  if(CONFIG_WORD_ADDRESS == address)
+    config_word = value;
+
+  fprintf(stderr,"setting config word to 0x%x\n",value);
+
+}
+/*-----------------------------------------------------------------*
+ * int getConfigWord(int address)
+ *
+ * Get the current value of the config word.
+ *
+ *-----------------------------------------------------------------*/
+
+int getConfigWord(int address)
+{
+  if(CONFIG_WORD_ADDRESS == address)
+    return config_word;
+
+  else
+    return 0;
+
+}
index c4ff2f333beb77ecd4b71cf9945e21f5d0424265..2d2a06323f4c4d1cde7bddf70d0b5c5511acf762 100644 (file)
@@ -89,4 +89,9 @@ typedef struct PIC_device {
 #define REG_isALIASED(r)   (finalMapping[(r)->address].alias != 0)
 #define REG_isVALID(r)     (finalMapping[(r)->address].isValid)
 
+
+/****************************************/
+void assignConfigWordValue(int address, int value);
+int getConfigWord(int address);
+
 #endif  /* __DEVICE_H__ */
index cec44669a969b8613c790784c16c7fccf96c9c51..d7771302d949bd267229986bb8f0e1f0c847f509 100644 (file)
@@ -7,6 +7,7 @@
 #include "common.h"
 #include "main.h"
 #include "ralloc.h"
+#include "device.h"
 //#include "gen.h"
 
 
@@ -173,7 +174,7 @@ _pic14_genAssemblerPreamble (FILE * of)
   }
 
   fprintf (of, "\tlist\tp=%s\n",&name[1]);
-  fprintf (of, "\t__config _wdt_off\n");
+  fprintf (of, "\t__CONFIG 0x%x\n",getConfigWord(0x2007));
   fprintf (of, "\ninclude \"%s.inc\"\n",name);
 }
 
index 06e03638faf5d8c8c746ac7fdec68f0a1d17cac0..c0554c039cc9a00759d4df1dc76d2c7e9123d918 100644 (file)
@@ -575,6 +575,12 @@ dirregWithName (char *name)
   return NULL; // name wasn't found in the hash table
 }
 
+int IS_CONFIG_ADDRESS(int address)
+{
+
+  return address == 0x2007;
+}
+
 /*-----------------------------------------------------------------*/
 /* allocDirReg - allocates register of given type                  */
 /*-----------------------------------------------------------------*/
@@ -626,25 +632,35 @@ allocDirReg (operand *op )
   reg = dirregWithName(name);
 
   if(!reg) {
+    int address = 0;
+
+    /* if this is at an absolute address, then get the address. */
+    if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
+      address = SPEC_ADDR ( OP_SYM_ETYPE(op));
+    }
 
     /* Register wasn't found in hash, so let's create
      * a new one and put it in the hash table AND in the 
      * dynDirectRegNames set */
+    if(!IS_CONFIG_ADDRESS(address)) {
+      reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,getSize (OP_SYMBOL (op)->type),0 );
+      debugLog ("  -- added %s to hash, size = %d\n", name,reg->size);
+
+      if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
+       reg->isFixed = 1;
+       reg->address = SPEC_ADDR ( OP_SYM_ETYPE(op));
+       debugLog ("  -- and it is at a fixed address 0x%02x\n",reg->address);
+      }
 
-    reg = newReg(REG_GPR, PO_DIR, rDirectIdx++, name,getSize (OP_SYMBOL (op)->type),0 );
-    debugLog ("  -- added %s to hash, size = %d\n", name,reg->size);
+      hTabAddItem(&dynDirectRegNames, regname2key(name), reg);
+      if (IS_BITVAR (OP_SYM_ETYPE(op)))
+       addSet(&dynDirectBitRegs, reg);
+      else
+       addSet(&dynDirectRegs, reg);
+    } else {
+      debugLog ("  -- %s is declared at address 0x2007\n",name);
 
-    if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) {
-      reg->isFixed = 1;
-      reg->address = SPEC_ADDR ( OP_SYM_ETYPE(op));
-      debugLog ("  -- and it is at a fixed address 0x%02x\n",reg->address);
     }
-
-    hTabAddItem(&dynDirectRegNames, regname2key(name), reg);
-    if (IS_BITVAR (OP_SYM_ETYPE(op)))
-      addSet(&dynDirectBitRegs, reg);
-    else
-      addSet(&dynDirectRegs, reg);
   }
 
   return reg;
@@ -2587,6 +2603,28 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
   debugAopGet ("  left:", IC_LEFT (ic));
   debugAopGet ("  right:", IC_RIGHT (ic));
 
+  /* if this is at an absolute address, then get the address. */
+  if (SPEC_ABSA ( OP_SYM_ETYPE(IC_RESULT(ic))) ) {
+    if(IS_CONFIG_ADDRESS( SPEC_ADDR ( OP_SYM_ETYPE(IC_RESULT(ic))))) {
+      debugLog ("  %d - found config word declaration\n", __LINE__);
+      if(IS_VALOP(IC_RIGHT(ic))) {
+       debugLog ("  setting config word to %x\n", 
+                 (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
+       assignConfigWordValue(  SPEC_ADDR ( OP_SYM_ETYPE(IC_RESULT(ic))),
+                               (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
+      }
+
+      /* remove the assignment from the iCode chain. */
+
+      remiCodeFromeBBlock (ebp, ic);
+      bitVectUnSetBit(OP_SYMBOL(IC_RESULT(ic))->defs,ic->key);
+      hTabDeleteItem (&iCodehTab, ic->key, ic, DELETE_ITEM, NULL);
+
+      return 1;
+
+    }
+  }
+
   if (!IS_ITEMP (IC_RESULT (ic))) {
     allocDirReg(IC_RESULT (ic));
     debugLog ("  %d - result is not temp\n", __LINE__);