#ifdef HAVE_ENDIAN_H
#include <endian.h>
#else
+#ifndef __BORLANDC__
#warning "Cannot determine ENDIANESS of this machine assuming LITTLE_ENDIAN"
#warning "If you running sdcc on an INTEL 80x86 Platform you are okay"
#endif
#endif
+#endif
#include "common.h"
#include "SDCCpeeph.h"
static char *one = "#0x01";
static char *spname ;
-static char *fReturn8051[] = {"dpl","dph","b","a" };
-static char *fReturn390[] = {"dpl","dph","dpx", "b","a" };
+char *fReturn8051[] = {"dpl","dph","b","a" };
+char *fReturn390[] = {"dpl","dph","dpx", "b","a" };
unsigned fReturnSize = 4; /* shared with ralloc.c */
-static char **fReturn = fReturn8051;
+char **fReturn = fReturn8051;
static char *accUse[] = {"a","b"};
static short rbank = -1;
return aop;
}
+static void genSetDPTR(int n)
+{
+ if (!n)
+ {
+ emitcode(";", "Select standard DPTR");
+ emitcode("mov", "dps, #0x00");
+ }
+ else
+ {
+ emitcode(";", "Select alternate DPTR");
+ emitcode("mov", "dps, #0x01");
+ }
+}
+
/*-----------------------------------------------------------------*/
/* pointerCode - returns the code for a pointer type */
/*-----------------------------------------------------------------*/
/* assign depending on the storage class */
/* if it is on the stack or indirectly addressable */
/* space we need to assign either r0 or r1 to it */
- if (sym->onStack || sym->iaccess) {
+ if ((sym->onStack && !options.stack10bit) || sym->iaccess) {
sym->aop = aop = newAsmop(0);
aop->aopu.aop_ptr = getFreePtr(ic,&aop,result);
aop->size = getSize(sym->type);
if (aop->type != AOP_STK) {
if (sym->onStack) {
-
if ( _G.accInUse )
emitcode("push","acc");
if ( _G.accInUse )
emitcode("pop","acc");
-
} else
emitcode("mov","%s,#%s",
aop->aopu.aop_ptr->name,
aop->aopu.aop_stk = sym->stack;
return aop;
}
+
+ if (sym->onStack && options.stack10bit)
+ {
+ /* It's on the 10 bit stack, which is located in
+ * far data space.
+ */
+
+ if ( _G.accInUse )
+ emitcode("push","acc");
+
+ emitcode("mov","a,_bp");
+ emitcode("add","a,#0x%02x",
+ ((sym->stack < 0) ?
+ ((char)(sym->stack - _G.nRegsSaved )) :
+ ((char)sym->stack)) & 0xff);
+
+ genSetDPTR(1);
+ emitcode ("mov","dpx1,#0x40");
+ emitcode ("mov","dph1,#0x00");
+ emitcode ("mov","dpl1, a");
+ genSetDPTR(0);
+
+ if ( _G.accInUse )
+ emitcode("pop","acc");
+
+ sym->aop = aop = newAsmop(AOP_DPTR2);
+ aop->size = getSize(sym->type);
+ return aop;
+ }
/* if in bit space */
if (IN_BITSPACE(space)) {
bitVectUnSetBit(ic->rUsed,R1_IDX);
getFreePtr(ic,&aop,FALSE);
+
+ if (options.stack10bit)
+ {
+ /* I'm not sure what to do here yet... */
+ /* #STUB */
+ fprintf(stderr,
+ "*** Warning: probably generating bad code for "
+ "10 bit stack mode.\n");
+ }
+
if (stk) {
emitcode ("mov","a,_bp");
emitcode ("add","a,#0x%02x",((char)stk) & 0xff);
emitcode ("mov","%s,a",aop->aopu.aop_ptr->name);
- } else
+ } else {
emitcode ("mov","%s,_bp",aop->aopu.aop_ptr->name);
+ }
while (sz--) {
emitcode("pop","acc");
return rs;
case AOP_DPTR:
+ case AOP_DPTR2:
+
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR(1);
+ }
+
while (offset > aop->coff) {
emitcode ("inc","dptr");
aop->coff++;
emitcode("clr","a");
emitcode("movc","a,@a+dptr");
}
- else
+ else {
emitcode("movx","a,@dptr");
+ }
+
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR(0);
+ }
+
return (dname ? "acc" : "a");
break;
case AOP_DPTR:
+ case AOP_DPTR2:
+
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR(1);
+ }
+
if (aop->code) {
werror(E_INTERNAL_ERROR,__FILE__,__LINE__,
"aopPut writting to code space");
MOVA(s);
emitcode ("movx","@dptr,a");
+
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR(0);
+ }
break;
case AOP_R0:
if (strcmp(s,"a")) {
MOVA(s);
- }
- emitcode("cjne","a,#0x01,%05d$",lbl->key+100);
- emitcode("","%05d$:",lbl->key+100);
+ }
+ emitcode("clr","c");
+ emitcode("jz","%05d$",lbl->key+100);
emitcode("cpl","c");
+ emitcode("","%05d$:",lbl->key+100);
emitcode("mov","%s,c",aop->aopu.aop_dir);
}
}
while (size--)
emitcode("dec","%s",aop->aopu.aop_ptr->name);
break;
- case AOP_DPTR :
+ case AOP_DPTR :
+ case AOP_DPTR2:
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR(1);
+ }
while (size--)
+ {
emitcode("lcall","__decdptr");
+ }
+
+ if (aop->type == AOP_DPTR2)
+ {
+ genSetDPTR(0);
+ }
break;
}
AOP_TYPE(x) == AOP_R0))
#define AOP_NEEDSACC(x) (AOP(x) && (AOP_TYPE(x) == AOP_CRY || \
- AOP_TYPE(x) == AOP_DPTR || AOP(x)->paged))
+ AOP_TYPE(x) == AOP_DPTR || AOP_TYPE(x) == AOP_DPTR2 || \
+ AOP(x)->paged))
#define AOP_INPREG(x) (x && (x->type == AOP_REG && \
(x->aopu.aop_reg[0] == mcs51_regWithIdx(R0_IDX) || \
return 0;
}
+#ifdef __BORLANDC__
+#define STRCASECMP stricmp
+#else
+#define STRCASECMP strcasecmp
+#endif
+
/*-----------------------------------------------------------------*/
/* inExcludeList - return 1 if the string is in exclude Reg list */
/*-----------------------------------------------------------------*/
int i =0;
if (options.excludeRegs[i] &&
- strcasecmp(options.excludeRegs[i],"none") == 0)
+ STRCASECMP(options.excludeRegs[i],"none") == 0)
return FALSE ;
for ( i = 0 ; options.excludeRegs[i]; i++) {
if (options.excludeRegs[i] &&
- strcasecmp(s,options.excludeRegs[i]) == 0)
+ STRCASECMP(s,options.excludeRegs[i]) == 0)
return TRUE;
}
return FALSE ;
if (!inExcludeList("dph"))
emitcode ("push","dph");
if (options.model == MODEL_FLAT24 && !inExcludeList("dpx"))
- emitcode ("push", "dpx");
+ {
+ emitcode ("push", "dpx");
+ /* Make sure we're using standard DPTR */
+ emitcode ("push", "dps");
+ emitcode ("mov", "dps, #0x00");
+ if (options.stack10bit)
+ {
+ /* This ISR could conceivably use DPTR2. Better save it. */
+ emitcode ("push", "dpl1");
+ emitcode ("push", "dph1");
+ emitcode ("push", "dpx1");
+ }
+ }
/* if this isr has no bank i.e. is going to
run with bank 0 , then we need to save more
registers :-) */
emitcode("inc","%s",spname);
}
else
+ {
/* set up the stack */
emitcode ("push","_bp"); /* save the callers stack */
+ }
emitcode ("mov","_bp,%s",spname);
}
symbol *sym = OP_SYMBOL(IC_LEFT(ic));
if (IS_RENT(sym->etype) || options.stackAuto)
+ {
emitcode ("mov","%s,_bp",spname);
+ }
/* if use external stack but some variables were
added to the local stack then decrement the
emitcode("dec","%s",spname);
}
else
+ {
emitcode ("pop","_bp");
+ }
}
/* restore the register bank */
}
if (options.model == MODEL_FLAT24 && !inExcludeList("dpx"))
+ {
+ if (options.stack10bit)
+ {
+ emitcode ("pop", "dpx1");
+ emitcode ("pop", "dph1");
+ emitcode ("pop", "dpl1");
+ }
+ emitcode ("pop", "dps");
emitcode ("pop", "dpx");
+ }
if (!inExcludeList("dph"))
emitcode ("pop","dph");
if (!inExcludeList("dpl"))
while (size--) {
char *l ;
if (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR) {
+ /* #NOCHANGE */
l = aopGet(AOP(IC_LEFT(ic)),offset++,
FALSE,TRUE);
emitcode("push","%s",l);
if (ic->op == LABEL && IC_LABEL(ic)->key == key)
{
- printf("findLabelBackwards = %d\n", count);
+ /* printf("findLabelBackwards = %d\n", count); */
return count;
}
}
- printf("findLabelBackwards: not found.\n");
+ /* printf("findLabelBackwards: not found.\n"); */
return 0;
}
}
/* so dptr know contains the address */
freeAsmop(left,NULL,ic,TRUE);
- aopOp(result,ic,FALSE);
+ aopOp(result,ic,FALSE);
/* if bit then unpack */
if (IS_BITVAR(retype))
emitcode("mov","a,_bp");
emitcode("add","a,#0x%02x",((char) sym->stack & 0xff));
aopPut(AOP(IC_RESULT(ic)),"a",0);
- } else
+ } else {
/* we can just move _bp */
aopPut(AOP(IC_RESULT(ic)),"_bp",0);
+ }
/* fill the result with zero */
size = AOP_SIZE(IC_RESULT(ic)) - 1;
+
+
+ if (options.stack10bit && size < (FPTRSIZE - 1))
+ {
+ fprintf(stderr,
+ "*** warning: pointer to stack var truncated.\n");
+ }
+
offset = 1;
- while (size--)
- aopPut(AOP(IC_RESULT(ic)),zero,offset++);
+ while (size--)
+ {
+ /* Yuck! */
+ if (options.stack10bit && offset == 2)
+ {
+ aopPut(AOP(IC_RESULT(ic)),"#0x40", offset++);
+ }
+ else
+ {
+ aopPut(AOP(IC_RESULT(ic)),zero,offset++);
+ }
+ }
goto release;
}
aopOp(right,ic,FALSE);
/* special case both in far space */
- if (AOP_TYPE(right) == AOP_DPTR &&
+ if ((AOP_TYPE(right) == AOP_DPTR ||
+ AOP_TYPE(right) == AOP_DPTR2) &&
IS_TRUE_SYMOP(result) &&
isOperandInFarSpace(result)) {
-
+
genFarFarAssign (result,right,ic);
- return ;
+ return ;
}
aopOp(result,ic,TRUE);
iCode *ic;
int cln = 0;
- /* Hack-o-matic: change fReturn based on model. */
- if (options.model == MODEL_FLAT24)
- {
- fReturn = fReturn390;
- fReturnSize = 5;
- }
-
lineHead = lineCurr = NULL;
/* if debug information required */