🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.2bsd
Article #263

clock function crashes /usr/ucb/px

#263
From: Steven M. Schultz
Date: Fri, 05 Jan 1990 21:34
107 lines
2465 bytes
Subject: clock function crashes 'px'
Index:	ucb/pascal/px/34fun.s 2.10BSD

Description:
	The "clock" function causes a floating point exception core
	dump in /usr/ucb/px.

Repeat-By:
	Put the following test program into p.p,

program spin(input,output);

var
	i,j: integer;

begin
	i := clock;
	writeln(i);
	j := 0;
	repeat
		j := j+1;
	until j >= 100000;
	i := clock;
	writeln(i);
end.

	Then:
	
	pi p.p
	px obj

	Note the floating point exception.

Fix:
	Even if the floating point exception did not occur, the
	answers returned could be wrong because only the low order
	of the time values were being used in the calculations.

	Actual cause of the exception was a divide by zero, there
	was a missing 'setl' instruction which led to a zero being
	used in the ticks to milliseconds conversion.

	In addition to returning the correct answer, the code has
	also been reduced in size.

	Apply the following patch to /usr/src/ucb/pascal/px/34fun.s,
	recompile and install 'px'.

*** 34fun.s.old	Fri Mar 13 05:27:43 1987
--- 34fun.s	Tue Jan  2 15:58:46 1990
***************
*** 36,46 ****
  	mov	$EARGV,_perrno
  	error	EARGV
  _SCLCK:
! 	mov	$6,-(sp)
  	br	1f
  _CLCK:
! 	mov	$2,-(sp)
  1:
  	sub	$16.,sp
  	mov	sp,r0
  	mov	r0,-(sp)
--- 36,47 ----
  	mov	$EARGV,_perrno
  	error	EARGV
  _SCLCK:
! 	mov	$4,-(sp)
  	br	1f
  _CLCK:
! 	clr	-(sp)
  1:
+ 	seti
  	sub	$16.,sp
  	mov	sp,r0
  	mov	r0,-(sp)
***************
*** 48,63 ****
  	tst	(sp)+
  	mov	sp,r0
  	add	16.(sp),r0
! 	mov	(r0),r0
  	add	$18.,sp
- 	mul	$1000.,r0
- 	mov	r1,-(sp)
- 	mov	r0,-(sp)
- 	movif	(sp)+,fr0
- 	mov	$HZ,-(sp)
- 	sxt	-(sp)
- 	movif	(sp)+,fr1
  	divf	fr1,fr0
  	movfi	fr0,-(sp)
  	return
  _DATE:
--- 49,60 ----
  	tst	(sp)+
  	mov	sp,r0
  	add	16.(sp),r0
! 	movif	$HZ,fr1
! 	setl
! 	movif	(r0),fr0
  	add	$18.,sp
  	divf	fr1,fr0
+ 	mulf	$042572,fr0		/ mulf $1000.,fr0 
  	movfi	fr0,-(sp)
  	return
  _DATE:
Technical Details
Message-ID: <43569@wlbr.IMSD.CONTEL.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!voder!wlbr!wlv!sms

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!voder!wlbr!wlv!sms
From: sms@wlv.imsd.contel.com (Steven M. Schultz)
Newsgroups: comp.bugs.2bsd
Subject: clock function crashes /usr/ucb/px
Message-ID: <43569@wlbr.IMSD.CONTEL.COM>
Date: 5 Jan 90 21:34:56 GMT
Sender: news@wlbr.IMSD.CONTEL.COM
Reply-To: sms@wlv.imsd.contel.com (Steven M. Schultz)
Organization: Contel Federal Systems
Lines: 107