From 5979bbd157a5f3cd8018aed666e4dd41a3e08edf Mon Sep 17 00:00:00 2001 From: tecodev Date: Mon, 24 Apr 2006 20:22:31 +0000 Subject: [PATCH] * 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 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4119 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 14 ++++++++++ src/pic/device.c | 68 ++++++++++++++++++++++++++++++++++-------------- src/pic/device.h | 8 ++++-- src/pic/glue.c | 37 +++++++++++++++++--------- src/pic/pcode.c | 4 +-- src/pic/ralloc.c | 12 ++++----- 6 files changed, 102 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd32bbc3..3284909e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2006-04-24 Raphael Neider + + * 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 * doc/Makefile: sync with nightly build makefile diff --git a/src/pic/device.c b/src/pic/device.c index ce4746ae..6abdcbd5 100644 --- a/src/pic/device.c +++ b/src/pic/device.c @@ -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; } diff --git a/src/pic/device.h b/src/pic/device.h index 5fb8a440..b80af236 100644 --- a/src/pic/device.h +++ b/src/pic/device.h @@ -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); diff --git a/src/pic/glue.c b/src/pic/glue.c index 6b6af973..f1809b7f 100644 --- a/src/pic/glue.c +++ b/src/pic/glue.c @@ -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); diff --git a/src/pic/pcode.c b/src/pic/pcode.c index 1540ec02..1752e981 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -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; } diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index de2463e8..3281321b 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -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); -- 2.30.2