From 5ee8507774af625a6bf974d7daa41b8db6eb521c Mon Sep 17 00:00:00 2001 From: epetrich Date: Fri, 8 Aug 2003 03:52:39 +0000 Subject: [PATCH] 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 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2819 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 13 ++++++++ src/SDCCglue.c | 77 +++++++++++++++++++++++++++++++++++++----------- src/avr/main.c | 4 ++- src/ds390/main.c | 3 ++ src/izt/i186.c | 1 + src/mcs51/main.c | 1 + src/pic/main.c | 1 + src/pic16/main.c | 1 + src/port.h | 10 +++++++ src/xa51/main.c | 1 + src/z80/main.c | 2 ++ 11 files changed, 95 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef9042de..c175d63e 100644 --- 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 * src/SDCCval.c (cheapestVal): changed behaviour to the same as constVal() diff --git a/src/SDCCglue.c b/src/SDCCglue.c index d1a9d8db..dea2f999 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -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; } diff --git a/src/avr/main.c b/src/avr/main.c index 5d5a3237..e60bcec6 100644 --- a/src/avr/main.c +++ b/src/avr/main.c @@ -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 */ diff --git a/src/ds390/main.c b/src/ds390/main.c index 43232604..330b8d7e 100644 --- a/src/ds390/main.c +++ b/src/ds390/main.c @@ -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 ! > */ diff --git a/src/izt/i186.c b/src/izt/i186.c index dbb92322..57cd968f 100644 --- a/src/izt/i186.c +++ b/src/izt/i186.c @@ -209,6 +209,7 @@ PORT i186_port = { NULL, NULL, FALSE, + TRUE, /* little endian */ 0, /* leave lt */ 0, /* leave gt */ 1, /* transform <= to ! > */ diff --git a/src/mcs51/main.c b/src/mcs51/main.c index e7af479f..cff99d5f 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -305,6 +305,7 @@ PORT mcs51_port = NULL, NULL, FALSE, + TRUE, /* little endian */ 0, /* leave lt */ 0, /* leave gt */ 1, /* transform <= to ! > */ diff --git a/src/pic/main.c b/src/pic/main.c index 66b23518..2a818bf3 100644 --- a/src/pic/main.c +++ b/src/pic/main.c @@ -424,6 +424,7 @@ PORT pic_port = NULL, _hasNativeMulFor, FALSE, + TRUE, /* little endian */ 0, /* leave lt */ 0, /* leave gt */ 1, /* transform <= to ! > */ diff --git a/src/pic16/main.c b/src/pic16/main.c index 33ed2da7..2228b5ec 100644 --- a/src/pic16/main.c +++ b/src/pic16/main.c @@ -471,6 +471,7 @@ PORT pic16_port = NULL, _hasNativeMulFor, FALSE, + TRUE, /* little endian */ 0, /* leave lt */ 0, /* leave gt */ 1, /* transform <= to ! > */ diff --git a/src/port.h b/src/port.h index 5bb49e82..3e3aec94 100644 --- a/src/port.h +++ b/src/port.h @@ -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*/ diff --git a/src/xa51/main.c b/src/xa51/main.c index 707bad09..af38ec35 100755 --- a/src/xa51/main.c +++ b/src/xa51/main.c @@ -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 ! > */ diff --git a/src/z80/main.c b/src/z80/main.c index 3bff23e2..2768d4d6 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -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 ! > */ -- 2.39.5