CODE GENERATION for a specific MCU . some of the
routines may be reusable, will have to see */
-static char *zero = "#0x00";
-static char *one = "#0x01";
+static char *zero = "#0";
+static char *one = "#1";
static char *spname;
#define D(x) x
if (sym->onStack && options.stack10bit)
{
+ short stack_val = -((sym->stack < 0) ?
+ ((short) (sym->stack - _G.nRegsSaved)) :
+ ((short) sym->stack)) ;
/* It's on the 10 bit stack, which is located in
* far data space.
*/
-
- if (_G.accInUse)
- emitcode ("push", "acc");
-
- if (_G.bInUse)
- emitcode ("push", "b");
-
- emitcode ("mov", "a,_bpx");
- emitcode ("clr","c");
- emitcode ("subb", "a,#!constbyte",
- -((sym->stack < 0) ?
- ((short) (sym->stack - _G.nRegsSaved)) :
- ((short) sym->stack)) & 0xff);
- emitcode ("mov","b,a");
- emitcode ("mov","a,_bpx+1");
- emitcode ("subb","a,#!constbyte",(-((sym->stack < 0) ?
- ((short) (sym->stack - _G.nRegsSaved)) :
- ((short) sym->stack)) >> 8) & 0xff);
- if (useDP2) {
- if (options.model == MODEL_FLAT24)
- emitcode ("mov", "dpx1,#!constbyte", (options.stack_loc >> 16) & 0xff);
- TR_DPTR("#2");
- emitcode ("mov", "dph1,a");
- emitcode ("mov", "dpl1,b");
- } else {
- if (options.model == MODEL_FLAT24)
- emitcode ("mov", "dpx,#!constbyte", (options.stack_loc >> 16) & 0xff);
- emitcode ("mov", "dph,a");
- emitcode ("mov", "dpl,b");
- }
-
- if (_G.bInUse)
- emitcode ("pop", "b");
-
- if (_G.accInUse)
- emitcode ("pop", "acc");
-
- sym->aop = aop = newAsmop ((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR));
- aop->size = getSize (sym->type);
- return aop;
+ if (stack_val < 0 && stack_val > -3) { /* between -3 & -1 */
+ if (useDP2) {
+ if (options.model == MODEL_FLAT24)
+ emitcode ("mov", "dpx1,#!constbyte", (options.stack_loc >> 16) & 0xff);
+ TR_DPTR("#2");
+ emitcode ("mov", "dph1,_bpx+1");
+ emitcode ("mov", "dpl1,_bpx");
+ emitcode ("mov","dps,#1");
+ } else {
+ if (options.model == MODEL_FLAT24)
+ emitcode ("mov", "dpx,#!constbyte", (options.stack_loc >> 16) & 0xff);
+ emitcode ("mov", "dph,_bpx+1");
+ emitcode ("mov", "dpl,_bpx");
+ }
+ stack_val = -stack_val;
+ while (stack_val--) {
+ emitcode ("inc","dptr");
+ }
+ if (useDP2) {
+ emitcode("mov","dps,#0");
+ }
+ } else {
+ if (_G.accInUse)
+ emitcode ("push", "acc");
+
+ if (_G.bInUse)
+ emitcode ("push", "b");
+
+ emitcode ("mov", "a,_bpx");
+ emitcode ("clr","c");
+ emitcode ("subb", "a,#!constbyte", stack_val & 0xff);
+ emitcode ("mov","b,a");
+ emitcode ("mov","a,_bpx+1");
+ emitcode ("subb","a,#!constbyte",(stack_val >> 8) & 0xff);
+ if (useDP2) {
+ if (options.model == MODEL_FLAT24)
+ emitcode ("mov", "dpx1,#!constbyte", (options.stack_loc >> 16) & 0xff);
+ TR_DPTR("#2");
+ emitcode ("mov", "dph1,a");
+ emitcode ("mov", "dpl1,b");
+ } else {
+ if (options.model == MODEL_FLAT24)
+ emitcode ("mov", "dpx,#!constbyte", (options.stack_loc >> 16) & 0xff);
+ emitcode ("mov", "dph,a");
+ emitcode ("mov", "dpl,b");
+ }
+
+ if (_G.bInUse)
+ emitcode ("pop", "b");
+
+ if (_G.accInUse)
+ emitcode ("pop", "acc");
+ }
+ sym->aop = aop = newAsmop ((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR));
+ aop->size = getSize (sym->type);
+ return aop;
}
/* if in bit space */
if (bitVectBitValue(ic->rMask,i))
rsave = bitVectSetBit(rsave,i);
}
+ rsave = bitVectCplAnd(rsave,ds390_rUmaskForOp (IC_RESULT(ic)));
} else {
/* safe the registers in use at this time but skip the
ones for the result */
if (bitVectBitValue(ic->rMask,i))
rsave = bitVectSetBit(rsave,i);
}
+ rsave = bitVectCplAnd(rsave,ds390_rUmaskForOp (IC_RESULT(ic)));
} else {
/* restore the registers in use at this time but skip the
ones for the result */
{
int size, offset = 0;
-#if 0
- aopOp (IC_LEFT (sic), sic, FALSE, FALSE);
- size = AOP_SIZE (IC_LEFT (sic));
-
- _startLazyDPSEvaluation ();
- while (size--)
- {
- char *l = aopGet (AOP(IC_LEFT(sic)), offset,
- FALSE, FALSE, TRUE);
- if ((AOP_TYPE(IC_LEFT(sic)) == AOP_DPTR) && size)
- {
- emitcode("mov", "%s,%s", regs390[offset].name, l);
- }
- else if (strcmp (l, fReturn[offset]))
- {
- emitcode ("mov", "%s,%s",
- fReturn[offset],
- l);
- }
- offset++;
- }
- _endLazyDPSEvaluation ();
- if (AOP_TYPE(IC_LEFT(sic)) == AOP_DPTR)
- {
- size = AOP_SIZE (IC_LEFT (sic));
- if (size)
- {
- size--;
- }
- while (size)
- {
- size--;
- emitcode("mov", "%s,%s",
- fReturn[size], regs390[size].name);
- }
- }
-#else
// we know that dpl(hxb) is the result, so
_startLazyDPSEvaluation ();
size=getSize(operandType(IC_LEFT(sic)));
offset++;
}
_endLazyDPSEvaluation ();
-#endif
freeAsmop (IC_LEFT (sic), NULL, sic, TRUE);
}
_G.sendSet = NULL;
/* adjust the stack for parameters if
required */
if (ic->parmBytes) {
+ int i;
if (options.stack10bit) {
- emitcode ("clr","c");
- emitcode ("mov","a,sp");
- emitcode ("subb","a,#!constbyte",ic->parmBytes & 0xff);
- emitcode ("mov","sp,a");
- emitcode ("mov","a,esp");
- emitcode ("subb","a,#!constbyte",(ic->parmBytes >> 8) & 0xff);
- emitcode ("mov","esp,a");
+ if (ic->parmBytes <= 4) {
+ emitcode(";","stack adjustment for parms");
+ for (i=0; i < ic->parmBytes ; i++) {
+ emitcode("pop","acc");
+ }
+ } else {
+ emitcode ("clr","c");
+ emitcode ("mov","a,sp");
+ emitcode ("subb","a,#!constbyte",ic->parmBytes & 0xff);
+ emitcode ("mov","sp,a");
+ emitcode ("mov","a,esp");
+ emitcode ("subb","a,#!constbyte",(ic->parmBytes >> 8) & 0xff);
+ emitcode ("mov","esp,a");
+ }
} else {
- int i;
if (ic->parmBytes > 3) {
emitcode ("mov", "a,%s", spname);
emitcode ("add", "a,#!constbyte", (-ic->parmBytes) & 0xff);
emitcode ("mov", "psw,#!constbyte", (FUNC_REGBANK (sym->type) << 3) & 0x00ff);
}
- if (IFFUNC_ISREENT (sym->type) || options.stackAuto) {
+ if ( (IFFUNC_ISREENT (sym->type) || options.stackAuto) &&
+ (sym->stack || FUNC_HASSTACKPARM(sym->type))) {
if (options.stack10bit) {
emitcode ("push","_bpx");
emitcode ("push","_bpx+1");
return;
}
- if (IFFUNC_ISREENT (sym->type) || options.stackAuto) {
+ if ((IFFUNC_ISREENT (sym->type) || options.stackAuto) &&
+ (sym->stack || FUNC_HASSTACKPARM(sym->type))) {
+
if (options.stack10bit) {
emitcode ("mov", "sp,_bpx", spname);
emitcode ("mov", "esp,_bpx+1", spname);
}
- if ((IFFUNC_ISREENT (sym->type) || options.stackAuto)) {
+ if ((IFFUNC_ISREENT (sym->type) || options.stackAuto) &&
+ (sym->stack || FUNC_HASSTACKPARM(sym->type))) {
+
if (options.useXstack) {
emitcode ("mov", "r0,%s", spname);
emitcode ("movx", "a,@r0");
if ((icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 4)
return FALSE;
+ if (size == 1 && AOP(IC_LEFT(ic)) == AOP(IC_RESULT(ic)) &&
+ AOP_TYPE(IC_LEFT(ic)) == AOP_DIR ) {
+ while (icount--) {
+ emitcode("inc","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE,FALSE));
+ }
+ return TRUE;
+ }
/* if increment 16 bits in register */
if (
AOP_TYPE (IC_LEFT (ic)) == AOP_REG &&
#define AOP_OP_3_NOFATAL(ic, rc) \
aopOp (IC_RIGHT(ic),ic,FALSE, FALSE); \
aopOp (IC_LEFT(ic),ic,FALSE, (AOP_TYPE(IC_RIGHT(ic)) == AOP_DPTR) || \
- (OP_SYMBOL(IC_RESULT(ic))->ruonly)); \
+ ((OP_SYMBOL(IC_RESULT(ic))->ruonly) && !isOperandEqual(IC_LEFT(ic),IC_RESULT(ic)))); \
if (AOP_TYPE(IC_LEFT(ic)) == AOP_DPTR2 && \
- (isOperandInFarSpace(IC_RESULT(ic)) || OP_SYMBOL(IC_RESULT(ic))->ruonly )) \
+ (isOperandInFarSpace(IC_RESULT(ic)) || (OP_SYMBOL(IC_RESULT(ic))->ruonly && !isOperandEqual(IC_LEFT(ic),IC_RESULT(ic))))) \
{ \
/* No can do; DPTR & DPTR2 in use, and we need another. */ \
rc = TRUE; \
if ((icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 4)
return FALSE;
+ if (size == 1 && AOP(IC_LEFT(ic)) == AOP(IC_RESULT(ic)) &&
+ AOP_TYPE(IC_LEFT(ic)) == AOP_DIR ) {
+ while (icount--) {
+ emitcode("dec","%s",aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE,FALSE));
+ }
+ return TRUE;
+ }
/* if decrement 16 bits in register */
if (AOP_TYPE (IC_LEFT (ic)) == AOP_REG &&
AOP_TYPE (IC_RESULT (ic)) == AOP_REG &&
/* if unsigned char cmp with lit, do cjne left,#right,zz */
if ((size == 1) && !sign &&
- (AOP_TYPE (right) == AOP_LIT && AOP_TYPE (left) != AOP_DIR))
+ (AOP_TYPE (right) == AOP_LIT && AOP_TYPE (left) != AOP_DIR && AOP_TYPE (left) != AOP_STR))
{
symbol *lbl = newiTempLabel (NULL);
emitcode ("cjne", "%s,%s,!tlabel",
/* hasInc - operand is incremented before any other use */
/*-----------------------------------------------------------------*/
static iCode *
-hasInc (operand *op, iCode *ic)
+hasInc (operand *op, iCode *ic, int osize)
{
sym_link *type = operandType(op);
sym_link *retype = getSpec (type);
if (!IS_SYMOP(op)) return NULL;
if (IS_BITVAR(retype)||!IS_PTR(type)) return NULL;
- isize = getSize(type->next);
+ if (osize != (isize = getSize(type->next))) return NULL;
while (lic) {
/* if operand of the form op = op + <sizeof *op> */
if (lic->op == '+' && isOperandEqual(IC_LEFT(lic),op) &&
{
operand *from , *to , *count;
symbol *lbl;
- bitVect *rsave = NULL;
+ bitVect *rsave;
int i;
/* we know it has to be 3 parameters */
assert (nparms == 3);
+ rsave = newBitVect(16);
/* save DPTR if it needs to be saved */
for (i = DPL_IDX ; i <= B_IDX ; i++ ) {
if (bitVectBitValue(ic->rMask,i))
symbol *lbl;
char *l;
int i;
- bitVect *rsave;
+ bitVect *rsave = NULL;
/* we know it has to be 3 parameters */
assert (nparms == 3);
to = parms[0];
val = parms[1];
count = parms[2];
-
+
/* save DPTR if it needs to be saved */
+ rsave = newBitVect(16);
for (i = DPL_IDX ; i <= B_IDX ; i++ ) {
if (bitVectBitValue(ic->rMask,i))
rsave = bitVectSetBit(rsave,i);
/* put pointer to state block into DPTR1 */
aopOp (psb, ic, FALSE, FALSE);
- emitcode ("mov","dpl1,%s",aopGet(AOP(psb),0,FALSE,FALSE,FALSE));
- emitcode ("mov","dph1,%s",aopGet(AOP(psb),1,FALSE,FALSE,FALSE));
- emitcode ("mov","dpx1,%s",aopGet(AOP(psb),2,FALSE,FALSE,FALSE));
+ if (AOP_TYPE (psb) == AOP_IMMD) {
+ emitcode ("mov","dps,#1");
+ emitcode ("mov", "dptr,%s", aopGet (AOP (psb), 0, TRUE, FALSE, FALSE));
+ emitcode ("mov","dps,#0");
+ } else {
+ emitcode ("mov","dpl1,%s",aopGet(AOP(psb),0,FALSE,FALSE,FALSE));
+ emitcode ("mov","dph1,%s",aopGet(AOP(psb),1,FALSE,FALSE,FALSE));
+ emitcode ("mov","dpx1,%s",aopGet(AOP(psb),2,FALSE,FALSE,FALSE));
+ }
freeAsmop (psb, NULL, ic, FALSE);
/* put libraryID into DPTR */
/* make the call */
emitcode ("lcall","MM_Deref");
-
- aopOp (IC_RESULT(ic),ic,FALSE,FALSE);
- if (AOP_TYPE(IC_RESULT(ic)) != AOP_STR) {
- aopPut(AOP(IC_RESULT(ic)),"dpl",0);
- aopPut(AOP(IC_RESULT(ic)),"dph",1);
- aopPut(AOP(IC_RESULT(ic)),"dpx",2);
+
+ {
+ symbol *rsym = OP_SYMBOL(IC_RESULT(ic));
+ if (rsym->liveFrom != rsym->liveTo) {
+ aopOp (IC_RESULT(ic),ic,FALSE,FALSE);
+ if (AOP_TYPE(IC_RESULT(ic)) != AOP_STR) {
+ aopPut(AOP(IC_RESULT(ic)),"dpl",0);
+ aopPut(AOP(IC_RESULT(ic)),"dph",1);
+ aopPut(AOP(IC_RESULT(ic)),"dpx",2);
+ }
+ }
}
freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
unsavermask(rsave);
}
+/*-----------------------------------------------------------------*/
+/* genMMUnrestrictedPersist - */
+/*-----------------------------------------------------------------*/
+static void genMMUnrestrictedPersist(iCode *ic,int nparms, operand **parms)
+{
+ bitVect *rsave ;
+ operand *handle;
+
+ assert (nparms == 1);
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+
+ handle=parms[0];
+ aopOp (handle,ic,FALSE,FALSE);
+
+ /* put the size in R3-R2 */
+ if (aopHasRegs(AOP(handle),R2_IDX,R3_IDX)) {
+ emitcode("push","%s",aopGet(AOP(handle),0,FALSE,TRUE,FALSE));
+ emitcode("push","%s",aopGet(AOP(handle),1,FALSE,TRUE,FALSE));
+ emitcode("pop","ar3");
+ emitcode("pop","ar2");
+ } else {
+ emitcode ("mov","r2,%s",aopGet(AOP(handle),0,FALSE,TRUE,FALSE));
+ emitcode ("mov","r3,%s",aopGet(AOP(handle),1,FALSE,TRUE,FALSE));
+ }
+ freeAsmop (handle, NULL, ic, FALSE);
+
+ /* make the call */
+ emitcode ("lcall","MM_UnrestrictedPersist");
+
+ {
+ symbol *rsym = OP_SYMBOL(IC_RESULT(ic));
+ if (rsym->liveFrom != rsym->liveTo) {
+ aopOp (IC_RESULT(ic),ic,FALSE,FALSE);
+ aopPut(AOP(IC_RESULT(ic)),"a",0);
+ freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
+ }
+ }
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genSystemExecJavaProcess - */
+/*-----------------------------------------------------------------*/
+static void genSystemExecJavaProcess(iCode *ic,int nparms, operand **parms)
+{
+ bitVect *rsave ;
+ operand *handle, *pp;
+
+ assert (nparms==2);
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+
+ pp = parms[0];
+ handle = parms[1];
+
+ /* put the handle in R3-R2 */
+ aopOp (handle,ic,FALSE,FALSE);
+ if (aopHasRegs(AOP(handle),R2_IDX,R3_IDX)) {
+ emitcode("push","%s",aopGet(AOP(handle),0,FALSE,TRUE,FALSE));
+ emitcode("push","%s",aopGet(AOP(handle),1,FALSE,TRUE,FALSE));
+ emitcode("pop","ar3");
+ emitcode("pop","ar2");
+ } else {
+ emitcode ("mov","r2,%s",aopGet(AOP(handle),0,FALSE,TRUE,FALSE));
+ emitcode ("mov","r3,%s",aopGet(AOP(handle),1,FALSE,TRUE,FALSE));
+ }
+ freeAsmop (handle, NULL, ic, FALSE);
+
+ /* put pointer in DPTR */
+ aopOp (pp,ic,FALSE,FALSE);
+ if (AOP_TYPE(pp) == AOP_IMMD) {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (pp), 0, TRUE, FALSE, FALSE));
+ } else if (AOP_TYPE(pp) != AOP_STR) { /* not already in dptr */
+ emitcode ("mov","dpl,%s",aopGet(AOP(pp),0,FALSE,FALSE,FALSE));
+ emitcode ("mov","dph,%s",aopGet(AOP(pp),1,FALSE,FALSE,FALSE));
+ emitcode ("mov","dpx,%s",aopGet(AOP(pp),2,FALSE,FALSE,FALSE));
+ }
+ freeAsmop (handle, NULL, ic, FALSE);
+
+ /* make the call */
+ emitcode ("lcall","System_ExecJavaProcess");
+
+ /* put result in place */
+ {
+ symbol *rsym = OP_SYMBOL(IC_RESULT(ic));
+ if (rsym->liveFrom != rsym->liveTo) {
+ aopOp (IC_RESULT(ic),ic,FALSE,FALSE);
+ aopPut(AOP(IC_RESULT(ic)),"a",0);
+ freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
+ }
+ }
+
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genSystemRTCRegisters - */
+/*-----------------------------------------------------------------*/
+static void genSystemRTCRegisters(iCode *ic,int nparms, operand **parms,
+ char *name)
+{
+ bitVect *rsave ;
+ operand *pp;
+
+ assert (nparms==1);
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+
+ pp=parms[0];
+ /* put pointer in DPTR */
+ aopOp (pp,ic,FALSE,FALSE);
+ if (AOP_TYPE (pp) == AOP_IMMD) {
+ emitcode ("mov","dps,#1");
+ emitcode ("mov", "dptr,%s", aopGet (AOP (pp), 0, TRUE, FALSE, FALSE));
+ emitcode ("mov","dps,#0");
+ } else {
+ emitcode ("mov","dpl1,%s",aopGet(AOP(pp),0,FALSE,FALSE,FALSE));
+ emitcode ("mov","dph1,%s",aopGet(AOP(pp),1,FALSE,FALSE,FALSE));
+ emitcode ("mov","dpx1,%s",aopGet(AOP(pp),2,FALSE,FALSE,FALSE));
+ }
+ freeAsmop (pp, NULL, ic, FALSE);
+
+ /* make the call */
+ emitcode ("lcall","System_%sRTCRegisters",name);
+
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genSystemThreadSleep - */
+/*-----------------------------------------------------------------*/
+static void genSystemThreadSleep(iCode *ic,int nparms, operand **parms, char *name)
+{
+ bitVect *rsave ;
+ operand *to, *s;
+
+ assert (nparms==1);
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+
+ to = parms[0];
+ aopOp(to,ic,FALSE,FALSE);
+ if (aopHasRegs(AOP(to),R2_IDX,R3_IDX) ||
+ aopHasRegs(AOP(to),R0_IDX,R1_IDX) ) {
+ emitcode ("push","%s",aopGet(AOP(to),0,FALSE,TRUE,FALSE));
+ emitcode ("push","%s",aopGet(AOP(to),1,FALSE,TRUE,FALSE));
+ emitcode ("push","%s",aopGet(AOP(to),2,FALSE,TRUE,FALSE));
+ emitcode ("push","%s",aopGet(AOP(to),3,FALSE,TRUE,FALSE));
+ emitcode ("pop","ar3");
+ emitcode ("pop","ar2");
+ emitcode ("pop","ar1");
+ emitcode ("pop","ar0");
+ } else {
+ emitcode ("mov","r0,%s",aopGet(AOP(to),0,FALSE,TRUE,FALSE));
+ emitcode ("mov","r1,%s",aopGet(AOP(to),1,FALSE,TRUE,FALSE));
+ emitcode ("mov","r2,%s",aopGet(AOP(to),2,FALSE,TRUE,FALSE));
+ emitcode ("mov","r3,%s",aopGet(AOP(to),3,FALSE,TRUE,FALSE));
+ }
+ freeAsmop (to, NULL, ic, FALSE);
+
+ /* suspend in acc */
+ s = parms[1];
+ aopOp(s,ic,FALSE,FALSE);
+ emitcode ("mov","a,%s",aopGet(AOP(s),0,FALSE,TRUE,FALSE));
+ freeAsmop (s, NULL, ic, FALSE);
+
+ /* make the call */
+ emitcode ("lcall","System_%s",name);
+
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genSystemThreadResume - */
+/*-----------------------------------------------------------------*/
+static void genSystemThreadResume(iCode *ic,int nparms, operand **parms)
+{
+ bitVect *rsave ;
+ operand *tid,*pid;
+
+ assert (nparms==2);
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+
+ tid = parms[0];
+ pid = parms[1];
+
+ /* PID in R0 */
+ aopOp(pid,ic,FALSE,FALSE);
+ emitcode ("mov","r0,%s",aopGet(AOP(pid),0,FALSE,TRUE,FALSE));
+ freeAsmop (pid, NULL, ic, FALSE);
+
+ /* tid into ACC */
+ aopOp(tid,ic,FALSE,FALSE);
+ emitcode ("mov","a,%s",aopGet(AOP(tid),0,FALSE,TRUE,FALSE));
+ freeAsmop (tid, NULL, ic, FALSE);
+
+ emitcode ("lcall","System_ThreadResume");
+
+ /* put result into place */
+ {
+ symbol *rsym = OP_SYMBOL(IC_RESULT(ic));
+ if (rsym->liveFrom != rsym->liveTo) {
+ aopOp (IC_RESULT(ic),ic,FALSE,FALSE);
+ aopPut(AOP(IC_RESULT(ic)),"a",0);
+ freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
+ }
+ }
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genSystemProcessResume - */
+/*-----------------------------------------------------------------*/
+static void genSystemProcessResume(iCode *ic,int nparms, operand **parms)
+{
+ bitVect *rsave ;
+ operand *pid;
+
+ assert (nparms==1);
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+
+ pid = parms[0];
+
+ /* pid into ACC */
+ aopOp(pid,ic,FALSE,FALSE);
+ emitcode ("mov","a,%s",aopGet(AOP(pid),0,FALSE,TRUE,FALSE));
+ freeAsmop (pid, NULL, ic, FALSE);
+
+ emitcode ("lcall","System_ProcessResume");
+
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genSystem - */
+/*-----------------------------------------------------------------*/
+static void genSystem (iCode *ic,int nparms,char *name)
+{
+ assert(nparms == 0);
+
+ emitcode ("lcall","System_%s",name);
+}
+
+/*-----------------------------------------------------------------*/
+/* genSystemPoll - */
+/*-----------------------------------------------------------------*/
+static void genSystemPoll(iCode *ic,int nparms, operand **parms,char *name)
+{
+ bitVect *rsave ;
+ operand *fp;
+
+ assert (nparms==1);
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+
+ fp = parms[0];
+ aopOp (fp,ic,FALSE,FALSE);
+ if (AOP_TYPE (fp) == AOP_IMMD) {
+ emitcode ("mov", "dptr,%s", aopGet (AOP (fp), 0, TRUE, FALSE, FALSE));
+ } else if (AOP_TYPE(fp) != AOP_STR) { /* not already in dptr */
+ emitcode ("mov","dpl,%s",aopGet(AOP(fp),0,FALSE,FALSE,FALSE));
+ emitcode ("mov","dph,%s",aopGet(AOP(fp),1,FALSE,FALSE,FALSE));
+ emitcode ("mov","dpx,%s",aopGet(AOP(fp),2,FALSE,FALSE,FALSE));
+ }
+ freeAsmop (fp, NULL, ic, FALSE);
+
+ emitcode ("lcall","System_%sPoll",name);
+
+ /* put result into place */
+ {
+ symbol *rsym = OP_SYMBOL(IC_RESULT(ic));
+ if (rsym->liveFrom != rsym->liveTo) {
+ aopOp (IC_RESULT(ic),ic,FALSE,FALSE);
+ aopPut(AOP(IC_RESULT(ic)),"a",0);
+ freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
+ }
+ }
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genSystemGetCurrentID - */
+/*-----------------------------------------------------------------*/
+static void genSystemGetCurrentID(iCode *ic,int nparms, operand **parms,char *name)
+{
+ assert (nparms==0);
+
+ emitcode ("lcall","System_GetCurrent%sId",name);
+ /* put result into place */
+ {
+ symbol *rsym = OP_SYMBOL(IC_RESULT(ic));
+ if (rsym->liveFrom != rsym->liveTo) {
+ aopOp (IC_RESULT(ic),ic,FALSE,FALSE);
+ aopPut(AOP(IC_RESULT(ic)),"a",0);
+ freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
+ }
+ }
+}
+
/*-----------------------------------------------------------------*/
/* genBuiltIn - calls the appropriate function to generating code */
/* for a built in function */
/*-----------------------------------------------------------------*/
static void genBuiltIn (iCode *ic)
{
- operand *bi_parms[MAX_BUILTIN_ARGS];
- int nbi_parms;
- iCode *bi_iCode;
- symbol *bif;
-
- /* get all the arguments for a built in function */
- bi_iCode = getBuiltinParms(ic,&nbi_parms,bi_parms);
-
- /* which function is it */
- bif = OP_SYMBOL(IC_LEFT(bi_iCode));
- if (strcmp(bif->name,"__builtin_memcpy_x2x")==0) {
- genMemcpyX2X(bi_iCode,nbi_parms,bi_parms,0);
- } else if (strcmp(bif->name,"__builtin_memcpy_c2x")==0) {
- genMemcpyX2X(bi_iCode,nbi_parms,bi_parms,1);
- } else if (strcmp(bif->name,"__builtin_memset_x")==0) {
- genMemsetX(bi_iCode,nbi_parms,bi_parms);
- } else if (strcmp(bif->name,"NatLib_LoadByte")==0) {
- genNatLibLoadPrimitive(bi_iCode,nbi_parms,bi_parms,1);
- } else if (strcmp(bif->name,"NatLib_LoadShort")==0) {
- genNatLibLoadPrimitive(bi_iCode,nbi_parms,bi_parms,2);
- } else if (strcmp(bif->name,"NatLib_LoadInt")==0) {
- genNatLibLoadPrimitive(bi_iCode,nbi_parms,bi_parms,4);
- } else if (strcmp(bif->name,"NatLib_LoadPointer")==0) {
- genNatLibLoadPointer(bi_iCode,nbi_parms,bi_parms);
- } else if (strcmp(bif->name,"NatLib_InstallImmutableStateBlock")==0) {
- genNatLibInstallStateBlock(bi_iCode,nbi_parms,bi_parms,"Immutable");
- } else if (strcmp(bif->name,"NatLib_InstallEphemeralStateBlock")==0) {
- genNatLibInstallStateBlock(bi_iCode,nbi_parms,bi_parms,"Ephemeral");
- } else if (strcmp(bif->name,"NatLib_RemoveImmutableStateBlock")==0) {
- genNatLibRemoveStateBlock(bi_iCode,nbi_parms,"Immutable");
- } else if (strcmp(bif->name,"NatLib_RemoveEphemeralStateBlock")==0) {
- genNatLibRemoveStateBlock(bi_iCode,nbi_parms,"Ephemeral");
- } else if (strcmp(bif->name,"NatLib_GetImmutableStateBlock")==0) {
- genNatLibGetStateBlock(bi_iCode,nbi_parms,bi_parms,"Immutable");
- } else if (strcmp(bif->name,"NatLib_GetEphemeralStateBlock")==0) {
- genNatLibGetStateBlock(bi_iCode,nbi_parms,bi_parms,"Ephemeral");
- } else if (strcmp(bif->name,"MM_XMalloc")==0) {
- genMMMalloc(bi_iCode,nbi_parms,bi_parms,3,"XMalloc");
- } else if (strcmp(bif->name,"MM_Malloc")==0) {
- genMMMalloc(bi_iCode,nbi_parms,bi_parms,2,"Malloc");
- } else if (strcmp(bif->name,"MM_ApplicationMalloc")==0) {
- genMMMalloc(bi_iCode,nbi_parms,bi_parms,2,"ApplicationMalloc");
- } else if (strcmp(bif->name,"MM_Free")==0) {
- genMMMalloc(bi_iCode,nbi_parms,bi_parms,2,"Free");
- } else if (strcmp(bif->name,"MM_Deref")==0) {
- genMMDeref(bi_iCode,nbi_parms,bi_parms);
- } else {
- werror(E_INTERNAL_ERROR,__FILE__,__LINE__,"unknown builtin function encountered\n");
- return ;
- }
- return ;
+ operand *bi_parms[MAX_BUILTIN_ARGS];
+ int nbi_parms;
+ iCode *bi_iCode;
+ symbol *bif;
+
+ /* get all the arguments for a built in function */
+ bi_iCode = getBuiltinParms(ic,&nbi_parms,bi_parms);
+
+ /* which function is it */
+ bif = OP_SYMBOL(IC_LEFT(bi_iCode));
+ if (strcmp(bif->name,"__builtin_memcpy_x2x")==0) {
+ genMemcpyX2X(bi_iCode,nbi_parms,bi_parms,0);
+ } else if (strcmp(bif->name,"__builtin_memcpy_c2x")==0) {
+ genMemcpyX2X(bi_iCode,nbi_parms,bi_parms,1);
+ } else if (strcmp(bif->name,"__builtin_memset_x")==0) {
+ genMemsetX(bi_iCode,nbi_parms,bi_parms);
+ } else if (strcmp(bif->name,"NatLib_LoadByte")==0) {
+ genNatLibLoadPrimitive(bi_iCode,nbi_parms,bi_parms,1);
+ } else if (strcmp(bif->name,"NatLib_LoadShort")==0) {
+ genNatLibLoadPrimitive(bi_iCode,nbi_parms,bi_parms,2);
+ } else if (strcmp(bif->name,"NatLib_LoadInt")==0) {
+ genNatLibLoadPrimitive(bi_iCode,nbi_parms,bi_parms,4);
+ } else if (strcmp(bif->name,"NatLib_LoadPointer")==0) {
+ genNatLibLoadPointer(bi_iCode,nbi_parms,bi_parms);
+ } else if (strcmp(bif->name,"NatLib_InstallImmutableStateBlock")==0) {
+ genNatLibInstallStateBlock(bi_iCode,nbi_parms,bi_parms,"Immutable");
+ } else if (strcmp(bif->name,"NatLib_InstallEphemeralStateBlock")==0) {
+ genNatLibInstallStateBlock(bi_iCode,nbi_parms,bi_parms,"Ephemeral");
+ } else if (strcmp(bif->name,"NatLib_RemoveImmutableStateBlock")==0) {
+ genNatLibRemoveStateBlock(bi_iCode,nbi_parms,"Immutable");
+ } else if (strcmp(bif->name,"NatLib_RemoveEphemeralStateBlock")==0) {
+ genNatLibRemoveStateBlock(bi_iCode,nbi_parms,"Ephemeral");
+ } else if (strcmp(bif->name,"NatLib_GetImmutableStateBlock")==0) {
+ genNatLibGetStateBlock(bi_iCode,nbi_parms,bi_parms,"Immutable");
+ } else if (strcmp(bif->name,"NatLib_GetEphemeralStateBlock")==0) {
+ genNatLibGetStateBlock(bi_iCode,nbi_parms,bi_parms,"Ephemeral");
+ } else if (strcmp(bif->name,"MM_XMalloc")==0) {
+ genMMMalloc(bi_iCode,nbi_parms,bi_parms,3,"XMalloc");
+ } else if (strcmp(bif->name,"MM_Malloc")==0) {
+ genMMMalloc(bi_iCode,nbi_parms,bi_parms,2,"Malloc");
+ } else if (strcmp(bif->name,"MM_ApplicationMalloc")==0) {
+ genMMMalloc(bi_iCode,nbi_parms,bi_parms,2,"ApplicationMalloc");
+ } else if (strcmp(bif->name,"MM_Free")==0) {
+ genMMMalloc(bi_iCode,nbi_parms,bi_parms,2,"Free");
+ } else if (strcmp(bif->name,"MM_Deref")==0) {
+ genMMDeref(bi_iCode,nbi_parms,bi_parms);
+ } else if (strcmp(bif->name,"MM_UnrestrictedPersist")==0) {
+ genMMUnrestrictedPersist(bi_iCode,nbi_parms,bi_parms);
+ } else if (strcmp(bif->name,"System_ExecJavaProcess")==0) {
+ genSystemExecJavaProcess(bi_iCode,nbi_parms,bi_parms);
+ } else if (strcmp(bif->name,"System_GetRTCRegisters")==0) {
+ genSystemRTCRegisters(bi_iCode,nbi_parms,bi_parms,"Get");
+ } else if (strcmp(bif->name,"System_SetRTCRegisters")==0) {
+ genSystemRTCRegisters(bi_iCode,nbi_parms,bi_parms,"Set");
+ } else if (strcmp(bif->name,"System_ThreadSleep")==0) {
+ genSystemThreadSleep(bi_iCode,nbi_parms,bi_parms,"ThreadSleep");
+ } else if (strcmp(bif->name,"System_ThreadSleep_ExitCriticalSection")==0) {
+ genSystemThreadSleep(bi_iCode,nbi_parms,bi_parms,"ThreadSleep_ExitCriticalSection");
+ } else if (strcmp(bif->name,"System_ProcessSleep")==0) {
+ genSystemThreadSleep(bi_iCode,nbi_parms,bi_parms,"ProcessSleep");
+ } else if (strcmp(bif->name,"System_ProcessSleep_ExitCriticalSection")==0) {
+ genSystemThreadSleep(bi_iCode,nbi_parms,bi_parms,"ProcessSleep_ExitCriticalSection");
+ } else if (strcmp(bif->name,"System_ThreadResume")==0) {
+ genSystemThreadResume(bi_iCode,nbi_parms,bi_parms);
+ } else if (strcmp(bif->name,"System_SaveThread")==0) {
+ genSystemThreadResume(bi_iCode,nbi_parms,bi_parms);
+ } else if (strcmp(bif->name,"System_ThreadResume")==0) {
+ genSystemThreadResume(bi_iCode,nbi_parms,bi_parms);
+ } else if (strcmp(bif->name,"System_ProcessResume")==0) {
+ genSystemProcessResume(bi_iCode,nbi_parms,bi_parms);
+ } else if (strcmp(bif->name,"System_SaveJavaThreadState")==0) {
+ genSystem(bi_iCode,nbi_parms,"SaveJavaThreadState");
+ } else if (strcmp(bif->name,"System_RestoreJavaThreadState")==0) {
+ genSystem(bi_iCode,nbi_parms,"RestoreJavaThreadState");
+ } else if (strcmp(bif->name,"System_ProcessYield")==0) {
+ genSystem(bi_iCode,nbi_parms,"ProcessYield");
+ } else if (strcmp(bif->name,"System_ProcessSuspend")==0) {
+ genSystem(bi_iCode,nbi_parms,"ProcessSuspend");
+ } else if (strcmp(bif->name,"System_RegisterPoll")==0) {
+ genSystemPoll(bi_iCode,nbi_parms,bi_parms,"Register");
+ } else if (strcmp(bif->name,"System_RemovePoll")==0) {
+ genSystemPoll(bi_iCode,nbi_parms,bi_parms,"Remove");
+ } else if (strcmp(bif->name,"System_GetCurrentThreadId")==0) {
+ genSystemGetCurrentID(bi_iCode,nbi_parms,bi_parms,"Thread");
+ } else if (strcmp(bif->name,"System_GetCurrentProcessId")==0) {
+ genSystemGetCurrentID(bi_iCode,nbi_parms,bi_parms,"Process");
+ } else {
+ werror(E_INTERNAL_ERROR,__FILE__,__LINE__,"unknown builtin function encountered\n");
+ return ;
+ }
+ return ;
}
/*-----------------------------------------------------------------*/
break;
case GET_VALUE_AT_ADDRESS:
- genPointerGet (ic,hasInc(IC_LEFT(ic),ic));
+ genPointerGet (ic,hasInc(IC_LEFT(ic),ic, getSize(operandType(IC_LEFT(ic)))));
break;
case '=':
if (POINTER_SET (ic))
- genPointerSet (ic,hasInc(IC_RESULT(ic),ic));
+ genPointerSet (ic,hasInc(IC_RESULT(ic),ic,getSize(operandType(IC_RIGHT(ic)))));
else
genAssign (ic);
break;