Subject: lib/38: Reversed operands in i386/sys/brk.S, and other libc/arch/i386 PIC stuff
To: None <gnats-admin>
From: None <thomas@mathematik.uni-Bremen.de>
List: netbsd-bugs
Date: 12/06/1993 12:50:05
>Number:         38
>Category:       lib
>Synopsis:       Reversed operands in i386/sys/brk.S, and other libc/arch/i386 PIC stuff
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    gnats-admin (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Dec  6 12:50:03 1993
>Originator:     Thomas Eberhardt
>Organization:
CeVis, University of Bremen, Germany
>Release:        
>Environment:
    	
System: NetBSD ed209 0.9a ED209#0 i386

Machine: i386
>Description:
	There are two movl statements in the assembly code for the brk
	function for the i386 architecture that have their operands
	in the wrong order.
	There is also a erroneous PIC_EPILOGUE at the end of
	gen/fixunsdfsi.S.
	Another thing: Shouldn't all the 'jmp cerror's in the various .S
	files be changed to 'jmp PIC_PLT(cerror)' as it is the case in
	sbrk.S?
	And last but not least: Shouldn't the PIC macros in SYS.h be moved
	to machine/asm.h to allow modification of the PROF macro so that it
	would be possible to build a profiled shared C library?
>How-To-Repeat:
	
>Fix:
*** sys/brk.S-	Thu Oct 21 03:19:26 1993
--- sys/brk.S	Mon Dec  6 01:34:40 1993
***************
*** 55,62 ****
  #ifdef PIC
  	movl	4(%esp),%eax
  	PIC_PROLOGUE
! 	movl	%edx,PIC_GOT(curbrk)	# set up GOT addressing
! 	movl	%ecx,PIC_GOT(minbrk)	#
  	cmpl	%eax,(%ecx)
  	PIC_EPILOGUE
  	jl	ok
--- 55,62 ----
  #ifdef PIC
  	movl	4(%esp),%eax
  	PIC_PROLOGUE
! 	movl	PIC_GOT(curbrk),%edx	# set up GOT addressing
! 	movl	PIC_GOT(minbrk),%ecx	#
  	cmpl	%eax,(%ecx)
  	PIC_EPILOGUE
  	jl	ok
*** gen/fixunsdfsi.S-	Thu Oct 21 03:03:39 1993
--- gen/fixunsdfsi.S	Mon Dec  6 00:51:11 1993
***************
*** 54,60 ****
  	PIC_EPILOGUE
  	fcoml	(%eax)
  #else
! 	fcoml	PIC_GOTOFF(fbiggestsigned)	/* bigger than biggest signed? */
  #endif
  	fstsw	%ax
  	sahf
--- 54,60 ----
  	PIC_EPILOGUE
  	fcoml	(%eax)
  #else
! 	fcoml	fbiggestsigned	/* bigger than biggest signed? */
  #endif
  	fstsw	%ax
  	sahf
***************
*** 71,82 ****
  	PIC_EPILOGUE
  	fsubl	(%eax)
  #else
! 	fsubl	PIC_GOTOFF(fbiggestsigned)	/* reduce for proper conversion */
  #endif
  	fistpl	4(%esp)		/* convert */
  	movl	4(%esp),%eax
  	orl	$0x80000000,%eax	/* restore bias */
- 	PIC_EPILOGUE
  	ret
  
  fbiggestsigned:	.double	0r2147483648.0
--- 71,81 ----
  	PIC_EPILOGUE
  	fsubl	(%eax)
  #else
! 	fsubl	fbiggestsigned	/* reduce for proper conversion */
  #endif
  	fistpl	4(%esp)		/* convert */
  	movl	4(%esp),%eax
  	orl	$0x80000000,%eax	/* restore bias */
  	ret
  
  fbiggestsigned:	.double	0r2147483648.0

------------------------------------------------------------------------------

I'm not sure if the following is really needed:

*** ./SYS.h-	Sun Nov  7 09:18:40 1993
--- ./SYS.h	Mon Dec  6 01:26:02 1993
***************
*** 60,69 ****
  #define PIC_GOTOFF(x)	x
  #endif
  
! #define	SYSCALL(x)	2: jmp cerror; ENTRY(x); lea SYS_/**/x,%eax; LCALL(7,0); jb 2b
  #define	RSYSCALL(x)	SYSCALL(x); ret
  #define	PSEUDO(x,y)	ENTRY(x); lea SYS_/**/y, %eax; ; LCALL(7,0); ret
! #define	CALL(x,y)	call _/**/y; addl $4*x,%esp
  /* gas fucks up offset -- although we don't currently need it, do for BCS */
  #define	LCALL(x,y)	.byte 0x9a ; .long y; .word x
  
--- 60,69 ----
  #define PIC_GOTOFF(x)	x
  #endif
  
! #define	SYSCALL(x)	2: jmp PIC_PLT(cerror); ENTRY(x); lea SYS_/**/x,%eax; LCALL(7,0); jb 2b
  #define	RSYSCALL(x)	SYSCALL(x); ret
  #define	PSEUDO(x,y)	ENTRY(x); lea SYS_/**/y, %eax; ; LCALL(7,0); ret
! #define	CALL(x,y)	call PIC_PLT(_/**/y); addl $4*x,%esp
  /* gas fucks up offset -- although we don't currently need it, do for BCS */
  #define	LCALL(x,y)	.byte 0x9a ; .long y; .word x
  
*** ./sys/exect.S-	Thu Oct 21 03:19:28 1993
--- ./sys/exect.S	Mon Dec  6 01:05:34 1993
***************
*** 53,56 ****
  	pushl	%edx
  	popf
  	LCALL(7,0)
! 	jmp	cerror		/* exect(file, argv, env); */
--- 53,56 ----
  	pushl	%edx
  	popf
  	LCALL(7,0)
! 	jmp	PIC_PLT(cerror)	/* exect(file, argv, env); */
*** ./sys/ptrace.S-	Thu Oct 21 03:19:33 1993
--- ./sys/ptrace.S	Mon Dec  6 01:06:02 1993
***************
*** 59,62 ****
  	jb	err
  	ret
  err:
! 	jmp	cerror
--- 59,62 ----
  	jb	err
  	ret
  err:
! 	jmp	PIC_PLT(cerror)
*** ./sys/sigprocmask.S-	Thu Oct 21 03:19:39 1993
--- ./sys/sigprocmask.S	Mon Dec  6 01:19:17 1993
***************
*** 45,51 ****
  #include "SYS.h"
  
  err:
! 	jmp	cerror
  
  ENTRY(sigprocmask)
  	movl	8(%esp),%ecx		# fetch new sigset pointer
--- 45,51 ----
  #include "SYS.h"
  
  err:
! 	jmp	PIC_PLT(cerror)
  
  ENTRY(sigprocmask)
  	movl	8(%esp),%ecx		# fetch new sigset pointer
*** ./sys/sigsuspend.S-	Thu Oct 21 03:19:41 1993
--- ./sys/sigsuspend.S	Mon Dec  6 01:19:28 1993
***************
*** 45,51 ****
  #include "SYS.h"
  
  err:
! 	jmp	cerror
  
  ENTRY(sigsuspend)
  	movl	4(%esp),%eax		# fetch mask arg
--- 45,51 ----
  #include "SYS.h"
  
  err:
! 	jmp	PIC_PLT(cerror)
  
  ENTRY(sigsuspend)
  	movl	4(%esp),%eax		# fetch mask arg
*** ./sys/syscall.S-	Thu Oct 21 03:19:43 1993
--- ./sys/syscall.S	Mon Dec  6 01:19:39 1993
***************
*** 53,56 ****
  	jb	1f
  	ret
  1:
! 	jmp	cerror
--- 53,56 ----
  	jb	1f
  	ret
  1:
! 	jmp	PIC_PLT(cerror)
>Audit-Trail:
>Unformatted:

------------------------------------------------------------------------------