+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
}
+/* 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;
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)
{
/*-----------------------------------------------------------------*
*
*-----------------------------------------------------------------*/
-unsigned getMaxRam(void)
+unsigned pic14_getMaxRam(void)
{
return pic->defMaxRAMaddrs;
}
* 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;
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;
}
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);
#include "newalloc.h"
#include "gen.h"
#include "main.h"
+#include "device.h"
#ifdef WORDS_BIGENDIAN
}
#define IS_DEFINED_HERE(sym) (!IS_EXTERN(sym->etype))
+extern int IS_CONFIG_ADDRESS( int addr );
static void
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);
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)) {
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
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);
{
port->genAssemblerPreamble(asmFile);
}
+
+ /* Emit the __config directive */
+ pic14_emitConfigWord (asmFile);
/* print the extern variables in this module */
pic14printExterns (asmFile);
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) {
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;
}
/*-----------------------------------------------------------------*/
extern void genpic14Code (iCode *);
-extern void assignConfigWordValue(int address, int value);
+extern void pic14_assignConfigWordValue(int address, int value);
/* Global data */
static struct
int IS_CONFIG_ADDRESS(int address)
{
- return address == 0x2007 || address == 0x2008;
+ return ((address == 0x2007) || (address == 0x2008));
}
/*-----------------------------------------------------------------*/
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));
}
/* 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);
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);