Subject: Changes for ns32k to get cross-linking working
To: None <tech-toolchain@netbsd.org, port-pc532@netbsd.org>
From: Bill Studenmund <wrstuden@sun510.nas.nasa.gov>
List: tech-toolchain
Date: 01/17/2000 13:20:40
I have been hacking on getting ld.old to cross-link for all architectures. 
I discovered no one has ever tried this for ns32k. :-)

Below are the changes I had to make to get it to work. Do they seem
reasonable (I don't have hardware to test, I just made sure the new ld
linked, and that the relocations looked right)?

Take care,

Bill

Index: md.c
===================================================================
RCS file: /cvsroot/basesrc/libexec/ld.aout_so/arch/ns32k/md.c,v
retrieving revision 1.12
diff -u -r1.12 md.c
--- md.c	1999/01/15 07:48:07	1.12
+++ md.c	2000/01/17 21:11:22
@@ -483,18 +483,18 @@
 
 	for (; n; n--, r++) {
 		r->r_address = md_swap_long(r->r_address);
-		bits = ((int *)r)[1];
-		r->r_symbolnum = md_swap_long(bits) & 0xffffff;
-		bits = ((unsigned char *)r)[7];
-		r->r_pcrel = ((bits >> 7) & 1);
-		r->r_length = ((bits >> 5) & 3);
-		r->r_extern = ((bits >> 4) & 1);
-		r->r_baserel = ((bits >> 3) & 1);
-		r->r_jmptable = ((bits >> 2) & 1);
-		r->r_relative = ((bits >> 1) & 1);
+		bits = md_swap_long(((int *)r)[1]);
+		r->r_symbolnum = bits & 0x3fffff;
 #ifdef N_SIZE
-		r->r_copy = (bits & 1);
+		r->r_copy = ((bits >> 22) & 1);
 #endif
+		r->r_relative = ((bits >> 23) & 1);
+		r->r_pcrel = ((bits >> 24) & 1);
+		r->r_length = ((bits >> 25) & 3);
+		r->r_extern = ((bits >> 27) & 1);
+		r->r_jmptable = ((bits >> 28) & 1);
+		r->r_disp = ((bits >> 29) & 3);
+		r->r_baserel = ((bits >> 31) & 1);
 	}
 }
 
@@ -507,17 +507,18 @@
 
 	for (; n; n--, r++) {
 		r->r_address = md_swap_long(r->r_address);
-		((int *)r)[1] = md_swap_long(r->r_symbolnum & 0xffffff00);
-		bits = ((r->r_pcrel << 7) & 0x80);
-		bits |= ((r->r_length << 5) & 0x60);
-		bits |= ((r->r_extern << 4) & 0x10);
-		bits |= ((r->r_baserel << 3) & 8);
-		bits |= ((r->r_jmptable << 2) & 4);
-		bits |= ((r->r_relative << 1) & 2);
+		bits = r->r_symbolnum & 0x003fffff;
 #ifdef N_SIZE
-		bits |= (r->r_copy & 1);
+		bits |= ((r->r_copy & 1) << 22);
 #endif
-		((unsigned char *)r)[7] = bits;
+		bits |= ((r->r_relative & 1) << 23);
+		bits |= ((r->r_pcrel & 1) << 24);
+		bits |= ((r->r_length & 3) << 25);
+		bits |= ((r->r_extern & 1) << 27);
+		bits |= ((r->r_jmptable & 1) << 28);
+		bits |= ((r->r_disp & 3) << 29);
+		bits |= ((r->r_baserel & 1) << 31);
+		((int *)r)[1] = md_swap_long(bits);
 	}
 }
 
@@ -527,9 +528,7 @@
 	int		n;
 {
 	for (; n; n--, j++) {
-		j->opcode = md_swap_short(j->opcode);
-		j->addr[0] = md_swap_short(j->addr[0]);
-		j->addr[1] = md_swap_short(j->addr[1]);
+		/* j->code is already in the right byte order */
 		j->reloc_index = md_swap_short(j->reloc_index);
 	}
 }
Index: md.h
===================================================================
RCS file: /cvsroot/basesrc/libexec/ld.aout_so/arch/ns32k/md.h,v
retrieving revision 1.7
diff -u -r1.7 md.h
--- md.h	1999/01/15 07:48:07	1.7
+++ md.h	2000/01/17 21:11:22
@@ -119,8 +119,8 @@
 #  define md_swapout_so_debug(d)		swap_so_debug(d)
 #  define md_swapin_rrs_hash(f,n)		swap_rrs_hash(f,n)
 #  define md_swapout_rrs_hash(f,n)		swap_rrs_hash(f,n)
-#  define md_swapin_sod(l,n)			swapin_link_object(l,n)
-#  define md_swapout_sod(l,n)			swapout_link_object(l,n)
+#  define md_swapin_sod(l,n)			swapin_sod(l,n)
+#  define md_swapout_sod(l,n)			swapout_sod(l,n)
 #  define md_swapout_got(g,n)			swap_longs((long*)(g),n)
 #  define md_swapin_ranlib_hdr(h,n)		swap_ranlib_hdr(h,n)
 #  define md_swapout_ranlib_hdr(h,n)		swap_ranlib_hdr(h,n)