+2004-03-01 Vangelis Rokas <vrokas AT otenet.gr>
+
+ * 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 <hans.dorn AT apl-landau.de>
+ patch applied by Vangelis Rokas <vrokas AT otenet.gr>
+
+ * 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 <borut.razem AT siol.net>
* src/Makefile.in, src/SDCCutil.c, support/Util/findme.c,
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");
}
+#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)
return 0;
}
}
+
#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;
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)) : "-"),
((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)
return aop;
}
+#if 0 // patch 14
/* special case for a function */
if (IS_FUNC(sym->type)) {
sym->aop = aop = newAsmop(AOP_IMMD);
DEBUGpic16_emitcode(";","%d size = %d, name =%s",__LINE__,aop->size,sym->rname);
return aop;
}
+#endif // patch 14
/* only remaining is far space */
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);
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;
/*-----------------------------------------------------------------*/
pCodeOp *pic16_popGetImmd(char *name, unsigned int offset, int index)
{
-
return pic16_newpCodeOpImmd(name, offset,index, 0);
}
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";
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 */;
}
-
+#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--) {
} else
pic16_emitcode("push","%s",l);
}
-#endif
}
+#endif // patch 14
void pic16_loadFromReturn(operand *op, int offset, pCodeOp *src)
{
{
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) {
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)));
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)));
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 */
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 */
/*-----------------------------------------------------------------*/
unsaveRegisters (ic);
}
+#endif // patch 14
+
/*-----------------------------------------------------------------*/
/* resultRemat - result is rematerializable */
_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:
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);
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;
}
* 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 ));
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 */
// (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(
// 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)));
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));
*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++;
}
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);
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)));
}
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
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))
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);
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);
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++;
/* 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);
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++;
}
}
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__);
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;i<size;i++) {
+ pic16_emitpcode(POC_MOVLW, pic16_popGet(AOP(right),i));
+ if(i < size-1)
+ pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_postinc0));
+ else
+ pic16_emitpcode(POC_MOVWF, pic16_popCopyReg(&pic16_pc_indf0));
+ }
+ } else {
+ // copy regs
+
+ for(i=0;i<size;i++) {
+ if(i < size-1)
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(right),i),
+ pic16_popCopyReg(&pic16_pc_postinc0)));
+ else
+ pic16_emitpcode(POC_MOVFF, pic16_popGet2p(pic16_popGet(AOP(right),i),
+ pic16_popCopyReg(&pic16_pc_indf0)));
}
- offset++;
}
goto release;
}
}
}
offset++;
- }
+ }
}
release:
pic16_emitpcode(POC_BTFSS, pic16_popGet(AOP(right),0));
pic16_emitpcode(POC_INCF, pic16_popGet(AOP(result),0));
}
+ } else if ( (AOP_TYPE(right) == AOP_PCODE) && (AOP(right)->aopu.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__);
/* 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 {
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
extern int initsfpnt;
+set *idataSymSet=NULL;
+
extern DEFSETFUNC (closeTmpFiles);
extern DEFSETFUNC (rmTmpFiles);
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 );
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));
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;
}
}
if(!pb)
return 0;
- fprintf(stderr, "%s\n",__FUNCTION__);
+ // fprintf(stderr, "%s\n",__FUNCTION__);
if (!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
else {
//printChar (oFile, s, strlen (s) + 1);
- for(remain=0; remain<strlen(s); remain++) {
- pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(s[remain])));
- //fprintf(stderr,"0x%02x ",s[remain]);
- }
+ for(remain=0; remain<strlen(s); remain++)
+ {
+ // pic16_addpCode2pBlock(pb,pic16_newpCode(POC_RETLW,pic16_newpCodeOpLit(s[remain])));
+ //fprintf(stderr,"0x%02x ",s[remain]);
+ pic16_emitDB(pb, s[remain]);
+ }
//fprintf(stderr,"\n");
}
return 1;
if(!pb)
return;
+
/* take care of the special case */
/* array of characters can be init */
/* by a string */
if (IS_CHAR (type->next)) {
- //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;
/* 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 */
pic16_addpCode2pBlock(pb,pic16_newpCodeLabel(sym->rname,-1));
printIval (sym, sym->type, sym->ival, pb);
+ pic16_flushDB(pb);
noAlloc--;
}
else
unsigned int address;
} absSym;
+
extern set *absSymSet;
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};
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};
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,
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 !
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;
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;
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;
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) {
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)
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);
}
/*-----------------------------------------------------------------*/
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;
}
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:
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:
while(b) {
if(b->pc == pc) {
//fprintf (stderr, "found label\n");
+ //pc->print(stderr, pc);
/* Found a label */
if(bprev) {
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) {
return NULL;
}
+
+
+//#define PCODE_DEBUG
/*-----------------------------------------------------------------*/
/* pic16_findNextInstruction - given a pCode, find the next instruction */
/* in the linked list */
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
/*-----------------------------------------------------------------*/
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 */
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;
}
if((pcnext = pic16_findNextInstruction(pc) )) {
+// pcnext->print(stderr, pcnext);
+
// Unlink the pCode label from it's pCode chain
pic16_unlinkpCode(pc);
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,
pCodeAsmDir
**************************************************/
-typedef struct pCodeAsmDir
-{
- pCode pc;
-
- char *directive;
- char *arg;
-
- pBranch *label;
-} pCodeAsmDir;
-
-
/*************************************************
pCodeFlow
} pCodeInstruction;
+
+/*************************************************
+ pCodeAsmDir
+**************************************************/
+
+typedef struct pCodeAsmDir
+{
+ pCodeInstruction pci;
+
+ char *directive;
+ char *arg;
+} pCodeAsmDir;
+
+
/*************************************************
pCodeLabel
**************************************************/
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);
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;
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);
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;
}
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);
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);
}
//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)
{
/* 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
#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) {
}
+#define NO_packRegsForAccUse
+#define NO_packRegsForSupport
+#define NO_packRegsForOneuse
+#define NO_cast_peep
+
+
+#ifndef NO_packRegsForSupport
/*-----------------------------------------------------------------*/
/* findAssignToSym : scanning backwards looks for first assig found */
/*-----------------------------------------------------------------*/
}
+#endif
+
+#ifndef NO_packRegsForSupport
/*-----------------------------------------------------------------*/
/* packRegsForSupport :- reduce some registers for support calls */
/*-----------------------------------------------------------------*/
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 */
/*-----------------------------------------------------------------*/
return sic;
}
+#endif
+
/*-----------------------------------------------------------------*/
/* isBitwiseOptimizable - requirements of JEAN LOUIS VERN */
return FALSE;
}
+
+#ifndef NO_packRegsForAccUse
+
/*-----------------------------------------------------------------*/
/* packRegsForAccUse - pack registers for acc use */
/*-----------------------------------------------------------------*/
-#if 0
-
static void
packRegsForAccUse (iCode * ic)
{
}
#endif
+
/*-----------------------------------------------------------------*/
/* packForPush - hueristics to reduce iCode for pushing */
/*-----------------------------------------------------------------*/
}
-/* 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 */
// 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 == '=')
/* 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 */
#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