Changes to support big endian targets:
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 8 Aug 2003 03:52:39 +0000 (03:52 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 8 Aug 2003 03:52:39 +0000 (03:52 +0000)
* src/ports.h
* src/SDCCglue.c
* src/avr/main.c
* src/ds390/main.c
* src/izt/i186.c
* src/mcs51/main.c
* src/pic/main.c
* src/pic16/main.c
* src/xa51/main.c
* src/z80/main.c

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2819 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCglue.c
src/avr/main.c
src/ds390/main.c
src/izt/i186.c
src/mcs51/main.c
src/pic/main.c
src/pic16/main.c
src/port.h
src/xa51/main.c
src/z80/main.c

index ef9042de876d12a82ad20f39be8641e097884236..c175d63e6305bcb1594ab3f863d7d877bb0baddb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,19 @@
 
        * src/z80/ralloc.c (joinPushes): made compatible with new signedness
 
+       Changes to support big endian targets:
+
+       * src/ports.h
+       * src/SDCCglue.c
+       * src/avr/main.c
+       * src/ds390/main.c
+       * src/izt/i186.c
+       * src/mcs51/main.c
+       * src/pic/main.c
+       * src/pic16/main.c
+       * src/xa51/main.c
+       * src/z80/main.c
+
 2003-08-06  Bernhard Held <bernhard@bernhardheld.de>
 
        * src/SDCCval.c (cheapestVal): changed behaviour to the same as constVal()
index d1a9d8db1fb3e0e0e87af1eb5b4f04e76ef447a6..dea2f99913b411e8e657b411b53cc226ed84f322 100644 (file)
@@ -581,11 +581,17 @@ _printPointerType (FILE * oFile, const char *name)
 {
   if (options.model == MODEL_FLAT24)
     {
-      fprintf (oFile, "\t.byte %s,(%s >> 8),(%s >> 16)", name, name, name);
+      if (port->little_endian)
+        fprintf (oFile, "\t.byte %s,(%s >> 8),(%s >> 16)", name, name, name);
+      else
+        fprintf (oFile, "\t.byte (%s >> 16),(%s >> 8),%s", name, name, name);
     }
   else
     {
-      fprintf (oFile, "\t.byte %s,(%s >> 8)", name, name);
+      if (port->little_endian)
+        fprintf (oFile, "\t.byte %s,(%s >> 8)", name, name);
+      else
+        fprintf (oFile, "\t.byte (%s >> 8),%s", name, name);
     }
 }
 
@@ -643,19 +649,26 @@ printIvalType (symbol *sym, sym_link * type, initList * ilist, FILE * oFile)
        case 2:
                if (port->use_dw_for_init)
                        tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, 2));
-               else
+               else if (port->little_endian)
                        fprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
+               else
+                       fprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 1), aopLiteral (val, 0));
                break;
        case 4:
                if (!val) {
                        tfprintf (oFile, "\t!dw !constword\n", 0);
                        tfprintf (oFile, "\t!dw !constword\n", 0);
                }
-               else {
+               else if (port->little_endian) {
                        fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
                                 aopLiteral (val, 0), aopLiteral (val, 1),
                                 aopLiteral (val, 2), aopLiteral (val, 3));
                }
+               else {
+                       fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+                                aopLiteral (val, 3), aopLiteral (val, 2),
+                                aopLiteral (val, 1), aopLiteral (val, 0));
+               }
                break;
        }
 }
@@ -701,7 +714,7 @@ void printIvalBitFields(symbol **sym, initList **ilist, FILE * oFile)
        case 2:
                tfprintf (oFile, "\t!dw !constword\n",ival);
                break;
-       case 4:
+       case 4: /* EEP: why is this db and not dw? */
                tfprintf (oFile, "\t!db  !constword,!constword\n",
                         (ival >> 8) & 0xffff, (ival & 0xffff));
                break;
@@ -951,30 +964,48 @@ printIvalCharPtr (symbol * sym, sym_link * type, value * val, FILE * oFile)
        case 2:
          if (port->use_dw_for_init)
            tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, size));
-         else
+         else if (port->little_endian)
            tfprintf (oFile, "\t.byte %s,%s\n",
                      aopLiteral (val, 0), aopLiteral (val, 1));
+         else
+           tfprintf (oFile, "\t.byte %s,%s\n",
+                     aopLiteral (val, 1), aopLiteral (val, 0));
          break;
        case 3:
          if (IS_GENPTR(type) && floatFromVal(val)!=0) {
            // non-zero mcs51 generic pointer
            werror (E_LITERAL_GENERIC);
          }
-         fprintf (oFile, "\t.byte %s,%s,%s\n",
-                  aopLiteral (val, 0), 
-                  aopLiteral (val, 1),
-                  aopLiteral (val, 2));
+         if (port->little_endian) {
+           fprintf (oFile, "\t.byte %s,%s,%s\n",
+                    aopLiteral (val, 0), 
+                    aopLiteral (val, 1),
+                    aopLiteral (val, 2));
+         } else {
+           fprintf (oFile, "\t.byte %s,%s,%s\n",
+                    aopLiteral (val, 2), 
+                    aopLiteral (val, 1),
+                    aopLiteral (val, 0));
+         }
          break;
        case 4:
          if (IS_GENPTR(type) && floatFromVal(val)!=0) {
            // non-zero ds390 generic pointer
            werror (E_LITERAL_GENERIC);
          }
-         fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
-                  aopLiteral (val, 0), 
-                  aopLiteral (val, 1), 
-                  aopLiteral (val, 2),
-                  aopLiteral (val, 3));
+         if (port->little_endian) {
+           fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+                    aopLiteral (val, 0), 
+                    aopLiteral (val, 1), 
+                    aopLiteral (val, 2),
+                    aopLiteral (val, 3));
+         } else {
+           fprintf (oFile, "\t.byte %s,%s,%s,%s\n",
+                    aopLiteral (val, 3), 
+                    aopLiteral (val, 2), 
+                    aopLiteral (val, 1),
+                    aopLiteral (val, 0));
+         }
          break;
        default:
          assert (0);
@@ -1033,12 +1064,22 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
        case 2:
          if (port->use_dw_for_init)
            tfprintf (oFile, "\t!dws\n", aopLiteralLong (val, 0, 2));
-         else
+         else if (port->little_endian)
            tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 0), aopLiteral (val, 1));
+         else
+           tfprintf (oFile, "\t.byte %s,%s\n", aopLiteral (val, 1), aopLiteral (val, 0));
          break;
        case 3: // how about '390??
-         fprintf (oFile, "\t.byte %s,%s,#0x%d\n",
-                  aopLiteral (val, 0), aopLiteral (val, 1), GPTYPE_CODE);
+         if (port->little_endian)
+           {
+             fprintf (oFile, "\t.byte %s,%s,#0x%d\n",
+                      aopLiteral (val, 0), aopLiteral (val, 1), GPTYPE_CODE);
+           }
+         else
+           {
+             fprintf (oFile, "\t.byte %s,%s,#0x%d\n",
+                      aopLiteral (val, 1), aopLiteral (val, 0), GPTYPE_CODE);
+           }
        }
       return;
     }
index 5d5a323716eadfc806049c7a1cfb554e0dcfbc6b..e60bcec632f86e3d07a33708832d1b07ed3767b1 100644 (file)
@@ -156,7 +156,8 @@ PORT avr_port = {
          glue,
         TRUE,                  /* Emit glue around main */
         MODEL_LARGE | MODEL_SMALL,
-        MODEL_SMALL},
+        MODEL_SMALL
+       },
        {
         _asmCmd,
          NULL,
@@ -221,6 +222,7 @@ PORT avr_port = {
        NULL,
         NULL,
        FALSE,
+       TRUE,                   /* little endian */
        0,                      /* leave lt */
        1,                      /* transform gt ==> not le */
        0,                      /* leave le */
index 4323260488b297d7f1347a86bb43d87f2b62fb0b..330b8d7e7d2a1ec48da4c7cb3af941ac0f719154 100644 (file)
@@ -412,6 +412,7 @@ PORT ds390_port =
   NULL,
   _ds390_nativeMulCheck,
   FALSE,
+  TRUE,                                /* little endian */
   0,                           /* leave lt */
   0,                           /* leave gt */
   1,                           /* transform <= to ! > */
@@ -702,6 +703,7 @@ PORT tininative_port =
   NULL,
   NULL,
   FALSE,
+  TRUE,                                /* little endian */
   0,                           /* leave lt */
   0,                           /* leave gt */
   1,                           /* transform <= to ! > */
@@ -910,6 +912,7 @@ PORT ds400_port =
   NULL,
   _ds390_nativeMulCheck,
   FALSE,
+  TRUE,                                /* little endian */
   0,                           /* leave lt */
   0,                           /* leave gt */
   1,                           /* transform <= to ! > */
index dbb92322cc21f5c6a3616a08b7dc7b7544206f8c..57cd968fc17ff55b79eb2629439fd834b7c202fd 100644 (file)
@@ -209,6 +209,7 @@ PORT i186_port = {
     NULL,
     NULL,
     FALSE,
+    TRUE,                              /* little endian */
     0,  /* leave lt */
     0,  /* leave gt */
     1,  /* transform <= to ! > */
index e7af479f8541dc41d4a29f9449d5ec062c21215d..cff99d5f1db12b8e14537533a3e3be89ea3e051a 100644 (file)
@@ -305,6 +305,7 @@ PORT mcs51_port =
   NULL,
   NULL,
   FALSE,
+  TRUE,                                /* little endian */
   0,                           /* leave lt */
   0,                           /* leave gt */
   1,                           /* transform <= to ! > */
index 66b235187a86df0625dcaaaa0a60beccd0b9952c..2a818bf36b73be8319e72e9aaf0ca81bb23abbf2 100644 (file)
@@ -424,6 +424,7 @@ PORT pic_port =
   NULL,
   _hasNativeMulFor,
   FALSE,
+  TRUE,                                /* little endian */
   0,                           /* leave lt */
   0,                           /* leave gt */
   1,                           /* transform <= to ! > */
index 33ed2da7ca73c457b9255476ed2c0abbdcf89e08..2228b5ec50298dfda979a7f1ecffebcdd08e2477 100644 (file)
@@ -471,6 +471,7 @@ PORT pic16_port =
   NULL,
   _hasNativeMulFor,
   FALSE,
+  TRUE,                                /* little endian */
   0,                           /* leave lt */
   0,                           /* leave gt */
   1,                           /* transform <= to ! > */
index 5bb49e82de4a793bd769774eae319448cf152312..3e3aec9411ad99a1129379e54d36c05b93abc5df 100644 (file)
@@ -17,6 +17,7 @@
 #define TARGET_ID_PIC16           7
 #define TARGET_ID_XA51     9
 #define TARGET_ID_DS400           10
+#define TARGET_ID_HC08     11
 
 /* Macro to test the target we are compiling for.
    Can only be used after SDCCmain has defined the port
@@ -30,6 +31,7 @@
 #define TARGET_IS_PIC   (port->id==TARGET_ID_PIC)
 #define TARGET_IS_PIC16        (port->id==TARGET_ID_PIC16)
 #define TARGET_IS_XA51 (port->id==TARGET_ID_XA51)
+#define TARGET_IS_HC08 (port->id==TARGET_ID_HC08)
 
 #define MAX_BUILTIN_ARGS       16
 /* definition of builtin functions */
@@ -251,6 +253,11 @@ typedef struct
      */
     bool use_dw_for_init;
 
+    /** TRUE for targets with little endian byte ordering, FALSE for
+        targets with big endian byte ordering.
+     */
+    bool little_endian;
+
     /* condition transformations */
     bool lt_nge;               /* transform (a < b)  to !(a >= b)  */
     bool gt_nle;               /* transform (a > b)  to !(a <= b)  */
@@ -303,5 +310,8 @@ extern PORT xa51_port;
 #if !OPT_DISABLE_DS400
 extern PORT ds400_port;
 #endif
+#if !OPT_DISABLE_HC08
+extern PORT hc08_port;
+#endif
 
 #endif /* PORT_INCLUDE*/
index 707bad099c831ccd8a42ada8e5e0e32a3b09a47d..af38ec353b9362b1a79b2b0343f80d695608e9c4 100755 (executable)
@@ -291,6 +291,7 @@ PORT xa51_port =
   NULL, // getMangledFunctionName()
   NULL, // hasNativeMulFor()
   TRUE, // use_dw_for_init
+  TRUE,                                /* little endian */
   0,                           /* leave lt */
   0,                           /* leave gt */
   1,                           /* transform <= to ! > */
index 3bff23e24963afd672db25f5e1eb229e50c9d992..2768d4d6698fae48837627737598c12472bd9019 100644 (file)
@@ -574,6 +574,7 @@ PORT z80_port =
   _mangleSupportFunctionName,
   _hasNativeMulFor,
   TRUE,
+  TRUE,                                /* little endian */
   0,                           /* leave lt */
   0,                           /* leave gt */
   1,                           /* transform <= to ! > */
@@ -670,6 +671,7 @@ PORT gbz80_port =
   _mangleSupportFunctionName,
   _hasNativeMulFor,
   TRUE,
+  TRUE,                                /* little endian */
   0,                           /* leave lt */
   0,                           /* leave gt */
   1,                           /* transform <= to ! > */