* src/z80/gen.c: Fixed up generator to pass the regresion tests, specifically fixing...
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 2 Sep 2001 04:21:43 +0000 (04:21 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 2 Sep 2001 04:21:43 +0000 (04:21 +0000)
* 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

17 files changed:
ChangeLog
device/include/asm/gbz80/features.h
device/include/asm/z80/features.h
device/lib/gbz80/Makefile
device/lib/gbz80/crt0.s
device/lib/gbz80/div.s
device/lib/gbz80/mul.s
device/lib/gbz80/printf.c
device/lib/gbz80/shift.s
device/lib/z80/Makefile
src/z80/gen.c
src/z80/main.c
src/z80/peeph.def
support/regression/Makefile
support/regression/tests/addsub.c [new file with mode: 0644]
support/tests/dhrystone/Makefile
support/tests/dhrystone/dhry.c

index 47a402a6f18c27afac7e323ce002904c84a96146..9c46fc01abe44137b8ec03c17670ff7c9cf5e129 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2001-09-01  Michael Hope  <michaelh@juju.net.nz>
 
+       * 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.
index 28866ec106a089d9ec4c815da1fd9a1f53a0b899..7e90a8dec9c0e977bbe974128273c06966e6e979 100644 (file)
@@ -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
 
index 28866ec106a089d9ec4c815da1fd9a1f53a0b899..7e90a8dec9c0e977bbe974128273c06966e6e979 100644 (file)
@@ -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
 
index b76118383d167c53408efa8d88510956a6dbb445..e0bddf0d4f0045a82de2ac3dcf55dd4ce7db8fa0 100644 (file)
@@ -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
index f4674b6d4f056b327f5da2a7499e531b51912423..653a2471961dbd51f6ae323c7c669482669a9d24 100644 (file)
@@ -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
index aaa82c28f93d865ac2ef98839091834aca62cef3..2c5f4bdf5390d646d5d07362c35d655403679a44 100644 (file)
@@ -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
        
index 9762a4016afa60c00623195f083789ea1cdf756f..453dfefa4491ff250a6718c1e4d21420a81379c7 100644 (file)
@@ -102,4 +102,9 @@ __muluint_rrx_hds::
 2$:
         dec     b
         jr      nz,1$
+
+        ;; Return in DE
+        ld      e,l
+        ld      d,h
+        
         ret
index 346eb3f1ad3ed600a49b36356c30785684b63bbd..d584bdb8c201db7d8eb643f75ab261d1120b237c 100644 (file)
@@ -5,10 +5,12 @@
 #include <stdarg.h>
 #include <stdio.h>
 
+#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? */
index f09de38279fce11e097f5be6a7d459217888004a..b6f012e4055e4ace29145e7cde6a6037bb82e616 100644 (file)
@@ -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$
index de0563224f5999f3995c73b13aa7eb9607b7df65..8d40d8678f4a2ed7040349a5ad056911f88abbe2 100644 (file)
@@ -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
index f697b995153b7d4e7197179d9a954871501b0dd6..c7a499828beab9055c97e1fcb47c574eb9507dcd 100644 (file)
@@ -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);
index 777ab9c0cd65b177e306051d37ae80209d8588bd..a13db0004787cb0c4da88e2d06ff2a2719e2090c 100644 (file)
@@ -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,
index 00375bed908c6e805d7da9ff135fa021a033673d..8e5464978cdd4ed141ead177d9ce4d674b7052b6 100644 (file)
@@ -102,3 +102,4 @@ replace restart {
 } by {
         xor     a,a
 }
+        
\ No newline at end of file
index b3c692d7457a720563776845e9a79d634dd6d45e..b20a27ef6c8e9b2892d8399de22a9db4763882ab 100644 (file)
@@ -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 (file)
index 0000000..ae3ce22
--- /dev/null
@@ -0,0 +1,43 @@
+/** Add, sub tests.
+
+    type: signed char, int, long
+    storage: static, 
+    attr: volatile
+*/
+#include <testfwk.h>
+
+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));
+}
index b36ccd92c2a9d29fc0dace75d676a4b3da8001cb..981940024a786740f063362d0639e8f77b2dc841 100644 (file)
@@ -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
index 1bb6d546fb2b920d8024874759725d238e487688..52cdb647b2335ecafc98ccf7e4cab59906b8eaa9 100644 (file)
 #include <tinibios.h>
 #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 <time.h>
 #include <types.h>
-#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