[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

`cnm' patch



Here's a patch for `cnm' of bammi's binutils (patched up to update40)
to allow its use on a little-endian cross development host.  (MH-MiNT
1.12h3 will make use of `cnm' to build magic.i on cross hosts --
thanks Juergen.)

Michael
-- 
Email: hohmuth@inf.tu-dresden.de
WWW:   http://www.inf.tu-dresden.de/~mh1/

--- /tmp/hohmuth/atari/cross/usr/src/bammi/utlsrc/cnm.c	Mon Oct 25 21:02:55 1993
+++ cnm.c	Sat Mar 18 00:52:41 1995
@@ -59,6 +59,18 @@
 # define SIZEOF_SYM ((size_t)14)
 #endif
 
+#ifdef BYTE_SWAP
+
+#define SWAP4(y) (((unsigned)(y)>>24) + (((unsigned)(y)>>8)&0xff00) + \
+                 (((unsigned)(y)<<8)&0xff0000) + ((unsigned)(y)<<24)) 
+#define SWAP2(y) ((((unsigned)(y)&0xff00)>>8) + (((unsigned)(y)&0x00ff)<<8))
+
+#else
+#define SWAP4(y) (y)
+#define SWAP2(y) (y)
+#endif /* BYTE_SWAP */
+
+
 struct xsym {
     char name[8];
     union {
@@ -321,21 +333,21 @@
     for(k = 0; k < n; k++)
     {
 	ckfread(&i, 2, 1, fd);
-	h->a_magic = i;
+	h->a_magic = SWAP2(i);
 	ckfread(&j, 4, 1, fd);
-	h->a_text = j;
+	h->a_text = SWAP4(j);
 	ckfread(&j, 4, 1, fd);
-	h->a_data = j;
+	h->a_data = SWAP4(j);
 	ckfread(&j, 4, 1, fd);
-	h->a_bss = j;
+	h->a_bss = SWAP4(j);
 	ckfread(&j, 4, 1, fd);
-	h->a_syms = j;
+	h->a_syms = SWAP4(j);
 	ckfread(&j, 4, 1, fd);
-	h->a_AZero1 = j;
+	h->a_AZero1 = SWAP4(j);
 	ckfread(&j, 4, 1, fd);
-	h->a_ldflgs = j;
+	h->a_ldflgs = SWAP4(j);
 	ckfread(&i, 2, 1, fd);
-	h->a_isreloc = i;
+	h->a_isreloc = SWAP2(i);
     }
     return k;
 }
@@ -352,6 +364,10 @@
 	ckfread(syms->name, 8, 1, fd);
 	ckfread(&(syms->sflgs), 2, 1, fd);
 	ckfread(&(syms->value), 4, 1, fd);
+#ifdef BYTE_SWAP
+	syms->sflgs = SWAP2(syms->sflgs);
+	syms->value = SWAP4(syms->value);
+#endif
    }
    return k;
 }