#ifdef HAVE_SYS_ISA_DEFS_H
#include <sys/isa_defs.h>
#else
+#ifdef HAVE_MACHINE_ENDIAN_H
+#include <machine/endian.h>
+#else
#ifdef HAVE_ENDIAN_H
#include <endian.h>
#else
#endif
#endif
#endif
+#endif
#include "common.h"
#include "SDCCpeeph.h"
sym = OP_SYMBOL (op);
-
/* if the type is a conditional */
if (sym->regType == REG_CND)
{
if (sym->ruonly)
{
unsigned i;
+
aop = op->aop = sym->aop = newAsmop (AOP_STR);
aop->size = getSize (sym->type);
for (i = 0; i < fReturnSizeMCS51; i++)
}
{
symbol *lbl = newiTempLabel (NULL);
- emitcode ("clr", "c; oops");
+ emitcode ("clr", "c");
emitcode ("jz", "%05d$", lbl->key + 100);
emitcode ("cpl", "c");
emitcode ("", "%05d$:", lbl->key + 100);
int i;
iCode *ic;
bitVect *rsave;
- sym_link *detype;
/* look for call */
for (ic = lic; ic; ic = ic->next)
/* if the registers have been saved already or don't need to be then
do nothing */
- if (ic->regsSaved || (OP_SYMBOL (IC_LEFT (ic))->calleeSave) ||
- SPEC_NAKED(OP_SYM_ETYPE(IC_LEFT (ic))))
+ if (ic->regsSaved || IFFUNC_CALLEESAVES(OP_SYMBOL(IC_LEFT(ic))->type) ||
+ IFFUNC_ISNAKED(OP_SYM_TYPE(IC_LEFT (ic))))
return;
/* find the registers in use at this time
if (bitVectBitValue (rsave, i))
emitcode ("push", "%s", mcs51_regWithIdx (i)->dname);
}
-
- detype = getSpec (operandType (IC_LEFT (ic)));
-
}
+
/*-----------------------------------------------------------------*/
/* unsaveRegisters - pop the pushed registers */
/*-----------------------------------------------------------------*/
static void
genCall (iCode * ic)
{
- sym_link *detype;
+ sym_link *dtype;
bool restoreBank = FALSE;
bool swapBanks = FALSE;
/* if we are calling a not _naked function that is not using
the same register bank then we need to save the
destination registers on the stack */
- detype = getSpec (operandType (IC_LEFT (ic)));
- if (detype && !SPEC_NAKED(detype) &&
- (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)) &&
- IS_ISR (currFunc->etype))
+ dtype = operandType (IC_LEFT (ic));
+ if (dtype && !IFFUNC_ISNAKED(dtype) &&
+ (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)) &&
+ IFFUNC_ISISR (currFunc->type))
{
if (!ic->bankSaved)
{
/* This is unexpected; the bank should have been saved in
* genFunction.
*/
- saveRBank (SPEC_BANK (detype), ic, FALSE);
+ saveRBank (FUNC_REGBANK (dtype), ic, FALSE);
restoreBank = TRUE;
}
swapBanks = TRUE;
if (swapBanks)
{
emitcode ("mov", "psw,#0x%02x",
- ((SPEC_BANK(detype)) << 3) & 0xff);
+ ((FUNC_REGBANK(dtype)) << 3) & 0xff);
}
/* make the call */
if (swapBanks)
{
emitcode ("mov", "psw,#0x%02x",
- ((SPEC_BANK(currFunc->etype)) << 3) & 0xff);
+ ((FUNC_REGBANK(currFunc->type)) << 3) & 0xff);
}
/* if we need assign a result value */
}
/* if we hade saved some registers then unsave them */
- if (ic->regsSaved && !(OP_SYMBOL (IC_LEFT (ic))->calleeSave))
+ if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype))
unsaveRegisters (ic);
/* if register bank was saved then pop them */
if (restoreBank)
- unsaveRBank (SPEC_BANK (detype), ic, FALSE);
+ unsaveRBank (FUNC_REGBANK (dtype), ic, FALSE);
}
/*-----------------------------------------------------------------*/
static void
genPcall (iCode * ic)
{
- sym_link *detype;
+ sym_link *dtype;
symbol *rlbl = newiTempLabel (NULL);
/* 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 */
- detype = getSpec (operandType (IC_LEFT (ic)));
- if (detype &&
- IS_ISR (currFunc->etype) &&
- (SPEC_BANK (currFunc->etype) != SPEC_BANK (detype)))
- saveRBank (SPEC_BANK (detype), ic, TRUE);
+ dtype = operandType (IC_LEFT (ic));
+ if (dtype &&
+ IFFUNC_ISISR (currFunc->type) &&
+ (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)))
+ saveRBank (FUNC_REGBANK (dtype), ic, TRUE);
/* push the return address on to the stack */
}
/* if register bank was saved then unsave them */
- if (detype &&
- (SPEC_BANK (currFunc->etype) !=
- SPEC_BANK (detype)))
- unsaveRBank (SPEC_BANK (detype), ic, TRUE);
+ if (dtype &&
+ (FUNC_REGBANK (currFunc->type) !=
+ FUNC_REGBANK (dtype)))
+ unsaveRBank (FUNC_REGBANK (dtype), ic, TRUE);
/* if we hade saved some registers then
unsave them */
if (ic->regsSaved)
unsaveRegisters (ic);
-
}
/*-----------------------------------------------------------------*/
genFunction (iCode * ic)
{
symbol *sym;
- sym_link *fetype;
+ sym_link *ftype;
bool switchedPSW = FALSE;
_G.nRegsSaved = 0;
emitcode (";", "-----------------------------------------");
emitcode ("", "%s:", sym->rname);
- fetype = getSpec (operandType (IC_LEFT (ic)));
+ ftype = operandType (IC_LEFT (ic));
- if (SPEC_NAKED(fetype))
+ if (IFFUNC_ISNAKED(ftype))
{
emitcode(";", "naked function: no prologue.");
return;
}
/* if critical function then turn interrupts off */
- if (SPEC_CRTCL (fetype))
+ if (IFFUNC_ISCRITICAL (ftype))
emitcode ("clr", "ea");
/* here we need to generate the equates for the
register bank if required */
- if (SPEC_BANK (fetype) != rbank)
+ if (FUNC_REGBANK (ftype) != rbank)
{
int i;
- rbank = SPEC_BANK (fetype);
+ rbank = FUNC_REGBANK (ftype);
for (i = 0; i < mcs51_nRegs; i++)
{
if (strcmp (regs8051[i].base, "0") == 0)
/* if this is an interrupt service routine then
save acc, b, dpl, dph */
- if (IS_ISR (sym->etype))
+ if (IFFUNC_ISISR (sym->type))
{
if (!inExcludeList ("acc"))
/* if this isr has no bank i.e. is going to
run with bank 0 , then we need to save more
registers :-) */
- if (!SPEC_BANK (sym->etype))
+ if (!FUNC_REGBANK (sym->type))
{
/* if this function does not call any other
function then we can be economical and
save only those registers that are used */
- if (!sym->hasFcall)
+ if (!IFFUNC_HASFCALL(sym->type))
{
int i;
*/
unsigned long banksToSave = 0;
- if (sym->hasFcall)
+ if (IFFUNC_HASFCALL(sym->type))
{
#define MAX_REGISTER_BANKS 4
if (i->op == CALL)
{
- sym_link *detype;
+ sym_link *dtype;
- detype = getSpec(operandType (IC_LEFT(i)));
- if (detype
- && SPEC_BANK(detype) != SPEC_BANK(sym->etype))
+ dtype = operandType (IC_LEFT(i));
+ if (dtype
+ && FUNC_REGBANK(dtype) != FUNC_REGBANK(sym->type))
{
/* Mark this bank for saving. */
- if (SPEC_BANK(detype) >= MAX_REGISTER_BANKS)
+ if (FUNC_REGBANK(dtype) >= MAX_REGISTER_BANKS)
{
- werror(E_NO_SUCH_BANK, SPEC_BANK(detype));
+ werror(E_NO_SUCH_BANK, FUNC_REGBANK(dtype));
}
else
{
- banksToSave |= (1 << SPEC_BANK(detype));
+ banksToSave |= (1 << FUNC_REGBANK(dtype));
}
/* And note that we don't need to do it in
*/
emitcode ("push", "psw");
emitcode ("mov", "psw,#0x%02x",
- (SPEC_BANK (sym->etype) << 3) & 0x00ff);
+ (FUNC_REGBANK (sym->type) << 3) & 0x00ff);
switchedPSW = TRUE;
}
}
}
}
+ // jwk: this needs a closer look
SPEC_ISR_SAVED_BANKS(currFunc->etype) = banksToSave;
}
}
{
/* if callee-save to be used for this function
then save the registers being used in this function */
- if (sym->calleeSave)
+ if (IFFUNC_CALLEESAVES(sym->type))
{
int i;
}
/* set the register bank to the desired value */
- if ((SPEC_BANK (sym->etype) || IS_ISR (sym->etype))
+ if ((FUNC_REGBANK (sym->type) || IFFUNC_ISISR (sym->type))
&& !switchedPSW)
{
emitcode ("push", "psw");
- emitcode ("mov", "psw,#0x%02x", (SPEC_BANK (sym->etype) << 3) & 0x00ff);
+ emitcode ("mov", "psw,#0x%02x", (FUNC_REGBANK (sym->type) << 3) & 0x00ff);
}
- if (IS_RENT (sym->etype) || options.stackAuto)
+ if (IFFUNC_ISREENT (sym->type) || options.stackAuto)
{
if (options.useXstack)
{
symbol *sym = OP_SYMBOL (IC_LEFT (ic));
- if (SPEC_NAKED(sym->etype))
+ if (IFFUNC_ISNAKED(sym->type))
{
emitcode(";", "naked function: no epilogue.");
return;
}
- if (IS_RENT (sym->etype) || options.stackAuto)
+ if (IFFUNC_ISREENT (sym->type) || options.stackAuto)
{
emitcode ("mov", "%s,_bp", spname);
}
}
- if ((IS_RENT (sym->etype) || options.stackAuto))
+ if ((IFFUNC_ISREENT (sym->type) || options.stackAuto))
{
if (options.useXstack)
{
}
/* restore the register bank */
- if (SPEC_BANK (sym->etype) || IS_ISR (sym->etype))
+ if (FUNC_REGBANK (sym->type) || IFFUNC_ISISR (sym->type))
{
- if (!SPEC_BANK (sym->etype) || !IS_ISR (sym->etype)
+ if (!FUNC_REGBANK (sym->type) || !IFFUNC_ISISR (sym->type)
|| !options.useXstack)
{
/* Special case of ISR using non-zero bank with useXstack
}
}
- if (IS_ISR (sym->etype))
+ if (IFFUNC_ISISR (sym->type))
{
/* now we need to restore the registers */
/* if this isr has no bank i.e. is going to
run with bank 0 , then we need to save more
registers :-) */
- if (!SPEC_BANK (sym->etype))
+ if (!FUNC_REGBANK (sym->type))
{
/* if this function does not call any other
function then we can be economical and
save only those registers that are used */
- if (!sym->hasFcall)
+ if (!IFFUNC_HASFCALL(sym->type))
{
int i;
* Restore any register banks saved by genFunction
* in reverse order.
*/
+ // jwk: this needs a closer look
unsigned savedBanks = SPEC_ISR_SAVED_BANKS(currFunc->etype);
int ix;
if (!inExcludeList ("acc"))
emitcode ("pop", "acc");
- if (SPEC_CRTCL (sym->etype))
+ if (IFFUNC_ISCRITICAL (sym->type))
emitcode ("setb", "ea");
/* if debug then send end of function */
}
else
{
- if (SPEC_CRTCL (sym->etype))
+ if (IFFUNC_ISCRITICAL (sym->type))
emitcode ("setb", "ea");
- if (sym->calleeSave)
+ if (IFFUNC_CALLEESAVES(sym->type))
{
int i;
iCode *lic = ic->next;
int isize ;
+ /* this could from a cast, e.g.: "(char xdata *) 0x7654;" */
+ if (!IS_SYMOP(op)) return NULL;
+
if (IS_BITVAR(retype)||!IS_PTR(type)) return NULL;
isize = getSize(type->next);
while (lic) {
return lic;
}
/* if the operand used or deffed */
- if (bitVectBitValue(ic->uses,op->key) || (unsigned) ic->defKey == op->key) {
+ if (bitVectBitValue(OP_USES(op),lic->key) || (unsigned) lic->defKey == op->key) {
return NULL;
}
lic = lic->next;
/* move it to the result */
size = AOP_SIZE (result);
offset = size - 1;
+ if (size == 1) { /* special case for 1 byte */
+ l = aopGet (AOP (left), offset, FALSE, FALSE);
+ MOVA (l);
+ emitcode ("rr", "a");
+ goto release;
+ }
CLRC;
while (size--)
{
MOVA (l);
}
emitcode ("mov", "acc.7,c");
+ release:
aopPut (AOP (result), "a", AOP_SIZE (result) - 1);
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
{
l = aopGet (AOP (left), offset, FALSE, FALSE);
MOVA (l);
+ if (size == 0) { /* special case for 1 byte */
+ emitcode("rl","a");
+ goto release;
+ }
emitcode ("add", "a,acc");
if (AOP_SIZE (result) > 1)
aopPut (AOP (result), "a", offset++);
MOVA (l);
}
emitcode ("mov", "acc.0,c");
+ release:
aopPut (AOP (result), "a", 0);
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
case CPOINTER:
emitcode ("clr", "a");
- emitcode ("movc", "a,%s", "@a+dptr");
+ emitcode ("movc", "a,@a+dptr");
break;
case GPOINTER:
case CPOINTER:
emitcode ("clr", "a");
emitcode ("inc", "dptr");
- emitcode ("movc", "a", "@a+dptr");
+ emitcode ("movc", "a,@a+dptr");
break;
case GPOINTER:
else
rname = aopGet (AOP (left), 0, FALSE, FALSE);
- aopOp (result, ic, FALSE);
+ //aopOp (result, ic, FALSE);
+ aopOp (result, ic, result?TRUE:FALSE);
/* if bitfield then unpack the bits */
if (IS_BITVAR (retype))
then don't need anything more */
if (!AOP_INPREG (AOP (result)))
{
- /* otherwise get a free pointer register */
- aop = newAsmop (0);
- preg = getFreePtr (ic, &aop, FALSE);
- emitcode ("mov", "%s,%s",
- preg->name,
- aopGet (AOP (result), 0, FALSE, TRUE));
- rname = preg->name;
+ if (
+ //AOP_TYPE (result) == AOP_STK
+ IS_AOP_PREG(result)
+ )
+ {
+ // Aha, it is a pointer, just in disguise.
+ rname = aopGet (AOP (result), 0, FALSE, FALSE);
+ if (*rname != '@')
+ {
+ fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n",
+ __FILE__, __LINE__);
+ }
+ else
+ {
+ // Expected case.
+ rname++; // skip the '@'.
+ }
+ }
+ else
+ {
+ /* otherwise get a free pointer register */
+ aop = newAsmop (0);
+ preg = getFreePtr (ic, &aop, FALSE);
+ emitcode ("mov", "%s,%s",
+ preg->name,
+ aopGet (AOP (result), 0, FALSE, TRUE));
+ rname = preg->name;
+ }
+ }
+ else
+ {
+ rname = aopGet (AOP (result), 0, FALSE, FALSE);
}
- else
- rname = aopGet (AOP (result), 0, FALSE, FALSE);
aopOp (right, ic, FALSE);
-
+
/* if bitfield then unpack the bits */
if (IS_BITVAR (retype) || IS_BITVAR (letype))
genPackBits ((IS_BITVAR (retype) ? retype : letype), right, rname, POINTER);
aopOp (result, ic, FALSE);
/* if the result is a bit */
- if (AOP_TYPE (result) == AOP_CRY)
+ // if (AOP_TYPE (result) == AOP_CRY /* works only for true symbols */
+ if (IS_BITVAR(OP_SYMBOL(result)->type))
{
/* if the right size is a literal then
we know what the value is */
freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
}
+/*-----------------------------------------------------------------*/
+/* gen51AggregateAssign - copy complete array's or structures */
+/*-----------------------------------------------------------------*/
+void gen51AggregateAssign(iCode *ic) {
+ operand *left=IC_LEFT(ic);
+ operand *right=IC_RIGHT(ic);
+ char *fromName=OP_SYMBOL(right)->rname;
+ char *toName=OP_SYMBOL(left)->rname;
+ int fromSize=getSize(OP_SYMBOL(right)->type);
+ int toSize=getSize(OP_SYMBOL(left)->type);
+ int count=toSize;
+
+ if (SPEC_OCLS(OP_SYMBOL(left)->etype)!=xdata ||
+ SPEC_OCLS(OP_SYMBOL(right)->etype)!=code) {
+ // well, this code isn't used yet from anywhere else as for initialising
+ fprintf (stderr, "*** error: %s:%d can only assign aggregates from cseg to xseg for now\n", ic->filename, ic->lineno);
+ exit (457);
+ }
+
+ if (fromSize!=toSize) {
+ fprintf (stderr, "*** error: %s:%d aggregates have different size\n",
+ ic->filename, ic->lineno);
+ exit (821);
+ }
+
+#if 1
+ // use the generic memcpy() for now
+ emitcode (";", "initialize %s", OP_SYMBOL(IC_LEFT(ic))->name);
+ emitcode ("mov", "dptr,#_memcpy_PARM_2");
+ emitcode ("mov", "a,#%s", fromName);
+ emitcode ("movx", "@dptr,a");
+ emitcode ("inc", "dptr");
+ emitcode ("mov", "a,#(%s>>8)", fromName);
+ emitcode ("movx", "@dptr,a");
+ emitcode ("inc", "dptr");
+ emitcode ("mov", "a,#%02x; only from cseg for now", 2);
+ emitcode ("movx", "@dptr,a");
+ emitcode ("mov", "dptr,#_memcpy_PARM_3");
+ emitcode ("mov", "a,#(%d>>0); number of bytes", count);
+ emitcode ("movx", "@dptr,a");
+ emitcode ("inc", "dptr");
+ emitcode ("mov", "a,#(%d>>8)", count);
+ emitcode ("movx", "@dptr,a");
+ emitcode ("mov", "dptr,#%s", toName);
+ emitcode ("mov", "b,#%02x; only to xseg for now", 1);
+ emitcode ("lcall", "_memcpy");
+#else
+ // more efficient, but will require the native_memcpy_cs2xs
+ emitcode ("mov", "r0,#%s", fromName);
+ emitcode ("mov", "r1,#(%s>>8)", fromName);
+ emitcode ("mov", "r2,#%s", toName);
+ emitcode ("mov", "r3,#(%s>>8)", toName);
+ emitcode ("mov", "r4,#%d", count);
+ emitcode ("mov", "r5,#(%d>>8)", count);
+ emitcode ("lcall", "_native_memcpy_cs2xs");
+#endif
+}
+
/*-----------------------------------------------------------------*/
/* gen51Code - generate code for 8051 based controllers */
/*-----------------------------------------------------------------*/
addSet (&_G.sendSet, ic);
break;
+ case ARRAYINIT:
+ gen51AggregateAssign(ic);
+ break;
+
default:
ic = ic;
}