From 12a13c467cb444adb9317ffca8f4899f5076de3f Mon Sep 17 00:00:00 2001 From: michaelh Date: Sun, 2 Sep 2001 04:21:43 +0000 Subject: [PATCH] * src/z80/gen.c: Fixed up generator to pass the regresion tests, specifically fixing loads for longs, genCmp, and turned on the map file. * device/lib/gbz80/Makefile: Fixed up all the libraries to pass the regression tests. * support/regression/ports/host/spec.mk: Updated to compile with the new type specifiers. * device/lib/Makefile.in (Z80SOURCES): Removed old _mululong, _mulslong, and unneeded _mulint. * device/lib/_mullong.c (_mulslong): Changed to actually return a value :) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1210 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 2 + device/include/asm/gbz80/features.h | 4 +- device/include/asm/z80/features.h | 4 +- device/lib/gbz80/Makefile | 5 +- device/lib/gbz80/crt0.s | 3 ++ device/lib/gbz80/div.s | 30 +++++------- device/lib/gbz80/mul.s | 5 ++ device/lib/gbz80/printf.c | 11 +++-- device/lib/gbz80/shift.s | 76 ++++++++++++++--------------- device/lib/z80/Makefile | 5 +- src/z80/gen.c | 64 ++++++++++++++++++++---- src/z80/main.c | 3 +- src/z80/peeph.def | 1 + support/regression/Makefile | 2 +- support/regression/tests/addsub.c | 43 ++++++++++++++++ support/tests/dhrystone/Makefile | 3 ++ support/tests/dhrystone/dhry.c | 21 +++----- 17 files changed, 187 insertions(+), 95 deletions(-) create mode 100644 support/regression/tests/addsub.c diff --git a/ChangeLog b/ChangeLog index 47a402a6..9c46fc01 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2001-09-01 Michael Hope + * device/lib/gbz80/Makefile: Fixed up all the libraries to pass the regression tests. + * support/regression/ports/host/spec.mk: Updated to compile with the new type specifiers. * device/lib/Makefile.in (Z80SOURCES): Removed old _mululong, _mulslong, and unneeded _mulint. diff --git a/device/include/asm/gbz80/features.h b/device/include/asm/gbz80/features.h index 28866ec1..7e90a8de 100644 --- a/device/include/asm/gbz80/features.h +++ b/device/include/asm/gbz80/features.h @@ -11,8 +11,8 @@ /* The following are disabled to make the dhrystone test more authentic. */ -#define _SDCC_PORT_PROVIDES_MEMCPY 1 -#define _SDCC_PORT_PROVIDES_STRCMP 1 +#define _SDCC_PORT_PROVIDES_MEMCPY 0 +#define _SDCC_PORT_PROVIDES_STRCMP 0 /* Register allocator is as good as hand coded asm. Cool. */ #define _SDCC_PORT_PROVIDES_STRCPY 0 diff --git a/device/include/asm/z80/features.h b/device/include/asm/z80/features.h index 28866ec1..7e90a8de 100644 --- a/device/include/asm/z80/features.h +++ b/device/include/asm/z80/features.h @@ -11,8 +11,8 @@ /* The following are disabled to make the dhrystone test more authentic. */ -#define _SDCC_PORT_PROVIDES_MEMCPY 1 -#define _SDCC_PORT_PROVIDES_STRCMP 1 +#define _SDCC_PORT_PROVIDES_MEMCPY 0 +#define _SDCC_PORT_PROVIDES_STRCMP 0 /* Register allocator is as good as hand coded asm. Cool. */ #define _SDCC_PORT_PROVIDES_STRCPY 0 diff --git a/device/lib/gbz80/Makefile b/device/lib/gbz80/Makefile index b7611838..e0bddf0d 100644 --- a/device/lib/gbz80/Makefile +++ b/device/lib/gbz80/Makefile @@ -5,7 +5,8 @@ TOPDIR = ../../.. SCC = $(TOPDIR)/bin/sdcc -mgbz80 SAS = $(TOPDIR)/bin/as-gbz80 -OBJ = putchar.o string.o printf.o div.o mul.o stubs.o shift.o +OBJ = div.o mul.o putchar.o printf.o shift.o stubs.o + LIB = gbz80.lib CC = $(SCC) AS = $(SAS) @@ -23,4 +24,4 @@ $(LIB): $(OBJ) Makefile _dummy _dummy: clean: - rm -f $(OBJ) *~ $(CLEANSPEC) *.dump* *.asm *.lib + rm -f *.o *.sym *.lst *~ $(CLEANSPEC) *.dump* *.asm *.lib diff --git a/device/lib/gbz80/crt0.s b/device/lib/gbz80/crt0.s index f4674b6d..653a2471 100644 --- a/device/lib/gbz80/crt0.s +++ b/device/lib/gbz80/crt0.s @@ -30,6 +30,9 @@ init: ;; Stack at the top of memory. ld sp,#0xdfff + ;; Setup global data + call gsinit + ;; Use _main instead of main to bypass sdcc's intelligence call _main jp _exit diff --git a/device/lib/gbz80/div.s b/device/lib/gbz80/div.s index aaa82c28..2c5f4bdf 100644 --- a/device/lib/gbz80/div.s +++ b/device/lib/gbz80/div.s @@ -15,8 +15,8 @@ __divschar_rrx_hds:: call .div8 - ld l,c - ld h,b + ld e,c + ld d,b ret @@ -34,9 +34,8 @@ __modschar_rrx_hds:: call .div8 - ld l,e - ld h,d - + ;; Already in DE + ret __divsint_rrx_s:: @@ -59,8 +58,8 @@ __divsint_rrx_hds:: call .div16 - ld l,c - ld h,b + ld e,c + ld d,b ret @@ -84,8 +83,7 @@ __modsint_rrx_hds:: call .div16 - ld l,e - ld h,d + ;; Already in DE ret @@ -103,8 +101,8 @@ __divuchar_rrx_hds:: ld c,l call .divu8 - ld l,c - ld h,b + ld e,c + ld d,b ret @@ -121,8 +119,7 @@ __moduchar_rrx_hds:: ld c,l call .divu8 - ld l,e - ld h,d + ;; Already in DE ret @@ -145,8 +142,8 @@ __divuint_rrx_hds:: ld c,l call .divu16 - ld l,c - ld h,b + ld e,c + ld d,b ret @@ -170,8 +167,7 @@ __moduint_rrx_hds:: call .divu16 - ld l,e - ld h,d + ;; Already in DE ret diff --git a/device/lib/gbz80/mul.s b/device/lib/gbz80/mul.s index 9762a401..453dfefa 100644 --- a/device/lib/gbz80/mul.s +++ b/device/lib/gbz80/mul.s @@ -102,4 +102,9 @@ __muluint_rrx_hds:: 2$: dec b jr nz,1$ + + ;; Return in DE + ld e,l + ld d,h + ret diff --git a/device/lib/gbz80/printf.c b/device/lib/gbz80/printf.c index 346eb3f1..d584bdb8 100644 --- a/device/lib/gbz80/printf.c +++ b/device/lib/gbz80/printf.c @@ -5,10 +5,12 @@ #include #include +#define STATIC + /* PENDING */ #define NULL 0 -static void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(), void *pData) +STATIC void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(char, void *), void *pData) { const char *_hex = "0123456789ABCDEF"; if (issigned && ((int)u < 0)) { @@ -20,13 +22,13 @@ static void _printn(unsigned u, unsigned base, char issigned, void (*emitter)(), (*emitter)(_hex[u%base], pData); } -static void _printf(const char *format, void (*emitter)(), void *pData, va_list va) +STATIC void _printf(const char *format, void (*emitter)(char, void *), void *pData, va_list va) { while (*format) { if (*format == '%') { switch (*++format) { case 'c': { - char c = va_arg(va, char); + char c = (char)va_arg(va, int); (*emitter)(c, pData); break; } @@ -67,7 +69,7 @@ static void _printf(const char *format, void (*emitter)(), void *pData, va_list void putchar(char c); -static void _char_emitter(char c, void *pData) +STATIC void _char_emitter(char c, void *pData) { /* PENDING: Make the compiler happy. */ pData = 0; @@ -80,7 +82,6 @@ int printf(const char *format, ...) va_list va; va_start(va, format); - _printf(format, _char_emitter, NULL, va); _printf(format, _char_emitter, NULL, va); /* PENDING: What to return? */ diff --git a/device/lib/gbz80/shift.s b/device/lib/gbz80/shift.s index f09de382..b6f012e4 100644 --- a/device/lib/gbz80/shift.s +++ b/device/lib/gbz80/shift.s @@ -1,85 +1,85 @@ ;; __rrulong_rrx_s:: - ld hl,#2+4 + ld hl,#2 add hl,sp - - ld c,(hl) - dec hl - ld d,(hl) - dec hl + ld e,(hl) - dec hl + inc hl + ld d,(hl) + inc hl + ld c,(hl) + inc hl + ld b,(hl) + inc hl ld a,(hl) - dec hl - ld l,(hl) - ld h,a - ld a,c + ld l,c + ld h,b 1$: or a,a ret z - rr d - rr e rr h rr l + rr d + rr e dec a jp 1$ __rrslong_rrx_s:: - ld hl,#2+4 + ld hl,#2 add hl,sp - ld c,(hl) - dec hl - ld d,(hl) - dec hl ld e,(hl) - dec hl + inc hl + ld d,(hl) + inc hl + ld c,(hl) + inc hl + ld b,(hl) + inc hl ld a,(hl) - dec hl - ld l,(hl) - ld h,a - ld a,c + ld l,c + ld h,b 1$: or a,a ret z - sra d - rr e - rr h + sra h rr l + rr d + rr e dec a jp 1$ __rlslong_rrx_s:: __rlulong_rrx_s:: - ld hl,#2+4 + ld hl,#2 add hl,sp - ld c,(hl) - dec hl - ld d,(hl) - dec hl ld e,(hl) - dec hl + inc hl + ld d,(hl) + inc hl + ld c,(hl) + inc hl + ld b,(hl) + inc hl ld a,(hl) - dec hl - ld l,(hl) - ld h,a - ld a,c + ld l,c + ld h,b 1$: or a,a ret z - rl l - rl h rl e rl d + rl l + rl h dec a jp 1$ diff --git a/device/lib/z80/Makefile b/device/lib/z80/Makefile index de056322..8d40d867 100644 --- a/device/lib/z80/Makefile +++ b/device/lib/z80/Makefile @@ -5,8 +5,7 @@ TOPDIR = ../../.. SCC = $(TOPDIR)/bin/sdcc -mz80 SAS = $(TOPDIR)/bin/as-z80 -OBJ = div.o mul.o putchar.o printf.o shift.o stubs.o \ - asm_strings.o +OBJ = div.o mul.o putchar.o printf.o shift.o stubs.o LIB = z80.lib CC = $(SCC) @@ -30,4 +29,4 @@ $(LIB): $(OBJ) Makefile _dummy _dummy: clean: - rm -f $(OBJ) *~ $(CLEANSPEC) *.dump* *.asm *.lib + rm -f *.o *.sym *.lst *~ $(CLEANSPEC) *.dump* *.asm *.lib diff --git a/src/z80/gen.c b/src/z80/gen.c index f697b995..c7a49982 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -217,6 +217,42 @@ static struct static const char *aopGet (asmop * aop, int offset, bool bit16); +static PAIR_ID +_getTempPairId(void) +{ + if (IS_GB) + { + return PAIR_DE; + } + else + { + return PAIR_HL; + } +} + +static const char * +_getTempPairName(void) +{ + return _pairs[_getTempPairId()].name; +} + +#if 0 +static const char * +_getTempPairPart(int idx) +{ + wassertl (idx == LSB || idx == MSB16, "Invalid pair offset"); + + if (idx == LSB) + { + return _pairs[_getTempPairId()].l; + } + else + { + return _pairs[_getTempPairId()].h; + } +} +#endif + static void _tidyUp (char *buf) { @@ -1064,18 +1100,21 @@ fetchPairLong (PAIR_ID pairId, asmop * aop, int offset) /* we need to get it byte by byte */ if (pairId == PAIR_HL && IS_GB && requiresHL (aop)) { aopGet (aop, offset, FALSE); - switch (aop->size) { + switch (aop->size - offset) { case 1: emit2 ("ld l,!*hl"); emit2 ("ld h,!immedbyte", 0); break; case 2: + // PENDING: Requires that you are only fetching two bytes. + case 4: emit2 ("!ldahli"); emit2 ("ld h,!*hl"); emit2 ("ld l,a"); break; default: - emitDebug ("; WARNING: mlh woosed out. This code is invalid."); + wassertl (0, "Attempted to fetch too much data into HL"); + break; } } else if (IS_Z80 && aop->type == AOP_IY) { @@ -1768,8 +1807,7 @@ assignResultValue (operand * oper) _push (PAIR_HL); aopPut (AOP (oper), _fReturn[0], 0); aopPut (AOP (oper), _fReturn[1], 1); - emit2 ("pop de"); - _G.stack.pushed -= 2; + _pop (PAIR_DE); aopPut (AOP (oper), _fReturn[0], 2); aopPut (AOP (oper), _fReturn[1], 3); } @@ -2921,15 +2959,16 @@ genMinusDec (iCode * ic) /* if increment 16 bits in register */ if (sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) && - (size == 2)) + (size == 2) + ) { - fetchPair (PAIR_HL, AOP (IC_RESULT (ic))); + fetchPair (_getTempPairId(), AOP (IC_RESULT (ic))); while (icount--) { - emit2 ("dec hl"); + emit2 ("dec %s", _getTempPairName()); } - aopPut (AOP (IC_RESULT (ic)), "l", LSB); - aopPut (AOP (IC_RESULT (ic)), "h", MSB16); + + commitPair (AOP (IC_RESULT (ic)), _getTempPairId()); return TRUE; } @@ -3030,6 +3069,9 @@ genMinus (iCode * ic) } else if (size == 4) { + /* Anything could be on the stack, and we can't afford + to setup the base pointer as that may nuke the carry. + */ emitDebug ("; WARNING: This sub is probably broken.\n"); } } @@ -3220,6 +3262,9 @@ genCmp (operand * left, operand * right, } else { +#if 0 + // PENDING: Doesn't work around zero + /* Special cases: On the GB: If the left or the right is a lit: @@ -3259,6 +3304,7 @@ genCmp (operand * left, operand * right, emit2 ("add hl,%s", _getPairIdName (id)); goto release; } +#endif if (AOP_TYPE (right) == AOP_LIT) { lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit); diff --git a/src/z80/main.c b/src/z80/main.c index 777ab9c0..a13db000 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -383,7 +383,7 @@ static const char *_gbz80_asmCmd[] = static const char *_gbz80_linkCmd[] = { - "link-z80", + "link-gbz80", "-n", // Don't echo output "-c", // Command line input "--", // Again, command line input... @@ -424,6 +424,7 @@ _link(const char *portName, const char *portExt, const char *portOutputType) "-- " // Again, command line input... "-b_CODE=0x%04X " // Code starts at 0x200 "-b_DATA=0x%04X " // RAM starts at 0x8000 + "-m " // Map file "-j ", // Output a symbol file as well portName, options.code_loc, diff --git a/src/z80/peeph.def b/src/z80/peeph.def index 00375bed..8e546497 100644 --- a/src/z80/peeph.def +++ b/src/z80/peeph.def @@ -102,3 +102,4 @@ replace restart { } by { xor a,a } + \ No newline at end of file diff --git a/support/regression/Makefile b/support/regression/Makefile index b3c692d7..b20a27ef 100644 --- a/support/regression/Makefile +++ b/support/regression/Makefile @@ -182,4 +182,4 @@ clean: rm -rf $(CASES_DIR) $(RESULTS_DIR) *.pyc inter-port-clean: - rm -f fwk/lib/*.o + rm -f fwk/lib/*.o fwk/lib/*.asm diff --git a/support/regression/tests/addsub.c b/support/regression/tests/addsub.c new file mode 100644 index 00000000..ae3ce224 --- /dev/null +++ b/support/regression/tests/addsub.c @@ -0,0 +1,43 @@ +/** Add, sub tests. + + type: signed char, int, long + storage: static, + attr: volatile +*/ +#include + +void +testAdd(void) +{ + {storage} {attr} {type} left, right, result; + + left = 5; + right = 26; + + result = left+right; + ASSERT(result == 31); + + left = 39; + right = -120; + + result = left+right; + ASSERT(result == (39-120)); +} + +void +testSub(void) +{ + {storage} {attr} {type} left, right, result; + + left = 5; + right = 26; + + result = left-right; + ASSERT(result == (5-26)); + + left = 39; + right = -76; + + result = left-right; + ASSERT(result == (39+76)); +} diff --git a/support/tests/dhrystone/Makefile b/support/tests/dhrystone/Makefile index b36ccd92..98194002 100644 --- a/support/tests/dhrystone/Makefile +++ b/support/tests/dhrystone/Makefile @@ -15,6 +15,9 @@ all: dhry.bin dhry.ihx: dhry.c $(CC) $(CFLAGS) dhry.c +dhry.gb: dhry.c + $(CC) $(CFLAGS) dhry.c + dhry.c: dhry.h dhry.bin: dhry.ihx diff --git a/support/tests/dhrystone/dhry.c b/support/tests/dhrystone/dhry.c index 1bb6d546..52cdb647 100644 --- a/support/tests/dhrystone/dhry.c +++ b/support/tests/dhrystone/dhry.c @@ -52,28 +52,18 @@ #include #define clock() ClockTicks() #define CLOCKS_PER_SEC 1000 -#undef PRINT_T_STATES #define memcpy(d,s,l) memcpyx(d,s,l) -#elif defined(__z80) +#elif defined(__z80) || defined(__gbz80) unsigned int _clock(void); #define clock _clock #define CLOCKS_PER_SEC 100 -#define PRINT_T_STATES 1 #else /** For clock() */ #include #include -#define PRINT_T_STATES -#endif - -/** Print the number of t-states this program has been executing for. - Optional :) -*/ -#ifdef PRINT_T_STATES -void _printTStates(void); #endif /** Set to one to print more messages about expected values etc. @@ -98,6 +88,10 @@ int Arr_2_Glob [50] [50]; /* Used instead of malloc() */ static Rec_Type _r[2]; +void mark(void) +{ +} + void Proc_1 (REG Rec_Pointer Ptr_Val_Par); void Proc_2 (One_Fifty *Int_Par_Ref); void Proc_5 (void); @@ -226,10 +220,6 @@ int main(void) DPRINTF(("Looping.\n")); } /* loop "for Run_Index" */ -#ifdef PRINT_T_STATES - _printTStates(); -#endif - printf("Run_Index = %d\n", Run_Index); runTime = clock() - runTime; @@ -292,6 +282,7 @@ int main(void) #endif #if 1 printf("Number of runs: %u. runTime: %u.\n", Number_Of_Runs, (unsigned)runTime); + mark(); printf("Dhrystones/s = %u\n", (unsigned)((unsigned long)Number_Of_Runs / (runTime/CLOCKS_PER_SEC))); printf("MIPS = d/s/1757 = (sigh, need floats...)\n"); #endif -- 2.30.2