+static void genNatLibLoadPointer(iCode *ic, int nparms, operand **parms)
+{
+ bitVect *rsave ;
+ operand *pnum, *result;
+ int size = 3;
+ int i;
+
+ assert (nparms==1);
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+
+ pnum = parms[0];
+ aopOp (pnum, ic, FALSE, FALSE);
+ emitcode ("mov","a,%s",aopGet(pnum,0,FALSE,FALSE,DP2_RESULT_REG));
+ freeAsmop (pnum, NULL, ic, FALSE);
+ emitcode ("lcall","NatLib_LoadPointer");
+ aopOp (result=IC_RESULT(ic), ic, FALSE, FALSE);
+ if (AOP_TYPE(result)!=AOP_STR) {
+ for (i = 0 ; i < size ; i++ ) {
+ aopPut(result,fReturn[i],i);
+ }
+ }
+ freeAsmop (result, NULL, ic, FALSE);
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genNatLibInstallStateBlock - */
+/*-----------------------------------------------------------------*/
+static void genNatLibInstallStateBlock(iCode *ic, int nparms,
+ operand **parms, const char *name)
+{
+ bitVect *rsave ;
+ operand *psb, *handle;
+ assert (nparms==2);
+
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+ psb = parms[0];
+ handle = parms[1];
+
+ /* put pointer to state block into DPTR1 */
+ aopOp (psb, ic, FALSE, FALSE);
+ if (AOP_TYPE (psb) == AOP_IMMD) {
+ emitcode ("mov","dps,#1");
+ emitcode ("mov", "dptr,%s",
+ aopGet (psb, 0, TRUE, FALSE, DP2_RESULT_REG));
+ emitcode ("mov","dps,#0");
+ } else {
+ emitcode ("mov","dpl1,%s",aopGet(psb,0,FALSE,FALSE,DP2_RESULT_REG));
+ emitcode ("mov","dph1,%s",aopGet(psb,1,FALSE,FALSE,DP2_RESULT_REG));
+ emitcode ("mov","dpx1,%s",aopGet(psb,2,FALSE,FALSE,DP2_RESULT_REG));
+ }
+ freeAsmop (psb, NULL, ic, FALSE);
+
+ /* put libraryID into DPTR */
+ emitcode ("mov","dptr,#LibraryID");
+
+ /* put handle into r3:r2 */
+ aopOp (handle, ic, FALSE, FALSE);
+ if (aopHasRegs(AOP(handle),R2_IDX,R3_IDX)) {
+ emitcode ("push","%s",aopGet(handle,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("push","%s",aopGet(handle,1,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("pop","ar3");
+ emitcode ("pop","ar2");
+ } else {
+ emitcode ("mov","r2,%s",aopGet(handle,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("mov","r3,%s",aopGet(handle,1,FALSE,TRUE,DP2_RESULT_REG));
+ }
+ freeAsmop (psb, NULL, ic, FALSE);
+
+ /* make the call */
+ emitcode ("lcall","NatLib_Install%sStateBlock",name);
+
+ /* put return value into place*/
+ _G.accInUse++;
+ aopOp (IC_RESULT(ic), ic, FALSE, FALSE);
+ _G.accInUse--;
+ aopPut(IC_RESULT(ic),"a",0);
+ freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genNatLibRemoveStateBlock - */
+/*-----------------------------------------------------------------*/
+static void genNatLibRemoveStateBlock(iCode *ic,int nparms,const char *name)
+{
+ bitVect *rsave ;
+
+ assert(nparms==0);
+
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+
+ /* put libraryID into DPTR */
+ emitcode ("mov","dptr,#LibraryID");
+ /* make the call */
+ emitcode ("lcall","NatLib_Remove%sStateBlock",name);
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genNatLibGetStateBlock - */
+/*-----------------------------------------------------------------*/
+static void genNatLibGetStateBlock(iCode *ic,int nparms,
+ operand **parms,const char *name)
+{
+ bitVect *rsave ;
+ symbol *lbl = newiTempLabel(NULL);
+
+ assert(nparms==0);
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+
+ /* put libraryID into DPTR */
+ emitcode ("mov","dptr,#LibraryID");
+ /* make the call */
+ emitcode ("lcall","NatLib_Remove%sStateBlock",name);
+ emitcode ("jnz","!tlabel",lbl->key+100);
+
+ /* put return value into place */
+ aopOp(IC_RESULT(ic),ic,FALSE,FALSE);
+ if (aopHasRegs(AOP(IC_RESULT(ic)),R2_IDX,R3_IDX)) {
+ emitcode ("push","ar3");
+ emitcode ("push","ar2");
+ emitcode ("pop","%s",
+ aopGet(IC_RESULT(ic),0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("pop","%s",
+ aopGet(IC_RESULT(ic),1,FALSE,TRUE,DP2_RESULT_REG));
+ } else {
+ aopPut(IC_RESULT(ic),"r2",0);
+ aopPut(IC_RESULT(ic),"r3",1);
+ }
+ freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
+ emitcode ("","!tlabeldef",lbl->key+100);
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genMMMalloc - */
+/*-----------------------------------------------------------------*/
+static void genMMMalloc (iCode *ic,int nparms, operand **parms,
+ int size, const char *name)
+{
+ bitVect *rsave ;
+ operand *bsize;
+ symbol *rsym;
+ symbol *lbl = newiTempLabel(NULL);
+
+ assert (nparms == 1);
+ /* save registers that need to be saved */
+ savermask(rsave = bitVectCplAnd (bitVectCopy (ic->rMask),
+ ds390_rUmaskForOp (IC_RESULT(ic))));
+
+ bsize=parms[0];
+ aopOp (bsize,ic,FALSE,FALSE);
+
+ /* put the size in R4-R2 */
+ if (aopHasRegs(AOP(bsize),R2_IDX, (size==3 ? R4_IDX: R3_IDX))) {
+ emitcode("push","%s",aopGet(bsize,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode("push","%s",aopGet(bsize,1,FALSE,TRUE,DP2_RESULT_REG));
+ if (size==3) {
+ emitcode("push","%s",aopGet(bsize,2,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode("pop","ar4");
+ }
+ emitcode("pop","ar3");
+ emitcode("pop","ar2");
+ } else {
+ emitcode ("mov","r2,%s",aopGet(bsize,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("mov","r3,%s",aopGet(bsize,1,FALSE,TRUE,DP2_RESULT_REG));
+ if (size==3) {
+ emitcode("mov","r4,%s",aopGet(bsize,2,FALSE,TRUE,DP2_RESULT_REG));
+ }
+ }
+ freeAsmop (bsize, NULL, ic, FALSE);
+
+ /* make the call */
+ emitcode ("lcall","MM_%s",name);
+ emitcode ("jz","!tlabel",lbl->key+100);
+ emitcode ("mov","r2,#!constbyte",0xff);
+ emitcode ("mov","r3,#!constbyte",0xff);
+ emitcode ("","!tlabeldef",lbl->key+100);
+ /* we don't care about the pointer : we just save the handle */
+ rsym = OP_SYMBOL(IC_RESULT(ic));
+ if (rsym->liveFrom != rsym->liveTo) {
+ aopOp(IC_RESULT(ic),ic,FALSE,FALSE);
+ if (aopHasRegs(AOP(IC_RESULT(ic)),R2_IDX,R3_IDX)) {
+ emitcode ("push","ar3");
+ emitcode ("push","ar2");
+ emitcode ("pop","%s",
+ aopGet(IC_RESULT(ic),0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("pop","%s",
+ aopGet(IC_RESULT(ic),1,FALSE,TRUE,DP2_RESULT_REG));
+ } else {
+ aopPut(IC_RESULT(ic),"r2",0);
+ aopPut(IC_RESULT(ic),"r3",1);
+ }
+ freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
+ }
+ unsavermask(rsave);
+}
+
+/*-----------------------------------------------------------------*/
+/* genMMDeref - */
+/*-----------------------------------------------------------------*/
+static void genMMDeref (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 R4-R2 */
+ if (aopHasRegs(AOP(handle),R2_IDX,R3_IDX)) {
+ emitcode("push","%s",
+ aopGet(handle,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode("push","%s",
+ aopGet(handle,1,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode("pop","ar3");
+ emitcode("pop","ar2");
+ } else {
+ emitcode ("mov","r2,%s",
+ aopGet(handle,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("mov","r3,%s",
+ aopGet(handle,1,FALSE,TRUE,DP2_RESULT_REG));
+ }
+ freeAsmop (handle, NULL, ic, FALSE);
+
+ /* make the call */
+ emitcode ("lcall","MM_Deref");
+
+ {
+ 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) {
+ _startLazyDPSEvaluation ();
+
+ aopPut(IC_RESULT(ic),"dpl",0);
+ aopPut(IC_RESULT(ic),"dph",1);
+ aopPut(IC_RESULT(ic),"dpx",2);
+
+ _endLazyDPSEvaluation ();
+
+ }
+ }
+ }
+ 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(handle,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode("push","%s",
+ aopGet(handle,1,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode("pop","ar3");
+ emitcode("pop","ar2");
+ } else {
+ emitcode ("mov","r2,%s",
+ aopGet(handle,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("mov","r3,%s",
+ aopGet(handle,1,FALSE,TRUE,DP2_RESULT_REG));
+ }
+ 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(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(handle,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode("push","%s",
+ aopGet(handle,1,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode("pop","ar3");
+ emitcode("pop","ar2");
+ } else {
+ emitcode ("mov","r2,%s",
+ aopGet(handle,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("mov","r3,%s",
+ aopGet(handle,1,FALSE,TRUE,DP2_RESULT_REG));
+ }
+ 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 (pp, 0, TRUE, FALSE, NULL));
+ } else if (AOP_TYPE(pp) != AOP_STR) { /* not already in dptr */
+ emitcode ("mov","dpl,%s",aopGet(pp,0,FALSE,FALSE,NULL));
+ emitcode ("mov","dph,%s",aopGet(pp,1,FALSE,FALSE,NULL));
+ emitcode ("mov","dpx,%s",aopGet(pp,2,FALSE,FALSE,NULL));
+ }
+ 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(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 (pp, 0, TRUE, FALSE, NULL));
+ emitcode ("mov","dps,#0");
+ } else {
+ emitcode ("mov","dpl1,%s",
+ aopGet(pp,0,FALSE,FALSE,DP2_RESULT_REG));
+ emitcode ("mov","dph1,%s",
+ aopGet(pp,1,FALSE,FALSE,DP2_RESULT_REG));
+ emitcode ("mov","dpx1,%s",
+ aopGet(pp,2,FALSE,FALSE,DP2_RESULT_REG));
+ }
+ 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(to,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("push","%s",
+ aopGet(to,1,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("push","%s",
+ aopGet(to,2,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("push","%s",
+ aopGet(to,3,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("pop","ar3");
+ emitcode ("pop","ar2");
+ emitcode ("pop","ar1");
+ emitcode ("pop","ar0");
+ } else {
+ emitcode ("mov","r0,%s",
+ aopGet(to,0,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("mov","r1,%s",
+ aopGet(to,1,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("mov","r2,%s",
+ aopGet(to,2,FALSE,TRUE,DP2_RESULT_REG));
+ emitcode ("mov","r3,%s",
+ aopGet(to,3,FALSE,TRUE,DP2_RESULT_REG));
+ }
+ freeAsmop (to, NULL, ic, FALSE);
+
+ /* suspend in acc */
+ s = parms[1];
+ aopOp(s,ic,FALSE,FALSE);
+ emitcode ("mov","a,%s",
+ aopGet(s,0,FALSE,TRUE,NULL));
+ 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(pid,0,FALSE,TRUE,DP2_RESULT_REG));
+ freeAsmop (pid, NULL, ic, FALSE);
+
+ /* tid into ACC */
+ aopOp(tid,ic,FALSE,FALSE);
+ emitcode ("mov","a,%s",
+ aopGet(tid,0,FALSE,TRUE,DP2_RESULT_REG));
+ 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(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(pid,0,FALSE,TRUE,DP2_RESULT_REG));
+ 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 (fp, 0, TRUE, FALSE, DP2_RESULT_REG));
+ } else if (AOP_TYPE(fp) != AOP_STR) { /* not already in dptr */
+ emitcode ("mov","dpl,%s",
+ aopGet(fp,0,FALSE,FALSE,DP2_RESULT_REG));
+ emitcode ("mov","dph,%s",
+ aopGet(fp,1,FALSE,FALSE,DP2_RESULT_REG));
+ emitcode ("mov","dpx,%s",
+ aopGet(fp,2,FALSE,FALSE,DP2_RESULT_REG));
+ }
+ 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(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(IC_RESULT(ic),"a",0);
+ freeAsmop (IC_RESULT(ic), NULL, ic, FALSE);
+ }
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* genDjnz - generate decrement & jump if not zero instrucion */
+/*-----------------------------------------------------------------*/
+static int
+genDjnz (iCode * ic, iCode * ifx)
+{
+ symbol *lbl, *lbl1;
+ if (!ifx)
+ return 0;
+
+ /* if the if condition has a false label
+ then we cannot save */
+ if (IC_FALSE (ifx))
+ return 0;
+
+ /* if the minus is not of the form a = a - 1 */
+ if (!isOperandEqual (IC_RESULT (ic), IC_LEFT (ic)) ||
+ !IS_OP_LITERAL (IC_RIGHT (ic)))
+ return 0;
+
+ if (operandLitValue (IC_RIGHT (ic)) != 1)
+ return 0;
+
+ /* if the size of this greater than one then no
+ saving */
+ if (getSize (operandType (IC_RESULT (ic))) > 1)
+ return 0;
+
+ /* otherwise we can save BIG */
+
+ D (emitcode (";", "genDjnz"));
+
+ lbl = newiTempLabel (NULL);
+ lbl1 = newiTempLabel (NULL);
+
+ aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+
+ if (AOP_NEEDSACC(IC_RESULT(ic)))
+ {
+ /* If the result is accessed indirectly via
+ * the accumulator, we must explicitly write
+ * it back after the decrement.
+ */
+ char *rByte = aopGet (IC_RESULT(ic), 0, FALSE, FALSE, NULL);
+
+ if (strcmp(rByte, "a"))
+ {
+ /* Something is hopelessly wrong */
+ fprintf(stderr, "*** warning: internal error at %s:%d\n",
+ __FILE__, __LINE__);
+ /* We can just give up; the generated code will be inefficient,
+ * but what the hey.
+ */
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ return 0;
+ }
+ emitcode ("dec", "%s", rByte);
+ aopPut (IC_RESULT (ic), rByte, 0);
+ emitcode ("jnz", "!tlabel", lbl->key + 100);
+ }
+ else if (IS_AOP_PREG (IC_RESULT (ic)))
+ {
+ emitcode ("dec", "%s",
+ aopGet (IC_RESULT (ic), 0, FALSE, FALSE, NULL));
+ MOVA (aopGet (IC_RESULT (ic), 0, FALSE, FALSE, NULL));
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ ifx->generated = 1;
+ emitcode ("jnz", "!tlabel", lbl->key + 100);
+ }
+ else
+ {
+ emitcode ("djnz", "%s,!tlabel", aopGet (IC_RESULT (ic), 0, FALSE, TRUE, NULL),
+ lbl->key + 100);
+ }
+ emitcode ("sjmp", "!tlabel", lbl1->key + 100);
+ emitLabel (lbl);
+ emitcode ("ljmp", "!tlabel", IC_TRUE (ifx)->key + 100);
+ emitLabel (lbl1);
+
+ if (!ifx->generated)
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ ifx->generated = 1;
+ return 1;
+}
+
+/*-----------------------------------------------------------------*/
+/* genReceive - generate code for a receive iCode */
+/*-----------------------------------------------------------------*/
+static void
+genReceive (iCode * ic)
+{
+ int size = getSize (operandType (IC_RESULT (ic)));
+ int offset = 0;
+ int rb1off ;
+
+ D (emitcode (";", "genReceive"));
+
+ if (ic->argreg == 1)
+ {
+ /* first parameter */
+ if (AOP_IS_STR(IC_RESULT(ic)))
+ {
+ /* Nothing to do: it's already in the proper place. */
+ return;
+ }
+ else
+ {
+ bool useDp2;
+
+ useDp2 = isOperandInFarSpace (IC_RESULT (ic)) &&
+ (OP_SYMBOL (IC_RESULT (ic))->isspilt ||
+ IS_TRUE_SYMOP (IC_RESULT (ic)));
+
+ _G.accInUse++;
+ aopOp (IC_RESULT (ic), ic, FALSE, useDp2);
+ _G.accInUse--;
+
+ /* Sanity checking... */
+ if (AOP_USESDPTR(IC_RESULT(ic)))
+ {
+ werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+ "genReceive got unexpected DPTR.");
+ }
+ assignResultValue (IC_RESULT (ic), NULL);
+ }
+ }
+ else if (ic->argreg > 12)
+ { /* bit parameters */
+ if (OP_SYMBOL (IC_RESULT (ic))->regs[0]->rIdx != ic->argreg-5)
+ {
+ aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+ emitcode ("mov", "c,%s", rb1regs[ic->argreg-5]);
+ outBitC(IC_RESULT (ic));
+ }
+ }
+ else
+ {
+ /* second receive onwards */
+ /* this gets a little tricky since unused receives will be
+ eliminated, we have saved the reg in the type field . and
+ we use that to figure out which register to use */
+ aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+ rb1off = ic->argreg;
+ while (size--)
+ {
+ aopPut (IC_RESULT (ic), rb1regs[rb1off++ -5], offset++);
+ }
+ }
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+}
+
+/*-----------------------------------------------------------------*/
+/* genDummyRead - generate code for dummy read of volatiles */
+/*-----------------------------------------------------------------*/
+static void
+genDummyRead (iCode * ic)
+{
+ operand *op;
+ int size, offset;
+
+ D (emitcode(";", "genDummyRead"));
+
+ op = IC_RIGHT (ic);
+ if (op && IS_SYMOP (op))
+ {
+ aopOp (op, ic, FALSE, FALSE);
+
+ /* if the result is a bit */
+ if (AOP_TYPE (op) == AOP_CRY)
+ emitcode ("mov", "c,%s", AOP (op)->aopu.aop_dir);
+ else
+ {
+ /* bit variables done */
+ /* general case */
+ size = AOP_SIZE (op);
+ offset = 0;
+ while (size--)
+ {
+ MOVA (aopGet (op, offset, FALSE, FALSE, FALSE));
+ offset++;
+ }
+ }
+
+ freeAsmop (op, NULL, ic, TRUE);
+ }
+
+ op = IC_LEFT (ic);
+ if (op && IS_SYMOP (op))
+ {
+ aopOp (op, ic, FALSE, FALSE);
+
+ /* if the result is a bit */
+ if (AOP_TYPE (op) == AOP_CRY)
+ emitcode ("mov", "c,%s", AOP (op)->aopu.aop_dir);
+ else
+ {
+ /* bit variables done */
+ /* general case */
+ size = AOP_SIZE (op);
+ offset = 0;
+ while (size--)
+ {
+ MOVA (aopGet (op, offset, FALSE, FALSE, FALSE));
+ offset++;
+ }
+ }
+
+ freeAsmop (op, NULL, ic, TRUE);
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* genCritical - generate code for start of a critical sequence */
+/*-----------------------------------------------------------------*/
+static void
+genCritical (iCode *ic)
+{
+ symbol *tlbl = newiTempLabel (NULL);
+
+ D (emitcode(";", "genCritical"));
+
+ if (IC_RESULT (ic))
+ {
+ aopOp (IC_RESULT (ic), ic, TRUE, FALSE);
+ aopPut (IC_RESULT (ic), one, 0); /* save old ea in an operand */
+ emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
+ aopPut (IC_RESULT (ic), zero, 0);
+ emitLabel (tlbl);
+ freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
+ }
+ else
+ {
+ emitcode ("setb", "c");
+ emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */
+ emitcode ("clr", "c");
+ emitLabel (tlbl);
+ emitcode ("push", "psw"); /* save old ea via c in psw on top of stack*/
+ }
+}
+
+/*-----------------------------------------------------------------*/
+/* genEndCritical - generate code for end of a critical sequence */
+/*-----------------------------------------------------------------*/
+static void
+genEndCritical (iCode *ic)
+{
+ D(emitcode("; genEndCritical",""));
+
+ if (IC_RIGHT (ic))
+ {
+ aopOp (IC_RIGHT (ic), ic, FALSE, FALSE);
+ if (AOP_TYPE (IC_RIGHT (ic)) == AOP_CRY)
+ {
+ emitcode ("mov", "c,%s", IC_RIGHT (ic)->aop->aopu.aop_dir);
+ emitcode ("mov", "ea,c");
+ }
+ else
+ {
+ MOVA (aopGet (IC_RIGHT (ic), 0, FALSE, FALSE, FALSE));
+ emitcode ("rrc", "a");
+ emitcode ("mov", "ea,c");
+ }
+ freeAsmop (IC_RIGHT (ic), NULL, ic, TRUE);
+ }
+ else
+ {
+ emitcode ("pop", "psw"); /* restore ea via c in psw on top of stack */
+ emitcode ("mov", "ea,c");
+ }
+}
+
+
+
+/*-----------------------------------------------------------------*/
+/* 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_memcmp_x2x")==0) {
+ genMemcmpX2X(bi_iCode,nbi_parms,bi_parms,0);
+ } else if (strcmp(bif->name,"__builtin_memcmp_c2x")==0) {
+ genMemcmpX2X(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,"__builtin_inp")==0) {
+ genInp(bi_iCode,nbi_parms,bi_parms);
+ } else if (strcmp(bif->name,"__builtin_outp")==0) {
+ genOutp(bi_iCode,nbi_parms,bi_parms);
+ } else if (strcmp(bif->name,"__builtin_swapw")==0) {
+ genSwapW(bi_iCode,nbi_parms,bi_parms);
+ /* JavaNative builtIns */
+ } 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 ;
+}
+
+/*-----------------------------------------------------------------*/
+/* gen390Code - generate code for Dallas 390 based controllers */
+/*-----------------------------------------------------------------*/
+void