From 00fd360adb7e15e6fc2642a2038c2ec611cdc799 Mon Sep 17 00:00:00 2001 From: sdattalo Date: Fri, 10 May 2002 21:53:41 +0000 Subject: [PATCH] Fixed several tiny bugs. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2014 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/pic/device.c | 50 +++++++++++++++++++++++++++++++++++++- src/pic/device.h | 5 ++++ src/pic/main.c | 3 ++- src/pic/ralloc.c | 62 ++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 106 insertions(+), 14 deletions(-) diff --git a/src/pic/device.c b/src/pic/device.c index db4e2b39..4e92fed4 100644 --- a/src/pic/device.c +++ b/src/pic/device.c @@ -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; + +} diff --git a/src/pic/device.h b/src/pic/device.h index c4ff2f33..2d2a0632 100644 --- a/src/pic/device.h +++ b/src/pic/device.h @@ -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__ */ diff --git a/src/pic/main.c b/src/pic/main.c index cec44669..d7771302 100644 --- a/src/pic/main.c +++ b/src/pic/main.c @@ -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); } diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index 06e03638..c0554c03 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -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__); -- 2.47.2