X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fz80%2Fgen.c;h=72d5726683ebcc6742b85efb135b77742e0331a3;hb=195ee3f3ee25ce2c5f2a59fbd2779c4cb80527c3;hp=8562c69a54ad76ed2faef643c886cec6c1c2f687;hpb=d2da99feec099aa224e1db53bc5a1ed42ed51ec9;p=fw%2Fsdcc diff --git a/src/z80/gen.c b/src/z80/gen.c index 8562c69a..72d57266 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -463,7 +463,7 @@ _emit2 (const char *inst, const char *fmt,...) { va_list ap; char lb[INITIAL_INLINEASM]; - char *lbp = lb; + unsigned char *lbp = lb; va_start (ap, fmt); @@ -1879,48 +1879,46 @@ aopPut (asmop * aop, const char *s, int offset) case AOP_SFR: if( IS_GB ) - { - // wassert (IS_GB); - if (strcmp (s, "a")) - emit2 ("ld a,%s", s); - emit2 ("ldh (%s+%d),a", aop->aopu.aop_dir, offset); - } + { + // wassert (IS_GB); + if (strcmp (s, "a")) + emit2 ("ld a,%s", s); + emit2 ("ldh (%s+%d),a", aop->aopu.aop_dir, offset); + } else - { /*.p.t.20030716 handling for i/o port read access for Z80 */ - if( aop->paged ) - { /* banked mode */ - if( aop->bcInUse ) emit2( "push bc" ); - - emit2( "ld bc,#%s", aop->aopu.aop_dir ); - - if(( s[0] == '#' ) /* immediate number */ - ||( s[0] == '(' ) /* indirect register (ix or iy ??)*/ - ||( isdigit( s[0] )))/* indirect register with offset (ix or iy ??)*/ - { - emit2( "ld a,%s", s ); - emit2( "out (c),a" ); - } - else - { - emit2( "out (c),%s", s ); - } + { /*.p.t.20030716 handling for i/o port read access for Z80 */ + if (aop->paged) + { /* banked mode */ + if (aop->bcInUse) + emit2( "push bc" ); + + if (strlen(s) != 1 + || (s[0] != 'a' && s[0] != 'd' && s[0] != 'e' + && s[0] != 'h' && s[0] != 'l')) + { + emit2( "ld a,%s", s ); + s = "a"; + } + + emit2( "ld bc,#%s", aop->aopu.aop_dir ); + emit2( "out (c),%s", s ); - if( aop->bcInUse ) - emit2( "pop bc" ); + if( aop->bcInUse ) + emit2( "pop bc" ); + else + spillPair (PAIR_BC); + } + else if( z80_opts.port_mode == 180 ) + { /* z180 in0/out0 mode */ + emit2( "ld a,%s", s ); + emit2( "out0 (%s),a", aop->aopu.aop_dir ); + } else - spillPair (PAIR_BC); - } - else if( z80_opts.port_mode == 180 ) - { /* z180 in0/out0 mode */ - emit2( "ld a,%s", s ); - emit2( "out0 (%s),a", aop->aopu.aop_dir ); - } - else - { /* 8 bit mode */ - emit2( "ld a,%s", s ); - emit2( "out (%s),a", aop->aopu.aop_dir ); + { /* 8 bit mode */ + emit2( "ld a,%s", s ); + emit2( "out (%s),a", aop->aopu.aop_dir ); + } } - } break; case AOP_REG: @@ -2916,7 +2914,7 @@ emitCall (iCode * ic, bool ispcall) } spillCached (); - /* Mark the regsiters as restored. */ + /* Mark the registers as restored. */ _G.saves.saved = FALSE; /* if we need assign a result value */ @@ -3102,8 +3100,11 @@ genFunction (iCode * ic) /* Create the function header */ emit2 ("!functionheader", sym->name); - sprintf (buffer, "%s_start", sym->rname); - emit2 ("!labeldef", buffer); + if (!IS_STATIC(sym->etype)) + { + sprintf (buffer, "%s_start", sym->rname); + emit2 ("!labeldef", buffer); + } emit2 ("!functionlabeldef", sym->rname); if (options.profile) @@ -3296,8 +3297,11 @@ genEndFunction (iCode * ic) emit2 ("ret"); } - sprintf (buffer, "%s_end", sym->rname); - emit2 ("!labeldef", buffer); + if (!IS_STATIC(sym->etype)) + { + sprintf (buffer, "%s_end", sym->rname); + emit2 ("!labeldef", buffer); + } _G.flushStatics = 1; _G.stack.pushed = 0; @@ -6037,6 +6041,9 @@ genLeftShift (iCode * ic) aopOp (left, ic, FALSE, FALSE); aopOp (result, ic, FALSE, FALSE); + if (AOP_TYPE (left) != AOP_REG || AOP_TYPE (result) != AOP_REG) + _push (PAIR_AF); + /* now move the left to the result if they are not the same */ @@ -6058,6 +6065,9 @@ genLeftShift (iCode * ic) offset = 0; tlbl1 = newiTempLabel (NULL); + if (AOP_TYPE (left) != AOP_REG || AOP_TYPE (result) != AOP_REG) + _pop (PAIR_AF); + emit2 ("!shortjp !tlabel", tlbl1->key + 100); emitLabel (tlbl->key + 100); l = aopGet (AOP (result), offset, FALSE); @@ -6311,6 +6321,9 @@ genRightShift (iCode * ic) aopOp (left, ic, FALSE, FALSE); aopOp (result, ic, FALSE, FALSE); + if (AOP_TYPE (left) != AOP_REG || AOP_TYPE (result) != AOP_REG) + _push (PAIR_AF); + /* now move the left to the result if they are not the same */ if (!sameRegs (AOP (left), AOP (result))) @@ -6330,6 +6343,9 @@ genRightShift (iCode * ic) tlbl1 = newiTempLabel (NULL); size = AOP_SIZE (result); offset = size - 1; + + if (AOP_TYPE (left) != AOP_REG || AOP_TYPE (result) != AOP_REG) + _pop (PAIR_AF); emit2 ("!shortjp !tlabel", tlbl1->key + 100); emitLabel (tlbl->key + 100);