From: vrokas Date: Mon, 1 Mar 2004 02:04:17 +0000 (+0000) Subject: * src/pic16/device.c (pic16_dump_section): fixed a bug that allowed X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=2b90ae9bb806159f33865713f849deae1ee52b1d;p=fw%2Fsdcc * src/pic16/device.c (pic16_dump_section): fixed a bug that allowed the sorting of rlist with NULL elements * (print_idataType, print_idata): NEW to create idata sections * src/pic16/device.h: idataSymSet new variable * src/pic16/gen.c (genFunction): fixed some bugs in string comparing, improved the aboslute section creation for ISRs, added FSR0L/FSR0H in registers that are saved in an ISR, * (genInline): fixed the processing of inline snippets, now they undergo no process by the peephole optimizer * src/pic16/glue.c (pic16emitRegularMap): symbols with initialiser are placed in idataSymSet, * (pic16emitStaticSeg): extern symbols are added in externs, * src/pic16/ralloc.c (pic16_allocDirReg): work around to reduce bank switching when aboslute variables are placed in access bank memory * (pic16_writeUsedRegs): added call to pic16_dump_idata, * (packRegsForSupport,packRegsForAccUse,packRegsForOneuse): commented out with #if, * (pic16_packRegisters): reintroduce the check for CAST because some symbols are not correctly handled, * src/pic16/pcode.h: changed the definition of pCodeAsmDir to hold a pCodeInstruction instead of pCode, * src/pic16/pcode.c (pic16_newpCodeAsmDir): modified for the new pCodeAsmDir definition, * (pic16_pCode2str, genericPrint): when an AsmDir pcode has a NULL directive, then the argument directive is emitted without the leading tab, hack for inline labels which must be in the first column, * (compareLabel,pic16_findNextInstruction), * (pic16_findPrevInstruction): added case for PO_ASMDIR, * (insertBankSwitch): modified for the new pCodeAsmDir, * src/pic16/gen.c (pic16_popGet): case PO_DIR, adds the offset to instance, * (pushSide): commented out with #if, * (assignResultValue): fixed some typos in saving registers, * (genPcall): FIXED and sync'ed with genCall, * (genDataPointerGet,genDataPointerSet): using offset not leoffset * (genNearPointerGet): fixed to handle some more cases, implementation scheme via table reads, * (genConstPointerGet): modified to access code memory correct, * (genCodePointerGet,genNearPointerSet,genGenPointerSet): modified and improved to handle some cases * glue.c (printIvalType,printIvalChar,emitStaticSeg): use "DB" instead of "RETLW" for init data * src/pic16/ralloc.c (pic16_allocDirReg): warning when a symbol is not IN_DIRSPACE, work around to reduce bank switching when aboslute variables are placed in access bank memory (<0x80 and >=0xf80), * src/pic16/pcode.c: added SFRs TBLPTR, TABLAT, added opcodes TBLRD, TBLRD_POSTINC,TBLRD_POSTDEC,TBLRD_PREINC,TBLWT,TBLWT_POSTINC, TBLWT_POSTDEC,TBLWT_PREINC * Fixed initialisation of BSR, set "alias" for SSAVE to "0" * (pic16_emitDB,pic16_flushDB): New functions to generate "DB" directives * (pic16_pCodeConstString): use "DB" instead of "RETLW" * src/pic16/pcode.h: added TBLRD*,TBLWT*, added pic16_emitDB, pic16_flushDB, made pic16_newpCodeAsmDir public, added TBLPTR, TABLAT * src/pic16/ralloc.h: added IDX_BSR,IDX_TBLPTR*,IDX_TABLAT git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3238 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index d50f997b..cd8d86a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,66 @@ +2004-03-01 Vangelis Rokas + + * src/pic16/device.c (pic16_dump_section): fixed a bug that allowed + the sorting of rlist with NULL elements + * (print_idataType, print_idata): NEW to create idata sections + * src/pic16/device.h: idataSymSet new variable + * src/pic16/gen.c (genFunction): fixed some bugs in string + comparing, improved the aboslute section creation for ISRs, + added FSR0L/FSR0H in registers that are saved in an ISR, + * (genInline): fixed the processing of inline snippets, + now they undergo no process by the peephole optimizer + * src/pic16/glue.c (pic16emitRegularMap): symbols with initialiser + are placed in idataSymSet, + * (pic16emitStaticSeg): extern symbols are added in externs, + * src/pic16/ralloc.c (pic16_allocDirReg): work around to reduce bank + switching when aboslute variables are placed in access bank memory + * (pic16_writeUsedRegs): added call to pic16_dump_idata, + * (packRegsForSupport,packRegsForAccUse,packRegsForOneuse): + commented out with #if, + * (pic16_packRegisters): reintroduce the check for CAST because some + symbols are not correctly handled, + * src/pic16/pcode.h: changed the definition of pCodeAsmDir to hold a + pCodeInstruction instead of pCode, + * src/pic16/pcode.c (pic16_newpCodeAsmDir): modified for the new + pCodeAsmDir definition, + * (pic16_pCode2str, genericPrint): when an AsmDir pcode has a NULL + directive, then the argument directive is emitted without the leading + tab, hack for inline labels which must be in the first column, + * (compareLabel,pic16_findNextInstruction), + * (pic16_findPrevInstruction): added case for PO_ASMDIR, + * (insertBankSwitch): modified for the new pCodeAsmDir, + +2004-03-01 Hans-Juergen Dorn + patch applied by Vangelis Rokas + + * src/pic16/gen.c (pic16_popGet): case PO_DIR, adds the offset to + instance, + * (pushSide): commented out with #if, + * (assignResultValue): fixed some typos in saving + registers, + * (genPcall): FIXED and sync'ed with genCall, + * (genDataPointerGet,genDataPointerSet): using offset not leoffset + * (genNearPointerGet): fixed to handle some more cases, + implementation scheme via table reads, + * (genConstPointerGet): modified to access code memory correct, + * (genCodePointerGet,genNearPointerSet,genGenPointerSet): modified + and improved to handle some cases + * glue.c (printIvalType,printIvalChar,emitStaticSeg): use "DB" + instead of "RETLW" for init data + * src/pic16/ralloc.c (pic16_allocDirReg): warning when a symbol is + not IN_DIRSPACE, work around to reduce bank switching when aboslute + variables are placed in access bank memory (<0x80 and >=0xf80), + * src/pic16/pcode.c: added SFRs TBLPTR, TABLAT, added opcodes TBLRD, + TBLRD_POSTINC,TBLRD_POSTDEC,TBLRD_PREINC,TBLWT,TBLWT_POSTINC, + TBLWT_POSTDEC,TBLWT_PREINC + * Fixed initialisation of BSR, set "alias" for SSAVE to "0" + * (pic16_emitDB,pic16_flushDB): New functions to generate "DB" + directives + * (pic16_pCodeConstString): use "DB" instead of "RETLW" + * src/pic16/pcode.h: added TBLRD*,TBLWT*, added pic16_emitDB, + pic16_flushDB, made pic16_newpCodeAsmDir public, added TBLPTR, TABLAT + * src/pic16/ralloc.h: added IDX_BSR,IDX_TBLPTR*,IDX_TABLAT + 2004-02-29 Borut Razem * src/Makefile.in, src/SDCCutil.c, support/Util/findme.c, diff --git a/src/pic16/device.c b/src/pic16/device.c index 6a5c7006..a9f5dfb3 100644 --- a/src/pic16/device.c +++ b/src/pic16/device.c @@ -283,14 +283,14 @@ void pic16_dump_section(FILE *of, set *section, int fix) for(rprev = setFirstItem(section); rprev; rprev = setNextItem(section)) { rlist[i] = rprev; i++; } - - /* sort symbols according to their address */ - qsort(rlist, elementsInSet(section), sizeof(regs *), regCompare); if(!i) { if(rlist)free(rlist); return; } + + /* sort symbols according to their address */ + qsort(rlist, i /*elementsInSet(section)*/, sizeof(regs *), regCompare); if(!fix) { fprintf(of, "\n\n\tudata\n"); @@ -349,6 +349,134 @@ void pic16_dump_int_registers(FILE *of, set *section) } +#ifdef WORDS_BIGENDIAN + #define _ENDIAN(x) (3-x) +#else + #define _ENDIAN(x) (x) +#endif + +#define BYTE_IN_LONG(x,b) ((x>>(8*_ENDIAN(b)))&0xff) + +/*-----------------------------------------------------------------*/ +/* printIvalType - generates ival for int/char */ +/*-----------------------------------------------------------------*/ +void print_idataType (FILE *of, symbol *sym, sym_link * type, initList * ilist) +{ + value *val; + unsigned long ulval; + + //fprintf(stderr, "%s\n",__FUNCTION__); + + /* if initList is deep */ + if (ilist->type == INIT_DEEP) + ilist = ilist->init.deep; + + if (!IS_AGGREGATE(sym->type) && getNelements(type, ilist)>1) { + werror (W_EXCESS_INITIALIZERS, "scalar", sym->name, sym->lineDef); + } + + if (!(val = list2val (ilist))) { + // assuming a warning has been thrown + val=constVal("0"); + } + + if (val->type != type) { + val = valCastLiteral(type, floatFromVal(val)); + } + + if(val) + ulval = (unsigned long) floatFromVal (val); + else + ulval =0; + + switch (getSize (type)) { + case 1: + fprintf(of, "%s\tdata\t0x%02x\n", sym->name, (unsigned char)BYTE_IN_LONG(ulval, 0)); +// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0)))); + break; + + case 2: +// fprintf(of, "%s\tdw\t0x%04x\n", sym->name, (unsigned int)(BYTE_IN_LONG(ulval, 0) +// + (BYTE_IN_LONG(ulval, 1) << 8))); + fprintf(of, "%s\tdata\t0x%02x,0x%02x\n", sym->name, (unsigned char)BYTE_IN_LONG(ulval, 0), + (unsigned char)(BYTE_IN_LONG(ulval, 1) << 8)); +// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0)))); +// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1)))); + break; + + case 4: + fprintf(of, "%s\tdw\t0x%04x,0x%04x\n", sym->name, (unsigned int)(BYTE_IN_LONG(ulval, 0) + + (BYTE_IN_LONG(ulval, 1) << 8)), + (unsigned)(BYTE_IN_LONG(ulval, 2) + + (BYTE_IN_LONG(ulval, 3) << 8))); +// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0)))); +// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1)))); +// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,2)))); +// pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,3)))); + break; + } +} + + + +/*-----------------------------------------------------------------*/ +/* printIval - generates code for initial value */ +/*-----------------------------------------------------------------*/ +void print_idata(FILE *of, symbol * sym, sym_link * type, initList * ilist) +{ + if (!ilist) + return; + + /* if structure then */ + if (IS_STRUCT (type)) + { + //fprintf(stderr,"%s struct\n",__FUNCTION__); + //printIvalStruct (sym, type, ilist, oFile); + return; + } + + /* if this is a pointer */ + if (IS_PTR (type)) + { + //fprintf(stderr,"%s pointer\n",__FUNCTION__); + //printIvalPtr (sym, type, ilist, oFile); + return; + } + + /* if this is an array */ + if (IS_ARRAY (type)) + { + //fprintf(stderr,"%s array\n",__FUNCTION__); +// printIvalArray (sym, type, ilist, pb); + return; + } + + /* if type is SPECIFIER */ + if (IS_SPEC (type)) + { +// fprintf(stderr,"%s spec\n",__FUNCTION__); + print_idataType(of, sym, type, ilist); + return; + } +} + + +void pic16_dump_idata(FILE *of, set *idataSymSet) +{ + int i; + symbol *ids; + + + i = elementsInSet(idataSymSet); + if(!i)return; + + fprintf(of, "\n\n; Initialised data (idata)\n"); + fprintf(of, "\tidata\n"); + for(ids = setFirstItem(idataSymSet); ids; ids = setNextItem(idataSymSet)) + print_idata(of, ids, ids->type, ids->ival); + +} + /*-----------------------------------------------------------------* * void pic16_list_valid_pics(int ncols, int list_alias) @@ -617,3 +745,4 @@ int pic16_getConfigWord(int address) return 0; } } + diff --git a/src/pic16/device.h b/src/pic16/device.h index d2bef36f..cd115fbb 100644 --- a/src/pic16/device.h +++ b/src/pic16/device.h @@ -67,6 +67,7 @@ typedef struct { #define STACK_MODEL_SMALL (pic16_options.stack_model == 0) #define STACK_MODEL_LARGE (pic16_options.stack_model == 1) +extern set *idataSymSet; extern pic16_options_t pic16_options; extern PIC16_device *pic16; diff --git a/src/pic16/gen.c b/src/pic16/gen.c index e52b0ed5..1d43e888 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -176,7 +176,6 @@ static int my_powof2 (unsigned long num) void DEBUGpic16_pic16_AopType(int line_no, operand *left, operand *right, operand *result) { - DEBUGpic16_emitcode ("; ","line = %d result %s=%s, left %s=%s, right %s=%s, size = %d", line_no, ((result) ? pic16_AopType(AOP_TYPE(result)) : "-"), @@ -186,7 +185,6 @@ void DEBUGpic16_pic16_AopType(int line_no, operand *left, operand *right, operan ((right) ? pic16_AopType(AOP_TYPE(right)) : "-"), ((right) ? pic16_aopGet(AOP(right),0,FALSE,FALSE) : "-"), ((result) ? AOP_SIZE(result) : 0)); - } void DEBUGpic16_pic16_AopTypeSign(int line_no, operand *left, operand *right, operand *result) @@ -594,6 +592,7 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result) return aop; } +#if 0 // patch 14 /* special case for a function */ if (IS_FUNC(sym->type)) { sym->aop = aop = newAsmop(AOP_IMMD); @@ -604,6 +603,7 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result) DEBUGpic16_emitcode(";","%d size = %d, name =%s",__LINE__,aop->size,sym->rname); return aop; } +#endif // patch 14 /* only remaining is far space */ @@ -617,20 +617,27 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result) PCOI(aop->aopu.pcop)->index = 0; } else { /* try to allocate via direct register */ - aop->aopu.pcop = pic16_popRegFromString(sym->rname, getSize(sym->type), 0); + aop->aopu.pcop = pic16_popRegFromString(sym->rname, getSize(sym->type), sym->offset); // Patch 8 // aop->size = getSize( sym->type ); } DEBUGpic16_emitcode(";","%d: rname %s, val %d, const = %d", __LINE__,sym->rname, 0, PCOI(aop->aopu.pcop)->_const); - pic16_allocDirReg (IC_LEFT(ic)); +#if 0 + if(!pic16_allocDirReg (IC_LEFT(ic))) + return NULL; +#endif if(IN_DIRSPACE( space )) aop->size = PTRSIZE; else if(IN_CODESPACE( space )) aop->size = FPTRSIZE; - else aop->size = AOP_SIZE( IC_LEFT(ic) ); + else if(IC_LEFT(ic)) aop->size = AOP_SIZE( IC_LEFT(ic) ); + else if(IC_RIGHT(ic)) aop->size = AOP_SIZE( IC_RIGHT(ic) ); + else { + assert( 0 ); + } DEBUGpic16_emitcode(";","%d size = %d",__LINE__,aop->size); @@ -1108,8 +1115,8 @@ char *pic16_aopGet (asmop *aop, int offset, bool bit16, bool dname) char *rs; //DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - /* offset is greater than - size then zero */ + + /* offset is greater than size then zero */ if (offset > (aop->size - 1) && aop->type != AOP_LIT) return zero; @@ -1349,7 +1356,6 @@ pCodeOp *pic16_popGetLit2(unsigned int lit, pCodeOp *arg2) /*-----------------------------------------------------------------*/ pCodeOp *pic16_popGetImmd(char *name, unsigned int offset, int index) { - return pic16_newpCodeOpImmd(name, offset,index, 0); } @@ -1381,8 +1387,8 @@ static pCodeOp *pic16_popRegFromString(char *str, int size, int offset) pCodeOp *pcop = Safe_calloc(1,sizeof(pCodeOpReg) ); pcop->type = PO_DIR; - DEBUGpic16_emitcode(";","%d %s %s",__LINE__, __FUNCTION__, str); -// fprintf(stderr, "%s:%d: register name = %s pos = %d/%d\n", __FUNCTION__, __LINE__, str, offset, size); + DEBUGpic16_emitcode(";","%d %s %s %d/%d",__LINE__, __FUNCTION__, str, size, offset); // patch 14 + // fprintf(stderr, "%s:%d: register name = %s pos = %d/%d\n", __FUNCTION__, __LINE__, str, offset, size); if(!str) str = "BAD_STRING"; @@ -1604,7 +1610,7 @@ pCodeOp *pic16_popGet (asmop *aop, int offset) //, bool bit16, bool dname) pcop = pic16_pCodeOpCopy(aop->aopu.pcop); #if 1 switch( aop->aopu.pcop->type ) { - case PO_DIR: PCOR(pcop)->instance = offset; break; + case PO_DIR: PCOR(pcop)->instance += offset; break; // patch 8 case PO_IMMEDIATE: PCOI(pcop)->offset = offset; break; default: assert( 0 ); /* should never reach here */; @@ -2360,13 +2366,12 @@ static void unsaveRegisters (iCode *ic) } - +#if 0 // patch 14 /*-----------------------------------------------------------------*/ /* pushSide - */ /*-----------------------------------------------------------------*/ static void pushSide(operand * oper, int size) { -#if 0 int offset = 0; DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); while (size--) { @@ -2379,8 +2384,8 @@ static void pushSide(operand * oper, int size) } else pic16_emitcode("push","%s",l); } -#endif } +#endif // patch 14 void pic16_loadFromReturn(operand *op, int offset, pCodeOp *src) { @@ -2404,7 +2409,7 @@ static void assignResultValue(operand * oper, int rescall) { int size = AOP_SIZE(oper); - DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); + DEBUGpic16_emitcode ("; ***","%s %d rescall:%d size:%d",__FUNCTION__,__LINE__,rescall,size); // patch 14 DEBUGpic16_pic16_AopType(__LINE__,oper,NULL,NULL); if(rescall) { @@ -2426,7 +2431,7 @@ static void assignResultValue(operand * oper, int rescall) if(size>2) { /* 24-bits, result in PRODH:PRODL:WREG */ - pic16_loadFromReturn(oper, 2, pic16_popCopyReg(&pic16_pc_prodl)); + pic16_loadFromReturn(oper, 2, pic16_popCopyReg(&pic16_pc_prodh)); // patch 14 // pic16_emitpcode(POC_MOVFF, // pic16_popGet2p(pic16_popCopyReg(&pic16_pc_prodh), pic16_popGet(AOP(oper), 2))); @@ -2434,7 +2439,7 @@ static void assignResultValue(operand * oper, int rescall) if(size>3) { /* 32-bits, result in FSR0L:PRODH:PRODL:WREG */ - pic16_loadFromReturn(oper, 3, pic16_popCopyReg(&pic16_pc_prodl)); + pic16_loadFromReturn(oper, 3, pic16_popCopyReg(&pic16_pc_fsr0l)); // patch14 // pic16_emitpcode(POC_MOVFF, // pic16_popGet2p(pic16_popCopyReg(&pic16_pc_fsr0l), pic16_popGet(AOP(oper), 3))); @@ -2459,7 +2464,7 @@ static void assignResultValue(operand * oper, int rescall) pic16_emitpcode(POC_INCF, pic16_popCopyReg( &pic16_pc_fsr1h )); } } - } else { + } else { if(!GpsuedoStkPtr) { // DEBUGpic16_emitcode("; ", "pop %d", GpsuedoStkPtr); /* The last byte in the assignment is in W */ @@ -2810,6 +2815,179 @@ static void genCall (iCode *ic) unsaveRegisters (ic); } + + +/*-----------------------------------------------------------------*/ // patch 14 +/* genPcall - generates a call by pointer statement */ +/*-----------------------------------------------------------------*/ + +// new version, created from genCall + +static void genPcall (iCode *ic) +{ + sym_link *dtype; + int stackParms=0; + symbol *retlbl = newiTempLabel(NULL); + pCodeOp *pcop_lbl = pic16_popGetLabel(retlbl->key); + + DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); + + /* if caller saves & we have not saved then */ + if (!ic->regsSaved) + saveRegisters(ic); + + /* if we are calling a function that is not using + * the same register bank then we need to save the + * destination registers on the stack */ + dtype = operandType(IC_LEFT(ic)); + if (currFunc && dtype && + (FUNC_REGBANK(currFunc->type) != FUNC_REGBANK(dtype)) && + IFFUNC_ISISR(currFunc->type) && + !ic->bankSaved) + + saverbank(FUNC_REGBANK(dtype),ic,TRUE); + + /* if send set is not empty the assign */ + if (_G.sendSet) { + iCode *sic; + + /* For the Pic port, there is no data stack. + * So parameters passed to functions are stored + * in registers. (The pCode optimizer will get + * rid of most of these :). */ + + int psuedoStkPtr=-1; + int firstTimeThruLoop = 1; + + _G.sendSet = reverseSet(_G.sendSet); + + /* First figure how many parameters are getting passed */ + for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) { + pic16_aopOp(IC_LEFT(sic),sic,FALSE); + psuedoStkPtr += AOP_SIZE(IC_LEFT(sic)); + pic16_freeAsmop (IC_LEFT(sic),NULL,sic,FALSE); + } + + stackParms = psuedoStkPtr; + + for (sic = setFirstItem(_G.sendSet) ; sic ; sic = setNextItem(_G.sendSet)) { + int size, offset = 0; + + pic16_aopOp(IC_LEFT(sic),sic,FALSE); + size = AOP_SIZE(IC_LEFT(sic)); + + while (size--) { + DEBUGpic16_emitcode ("; ","%d left %s",__LINE__, + pic16_AopType(AOP_TYPE(IC_LEFT(sic)))); + DEBUGpic16_emitcode("; ", "push %d", psuedoStkPtr-1); + + if(!firstTimeThruLoop) { + /* If this is not the first time we've been through the loop + * then we need to save the parameter in a temporary + * register. The last byte of the last parameter is + * passed in W. */ + + pushw(); + --psuedoStkPtr; // sanity check + } + + firstTimeThruLoop=0; + + mov2w (AOP(IC_LEFT(sic)), offset); + offset++; + } + pic16_freeAsmop (IC_LEFT(sic),NULL,sic,TRUE); + } + _G.sendSet = NULL; + } + + pic16_aopOp(IC_LEFT(ic),ic,FALSE); + + // push return address + // push $ on return stack, then replace with retlbl + + // Note: retlbl is supplied as dummy operand to PUSH + // This has the nice side effect of keeping the label from being optimized out :o) + pic16_emitpcode(POC_PUSH, pic16_popGetLabel(retlbl->key)); + + pic16_emitpcode(POC_MOVLW, pic16_popGetImmd(pcop_lbl->name, 0, 0)); + pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_tosl)); + pic16_emitpcode(POC_MOVLW, pic16_popGetImmd(pcop_lbl->name, 1, 0)); + pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_tosh)); + pic16_emitpcode(POC_MOVLW, pic16_popGetImmd(pcop_lbl->name, 2, 0)); + pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_tosu)); + + /* make the call by writing the pointer into pc */ +// FIXME Disabled writes to PCLATU because of gpsim problems +#if 0 + pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)),2), pic16_popCopyReg(&pic16_pc_pclatu))); +#endif + pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)),1), pic16_popCopyReg(&pic16_pc_pclath))); + // note: MOVFF to PCL not allowed + pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(IC_LEFT(ic)),0)); + pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_pcl)); + + /* return address is here: (X) */ + pic16_emitpLabel(retlbl->key); + + pic16_freeAsmop (IC_LEFT(ic),NULL,ic,TRUE); + + GpsuedoStkPtr=0; + /* if we need assign a result value */ + if ((IS_ITEMP(IC_RESULT(ic)) && + (OP_SYMBOL(IC_RESULT(ic))->nRegs || + OP_SYMBOL(IC_RESULT(ic))->spildir )) || + IS_TRUE_SYMOP(IC_RESULT(ic)) ) { + + _G.accInUse++; + pic16_aopOp(IC_RESULT(ic),ic,FALSE); + _G.accInUse--; + + assignResultValue(IC_RESULT(ic), 1); + + DEBUGpic16_emitcode ("; ","%d left %s",__LINE__, + pic16_AopType(AOP_TYPE(IC_RESULT(ic)))); + + pic16_freeAsmop(IC_RESULT(ic),NULL, ic,TRUE); + } + + if(stackParms>0) { + pic16_emitpcode(POC_MOVLW, pic16_popGetLit(stackParms)); + pic16_emitpcode(POC_ADDWF, pic16_popCopyReg( &pic16_pc_fsr1l )); + if(STACK_MODEL_LARGE) { + emitSKPNC; + pic16_emitpcode(POC_INCF, pic16_popCopyReg( &pic16_pc_fsr1h )); + } + } + + /* adjust the stack for parameters if required */ +// fprintf(stderr, "%s:%d: %s ic->parmBytes= %d\n", __FILE__, __LINE__, OP_SYMBOL(IC_LEFT(ic))->name, ic->parmBytes); + + if (ic->parmBytes) { + int i; + + if (ic->parmBytes > 3) { + pic16_emitcode("mov","a,%s",spname); + pic16_emitcode("add","a,#0x%02x", (- ic->parmBytes) & 0xff); + pic16_emitcode("mov","%s,a",spname); + } else + for ( i = 0 ; i < ic->parmBytes ;i++) + pic16_emitcode("dec","%s",spname); + } + + /* if register bank was saved then pop them */ + if (ic->bankSaved) + unsaverbank(FUNC_REGBANK(dtype),ic,TRUE); + + /* if we hade saved some registers then unsave them */ + if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype)) + unsaveRegisters (ic); +} + + +#if 0 // patch 14 +// old version, kept for reference + /*-----------------------------------------------------------------*/ /* genPcall - generates a call by pointer statement */ /*-----------------------------------------------------------------*/ @@ -2920,6 +3098,8 @@ static void genPcall (iCode *ic) unsaveRegisters (ic); } +#endif // patch 14 + /*-----------------------------------------------------------------*/ /* resultRemat - result is rematerializable */ @@ -2984,6 +3164,7 @@ static void genFunction (iCode *ic) _G.nRegsSaved = 0; ftype = operandType(IC_LEFT(ic)); + sym = OP_SYMBOL(IC_LEFT(ic)); if(/*!IFFUNC_ISNAKED(ftype) &&*/ IFFUNC_ISISR(ftype)) { /* create an absolute section at the interrupt vector: @@ -2993,34 +3174,60 @@ static void genFunction (iCode *ic) char asymname[128]; { - int i; + int i, found=-1; sym = OP_SYMBOL( IC_LEFT(ic)); - for(i=1;i<=2;i++) - if(STRCASECMP(interrupts[i]->name, sym->name))break; + for(i=0;i<=2;i++) { +// fprintf(stderr, "comparing name int %d\t%s with %s\n", +// i, interrupts[i]->name, sym->name); + if(interrupts[i]->name + && !STRCASECMP(interrupts[i]->name, sym->name)) { + found = i; + break; + } + } - if(i>2) { + if(found == -1) { fprintf(stderr, "PIC16 port: %s:%d: interrupt function but cannot locate symbol (%s)\n", __FILE__, __LINE__, sym->name); exit(-1); } - ivec = i; + ivec = found; } - sprintf(asymname, "ivec_%s", sym->name); + sprintf(asymname, "ivec_%d_%s", ivec, sym->name); asym = newSymbol(asymname, 0); pic16_emitcode(";","-----------------------------------------"); pic16_emitcode(";"," interrupt vector %d for function %s", ivec, sym->name); pic16_emitcode(";","-----------------------------------------"); + pic16_addpCode2pBlock(pb, pic16_newpCodeFunction(moduleName, asym->name)); + pic16_pBlockConvert2Absolute(pb); + pic16_emitpcode(POC_GOTO, pic16_popGetWithString( sym->rname )); - pic16_pBlockConvert2Absolute(pb); + /* mark the end of this tiny function */ + pic16_addpCode2pBlock(pb,pic16_newpCodeFunction(NULL,NULL)); + + { + absSym *abSym; + + abSym = Safe_calloc(1, sizeof(absSym)); + abSym->name = Safe_strdup( asymname ); + + switch( ivec ) { + case 0: abSym->address = 0x000000; break; + case 1: abSym->address = 0x000008; break; + case 2: abSym->address = 0x000018; break; + } + + addSet(&absSymSet, abSym); + } } /* create the function header */ pic16_emitcode(";","-----------------------------------------"); - pic16_emitcode(";"," function %s",(sym = OP_SYMBOL(IC_LEFT(ic)))->name); + pic16_emitcode(";"," function %s",sym->name); pic16_emitcode(";","-----------------------------------------"); pic16_emitcode("","%s:",sym->rname); @@ -3030,7 +3237,7 @@ static void genFunction (iCode *ic) absSym *ab; for(ab = setFirstItem(absSymSet); ab; ab = setNextItem(absSymSet)) - if(strcmp(ab->name, sym->name)) { + if(!strcmp(ab->name, sym->name)) { pic16_pBlockConvert2Absolute(pb); break; } @@ -3051,7 +3258,7 @@ static void genFunction (iCode *ic) * save acc, b, dpl, dph */ if (IFFUNC_ISISR(sym->type)) { int i; - /* an ISR should save: WREG, STATUS, BSR, PRODL, PRODH */ + /* an ISR should save: WREG, STATUS, BSR, PRODL, PRODH, FSR0L, FSR0H */ pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_wreg )); pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_status )); pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_bsr )); @@ -3060,29 +3267,8 @@ static void genFunction (iCode *ic) pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_fsr0l )); pic16_pushpCodeOp( pic16_popCopyReg( &pic16_pc_fsr0h )); - -#if 0 - /* VR -- this is the old code which clears STATUS register for - * the ISR routine. Why? */ - pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_wsave)); - pic16_emitpcode(POC_SWAPFW, pic16_popCopyReg(&pic16_pc_status)); - pic16_emitpcode(POC_CLRF, pic16_popCopyReg(&pic16_pc_status)); - pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_ssave)); -#endif - - pic16_pBlockConvert2ISR(pb); - -#if 0 - if (!inExcludeList("acc")) - pic16_emitcode ("push","acc"); - if (!inExcludeList("b")) - pic16_emitcode ("push","b"); - if (!inExcludeList("dpl")) - pic16_emitcode ("push","dpl"); - if (!inExcludeList("dph")) - pic16_emitcode ("push","dph"); -#endif - + pic16_pBlockConvert2ISR(pb); + /* if any registers used */ if (sym->regsUsed) { /* save the registers used */ @@ -3357,7 +3543,7 @@ void pic16_storeForReturn(operand *op, int offset, pCodeOp *dest) // (AOP(left)->aopu.pcop->type == PO_DIR)? if(AOP(op)->aopu.pcop->type == PO_IMMEDIATE) { - pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(op), offset)); + pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(op), offset)); // patch 12 pic16_emitpcode(POC_MOVWF, dest); } else { pic16_emitpcode(POC_MOVFF, pic16_popGet2p( @@ -3402,9 +3588,9 @@ static void genRet (iCode *ic) // pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)), 1), pic16_popCopyReg(&pic16_pc_prodl))); } - pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(IC_LEFT(ic)), 0)); +// pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(IC_LEFT(ic)), 0)); // patch 12 -// pic16_storeForReturn(IC_LEFT(ic), 0, pic16_popCopyReg(&pic16_pc_wreg)); + pic16_storeForReturn(IC_LEFT(ic), 0, pic16_popCopyReg(&pic16_pc_wreg)); // patch 12 // pic16_emitpcode(POC_MOVFF, // pic16_popGet2p(pic16_popGet(AOP(IC_LEFT(ic)), 0), pic16_popCopyReg(&pic16_pc_wreg))); @@ -4979,6 +5165,7 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) pic16_emitpcode(POC_GOTO,pic16_popGetLabel(lbl->key)); break; default: + DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); while (size--) { if(lit & 0xff) { pic16_emitpcode(POC_MOVFW,pic16_popGet(AOP(left),offset)); @@ -6524,18 +6711,17 @@ static void genInline (iCode *ic) *bp++ = '\0'; if(*bp1) -#if 0 pic16_addpCode2pBlock(pb, pic16_newpCodeAsmDir(bp1, NULL)); // inline directly, no process -#else - pic16_addpCode2pBlock(pb, pic16_AssembleLine(bp1, 1)); -#endif bp1 = bp; } else { if (*bp == ':') { bp++; *bp = '\0'; bp++; - pic16_emitcode(bp1,""); + + /* print label, use this special format with NULL directive + * to denote that the argument should not be indented with tab */ + pic16_addpCode2pBlock(pb, pic16_newpCodeAsmDir(NULL, bp1)); // inline directly, no process bp1 = bp; } else bp++; @@ -6543,11 +6729,7 @@ static void genInline (iCode *ic) } if ((bp1 != bp) && *bp1) -#if 0 pic16_addpCode2pBlock(pb, pic16_newpCodeAsmDir(bp1, NULL)); // inline directly, no process -#else - pic16_addpCode2pBlock(pb, pic16_AssembleLine(bp1, 1)); -#endif Safe_free(buffer); @@ -8545,11 +8727,11 @@ static void genDataPointerGet(operand *left, if(AOP(result)->aopu.pcop->type == PO_IMMEDIATE || AOP(left)->aopu.pcop->type == PO_IMMEDIATE) { - mov2w(AOP(left), leoffset); + mov2w(AOP(left), offset); // patch 8 pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result), offset)); } else { pic16_emitpcode(POC_MOVFF, pic16_popGet2p( - pic16_popGet(AOP(left), leoffset), + pic16_popGet(AOP(left), offset), //patch 8 pic16_popGet(AOP(result), offset))); } @@ -8580,12 +8762,14 @@ static void genNearPointerGet (operand *left, sym_link *ltype = operandType(left); DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - rtype = operandType(result); retype= getSpec(rtype); pic16_aopOp(left,ic,FALSE); + pic16_DumpOp("(left)",left); + pic16_DumpOp("(result)",result); + /* if left is rematerialisable and * result is not bit variable type and * the left is pointer to data space i.e @@ -8608,12 +8792,21 @@ static void genNearPointerGet (operand *left, DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); /* VR -- the whole concept is to load FSR0 with the address of the symbol */ - pic16_loadFSR0( left ); + if( (AOP_TYPE(left) == AOP_PCODE) + && ((AOP(left)->aopu.pcop->type == PO_IMMEDIATE) + || (AOP(left)->aopu.pcop->type == PO_DIR))) // patch 10 + { + pic16_loadFSR0( left ); // patch 10 + } else { + // set up FSR0 with address from left + pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),0), pic16_popCopyReg(&pic16_pc_fsr0l))); // patch 10 + pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),1), pic16_popCopyReg(&pic16_pc_fsr0h))); // patch 10 + } } // else // rname = pic16_aopGet(AOP(left),0,FALSE,FALSE); - pic16_aopOp (result,ic,FALSE); + pic16_aopOp (result,ic,FALSE); /* if bitfield then unpack the bits */ if (IS_BITFIELD(retype)) @@ -8947,19 +9140,21 @@ static void genConstPointerGet (operand *left, operand *result, iCode *ic) { //sym_link *retype = getSpec(operandType(result)); - symbol *albl = newiTempLabel(NULL); - symbol *blbl = newiTempLabel(NULL); - PIC_OPCODE poc; + // symbol *albl = newiTempLabel(NULL); // patch 15 + // symbol *blbl = newiTempLabel(NULL); // + // PIC_OPCODE poc; // patch 15 + int size; + int offset = 0; DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); pic16_aopOp(left,ic,FALSE); - pic16_aopOp(result,ic,FALSE); - + pic16_aopOp(result,ic,TRUE); + size = AOP_SIZE(result); DEBUGpic16_pic16_AopType(__LINE__,left,NULL,result); DEBUGpic16_emitcode ("; "," %d getting const pointer",__LINE__); - +#if 0 // patch 15 pic16_emitpcode(POC_CALL,pic16_popGetLabel(albl->key)); pic16_emitpcode(POC_GOTO,pic16_popGetLabel(blbl->key)); pic16_emitpLabel(albl->key); @@ -8975,8 +9170,36 @@ static void genConstPointerGet (operand *left, pic16_emitpLabel(blbl->key); pic16_emitpcode(POC_MOVWF,pic16_popGet(AOP(result),0)); +#endif // patch 15 + + + // set up table pointer + if( (AOP_TYPE(left) == AOP_PCODE) + && ((AOP(left)->aopu.pcop->type == PO_IMMEDIATE) + || (AOP(left)->aopu.pcop->type == PO_DIR))) // patch 15 ...... + { + pic16_emitpcode(POC_MOVLW,pic16_popGet(AOP(left),0)); + pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_tblptrl)); + pic16_emitpcode(POC_MOVLW,pic16_popGet(AOP(left),1)); + pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_tblptrh)); + pic16_emitpcode(POC_MOVLW,pic16_popGet(AOP(left),2)); + pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_tblptru)); + } + else + { + pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),0), pic16_popCopyReg(&pic16_pc_tblptrl))); + pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),1), pic16_popCopyReg(&pic16_pc_tblptrh))); + pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(left),2), pic16_popCopyReg(&pic16_pc_tblptru))); + } + while(size--) + { + pic16_emitpcodeNULLop(POC_TBLRD_POSTINC); + pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popCopyReg(&pic16_pc_tablat), pic16_popGet(AOP(result),offset))); + offset++; + } + // .... patch 15 pic16_freeAsmop(left,NULL,ic,TRUE); pic16_freeAsmop(result,NULL,ic,TRUE); @@ -9277,13 +9500,13 @@ static void genDataPointerSet(operand *right, lit = lit >> (8*offset); if(lit&0xff) { pic16_emitpcode(POC_MOVLW, pic16_popGetLit(lit&0xff)); - pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),resoffset)); + pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); // pstch 8 } else { - pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),resoffset)); + pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),offset)); // patch 8 } } else { mov2w(AOP(right), offset); - pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),resoffset)); + pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); // patch 8 } offset++; resoffset++; @@ -9338,7 +9561,17 @@ static void genNearPointerSet (operand *right, /* otherwise get a free pointer register */ DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - pic16_loadFSR0( result ); + if( (AOP_TYPE(result) == AOP_PCODE) + && ((AOP(result)->aopu.pcop->type == PO_IMMEDIATE) + || (AOP(result)->aopu.pcop->type == PO_DIR))) // patch 10 + { + pic16_loadFSR0( result ); // patch 10 + } else { + // set up FSR0 with address of result + pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(result),0), pic16_popCopyReg(&pic16_pc_fsr0l))); // patch 10 + pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(result),1), pic16_popCopyReg(&pic16_pc_fsr0h))); // patch 10 + } + } // else // rname = pic16_aopGet(AOP(result),0,FALSE,FALSE); @@ -9362,23 +9595,25 @@ static void genNearPointerSet (operand *right, pic16_emitcode("movf","indf0,w ;1"); } else { - if (AOP_TYPE(right) == AOP_LIT) { - unsigned int lit = (unsigned int) floatFromVal (AOP(IC_RIGHT(ic))->aopu.aop_lit); - - if(lit) { - pic16_emitcode("movlw","%s",l); - pic16_emitcode("movwf","indf0 ;2"); - } else - pic16_emitcode("clrf","indf0"); - } else { - pic16_emitcode("movf","%s,w",l); - pic16_emitcode("movwf","indf0 ;2"); - } - //pic16_emitcode("mov","@%s,%s",rname,l); + if (AOP_TYPE(right) == AOP_LIT) { // patch 10 + pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(right),offset)); // + if (size) { // + pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_postinc0)); // + } else { // + pic16_emitpcode(POC_MOVWF,pic16_popCopyReg(&pic16_pc_indf0)); // + } // + } else { // no literal // + if(size) { // + pic16_emitpcode(POC_MOVFF, // + pic16_popGet2p(pic16_popGet(AOP(right),offset), // + pic16_popCopyReg(&pic16_pc_postinc0))); // + } else { // + pic16_emitpcode(POC_MOVFF, // + pic16_popGet2p(pic16_popGet(AOP(right),offset), // + pic16_popCopyReg(&pic16_pc_indf0))); // + } // + } // patch 10 } - if (size) - pic16_emitcode("incf","fsr0,f ;3"); - //pic16_emitcode("inc","%s",rname); offset++; } } @@ -9552,7 +9787,7 @@ static void genFarPointerSet (operand *right, static void genGenPointerSet (operand *right, operand *result, iCode *ic) { - int size, offset, lit; + int i, size, offset, lit; sym_link *retype = getSpec(operandType(right)); DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); @@ -9599,13 +9834,28 @@ static void genGenPointerSet (operand *right, DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - while(size--) { - if(size) { - pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(right),offset), pic16_popCopyReg(&pic16_pc_postinc0))); - } else { - pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(right),offset), pic16_popCopyReg(&pic16_pc_indf0))); + if(AOP_TYPE(right) == AOP_LIT) + { + // copy literal + // note: pic16_popGet handles sign extension + for(i=0;iaopu.pcop->type == PO_IMMEDIATE) ) { + pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(right),offset)); + pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),offset)); } else { DEBUGpic16_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); @@ -10447,7 +10700,7 @@ static void genCast (iCode *ic) /* now depending on the sign of the destination */ size = AOP_SIZE(result) - AOP_SIZE(right); /* if unsigned or not an integral type */ - if (SPEC_USIGN(rtype) || !IS_SPEC(rtype)) { + if (SPEC_USIGN( getSpec(rtype) ) || !IS_SPEC(rtype)) { while (size--) pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),offset++)); } else { diff --git a/src/pic16/genarith.c b/src/pic16/genarith.c index 2015eb59..21d54eb9 100644 --- a/src/pic16/genarith.c +++ b/src/pic16/genarith.c @@ -983,7 +983,7 @@ void pic16_genPlus (iCode *ic) if ((AOP_TYPE(left) == AOP_PCODE) && ( (AOP(left)->aopu.pcop->type == PO_LITERAL) || - (AOP(left)->aopu.pcop->type == PO_DIR) || +// (AOP(left)->aopu.pcop->type == PO_DIR) || // patch 9 (AOP(left)->aopu.pcop->type == PO_IMMEDIATE))) { // add to literal operand diff --git a/src/pic16/glue.c b/src/pic16/glue.c index c1a71805..935d183b 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -58,6 +58,8 @@ extern char *iComments2; extern int initsfpnt; +set *idataSymSet=NULL; + extern DEFSETFUNC (closeTmpFiles); extern DEFSETFUNC (rmTmpFiles); @@ -219,8 +221,8 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag) reg = pic16_dirregWithName( sym->name ); if(!reg) { - fprintf(stderr, "%s:%d: implicit add of symbol = %s\n", - __FUNCTION__, __LINE__, sym->name); +// fprintf(stderr, "%s:%d: implicit add of symbol = %s\n", +// __FUNCTION__, __LINE__, sym->name); op = operandFromSymbol( sym ); reg = pic16_allocDirReg( op ); @@ -281,9 +283,11 @@ pic16emitRegularMap (memmap * map, bool addPublics, bool arFlag) if (IS_AGGREGATE (sym->type)) ival = initAggregates (sym, sym->ival, NULL); - else + else { + addSet(&idataSymSet, copySymbol(sym)); ival = newNode ('=', newAst_VALUE(symbolVal (sym)), decorateType (resolveSymbols (list2expr (sym->ival)), RESULT_CHECK)); + } codeOutFile = statsg->oFile; GcurMemmap = statsg; eBBlockFromiCode (iCodeFromAst (ival)); @@ -329,19 +333,26 @@ printIvalType (symbol *sym, sym_link * type, initList * ilist, pBlock *pb) switch (getSize (type)) { case 1: - pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0)))); + // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0)))); + pic16_emitDB(pb, BYTE_IN_LONG(ulval,0)); break; case 2: - pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0)))); - pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1)))); + // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0)))); + // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1)))); + pic16_emitDB(pb, BYTE_IN_LONG(ulval,0)); + pic16_emitDB(pb, BYTE_IN_LONG(ulval,1)); break; case 4: - pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0)))); - pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1)))); - pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,2)))); - pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,3)))); + // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,0)))); + // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,1)))); + // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,2)))); + // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(BYTE_IN_LONG(ulval,3)))); + pic16_emitDB(pb, BYTE_IN_LONG(ulval,0)); + pic16_emitDB(pb, BYTE_IN_LONG(ulval,1)); + pic16_emitDB(pb, BYTE_IN_LONG(ulval,2)); + pic16_emitDB(pb, BYTE_IN_LONG(ulval,3)); break; } } @@ -358,7 +369,7 @@ printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s) if(!pb) return 0; - fprintf(stderr, "%s\n",__FUNCTION__); + // fprintf(stderr, "%s\n",__FUNCTION__); if (!s) { @@ -374,9 +385,14 @@ printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s) pic16_addpCode2pBlock(pb,pic16_newpCodeCharP(";omitting call to printChar")); if ((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0) - while (remain--) - //tfprintf (oFile, "\t!db !constbyte\n", 0); - pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(0))); + { + while (remain--) + { + //tfprintf (oFile, "\t!db !constbyte\n", 0); + // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(0))); + pic16_emitDB(pb,0); + } + } return 1; } else @@ -385,10 +401,12 @@ printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s) else { //printChar (oFile, s, strlen (s) + 1); - for(remain=0; remainnext)) { - //fprintf(stderr,"%s:%d - is_char\n",__FUNCTION__,__LINE__); + fprintf(stderr,"%s:%d - is_char\n",__FUNCTION__,__LINE__); if (!IS_LITERAL(list2val(ilist)->etype)) { werror (W_INIT_WRONG); return; @@ -530,8 +549,10 @@ pic16emitStaticSeg (memmap * map) /* if it is "extern" then do nothing */ - if (IS_EXTERN (sym->etype)) + if (IS_EXTERN (sym->etype)) { + addSetHead(&externs, sym); continue; + } /* if it is not static add it to the public table */ @@ -592,6 +613,7 @@ pic16emitStaticSeg (memmap * map) pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(sym->rname,-1)); printIval (sym, sym->type, sym->ival, pb); + pic16_flushDB(pb); noAlloc--; } else diff --git a/src/pic16/main.h b/src/pic16/main.h index 087476d0..a49bc5ca 100644 --- a/src/pic16/main.h +++ b/src/pic16/main.h @@ -32,6 +32,7 @@ typedef struct absSym { unsigned int address; } absSym; + extern set *absSymSet; diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index 9c4de584..72b9df10 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -57,9 +57,19 @@ pCodeOpReg pic16_pc_status = {{PO_STATUS, "STATUS"}, -1, NULL,0,NULL}; pCodeOpReg pic16_pc_intcon = {{PO_INTCON, "INTCON"}, -1, NULL,0,NULL}; pCodeOpReg pic16_pc_pcl = {{PO_PCL, "PCL"}, -1, NULL,0,NULL}; pCodeOpReg pic16_pc_pclath = {{PO_PCLATH, "PCLATH"}, -1, NULL,0,NULL}; +pCodeOpReg pic16_pc_pclatu = {{PO_PCLATU, "PCLATU"}, -1, NULL,0,NULL}; // patch 14 pCodeOpReg pic16_pc_wreg = {{PO_WREG, "WREG"}, -1, NULL,0,NULL}; pCodeOpReg pic16_pc_bsr = {{PO_BSR, "BSR"}, -1, NULL,0,NULL}; +pCodeOpReg pic16_pc_tosl = {{PO_SFR_REGISTER, "TOSL"}, -1, NULL,0,NULL}; // patch 14 +pCodeOpReg pic16_pc_tosh = {{PO_SFR_REGISTER, "TOSH"}, -1, NULL,0,NULL}; // +pCodeOpReg pic16_pc_tosu = {{PO_SFR_REGISTER, "TOSU"}, -1, NULL,0,NULL}; // patch 14 + +pCodeOpReg pic16_pc_tblptrl = {{PO_SFR_REGISTER, "TBLPTRL"}, -1, NULL,0,NULL}; // patch 15 +pCodeOpReg pic16_pc_tblptrh = {{PO_SFR_REGISTER, "TBLPTRH"}, -1, NULL,0,NULL}; // +pCodeOpReg pic16_pc_tblptru = {{PO_SFR_REGISTER, "TBLPTRU"}, -1, NULL,0,NULL}; // +pCodeOpReg pic16_pc_tablat = {{PO_SFR_REGISTER, "TABLAT"}, -1, NULL,0,NULL}; // patch 15 + //pCodeOpReg pic16_pc_fsr0 = {{PO_FSR0, "FSR0"}, -1, NULL,0,NULL}; //deprecated ! pCodeOpReg pic16_pc_fsr0l = {{PO_FSR0, "FSR0L"}, -1, NULL, 0, NULL}; @@ -69,23 +79,23 @@ pCodeOpReg pic16_pc_fsr1h = {{PO_FSR0, "FSR1H"}, -1, NULL, 0, NULL}; pCodeOpReg pic16_pc_fsr2l = {{PO_FSR0, "FSR2L"}, -1, NULL, 0, NULL}; pCodeOpReg pic16_pc_fsr2h = {{PO_FSR0, "FSR2H"}, -1, NULL, 0, NULL}; -pCodeOpReg pic16_pc_indf0 = {{PO_INDF0, "INDF0"}, -1, NULL,0,NULL}; +pCodeOpReg pic16_pc_indf0 = {{PO_INDF0, "INDF0"}, -1, NULL,0,NULL}; pCodeOpReg pic16_pc_postinc0 = {{PO_INDF0, "POSTINC0"}, -1, NULL, 0, NULL}; pCodeOpReg pic16_pc_postdec0 = {{PO_INDF0, "POSTDEC0"}, -1, NULL, 0, NULL}; -pCodeOpReg pic16_pc_preinc0 = {{PO_INDF0, "PREINC0"}, -1, NULL, 0, NULL}; -pCodeOpReg pic16_pc_plusw0 = {{PO_INDF0, "PLUSW0"}, -1, NULL, 0, NULL}; +pCodeOpReg pic16_pc_preinc0 = {{PO_INDF0, "PREINC0"}, -1, NULL, 0, NULL}; +pCodeOpReg pic16_pc_plusw0 = {{PO_INDF0, "PLUSW0"}, -1, NULL, 0, NULL}; -pCodeOpReg pic16_pc_indf1 = {{PO_INDF0, "INDF1"}, -1, NULL,0,NULL}; +pCodeOpReg pic16_pc_indf1 = {{PO_INDF0, "INDF1"}, -1, NULL,0,NULL}; pCodeOpReg pic16_pc_postinc1 = {{PO_INDF0, "POSTINC1"}, -1, NULL, 0, NULL}; pCodeOpReg pic16_pc_postdec1 = {{PO_INDF0, "POSTDEC1"}, -1, NULL, 0, NULL}; -pCodeOpReg pic16_pc_preinc1 = {{PO_INDF0, "PREINC1"}, -1, NULL, 0, NULL}; -pCodeOpReg pic16_pc_plusw1 = {{PO_INDF0, "PLUSW1"}, -1, NULL, 0, NULL}; +pCodeOpReg pic16_pc_preinc1 = {{PO_INDF0, "PREINC1"}, -1, NULL, 0, NULL}; +pCodeOpReg pic16_pc_plusw1 = {{PO_INDF0, "PLUSW1"}, -1, NULL, 0, NULL}; -pCodeOpReg pic16_pc_indf2 = {{PO_INDF0, "INDF2"}, -1, NULL,0,NULL}; +pCodeOpReg pic16_pc_indf2 = {{PO_INDF0, "INDF2"}, -1, NULL,0,NULL}; pCodeOpReg pic16_pc_postinc2 = {{PO_INDF0, "POSTINC2"}, -1, NULL, 0, NULL}; pCodeOpReg pic16_pc_postdec2 = {{PO_INDF0, "POSTDEC2"}, -1, NULL, 0, NULL}; -pCodeOpReg pic16_pc_preinc2 = {{PO_INDF0, "PREINC2"}, -1, NULL, 0, NULL}; -pCodeOpReg pic16_pc_plusw2 = {{PO_INDF0, "PLUSW2"}, -1, NULL, 0, NULL}; +pCodeOpReg pic16_pc_preinc2 = {{PO_INDF0, "PREINC2"}, -1, NULL, 0, NULL}; +pCodeOpReg pic16_pc_plusw2 = {{PO_INDF0, "PLUSW2"}, -1, NULL, 0, NULL}; pCodeOpReg pic16_pc_prodl = {{PO_PRODL, "PRODL"}, -1, NULL, 0, NULL}; pCodeOpReg pic16_pc_prodh = {{PO_PRODH, "PRODH"}, -1, NULL, 0, NULL}; @@ -2355,6 +2365,214 @@ pCodeInstruction pic16_pciSWAPFW = { PCI_MAGIC }; +pCodeInstruction pic16_pciTBLRD = { // patch 15 + {PC_OPCODE, NULL, NULL, 0, NULL, + genericDestruct, + genericPrint}, + POC_TBLRD, + "TBLRD*", + NULL, // from branch + NULL, // to branch + NULL, // label + NULL, // operand + NULL, // flow block + NULL, // C source + 0, // num ops + 0,0, // dest, bit instruction + 0,0, // branch, skip + 0, // literal operand + 0, // RAM access bit + 0, // fast call/return mode select bit + 0, // second memory operand + 0, // second literal operand + POC_NOP, + PCC_NONE, // inCond + PCC_NONE , // outCond + PCI_MAGIC +}; + +pCodeInstruction pic16_pciTBLRD_POSTINC = { // patch 15 + {PC_OPCODE, NULL, NULL, 0, NULL, + genericDestruct, + genericPrint}, + POC_TBLRD_POSTINC, + "TBLRD*+", + NULL, // from branch + NULL, // to branch + NULL, // label + NULL, // operand + NULL, // flow block + NULL, // C source + 0, // num ops + 0,0, // dest, bit instruction + 0,0, // branch, skip + 0, // literal operand + 0, // RAM access bit + 0, // fast call/return mode select bit + 0, // second memory operand + 0, // second literal operand + POC_NOP, + PCC_NONE, // inCond + PCC_NONE , // outCond + PCI_MAGIC +}; + +pCodeInstruction pic16_pciTBLRD_POSTDEC = { // patch 15 + {PC_OPCODE, NULL, NULL, 0, NULL, + genericDestruct, + genericPrint}, + POC_TBLRD_POSTDEC, + "TBLRD*-", + NULL, // from branch + NULL, // to branch + NULL, // label + NULL, // operand + NULL, // flow block + NULL, // C source + 0, // num ops + 0,0, // dest, bit instruction + 0,0, // branch, skip + 0, // literal operand + 0, // RAM access bit + 0, // fast call/return mode select bit + 0, // second memory operand + 0, // second literal operand + POC_NOP, + PCC_NONE, // inCond + PCC_NONE , // outCond + PCI_MAGIC +}; + +pCodeInstruction pic16_pciTBLRD_PREINC = { // patch 15 + {PC_OPCODE, NULL, NULL, 0, NULL, + genericDestruct, + genericPrint}, + POC_TBLRD_PREINC, + "TBLRD+*", + NULL, // from branch + NULL, // to branch + NULL, // label + NULL, // operand + NULL, // flow block + NULL, // C source + 0, // num ops + 0,0, // dest, bit instruction + 0,0, // branch, skip + 0, // literal operand + 0, // RAM access bit + 0, // fast call/return mode select bit + 0, // second memory operand + 0, // second literal operand + POC_NOP, + PCC_NONE, // inCond + PCC_NONE , // outCond + PCI_MAGIC +}; + +pCodeInstruction pic16_pciTBLWT = { // patch 15 + {PC_OPCODE, NULL, NULL, 0, NULL, + genericDestruct, + genericPrint}, + POC_TBLWT, + "TBLWT*", + NULL, // from branch + NULL, // to branch + NULL, // label + NULL, // operand + NULL, // flow block + NULL, // C source + 0, // num ops + 0,0, // dest, bit instruction + 0,0, // branch, skip + 0, // literal operand + 0, // RAM access bit + 0, // fast call/return mode select bit + 0, // second memory operand + 0, // second literal operand + POC_NOP, + PCC_NONE, // inCond + PCC_NONE , // outCond + PCI_MAGIC +}; + +pCodeInstruction pic16_pciTBLWT_POSTINC = { // patch 15 + {PC_OPCODE, NULL, NULL, 0, NULL, + genericDestruct, + genericPrint}, + POC_TBLWT_POSTINC, + "TBLWT*+", + NULL, // from branch + NULL, // to branch + NULL, // label + NULL, // operand + NULL, // flow block + NULL, // C source + 0, // num ops + 0,0, // dest, bit instruction + 0,0, // branch, skip + 0, // literal operand + 0, // RAM access bit + 0, // fast call/return mode select bit + 0, // second memory operand + 0, // second literal operand + POC_NOP, + PCC_NONE, // inCond + PCC_NONE , // outCond + PCI_MAGIC +}; + +pCodeInstruction pic16_pciTBLWT_POSTDEC = { // patch 15 + {PC_OPCODE, NULL, NULL, 0, NULL, + genericDestruct, + genericPrint}, + POC_TBLWT_POSTDEC, + "TBLWT*-", + NULL, // from branch + NULL, // to branch + NULL, // label + NULL, // operand + NULL, // flow block + NULL, // C source + 0, // num ops + 0,0, // dest, bit instruction + 0,0, // branch, skip + 0, // literal operand + 0, // RAM access bit + 0, // fast call/return mode select bit + 0, // second memory operand + 0, // second literal operand + POC_NOP, + PCC_NONE, // inCond + PCC_NONE , // outCond + PCI_MAGIC +}; + +pCodeInstruction pic16_pciTBLWT_PREINC = { // patch 15 + {PC_OPCODE, NULL, NULL, 0, NULL, + genericDestruct, + genericPrint}, + POC_TBLWT_PREINC, + "TBLWT+*", + NULL, // from branch + NULL, // to branch + NULL, // label + NULL, // operand + NULL, // flow block + NULL, // C source + 0, // num ops + 0,0, // dest, bit instruction + 0,0, // branch, skip + 0, // literal operand + 0, // RAM access bit + 0, // fast call/return mode select bit + 0, // second memory operand + 0, // second literal operand + POC_NOP, + PCC_NONE, // inCond + PCC_NONE , // outCond + PCI_MAGIC +}; + pCodeInstruction pic16_pciTSTFSZ = { // mdubuc - New {PC_OPCODE, NULL, NULL, 0, NULL, // genericAnalyze, @@ -2557,8 +2775,20 @@ void pic16_pCodeInitRegisters(void) pic16_pc_status.r = pic16_allocProcessorRegister(IDX_STATUS,"STATUS", PO_STATUS, 0x80); pic16_pc_pcl.r = pic16_allocProcessorRegister(IDX_PCL,"PCL", PO_PCL, 0x80); pic16_pc_pclath.r = pic16_allocProcessorRegister(IDX_PCLATH,"PCLATH", PO_PCLATH, 0x80); + pic16_pc_pclatu.r = pic16_allocProcessorRegister(IDX_PCLATU,"PCLATU", PO_PCLATU, 0x80); pic16_pc_intcon.r = pic16_allocProcessorRegister(IDX_INTCON,"INTCON", PO_INTCON, 0x80); pic16_pc_wreg.r = pic16_allocProcessorRegister(IDX_WREG,"WREG", PO_WREG, 0x80); + pic16_pc_bsr.r = pic16_allocProcessorRegister(IDX_BSR,"BSR", PO_BSR, 0x80); + + pic16_pc_tosl.r = pic16_allocProcessorRegister(IDX_TOSL,"TOSL", PO_SFR_REGISTER, 0x80); + pic16_pc_tosh.r = pic16_allocProcessorRegister(IDX_TOSH,"TOSH", PO_SFR_REGISTER, 0x80); + pic16_pc_tosu.r = pic16_allocProcessorRegister(IDX_TOSU,"TOSU", PO_SFR_REGISTER, 0x80); + + pic16_pc_tblptrl.r = pic16_allocProcessorRegister(IDX_TBLPTRL,"TBLPTRL", PO_SFR_REGISTER, 0x80); // patch 15 + pic16_pc_tblptrh.r = pic16_allocProcessorRegister(IDX_TBLPTRH,"TBLPTRH", PO_SFR_REGISTER, 0x80); // patch 15 + pic16_pc_tblptru.r = pic16_allocProcessorRegister(IDX_TBLPTRU,"TBLPTRU", PO_SFR_REGISTER, 0x80); // patch 15 + pic16_pc_tablat.r = pic16_allocProcessorRegister(IDX_TABLAT,"TABLAT", PO_SFR_REGISTER, 0x80); // patch 15 + // pic16_pc_fsr0.r = pic16_allocProcessorRegister(IDX_FSR0,"FSR0", PO_FSR0, 0x80); // deprecated ! @@ -2594,7 +2824,19 @@ void pic16_pCodeInitRegisters(void) pic16_pc_intcon.rIdx = IDX_INTCON; pic16_pc_pcl.rIdx = IDX_PCL; pic16_pc_pclath.rIdx = IDX_PCLATH; + pic16_pc_pclatu.rIdx = IDX_PCLATU; pic16_pc_wreg.rIdx = IDX_WREG; + pic16_pc_bsr.rIdx = IDX_BSR; + + pic16_pc_tosl.rIdx = IDX_TOSL; + pic16_pc_tosh.rIdx = IDX_TOSH; + pic16_pc_tosu.rIdx = IDX_TOSU; + + pic16_pc_tblptrl.rIdx = IDX_TBLPTRL; // patch 15 + pic16_pc_tblptrh.rIdx = IDX_TBLPTRH; // patch 15 + pic16_pc_tblptru.rIdx = IDX_TBLPTRU; // patch 15 + pic16_pc_tablat.rIdx = IDX_TABLAT; // patch 15 + // pic16_pc_fsr0.rIdx = IDX_FSR0; pic16_pc_fsr0l.rIdx = IDX_FSR0L; pic16_pc_fsr0h.rIdx = IDX_FSR0H; @@ -2621,7 +2863,7 @@ void pic16_pCodeInitRegisters(void) pic16_pc_prodh.rIdx = IDX_PRODH; pic16_pc_kzero.r = pic16_allocInternalRegister(IDX_KZ,"KZ",PO_GPR_REGISTER,0); - pic16_pc_ssave.r = pic16_allocInternalRegister(IDX_SSAVE,"SSAVE", PO_GPR_REGISTER, 0x80); + pic16_pc_ssave.r = pic16_allocInternalRegister(IDX_SSAVE,"SSAVE", PO_GPR_REGISTER, 0); pic16_pc_wsave.r = pic16_allocInternalRegister(IDX_WSAVE,"WSAVE", PO_GPR_REGISTER, 0); pic16_pc_kzero.rIdx = IDX_KZ; @@ -2755,6 +2997,14 @@ void pic16initMnemonics(void) pic16Mnemonics[POC_SUBFWB_D1] = &pic16_pciSUBFWB_D1; pic16Mnemonics[POC_SWAPF] = &pic16_pciSWAPF; pic16Mnemonics[POC_SWAPFW] = &pic16_pciSWAPFW; + pic16Mnemonics[POC_TBLRD] = &pic16_pciTBLRD; // patch 15 + pic16Mnemonics[POC_TBLRD_POSTINC] = &pic16_pciTBLRD_POSTINC; // + pic16Mnemonics[POC_TBLRD_POSTDEC] = &pic16_pciTBLRD_POSTDEC; // + pic16Mnemonics[POC_TBLRD_PREINC] = &pic16_pciTBLRD_PREINC; // + pic16Mnemonics[POC_TBLWT] = &pic16_pciTBLWT; // + pic16Mnemonics[POC_TBLWT_POSTINC] = &pic16_pciTBLWT_POSTINC; // + pic16Mnemonics[POC_TBLWT_POSTDEC] = &pic16_pciTBLWT_POSTDEC; // + pic16Mnemonics[POC_TBLWT_PREINC] = &pic16_pciTBLWT_PREINC; // patch 15 pic16Mnemonics[POC_TSTFSZ] = &pic16_pciTSTFSZ; pic16Mnemonics[POC_XORLW] = &pic16_pciXORLW; pic16Mnemonics[POC_XORWF] = &pic16_pciXORWF; @@ -3327,12 +3577,12 @@ pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...) char *lbp=buffer; pcad = Safe_calloc(1, sizeof(pCodeAsmDir)); - pcad->pc.type = PC_ASMDIR; - pcad->pc.prev = pcad->pc.next = NULL; - pcad->pc.pb = NULL; + pcad->pci.pc.type = PC_ASMDIR; + pcad->pci.pc.prev = pcad->pci.pc.next = NULL; + pcad->pci.pc.pb = NULL; - pcad->pc.destruct = genericDestruct; - pcad->pc.print = genericPrint; + pcad->pci.pc.destruct = genericDestruct; + pcad->pci.pc.print = genericPrint; if(asdir && *asdir) { @@ -3707,6 +3957,64 @@ pCodeOp *pic16_newpCodeOp(char *name, PIC_OPTYPE type) return pcop; } + +typedef struct DBdata + { + int count; + char buffer[256]; + } DBdata; + +struct DBdata DBd; +static int DBd_init = -1; + +/*-----------------------------------------------------------------*/ +/* Add "DB" directives to a pBlock */ +/*-----------------------------------------------------------------*/ +void pic16_emitDB(pBlock *pb, char c) +{ + int l; + if (DBd_init<0) // we need to initialize + { + DBd_init = 0; + DBd.count = 0; + DBd.buffer[0] = '\0'; + } + + l = strlen(DBd.buffer); + + if (DBd.count>0) + { + sprintf(DBd.buffer+l,", 0x%02x", c & 0xff); + } + else + { + sprintf(DBd.buffer,"0x%02x", c & 0xff); + } + + DBd.count++; + + if (DBd.count>=16) + { + pic16_addpCode2pBlock(pb,pic16_newpCodeAsmDir("DB", "%s", DBd.buffer)); + DBd.count = 0; + DBd.buffer[0] = '\0'; + } + +} + +/*-----------------------------------------------------------------*/ +/* Flush pending "DB" data to a pBlock */ +/*-----------------------------------------------------------------*/ +void pic16_flushDB(pBlock *pb) +{ + if (DBd.count>0) + { + pic16_addpCode2pBlock(pb,pic16_newpCodeAsmDir("DB", "%s", DBd.buffer)); + DBd.count = 0; + DBd.buffer[0] = '\0'; + } +} + /*-----------------------------------------------------------------*/ /*-----------------------------------------------------------------*/ void pic16_pCodeConstString(char *name, char *value) @@ -3728,10 +4036,9 @@ void pic16_pCodeConstString(char *name, char *value) pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(name,-1)); do { - pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(*value))); + pic16_emitDB(pb, *value); }while (*value++); - - + pic16_flushDB(pb); } /*-----------------------------------------------------------------*/ @@ -3889,7 +4196,7 @@ void pic16_printpBlock(FILE *of, pBlock *pb) if(pb->dbName == 'A') { absSym *ab; for(ab=setFirstItem(absSymSet); ab; ab=setNextItem(absSymSet)) - if(strcmp(ab->name, PCF(pc)->fname)) { + if(!strcmp(ab->name, PCF(pc)->fname)) { fprintf(of, "\t0X%06X", ab->address); break; } @@ -4277,7 +4584,13 @@ static char *pic16_pCode2str(char *str, size_t size, pCode *pc) SAFE_snprintf(&s,&size,";#CSRC\t%s %d\t%s\n", PCCS(pc)->file_name, PCCS(pc)->line_number, PCCS(pc)->line); break; case PC_ASMDIR: - SAFE_snprintf(&s,&size,"\t%s\t%s\n", PCAD(pc)->directive, PCAD(pc)->arg?PCAD(pc)->arg:""); + if(PCAD(pc)->directive) { + SAFE_snprintf(&s,&size,"\t%s%s%s\n", PCAD(pc)->directive, PCAD(pc)->arg?"\t":"", PCAD(pc)->arg?PCAD(pc)->arg:""); + } else + if(PCAD(pc)->arg) { + /* special case to handle inline labels without a tab */ + SAFE_snprintf(&s,&size,"%s\n", PCAD(pc)->arg); + } break; case PC_BAD: @@ -4360,16 +4673,23 @@ static void genericPrint(FILE *of, pCode *pc) case PC_CSOURCE: fprintf(of,";#CSRC\t%s %d\t\t%s\n", PCCS(pc)->file_name, PCCS(pc)->line_number, PCCS(pc)->line); break; + case PC_ASMDIR: { - pBranch *pbl = PCAD(pc)->label; + pBranch *pbl = PCAD(pc)->pci.label; while(pbl && pbl->pc) { if(pbl->pc->type == PC_LABEL) pCodePrintLabel(of, pbl->pc); pbl = pbl->next; } } - fprintf(of, "\t%s\t%s\n", PCAD(pc)->directive, PCAD(pc)->arg?PCAD(pc)->arg:""); + if(PCAD(pc)->directive) { + fprintf(of, "\t%s%s%s\n", PCAD(pc)->directive, PCAD(pc)->arg?"\t":"", PCAD(pc)->arg?PCAD(pc)->arg:""); + } else + if(PCAD(pc)->arg) { + /* special case to handle inline labels without tab */ + fprintf(of, "%s\n", PCAD(pc)->arg); + } break; case PC_LABEL: @@ -4470,6 +4790,7 @@ static void unlinkpCodeFromBranch(pCode *pcl , pCode *pc) while(b) { if(b->pc == pc) { //fprintf (stderr, "found label\n"); + //pc->print(stderr, pc); /* Found a label */ if(bprev) { @@ -4651,7 +4972,9 @@ static int compareLabel(pCode *pc, pCodeOpLabel *pcop_label) if( ((pCodeLabel *)pc)->key == pcop_label->key) return TRUE; } - if(pc->type == PC_OPCODE) { + if((pc->type == PC_OPCODE) + || (pc->type == PC_ASMDIR) + ) { pbr = PCI(pc)->label; while(pbr) { if(pbr->pc->type == PC_LABEL) { @@ -4754,6 +5077,9 @@ static pCode * findPrevpCode(pCode *pc, PC_TYPE pct) return NULL; } + + +//#define PCODE_DEBUG /*-----------------------------------------------------------------*/ /* pic16_findNextInstruction - given a pCode, find the next instruction */ /* in the linked list */ @@ -4763,7 +5089,10 @@ pCode * pic16_findNextInstruction(pCode *pci) pCode *pc = pci; while(pc) { - if((pc->type == PC_OPCODE) || (pc->type == PC_WILD)) + if((pc->type == PC_OPCODE) + || (pc->type == PC_WILD) + || (pc->type == PC_ASMDIR) + ) return pc; #ifdef PCODE_DEBUG @@ -4783,8 +5112,29 @@ pCode * pic16_findNextInstruction(pCode *pci) /*-----------------------------------------------------------------*/ pCode * pic16_findPrevInstruction(pCode *pci) { - return findPrevpCode(pci, PC_OPCODE); + pCode *pc = pci; + + while(pc) { + if((pc->type == PC_OPCODE) + || (pc->type == PC_WILD) + || (pc->type == PC_ASMDIR) + ) + return pc; + + +#ifdef PCODE_DEBUG + fprintf(stderr,"pic16_findPrevInstruction: "); + printpCode(stderr, pc); +#endif + pc = pc->next; + } + + //fprintf(stderr,"Couldn't find instruction\n"); + return NULL; } + +#undef PCODE_DEBUG + #if 0 /*-----------------------------------------------------------------*/ /* findFunctionEnd - given a pCode find the end of the function */ @@ -5510,7 +5860,7 @@ static void insertBankSwitch(int position, pCode *pc, int bsr) if(PCI(pc)->label) { // fprintf(stderr, "%s:%d: moving label due to bank switch directive src= 0x%p dst= 0x%p\n", // __FILE__, __LINE__, pc, new_pc); - PCAD(new_pc)->label = PCI(pc)->label; + PCAD(new_pc)->pci.label = PCI(pc)->label; PCI(pc)->label = NULL; } @@ -5829,6 +6179,8 @@ void pic16_pBlockMergeLabels(pBlock *pb) if((pcnext = pic16_findNextInstruction(pc) )) { +// pcnext->print(stderr, pcnext); + // Unlink the pCode label from it's pCode chain pic16_unlinkpCode(pc); diff --git a/src/pic16/pcode.h b/src/pic16/pcode.h index 4d2ce533..1b93a49e 100644 --- a/src/pic16/pcode.h +++ b/src/pic16/pcode.h @@ -268,6 +268,14 @@ typedef enum POC_SWAPF, POC_SWAPFW, // POC_TRIS , // To be removed + POC_TBLRD, // patch 15 + POC_TBLRD_POSTINC, // + POC_TBLRD_POSTDEC, // + POC_TBLRD_PREINC, // + POC_TBLWT, // + POC_TBLWT_POSTINC, // + POC_TBLWT_POSTDEC, // + POC_TBLWT_PREINC, // patch 15 POC_TSTFSZ, POC_XORLW, POC_XORWF, @@ -501,17 +509,6 @@ typedef struct pCodeCSource pCodeAsmDir **************************************************/ -typedef struct pCodeAsmDir -{ - pCode pc; - - char *directive; - char *arg; - - pBranch *label; -} pCodeAsmDir; - - /************************************************* pCodeFlow @@ -623,6 +620,20 @@ typedef struct pCodeInstruction } pCodeInstruction; + +/************************************************* + pCodeAsmDir +**************************************************/ + +typedef struct pCodeAsmDir +{ + pCodeInstruction pci; + + char *directive; + char *arg; +} pCodeAsmDir; + + /************************************************* pCodeLabel **************************************************/ @@ -897,6 +908,10 @@ void pic16_printCallTree(FILE *of); void pCodePeepInit(void); void pic16_pBlockConvert2ISR(pBlock *pb); void pic16_pBlockConvert2Absolute(pBlock *pb); +void pic16_emitDB(pBlock *pb, char c); // Add DB directives to a pBlock +void pic16_flushDB(pBlock *pb); // Add pending DB data to a pBlock + +pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...); pCodeOp *pic16_newpCodeOpLabel(char *name, int key); pCodeOp *pic16_newpCodeOpImmd(char *name, int offset, int index, int code_space); @@ -923,7 +938,15 @@ extern pCodeOpReg pic16_pc_status; extern pCodeOpReg pic16_pc_intcon; extern pCodeOpReg pic16_pc_pcl; extern pCodeOpReg pic16_pc_pclath; +extern pCodeOpReg pic16_pc_pclatu; // patch 14 extern pCodeOpReg pic16_pc_wreg; +extern pCodeOpReg pic16_pc_tosl; // patch 14 +extern pCodeOpReg pic16_pc_tosh; // patch 14 +extern pCodeOpReg pic16_pc_tosu; // patch 14 +extern pCodeOpReg pic16_pc_tblptrl; // patch 15 +extern pCodeOpReg pic16_pc_tblptrh; // +extern pCodeOpReg pic16_pc_tblptru; // +extern pCodeOpReg pic16_pc_tablat; // patch 15 extern pCodeOpReg pic16_pc_bsr; extern pCodeOpReg pic16_pc_fsr0; extern pCodeOpReg pic16_pc_fsr0l; diff --git a/src/pic16/ralloc.c b/src/pic16/ralloc.c index 078774ac..6a58ede3 100644 --- a/src/pic16/ralloc.c +++ b/src/pic16/ralloc.c @@ -571,6 +571,15 @@ pic16_allocDirReg (operand *op ) name = OP_SYMBOL (op)->rname[0] ? OP_SYMBOL (op)->rname : OP_SYMBOL (op)->name; + if(!SPEC_OCLS( OP_SYM_ETYPE(op))) { // patch 13 + if(pic16_debug_verbose) // + { // + fprintf(stderr, "%s:%d symbol %s(r:%s) is not assigned to a memmap\n", __FILE__, __LINE__, // + OP_SYMBOL(op)->name, OP_SYMBOL(op)->rname); // + } // + return NULL; // + } // patch 13 + debugLog ("%s symbol name %s\n", __FUNCTION__,name); // fprintf(stderr, "%s symbol name %s\n", __FUNCTION__,name); @@ -638,6 +647,7 @@ pic16_allocDirReg (operand *op ) if(pic16_debug_verbose) fprintf(stderr, "%s:%d symbol %s in codespace\n", __FILE__, __LINE__, OP_SYMBOL(op)->name); + debugLog("%s:%d sym: %s in codespace\n", __FUNCTION__, __LINE__, OP_SYMBOL(op)->name); return NULL; } @@ -646,6 +656,15 @@ pic16_allocDirReg (operand *op ) if(SPEC_SCLS(OP_SYM_ETYPE(op)))regtype = REG_SFR; + if(!IN_DIRSPACE( SPEC_OCLS( OP_SYM_ETYPE(op)))) { // patch 13 + if(pic16_debug_verbose) // + { // + fprintf(stderr, "%s:%d symbol %s NOT in dirspace\n", __FILE__, __LINE__, // + OP_SYMBOL(op)->name); // + } // +// return NULL; // + } // patch 13 + reg = newReg(regtype, PO_DIR, rDirectIdx++, name,getSize (OP_SYMBOL (op)->type),0, op); debugLog ("%d -- added %s to hash, size = %d\n", __LINE__, name,reg->size); @@ -676,6 +695,12 @@ pic16_allocDirReg (operand *op ) if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) { reg->isFixed = 1; reg->address = SPEC_ADDR ( OP_SYM_ETYPE(op)); + + /* work around for user defined registers in access bank */ + if((reg->address < 0x80) + || (reg->address >= 0xf80)) + reg->accessBank = 1; + debugLog (" -- and it is at a fixed address 0x%02x\n",reg->address); } @@ -928,6 +953,7 @@ extern void pic16_dump_equates(FILE *of, set *equs); //extern void pic16_dump_map(void); extern void pic16_dump_section(FILE *of, set *section, int fix); extern void pic16_dump_int_registers(FILE *of, set *section); +extern void pic16_dump_idata(FILE *of, set *idataSymSet); static void packBits(set *bregs) { @@ -1081,14 +1107,17 @@ void pic16_writeUsedRegs(FILE *of) /* dump equates */ pic16_dump_equates(of, pic16_equ_data); - + + /* dump initialised data */ + pic16_dump_idata(of, idataSymSet); + /* dump internal registers */ pic16_dump_int_registers(of, pic16_int_regs); /* dump other variables */ pic16_dump_section(of, pic16_rel_udata, 0); pic16_dump_section(of, pic16_fix_udata, 1); - + } #if 0 @@ -2563,8 +2592,9 @@ regTypeNum () #else if(IS_CODEPTR (sym->type)) { #endif - debugLog (" %d const pointer type requires %d registers, changing to 2\n",__LINE__,sym->nRegs); - sym->nRegs = 2; + // what IS this ???? (HJD) + debugLog (" %d const pointer type requires %d registers, changing to 3\n",__LINE__,sym->nRegs); // patch 14 + sym->nRegs = 3; // patch 14 } if (sym->nRegs > 4) { @@ -2985,6 +3015,13 @@ pack: } +#define NO_packRegsForAccUse +#define NO_packRegsForSupport +#define NO_packRegsForOneuse +#define NO_cast_peep + + +#ifndef NO_packRegsForSupport /*-----------------------------------------------------------------*/ /* findAssignToSym : scanning backwards looks for first assig found */ /*-----------------------------------------------------------------*/ @@ -3062,7 +3099,10 @@ findAssignToSym (operand * op, iCode * ic) } +#endif + +#ifndef NO_packRegsForSupport /*-----------------------------------------------------------------*/ /* packRegsForSupport :- reduce some registers for support calls */ /*-----------------------------------------------------------------*/ @@ -3140,10 +3180,12 @@ right: return change; } +#endif -#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly) +#define IS_OP_RUONLY(x) (x && IS_SYMOP(x) && OP_SYMBOL(x)->ruonly) +#ifndef NO_packRegsForOneuse /*-----------------------------------------------------------------*/ /* packRegsForOneuse : - will reduce some registers for single Use */ /*-----------------------------------------------------------------*/ @@ -3273,6 +3315,8 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp) return sic; } +#endif + /*-----------------------------------------------------------------*/ /* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */ @@ -3304,11 +3348,12 @@ isBitwiseOptimizable (iCode * ic) return FALSE; } + +#ifndef NO_packRegsForAccUse + /*-----------------------------------------------------------------*/ /* packRegsForAccUse - pack registers for acc use */ /*-----------------------------------------------------------------*/ -#if 0 - static void packRegsForAccUse (iCode * ic) { @@ -3464,6 +3509,7 @@ accuse: } #endif + /*-----------------------------------------------------------------*/ /* packForPush - hueristics to reduce iCode for pushing */ /*-----------------------------------------------------------------*/ @@ -3582,14 +3628,6 @@ static void isData(sym_link *sl) } -/* set if conditional to 1 to disable optimizations */ - -#define NO_packRegsForAccUse -#if 0 -#define NO_packRegsForSupport -#define NO_packRegsForOneuse -//#define NO_cast_peep -#endif /*--------------------------------------------------------------------*/ /* pic16_packRegisters - does some transformations to reduce */ /* register pressure */ @@ -3616,7 +3654,8 @@ pic16_packRegisters (eBBlock * ebp) // debugLog("%d\n", __LINE__); /* find assignment of the form TrueSym := iTempNN:1 */ /* see BUGLOG0001 for workaround with the CAST - VR */ - if ((ic->op == '=' || ic->op == CAST) && !POINTER_SET (ic)) + if ( (ic->op == '=' || ic->op == CAST) && !POINTER_SET (ic) ) // patch 11 +// if ( (ic->op == '=') && !POINTER_SET (ic) ) // patch 11 change += packRegsForAssign (ic, ebp); /* debug stuff */ if (ic->op == '=') @@ -4040,6 +4079,10 @@ pic16_assignRegisters (eBBlock ** ebbs, int count) /* and serially allocate registers */ serialRegAssign (ebbs, count); +// debugLog ("ebbs after serialRegAssign:\n"); +// dumpEbbsToDebug (ebbs, count); + + //pic16_freeAllRegs(); /* if stack was extended then tell the user */ diff --git a/src/pic16/ralloc.h b/src/pic16/ralloc.h index b337893f..3d7bc269 100644 --- a/src/pic16/ralloc.h +++ b/src/pic16/ralloc.h @@ -126,37 +126,48 @@ regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alia #define IDX_PCL 0xff9 #define IDX_STATUS 0xfd8 #define IDX_PCLATH 0xffa +#define IDX_PCLATU 0xffb /* patch 14 */ #define IDX_INTCON 0xff2 #define IDX_WREG 0xfe8 +#define IDX_BSR 0xfe0 + +#define IDX_TOSL 0xffd /* patch 14 */ +#define IDX_TOSH 0xffe /* patch 14 */ +#define IDX_TOSU 0xfff /* patch 14 */ + +#define IDX_TBLPTRL 0xff6 /* patch 15 */ +#define IDX_TBLPTRH 0xff7 /* patch 15 */ +#define IDX_TBLPTRU 0xff8 /* patch 15 */ +#define IDX_TABLAT 0xff5 /* patch 15 */ #define IDX_FSR0 0xfe9 #define IDX_FSR0L 0xfe9 #define IDX_FSR0H 0xfea -#define IDX_FSR1L 0xfe1 -#define IDX_FSR1H 0xfe2 -#define IDX_FSR2L 0xfd9 -#define IDX_FSR2H 0xfda - -#define IDX_INDF0 0xfef -#define IDX_POSTINC0 0xfee -#define IDX_POSTDEC0 0xfed -#define IDX_PREINC0 0xfec -#define IDX_PLUSW0 0xfeb - -#define IDX_INDF1 0xfe7 -#define IDX_POSTINC1 0xfe6 -#define IDX_POSTDEC1 0xfe5 -#define IDX_PREINC1 0xfe4 -#define IDX_PLUSW1 0xfe3 - -#define IDX_INDF2 0xfdf -#define IDX_POSTINC2 0xfde -#define IDX_POSTDEC2 0xfdd -#define IDX_PREINC2 0xfdc -#define IDX_PLUSW2 0xfdb - -#define IDX_PRODL 0xff3 -#define IDX_PRODH 0xff4 +#define IDX_FSR1L 0xfe1 +#define IDX_FSR1H 0xfe2 +#define IDX_FSR2L 0xfd9 +#define IDX_FSR2H 0xfda + +#define IDX_INDF0 0xfef +#define IDX_POSTINC0 0xfee +#define IDX_POSTDEC0 0xfed +#define IDX_PREINC0 0xfec +#define IDX_PLUSW0 0xfeb + +#define IDX_INDF1 0xfe7 +#define IDX_POSTINC1 0xfe6 +#define IDX_POSTDEC1 0xfe5 +#define IDX_PREINC1 0xfe4 +#define IDX_PLUSW1 0xfe3 + +#define IDX_INDF2 0xfdf +#define IDX_POSTINC2 0xfde +#define IDX_POSTDEC2 0xfdd +#define IDX_PREINC2 0xfdc +#define IDX_PLUSW2 0xfdb + +#define IDX_PRODL 0xff3 +#define IDX_PRODH 0xff4 #define IDX_KZ 0x7fff /* Known zero - actually just a general purpose reg. */ #define IDX_WSAVE 0x7ffe