Subject: Changes to libexec/ld.aout_so/arch/sparc/md.c
To: None <port-sparc@netbsd.org, tech-toolchain@netbsd.org>
From: Bill Studenmund <wrstuden@nas.nasa.gov>
List: tech-toolchain
Date: 01/15/2000 16:39:30
Would anyone mind if I made the following changes to
libexec/ld.aout_so/arch/sparc/md.h?

They mask the iflush code if CROSS_LINKER is defined, and they add byte
swapping code if NEED_SWAP is defined.

I'm not sure if the exec header code is right. I copied it from m68k/md.c.

Take care,

Bill

--- /current/src/libexec/ld.aout_so/arch/sparc/md.c	Thu Dec 17 06:29:50 1998
+++ md.c	Sat Jan 15 16:10:30 2000
@@ -98,6 +98,7 @@
 	32, 0, 22	/* _GLOB_DAT, JMP_SLOT, _RELATIVE */
 };
 
+#ifndef CROSS_LINKER
 static void iflush __P((jmpslot_t *));
 
 static __inline void
@@ -108,6 +109,7 @@
 	__asm __volatile("iflush %0+4" : : "r" (sp));
 	__asm __volatile("iflush %0+8" : : "r" (sp));
 }
+#endif	/* !CROSS_LINKER */
 
 /*
  * Get relocation addend corresponding to relocation record RP
@@ -205,7 +207,9 @@
 	sp->opcode1 = SETHI | ((addr >> 10) & 0x003fffff);
 	sp->opcode2 = JMP | (addr & 0x000003ff);
 	sp->reloc_index = NOP;
+#ifndef CROSS_LINKER
 	iflush(sp);
+#endif
 }
 
 void
@@ -265,7 +269,9 @@
 	/* The following is a RELOC_WDISP30 relocation */
 	sp->opcode2 = CALL | ((fudge >> 2) & 0x3fffffff);
 	sp->reloc_index = NOP | index;
+#ifndef CROSS_LINKER
 	iflush(sp);
+#endif
 }
 
 /*
@@ -359,3 +365,84 @@
 #endif
 }
 #endif /* RTLD */
+
+#ifdef NEED_SWAP
+/*
+ * Byte swap routines for cross-linking.
+ */
+
+void
+md_swapin_exec_hdr(h)
+	struct exec *h;
+{
+	int skip = 0;
+
+	if (!N_BADMAG(*h))
+		skip = 1;
+
+	swap_longs((long *)h + skip, sizeof(*h)/sizeof(long) - skip);
+}
+
+void
+md_swapout_exec_hdr(h)
+	struct exec *h;
+{
+	/* NetBSD: Always leave magic alone */
+	int skip = 1;
+#if 0
+	if (N_GETMAGIC(*h) == OMAGIC)
+		skip = 0;
+#endif
+
+	swap_longs((long *)h + skip, sizeof(*h)/sizeof(long) - skip);
+}
+
+
+void
+md_swapin_reloc(r, n)
+	struct relocation_info *r;
+	int n;
+{
+	int	bits;
+
+	for (; n; n--, r++) {
+		r->r_address = md_swap_long(r->r_address);
+		bits = ((int *)r)[1];
+		r->r_symbolnum = md_swap_long(bits) >> 8;
+		bits >>= 24;
+		r->r_extern = (bits >> 7) & 1;
+		r->r_type = (bits & 5);
+		r->r_addend = md_swap_long(r->r_addend);
+	}
+}
+
+void
+md_swapout_reloc(r, n)
+	struct relocation_info *r;
+	int n;
+{
+	int	bits;
+
+	for (; n; n--, r++) {
+		r->r_address = md_swap_long(r->r_address);
+		bits = (r->r_extern & 1) << 7;
+		bits |= (r->r_type & 5);
+		((int *)r)[1] = md_swap_long(r->r_symbolnum) >> 8;
+		((unsigned char *)r)[7] = bits;
+		r->r_addend = md_swap_long(r->r_addend);
+	}
+}
+
+void
+md_swapout_jmpslot(j, n)
+	jmpslot_t	*j;
+	int		n;
+{
+	for (; n; n--, j++) {
+		j->opcode1 = md_swap_long(j->opcode1);
+		j->opcode2 = md_swap_long(j->opcode2);
+		j->reloc_index = md_swap_short(j->reloc_index);
+	}
+}
+
+#endif /* NEED_SWAP */