Subject: Patches to libc to build on pmax and prepend underscores to
To: None <port-pmax@netbsd.org>
From: Jonathan Stone <jonathan@DSG.Stanford.EDU>
List: port-pmax
Date: 09/17/1994 23:44:22
The following  patch adds a macro XTERNAL() to machAsmDefs.h,
which prepends an underscore to a symbol. (The intent here is
to conditionalize the macro on something appropriate, so that
if anyone needs to compile an ECOFF kernel, for instance, they
can do so easily).   

The patch changes the macros LEAF(), NON_LEAF(), etc,
and END(), to apply XTERNAL() to their label arguments.
The patch also applies XTERNAL()  to several labels defined
in assembly code in libc.a,  in crt0.s, and in locore.s.

This patch file also includes changes to various Makefiles underneath
lib/libc, which didn't have appropriate explicit source dependencies
for ``${MACHINE_ARCH} == "pmax"'', but which needed some. These
Makefile changes assume one either renames or symlinks files with a .s
suffix to have a .S suffix; gcc doesn't implicitly preprocess assembly
code in files with a .s suffix.  Renaming the files seemed at least as
good as adding special-case rules to explicitly run cpp.

The result lets me build a kernel and all of a non-GNU user-land,
with gcc 2.5.8 hacked to prepend an ``_'' to variable names.
Some additional changes to locore.s are clearly needed.

(I apologize for changing the RCS ids in the patches below;
 I accidentally supp'ed a collection that stomped over some of
 the changes, and ended up recovering them RCS.)

The following files are modified:

sys/arch/pmax/include/MachAsmDefs.h
csu/mips/crt0.s
libc/arch/mips/gen/setjmp.s
libc/arch/mips/gen/_setjmp.s
libc/arch/mips/string/index.s
libc/arch/mips/sys/setlogin.s
libc/arch/mips/sys/cerror.s
libc/arch/mips/sys/reboot.s
libc/arch/mips/sys/ptrace.s
libc/gen/Makefile.inc
libc/net/Makefile.inc
libc/stdlib/strtod.c
libc/string/Makefile.inc


*** sys/arch/pmax/include/machAsmDefs.h	Mon May 30 04:07:54 1994
--- sys/arch/pmax/include/machAsmDefs.h.dsg	Fri Sep 16 13:57:40 1994
***************
*** 61,66 ****
--- 61,72 ----
  #include <machine/regdef.h>
  
  /*
+  * Some C compilers for mips processors prepend an underscore to
+  * external names; some don't.
+  */
+ #define XTERNAL(x) _ ## x
+ 
+ /*
   * Define -pg profile entry code.
   */
  #if defined(GPROF) || defined(PROF)
***************
*** 81,89 ****
   *	Declare a leaf routine.
   */
  #define LEAF(x) \
! 	.globl x; \
! 	.ent x, 0; \
! x: ; \
  	.frame sp, 0, ra; \
  	MCOUNT
  
--- 87,95 ----
   *	Declare a leaf routine.
   */
  #define LEAF(x) \
! 	.globl XTERNAL(x); \
! 	.ent XTERNAL(x), 0; \
! XTERNAL(x): ; \
  	.frame sp, 0, ra; \
  	MCOUNT
  
***************
*** 93,101 ****
   *	Declare a non-profiled leaf routine.
   */
  #define NLEAF(x) \
! 	.globl x; \
! 	.ent x, 0; \
! x: ; \
  	.frame sp, 0, ra
  
  /*
--- 99,107 ----
   *	Declare a non-profiled leaf routine.
   */
  #define NLEAF(x) \
! 	.globl XTERNAL(x); \
! 	.ent XTERNAL(x), 0; \
! XTERNAL(x): ; \
  	.frame sp, 0, ra
  
  /*
***************
*** 102,110 ****
   * ALEAF -- declare alternate entry to a leaf routine.
   */
  #define	ALEAF(x)					\
! 	.globl	x;					\
! 	.aent	x,0;					\
! x:
  
  /*
   * NON_LEAF(x)
--- 108,116 ----
   * ALEAF -- declare alternate entry to a leaf routine.
   */
  #define	ALEAF(x)					\
! 	.globl	XTERNAL(x);					\
! 	.aent	XTERNAL(x),0;					\
! XTERNAL(x):
  
  /*
   * NON_LEAF(x)
***************
*** 112,120 ****
   *	Declare a non-leaf routine (a routine that makes other C calls).
   */
  #define NON_LEAF(x, fsize, retpc) \
! 	.globl x; \
! 	.ent x, 0; \
! x: ; \
  	.frame sp, fsize, retpc; \
  	MCOUNT
  
--- 118,126 ----
   *	Declare a non-leaf routine (a routine that makes other C calls).
   */
  #define NON_LEAF(x, fsize, retpc) \
! 	.globl XTERNAL(x); \
! 	.ent XTERNAL(x), 0; \
! XTERNAL(x): ; \
  	.frame sp, fsize, retpc; \
  	MCOUNT
  
***************
*** 125,133 ****
   *	(a routine that makes other C calls).
   */
  #define NNON_LEAF(x, fsize, retpc) \
! 	.globl x; \
! 	.ent x, 0; \
! x: ; \
  	.frame sp, fsize, retpc
  
  /*
--- 131,139 ----
   *	(a routine that makes other C calls).
   */
  #define NNON_LEAF(x, fsize, retpc) \
! 	.globl XTERNAL(x); \
! 	.ent XTERNAL(x), 0; \
! XTERNAL(x): ; \
  	.frame sp, fsize, retpc
  
  /*
***************
*** 136,142 ****
   *	Mark end of a procedure.
   */
  #define END(x) \
! 	.end x
  
  #define STAND_FRAME_SIZE	24
  #define STAND_RA_OFFSET		20
--- 142,148 ----
   *	Mark end of a procedure.
   */
  #define END(x) \
! 	.end XTERNAL(x)
  
  #define STAND_FRAME_SIZE	24
  #define STAND_RA_OFFSET		20
***************
*** 146,157 ****
   */
  #define PANIC(msg) \
  	la	a0, 9f; \
! 	jal	panic; \
  	MSG(msg)
  
  #define	PRINTF(msg) \
  	la	a0, 9f; \
! 	jal	printf; \
  	MSG(msg)
  
  #define	MSG(msg) \
--- 152,163 ----
   */
  #define PANIC(msg) \
  	la	a0, 9f; \
! 	jal	XTERNAL(panic); \
  	MSG(msg)
  
  #define	PRINTF(msg) \
  	la	a0, 9f; \
! 	jal	XTERNAL(printf); \
  	MSG(msg)
  
  #define	MSG(msg) \
*** lib/csu/mips/crt0.s	Tue May 24 00:33:49 1994
--- lib/csu/mips/crt0.s.dsg	Sat Sep 17 22:52:00 1994
***************
*** 34,50 ****
   * SUCH DAMAGE.
   *
   *	from: @(#)crt0.s	8.2 (Berkeley) 3/21/94
!  *	$Id: crt0.s,v 1.1 1994/05/24 07:33:49 glass Exp $    
   */
  
  #include <machine/regdef.h>
  #include <machine/machAsmDefs.h>
  
- 	.comm	environ, 4
  	.data
  	.align	2
! 	.globl	__progname
! __progname:
  	.word	$L1
  $L1:
  	.word	0		# null string plus padding
--- 34,50 ----
   * SUCH DAMAGE.
   *
   *	from: @(#)crt0.s	8.2 (Berkeley) 3/21/94
!  *	$Id: crt0.s,v 1.2 1994/09/18 05:47:54 jonathan Exp jonathan $    
   */
  
  #include <machine/regdef.h>
  #include <machine/machAsmDefs.h>
  
  	.data
+ 	.comm	XTERNAL(environ), 4
  	.align	2
! 	.globl	XTERNAL(__progname)
! XTERNAL(__progname):
  	.word	$L1
  $L1:
  	.word	0		# null string plus padding
***************
*** 57,63 ****
  	addu	s2, s1, 4	# skip null pointer on stack
  	sll	v0, s0, 2	# add number of argv pointers
  	addu	s2, s2, v0	# final pointer to environment list
! 	sw	s2, environ	# save environment pointer
  	subu	sp, sp, 24	# allocate standard frame
  	.mask	0x80000000, -4
  	sw	zero, 20(sp)	# clear return address for debugging
--- 57,63 ----
  	addu	s2, s1, 4	# skip null pointer on stack
  	sll	v0, s0, 2	# add number of argv pointers
  	addu	s2, s2, v0	# final pointer to environment list
! 	sw	s2, XTERNAL(environ)	# save environment pointer
  	subu	sp, sp, 24	# allocate standard frame
  	.mask	0x80000000, -4
  	sw	zero, 20(sp)	# clear return address for debugging
***************
*** 65,94 ****
  eprol:
  	la	a0, eprol
  	la	a1, etext
! 	jal	monstartup	# monstartup(eprol, etext);
  	nop
  	la	a0, _mcleanup
! 	jal	atexit		# atext(_mcleanup);
  	nop
! 	sw	zero, errno
  #endif
  	lw	a0, 0(s1)	# a0 = argv[0];
  	nop
  	beq	a0, zero, 2f	# skip if a0 == NULL
  	move	s3, a0		# save argv[0]
! 	jal	strrchr
  	li	a1, 0x2f	# a1 = '/'
  	bne	v0, zero, 1f	# if slash found
  	addu	v0, v0, 1
  	move	v0, s3		# v0 = argv[0];
  1:
! 	sw	v0, __progname
  2:
  	move	a0, s0
  	move	a1, s1
! 	jal	main		# v0 = main(argc, argv, env);
  	move	a2, s2
! 	jal	exit		# exit(v0);
  	move	a0, v0
  	break	0
  	.set	reorder
--- 65,94 ----
  eprol:
  	la	a0, eprol
  	la	a1, etext
! 	jal	XTERNAL(monstartup)	# monstartup(eprol, etext);
  	nop
  	la	a0, _mcleanup
! 	jal	XTERNAL(atexit)		# atext(_mcleanup);
  	nop
! 	sw	zero, XTERNAL(errno)
  #endif
  	lw	a0, 0(s1)	# a0 = argv[0];
  	nop
  	beq	a0, zero, 2f	# skip if a0 == NULL
  	move	s3, a0		# save argv[0]
! 	jal	XTERNAL(strrchr)
  	li	a1, 0x2f	# a1 = '/'
  	bne	v0, zero, 1f	# if slash found
  	addu	v0, v0, 1
  	move	v0, s3		# v0 = argv[0];
  1:
! 	sw	v0, XTERNAL(__progname)
  2:
  	move	a0, s0
  	move	a1, s1
! 	jal	XTERNAL(main)		# v0 = main(argc, argv, env);
  	move	a2, s2
! 	jal	XTERNAL(exit)		# exit(v0);
  	move	a0, v0
  	break	0
  	.set	reorder
*** lib/libc/arch/mips/gen/setjmp.s	Tue May 24 00:12:38 1994
--- lib/libc/arch/mips/gen/setjmp.s.dsg	Sat Sep 17 21:30:43 1994
***************
*** 62,73 ****
  	sw	ra, STAND_RA_OFFSET(sp)		# save state
  	sw	a0, SETJMP_FRAME_SIZE(sp)
  	move	a0, zero			# get current signal mask
! 	jal	sigblock
  	lw	v1, SETJMP_FRAME_SIZE(sp)	# v1 = jmpbuf
  	sw	v0, (1 * 4)(v1)			# save sc_mask = sigblock(0)
  	move	a0, zero
  	addu	a1, sp, STAND_FRAME_SIZE	# pointer to struct sigaltstack
! 	jal	sigaltstack
  	lw	a0, SETJMP_FRAME_SIZE(sp)	# restore jmpbuf
  	lw	v1, STAND_FRAME_SIZE+8(sp)	# get old ss_onstack
  	and	v1, v1, 1			# extract onstack flag
--- 62,73 ----
  	sw	ra, STAND_RA_OFFSET(sp)		# save state
  	sw	a0, SETJMP_FRAME_SIZE(sp)
  	move	a0, zero			# get current signal mask
! 	jal	XTERNAL(sigblock)
  	lw	v1, SETJMP_FRAME_SIZE(sp)	# v1 = jmpbuf
  	sw	v0, (1 * 4)(v1)			# save sc_mask = sigblock(0)
  	move	a0, zero
  	addu	a1, sp, STAND_FRAME_SIZE	# pointer to struct sigaltstack
! 	jal	XTERNAL(sigaltstack)
  	lw	a0, SETJMP_FRAME_SIZE(sp)	# restore jmpbuf
  	lw	v1, STAND_FRAME_SIZE+8(sp)	# get old ss_onstack
  	and	v1, v1, 1			# extract onstack flag
***************
*** 114,119 ****
  	li	v0, SYS_sigreturn
  	syscall
  botch:
! 	jal	longjmperror
! 	jal	abort
  END(longjmp)
--- 114,119 ----
  	li	v0, SYS_sigreturn
  	syscall
  botch:
! 	jal	XTERNAL(longjmperror)
! 	jal	XTERNAL(abort)
  END(longjmp)
*** lib/libc/arch/mips/gen/_setjmp.s	Tue May 24 00:12:18 1994
--- lib/libc/arch/mips/gen/_setjmp.s.dsg	Sat Sep 17 21:32:33 1994
***************
*** 118,125 ****
  	j	ra
  	move	v0, a1
  botch:
! 	jal	longjmperror
  	nop
! 	jal	abort
  	nop
  END(_longjmp)
--- 118,125 ----
  	j	ra
  	move	v0, a1
  botch:
! 	jal	XTERNAL(longjmperror)
  	nop
! 	jal	XTERNAL(abort)
  	nop
  END(_longjmp)
*** lib/libc/arch/mips/string/index.s	Fri Sep 16 16:09:19 1994
--- lib/libc/arch/mips/string/index.s.dsg	Sat Sep 17 21:41:36 1994
***************
*** 45,51 ****
  	lbu	a2, 0(a0)		# get a byte
  	addu	a0, a0, 1
  	beq	a2, a1, fnd
! 	bne	a2, zero, index
  notfnd:
  	move	v0, zero
  	j	ra
--- 45,51 ----
  	lbu	a2, 0(a0)		# get a byte
  	addu	a0, a0, 1
  	beq	a2, a1, fnd
! 	bne	a2, zero, XTERNAL(index)
  notfnd:
  	move	v0, zero
  	j	ra
*** lib/libc/arch/mips/sys/setlogin.s	Tue May 24 00:13:20 1994
--- lib/libc/arch/mips/sys/setlogin.s.dsg	Sat Sep 17 21:48:04 1994
***************
*** 45,51 ****
  	li	v0, SYS_setlogin	# setlogin(name)
  	syscall
  	bne	a3, zero, 1f
! 	sw	zero, _logname_valid	# in getlogin()
  	j	ra
  1:
  	j	_cerror
--- 45,51 ----
  	li	v0, SYS_setlogin	# setlogin(name)
  	syscall
  	bne	a3, zero, 1f
! 	sw	zero, XTERNAL(__logname_valid)	# in getlogin()
  	j	ra
  1:
  	j	_cerror
*** lib/libc/arch/mips/sys/cerror.s	Tue May 24 00:13:08 1994
--- lib/libc/arch/mips/sys/cerror.s.dsg	Sat Sep 17 22:19:59 1994
***************
*** 38,51 ****
  
  #if defined(LIBC_SCCS) && !defined(lint)
  	ASMSTR("from: @(#)cerror.s	8.1 (Berkeley) 6/16/93")
! 	ASMSTR("$Id: cerror.s,v 1.1 1994/05/24 07:13:08 glass Exp $")
  #endif /* LIBC_SCCS and not lint */
  
! 	.globl	errno
! LEAF(_cerror)
  	.set	noreorder
! 	sw	v0, errno
  	li	v0, -1
  	j	ra
  	li	v1, -1
! END(_cerror)
--- 38,51 ----
  
  #if defined(LIBC_SCCS) && !defined(lint)
  	ASMSTR("from: @(#)cerror.s	8.1 (Berkeley) 6/16/93")
! 	ASMSTR("$Id: cerror.s,v 1.2 1994/09/18 05:15:46 jonathan Exp jonathan $")
  #endif /* LIBC_SCCS and not lint */
  
! 	.globl	XTERNAL(errno)
! LEAF(cerror)
  	.set	noreorder
! 	sw	v0, XTERNAL(errno)
  	li	v0, -1
  	j	ra
  	li	v1, -1
! END(cerror)
*** lib/libc/arch/mips/sys/reboot.s	Tue May 24 00:13:16 1994
--- lib/libc/arch/mips/sys/reboot.s.dsg	Sat Sep 17 21:43:01 1994
***************
*** 45,51 ****
  	li	v0, SYS_reboot
  	syscall
  	bne	a3, zero, 1f
! 	jal	abort
  1:
  	j	_cerror
  END(reboot)
--- 45,51 ----
  	li	v0, SYS_reboot
  	syscall
  	bne	a3, zero, 1f
! 	jal	XTERNAL(abort)
  1:
  	j	_cerror
  END(reboot)
*** lib/libc/arch/mips/sys/ptrace.s	Tue May 24 00:13:15 1994
--- lib/libc/arch/mips/sys/ptrace.s.dsg	Sat Sep 17 22:55:15 1994
***************
*** 38,48 ****
  
  #if defined(LIBC_SCCS) && !defined(lint)
  	ASMSTR("from: @(#)ptrace.s	8.1 (Berkeley) 6/4/93")
! 	ASMSTR("$Id: ptrace.s,v 1.1 1994/05/24 07:13:15 glass Exp $")
  #endif /* LIBC_SCCS and not lint */
  
  LEAF(ptrace)
! 	sw	zero, errno
  	li	v0, SYS_ptrace
  	syscall
  	bne	a3, zero, 1f
--- 38,48 ----
  
  #if defined(LIBC_SCCS) && !defined(lint)
  	ASMSTR("from: @(#)ptrace.s	8.1 (Berkeley) 6/4/93")
! 	ASMSTR("$Id: ptrace.s,v 1.2 1994/09/18 05:54:03 jonathan Exp $")
  #endif /* LIBC_SCCS and not lint */
  
  LEAF(ptrace)
! 	sw	zero, XTERNAL(errno)
  	li	v0, SYS_ptrace
  	syscall
  	bne	a3, zero, 1f
*** lib/libc/gen/Makefile.inc	Mon Aug 29 08:04:13 1994
--- lib/libc/gen/Makefile.inc.dsg	Sat Sep 17 23:04:31 1994
***************
*** 49,54 ****
--- 49,57 ----
  .elif (${MACHINE_ARCH} == "sparc")
  SRCS+=	_setjmp.S fabs.S frexp.c infinity.c isnan.c ldexp.c modf.S
  SRCS+=	fixunsdfsi.S mul.S umul.S saveregs.S setjmp.S
+ .elif (${MACHINE_ARCH} == "mips")
+ SRCS+=	_setjmp.S fabs.S frexp.c infinity.c isinf.S ldexp.S modf.S
+ SRCS+=	setjmp.S
  .endif
  
  MAN3+=	alarm.0 clock.0 confstr.0 ctermid.0 ctime.0 ctype.0 \
*** lib/libc/net/Makefile.inc	Thu Dec 16 22:24:47 1993
--- lib/libc/net/Makefile.inc.dsg	Sat Sep 17 22:39:33 1994
***************
*** 25,30 ****
--- 25,32 ----
  SRCS+=	htonl.S htons.S ntohl.S ntohs.S
  .elif (${MACHINE_ARCH} == "sparc")
  SRCS+=	htonl.S htons.S ntohl.S ntohs.S
+ .elif (${MACHINE_ARCH} == "mips")
+ SRCS+=	htonl.S htons.S
  .else 
  SRCS+=	htonl.c htons.c ntohl.c ntohs.c
  .endif
*** lib/libc/stdlib/strtod.c	Fri Feb 25 02:53:48 1994
--- lib/libc/stdlib/strtod.c.dsg	Sat Sep 17 23:05:37 1994
***************
*** 90,99 ****
   */
  
  #if defined(LIBC_SCCS) && !defined(lint)
! static char *rcsid = "$Id: strtod.c,v 1.14 1994/08/29 15:06:17 jtc Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #if defined(i386) || defined(ns32k)
  #define IEEE_8087
  #endif
  #if defined(hp300) || defined(sparc) || defined(amiga) || defined(mc68000)
--- 90,99 ----
   */
  
  #if defined(LIBC_SCCS) && !defined(lint)
! static char *rcsid = "$Id: strtod.c,v 1.15 1994/09/18 04:23:42 jonathan Exp $";
  #endif /* LIBC_SCCS and not lint */
  
! #if defined(i386) || defined(ns32k) || defined(mipsel)
  #define IEEE_8087
  #endif
  #if defined(hp300) || defined(sparc) || defined(amiga) || defined(mc68000)
*** lib/libc/string/Makefile.inc	Thu Jul  7 01:14:05 1994
--- lib/libc/string/Makefile.inc.dsg	Sat Sep 17 22:24:31 1994
***************
*** 42,47 ****
--- 42,52 ----
  	rindex.c strcat.c strcmp.c strcpy.c strcspn.c strlen.S \
  	strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \
  	strspn.c strstr.c swab.c
+ .elif (${MACHINE_ARCH} == "mips")
+ SRCS+=	bcmp.S bcopy.S bzero.S  ffs.S index.S memchr.c memcmp.c memset.c \
+ 	rindex.S strcat.c strcmp.S strcpy.c strcspn.c strlen.S \
+ 	strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \
+ 	strspn.c strstr.c swab.c
  .endif
  
  # if no machine specific memmove(3), build one out of bcopy(3).