* src/pic/device.c (pic14_assignConfigWordValue): remember assignments to
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 24 Apr 2006 20:22:31 +0000 (20:22 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 24 Apr 2006 20:22:31 +0000 (20:22 +0000)
    config word, "pic14_"-prefixed some extern functions
  (pic14_emitConfigWord): emit __config directive(s) if assignment to
    config word has been found
* src/pic/device.h: added prototypes
* src/pic/pcode.c: added "pic14_"-prefix where needed
* src/pic/ralloc.c (IS_CONFIG_ADDRESS,pic14_assignRegisters): cosmetic fixup
* src/pic/glue.c (pic14_constructAbsMap): handle assignments to config words,
  (pic14emitRegularMap): ignore config words,
  (pic14createInterruptVect): moved generating __config directives away
  (picglue): have __config directives emitted

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4119 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/pic/device.c
src/pic/device.h
src/pic/glue.c
src/pic/pcode.c
src/pic/ralloc.c

index bd32bbc3bb8336290460c22433d225fbb5c5ab5f..3284909e14941f0046dcec5d7f232985dfe69a24 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2006-04-24 Raphael Neider <rneider AT web.de>
+
+       * src/pic/device.c (pic14_assignConfigWordValue): remember assignments to
+           config word, "pic14_"-prefixed some extern functions
+         (pic14_emitConfigWord): emit __config directive(s) if assignment to
+           config word has been found
+       * src/pic/device.h: added prototypes
+       * src/pic/pcode.c: added "pic14_"-prefix where needed
+       * src/pic/ralloc.c (IS_CONFIG_ADDRESS,pic14_assignRegisters): cosmetic fixup
+       * src/pic/glue.c (pic14_constructAbsMap): handle assignments to config words,
+         (pic14emitRegularMap): ignore config words,
+         (pic14createInterruptVect): moved generating __config directives away
+         (picglue): have __config directives emitted
+
 2006-04-24 Borut Razem <borut.razem AT siol.net>
 
        * doc/Makefile: sync with nightly build makefile
index ce4746aebdf440fd449ca050dce1348ad7b23f8d..6abdcbd54fa35f3bbca67c72c0f6ac12297c68ae 100644 (file)
@@ -932,17 +932,19 @@ void assignRelocatableRegisters(set *regset, int used)
        
 }
 
+/* Keep track of whether we found an assignment to the __config words. */
+static int pic14_hasSetConfigWord = 0;
 
 /*-----------------------------------------------------------------*
-*  void assignConfigWordValue(int address, int value)
-*
-* Most midrange PICs have one config word at address 0x2007.
-* Newer PIC14s have a second config word at address 0x2008.
-* This routine will assign values to those addresses.
-*
-*-----------------------------------------------------------------*/
+ *  void assignConfigWordValue(int address, int value)
+ *
+ * Most midrange PICs have one config word at address 0x2007.
+ * Newer PIC14s have a second config word at address 0x2008.
+ * This routine will assign values to those addresses.
+ *
+ *-----------------------------------------------------------------*/
 
-void assignConfigWordValue(int address, int value)
+void pic14_assignConfigWordValue(int address, int value)
 {
        if (CONFIG_WORD_ADDRESS == address)
                config_word = value;
@@ -951,16 +953,44 @@ void assignConfigWordValue(int address, int value)
                config2_word = value;
        
        //fprintf(stderr,"setting config word 0x%x to 0x%x\n", address, value);
-       
+       pic14_hasSetConfigWord = 1;
 }
+
 /*-----------------------------------------------------------------*
-* int getConfigWord(int address)
-*
-* Get the current value of a config word.
-*
-*-----------------------------------------------------------------*/
+ * int pic14_emitConfigWord (FILE * vFile)
+ * 
+ * Emit the __config directives iff we found a previous assignment
+ * to the config word.
+ *-----------------------------------------------------------------*/
+extern char *iComments2;
+int pic14_emitConfigWord (FILE * vFile)
+{
+  if (pic14_hasSetConfigWord)
+  {
+    fprintf (vFile, "%s", iComments2);
+    fprintf (vFile, "; config word \n");
+    fprintf (vFile, "%s", iComments2);
+    if (pic14_getHasSecondConfigReg())
+    {
+      fprintf (vFile, "\t__config _CONFIG1, 0x%x\n", pic14_getConfigWord(0x2007));
+      fprintf (vFile, "\t__config _CONFIG2, 0x%x\n", pic14_getConfigWord(0x2008));
+    }
+    else
+      fprintf (vFile, "\t__config 0x%x\n", pic14_getConfigWord(0x2007));
+
+    return 1;
+  }
+  return 0;
+}
+
+/*-----------------------------------------------------------------*
+ * int pic14_getConfigWord(int address)
+ *
+ * Get the current value of a config word.
+ *
+ *-----------------------------------------------------------------*/
 
-int getConfigWord(int address)
+int pic14_getConfigWord(int address)
 {
        switch (address)
        {
@@ -978,7 +1008,7 @@ int getConfigWord(int address)
 /*-----------------------------------------------------------------*
 *  
 *-----------------------------------------------------------------*/
-unsigned getMaxRam(void)
+unsigned pic14_getMaxRam(void)
 {
        return pic->defMaxRAMaddrs;
 }
@@ -988,7 +1018,7 @@ unsigned getMaxRam(void)
 *  int getHasSecondConfigReg(void) - check if the device has a 
 *  second config register, rather than just one.
 *-----------------------------------------------------------------*/
-int getHasSecondConfigReg(void)
+int pic14_getHasSecondConfigReg(void)
 {
        if(!pic)
                return 0;
@@ -1018,8 +1048,8 @@ int pic14_getSharebankAddress(void)
        int sharebankAddress = 0x7f;
        /* If total RAM is less than 0x7f as with 16f84 then reduce
         * sharebankAddress to fit */
-       if ((unsigned)sharebankAddress > getMaxRam())
-               sharebankAddress = (int)getMaxRam();
+       if ((unsigned)sharebankAddress > pic14_getMaxRam())
+               sharebankAddress = (int)pic14_getMaxRam();
        return sharebankAddress;
 }
 
index 5fb8a44048a1658b98135de09edf77375c4c450c..b80af23667c554bdbfeadbffbcd1ba6e59ce46f8 100644 (file)
@@ -107,8 +107,12 @@ int REGallBanks(regs *reg);
 void addMemRange(memRange *r, int type);
 void setMaxRAM(int size);
 void setDefMaxRam(void);
-unsigned getMaxRam(void);
-int getHasSecondConfigReg(void);
+
+void pic14_assignConfigWordValue(int address, int value);
+int pic14_emitConfigWord (FILE * vFile);
+int pic14_getConfigWord(int address);
+unsigned pic14_getMaxRam(void);
+int pic14_getHasSecondConfigReg(void);
 int pic14_getSharebankSize(void);
 int pic14_getSharebankAddress(void);
 
index 6b6af973999c8848517a68b6d7cde1d4e8bd43d6..f1809b7fddb620e1d0202aef2d91a1ed96543d49 100644 (file)
@@ -29,6 +29,7 @@
 #include "newalloc.h"
 #include "gen.h"
 #include "main.h"
+#include "device.h"
 
 
 #ifdef WORDS_BIGENDIAN
@@ -224,6 +225,7 @@ emitSymbolToFile (FILE *of, const char *name, const char *section_type, int size
 }
 
 #define IS_DEFINED_HERE(sym)   (!IS_EXTERN(sym->etype))
+extern int IS_CONFIG_ADDRESS( int addr );
 static void
 pic14_constructAbsMap (FILE *ofile)
 {
@@ -243,6 +245,20 @@ pic14_constructAbsMap (FILE *ofile)
       if (IS_DEFINED_HERE(sym) && SPEC_ABSA(sym->etype))
       {
        addr = SPEC_ADDR(sym->etype);
+
+       /* handle CONFIG words here */
+       if (IS_CONFIG_ADDRESS( addr ))
+       {
+         //fprintf( stderr, "%s: assignment to CONFIG@0x%x found\n", __FUNCTION__, addr );
+         //fprintf( stderr, "ival: %p (0x%x)\n", sym->ival, (int)list2int( sym->ival ) );
+         if (sym->ival) {
+           pic14_assignConfigWordValue( addr, (int)list2int( sym->ival ) );
+         } else {
+           fprintf( stderr, "ERROR: Symbol %s, which is covering a __CONFIG word must be initialized!\n", sym->name );
+         }
+         continue;
+       }
+       
        if (max == -1 || addr > max) max = addr;
        if (min == -1 || addr < min) min = addr;
        //fprintf (stderr, "%s: sym %s @ 0x%x\n", __FUNCTION__, sym->name, addr);
@@ -340,6 +356,11 @@ pic14emitRegularMap (memmap * map, bool addPublics, bool arFlag)
        sym = setNextItem (map->syms)) {
                
                //printf("%s\n",sym->name);
+
+               /* ignore if config word */
+               if (SPEC_ABSA(sym->etype)
+                   && IS_CONFIG_ADDRESS(SPEC_ADDR(sym->etype)))
+                       continue;
                
                /* if extern then add it into the extern list */
                if (IS_EXTERN (sym->etype)) {
@@ -444,7 +465,7 @@ pic14emitRegularMap (memmap * map, bool addPublics, bool arFlag)
                it is a global variable */
                if (sym->ival && sym->level == 0) {
                        ast *ival = NULL;
-                       
+               
                        if (IS_AGGREGATE (sym->type))
                                ival = initAggregates (sym, sym->ival, NULL);
                        else
@@ -982,17 +1003,6 @@ pic14createInterruptVect (FILE * vFile)
                return;
        }
        
-       fprintf (vFile, "%s", iComments2);
-       fprintf (vFile, "; config word \n");
-       fprintf (vFile, "%s", iComments2);
-       if (getHasSecondConfigReg())
-       {
-               fprintf (vFile, "\t__config _CONFIG1, 0x%x\n", getConfigWord(0x2007));
-               fprintf (vFile, "\t__config _CONFIG2, 0x%x\n", getConfigWord(0x2008));
-       }
-       else
-               fprintf (vFile, "\t__config 0x%x\n", getConfigWord(0x2007));
-       
        fprintf (vFile, "%s", iComments2);
        fprintf (vFile, "; reset vector \n");
        fprintf (vFile, "%s", iComments2);
@@ -1289,6 +1299,9 @@ picglue ()
        {
                port->genAssemblerPreamble(asmFile);
        }
+
+       /* Emit the __config directive */
+       pic14_emitConfigWord (asmFile);
        
        /* print the extern variables in this module */
        pic14printExterns (asmFile);
index 1540ec025695cb368e210ad1a62efd9db9b950d7..1752e9810651d54d5542932233291422a23bf565 100644 (file)
@@ -4617,7 +4617,7 @@ static int BankSelect(pCodeInstruction *pci, int cur_bank, regs *reg)
                insertBankSel(pci, reg->name); // Let linker choose the bank selection
        } else if ((cur_bank == -1)||(cur_bank == 'L')||(cur_bank == 'E')) { // Current bank unknown and new register bank is known then can set bank bits
                insertBankSwitch(pci, bank&1, PIC_RP0_BIT);
-               if (getMaxRam()&0x100)
+               if (pic14_getMaxRam()&0x100)
                        insertBankSwitch(pci, bank&2, PIC_RP1_BIT);
        } else { // Current bank and new register banks known - can set bank bits
                switch((cur_bank^bank) & 3) {
@@ -4631,7 +4631,7 @@ static int BankSelect(pCodeInstruction *pci, int cur_bank, regs *reg)
                        break;
                case 3:
                        insertBankSwitch(pci, bank&1, PIC_RP0_BIT);
-                       if (getMaxRam()&0x100)
+                       if (pic14_getMaxRam()&0x100)
                                insertBankSwitch(pci, bank&2, PIC_RP1_BIT);
                        break;
                }
index de2463e89e34e773eca58fd808afb142373ccc86..3281321b7524b239859904ea79bd362d1a6cb859 100644 (file)
@@ -52,7 +52,7 @@
 /*-----------------------------------------------------------------*/
 
 extern void genpic14Code (iCode *);
-extern void assignConfigWordValue(int address, int value);
+extern void pic14_assignConfigWordValue(int address, int value);
 
 /* Global data */
 static struct
@@ -603,7 +603,7 @@ dirregWithName (char *name)
 int IS_CONFIG_ADDRESS(int address)
 {
        
-       return address == 0x2007 || address == 0x2008;
+       return ((address == 0x2007) || (address == 0x2008));
 }
 
 /*-----------------------------------------------------------------*/
@@ -2961,7 +2961,7 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
                        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))),
+                               pic14_assignConfigWordValue(  SPEC_ADDR ( OP_SYM_ETYPE(IC_RESULT(ic))),
                                        (int) floatFromVal (IC_RIGHT(ic)->operand.valOperand));
                        }
                        
@@ -3754,7 +3754,7 @@ packRegisters (eBBlock * ebp)
                /* TrueSym := iTempNN:1             */
                for (ic = ebp->sch; ic; ic = ic->next)
                {
-                       
+
                        /* find assignment of the form TrueSym := iTempNN:1 */
                        if (ic->op == '=' && !POINTER_SET (ic))
                                change += packRegsForAssign (ic, ebp);
@@ -4134,8 +4134,8 @@ pic14_assignRegisters (ebbIndex * ebbi)
        iCode *ic;
        int i;
        
-       debugLog ("<><><><><><><><><><><><><><><><><>\nstarting\t%s:%s", __FILE__, __FUNCTION__);
-       debugLog ("\nebbs before optimizing:\n");
+       debugLog ("<><><><><><><><><><><><><><><><><>\nstarting\t%s:%s\n", __FILE__, __FUNCTION__);
+       debugLog ("ebbs before optimizing:\n");
        dumpEbbsToDebug (ebbs, count);
        
        setToNull ((void *) &_G.funcrUsed);