From: michaelh Date: Sun, 7 Oct 2001 18:28:35 +0000 (+0000) Subject: * src/z80/gen.c (setupPair): Added 'extended stack' support for the z80. Can now... X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=d7ea4ed7cf4844be678bacdf2ed38e4073335013;p=fw%2Fsdcc * src/z80/gen.c (setupPair): Added 'extended stack' support for the z80. Can now have local variables or parameters of more than 127 bytes in size. Increadibly slow, but it will work. Currently anything involving the carry flag. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1373 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 204e19bd..203d72e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2001-10-07 Michael Hope + * src/z80/gen.c (setupPair): Added 'extended stack' support for the z80. Can now have local variables or parameters of more than 127 bytes in size. Increadibly slow, but it will work. Currently anything involving the carry flag. + * support/Util/NewAlloc.c (freeTrace): Changed free for the gc case to not free at all. Fixes runtime segfault. * support/regression/tests/scott-compare3.c (c_abcd): Fixed up casts. diff --git a/src/z80/gen.c b/src/z80/gen.c index 91528e38..7421f800 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -167,10 +167,6 @@ static struct // PENDING #define ACC_NAME _pairs[PAIR_AF].h -#define RESULTONSTACK(x) \ - (IC_RESULT(x) && IC_RESULT(x)->aop && \ - IC_RESULT(x)->aop->type == AOP_STK ) - enum { LSB, @@ -539,8 +535,21 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool requires_a) /* Assign depending on the storage class */ if (sym->onStack || sym->iaccess) { - emitDebug ("; AOP_STK for %s", sym->rname); - sym->aop = aop = newAsmop (AOP_STK); + /* The pointer that is used depends on how big the offset is. + Normally everything is AOP_STK, but for offsets of < -127 or + > 128 on the Z80 an extended stack pointer is used. + */ + if (IS_Z80 && (sym->stack < -127 || sym->stack > (int)(128-getSize (sym->type)))) + { + emitDebug ("; AOP_EXSTK for %s", sym->rname); + sym->aop = aop = newAsmop (AOP_EXSTK); + } + else + { + emitDebug ("; AOP_STK for %s", sym->rname); + sym->aop = aop = newAsmop (AOP_STK); + } + aop->size = getSize (sym->type); aop->aopu.aop_stk = sym->stack; return aop; @@ -1038,6 +1047,7 @@ requiresHL (asmop * aop) case AOP_IY: case AOP_HL: case AOP_STK: + case AOP_EXSTK: return TRUE; default: return FALSE; @@ -1150,12 +1160,39 @@ setupPair (PAIR_ID pairId, asmop * aop, int offset) switch (aop->type) { case AOP_IY: + wassertl (pairId == PAIR_IY, "AOP_IY must be in IY"); fetchLitPair (pairId, aop, 0); break; + case AOP_HL: fetchLitPair (pairId, aop, offset); _G.pairs[pairId].offset = offset; break; + + case AOP_EXSTK: + wassertl (IS_Z80, "Only the Z80 has an extended stack"); + wassertl (pairId == PAIR_IY, "The Z80 extended stack must be in IY"); + + { + int offset = aop->aopu.aop_stk + _G.stack.offset; + + if (_G.pairs[pairId].last_type == aop->type && + _G.pairs[pairId].offset == offset) + { + /* Already setup */ + } + else + { + /* PENDING: Do this better. */ + sprintf (buffer, "%d", offset + _G.stack.pushed); + emit2 ("ld iy,!hashedstr", buffer); + emit2 ("add iy,sp"); + _G.pairs[pairId].last_type = aop->type; + _G.pairs[pairId].offset = offset; + } + } + break; + case AOP_STK: { /* Doesnt include _G.stack.pushed */ @@ -1263,6 +1300,13 @@ aopGet (asmop * aop, int offset, bool bit16) return traceAlloc(&_G.trace.aops, Safe_strdup(s)); + case AOP_EXSTK: + wassert (IS_Z80); + setupPair (PAIR_IY, aop, offset); + tsprintf (s, "!*iyx", offset, offset); + + return traceAlloc(&_G.trace.aops, Safe_strdup(s)); + case AOP_STK: if (IS_GB) { @@ -1398,14 +1442,17 @@ aopPut (asmop * aop, const char *s, int offset) case AOP_IY: wassert (!IS_GB); - setupPair (PAIR_IY, aop, offset); if (!canAssignToPtr (s)) { emit2 ("ld a,%s", s); + setupPair (PAIR_IY, aop, offset); emit2 ("ld !*iyx,a", offset); } else - emit2 ("ld !*iyx,%s", offset, s); + { + setupPair (PAIR_IY, aop, offset); + emit2 ("ld !*iyx,%s", offset, s); + } break; case AOP_HL: @@ -1421,6 +1468,21 @@ aopPut (asmop * aop, const char *s, int offset) emit2 ("ld !*hl,%s", s); break; + case AOP_EXSTK: + wassert (!IS_GB); + if (!canAssignToPtr (s)) + { + emit2 ("ld a,%s", s); + setupPair (PAIR_IY, aop, offset); + emit2 ("ld !*iyx,a", offset); + } + else + { + setupPair (PAIR_IY, aop, offset); + emit2 ("ld !*iyx,%s", offset, s); + } + break; + case AOP_STK: if (IS_GB) { diff --git a/src/z80/gen.h b/src/z80/gen.h index 57277a34..8751531c 100644 --- a/src/z80/gen.h +++ b/src/z80/gen.h @@ -53,7 +53,9 @@ typedef enum /* Is in H and L */ AOP_HLREG, /* Simple literal. */ - AOP_SIMPLELIT + AOP_SIMPLELIT, + /* Is in the extended stack pointer (IY on the Z80) */ + AOP_EXSTK } AOP_TYPE; diff --git a/support/regression/tests/bp.c b/support/regression/tests/bp.c index f534c98e..41cd4c77 100644 --- a/support/regression/tests/bp.c +++ b/support/regression/tests/bp.c @@ -15,8 +15,8 @@ verifyBlock(char *p, char val, int len) return 1; } -char -spoil(char a) +int +spoil(int a) { return a; } @@ -42,7 +42,7 @@ void testBP(void) { char above[ABOVE_MEM_SIZE]; - char f; + int f; char below[BELOW_MEM_SIZE]; memset(above, ABOVE_MEM_TEST_SIZE, sizeof(above)); @@ -56,4 +56,5 @@ testBP(void) ASSERT(verifyBlock(above, ABOVE_MEM_TEST_SIZE, sizeof(above))); ASSERT(verifyBlock(below, BELOW_MEM_TEST_SIZE, sizeof(below))); + }