h55867
s 00097/00000/00000
d D 1.1 82/08/03 08:40:58 cecily 1 0
e
u
U
t
T
I 1
	title	unix c library -- runtime initialization with monitor
	entry	_exit
	extrn	exit
	entry	countbas
	entry	environ
	extrn	main
	extrn	etext,sbrk,monitor
*
r0	equ	0
r1	equ	1
r2	equ	2
sp	equ	7
rf	equ	15
*
write	equ	4	write svc
cbufs	equ	100	no. of words in call-count buffer
*
countbas	dc	0	next available call-count buffer entry
*
	pure
start	equ	*
* rearrange args on stack
	sis	sp,2*adc
	lda	r0,2*adc(sp)
	sta	r0,0(sp)
	la	r1,3*adc(sp)
	sta	r1,adc(sp)
envlp	equ	*
	lda	r0,0(r1)
	bz	fndenv
	ais	r1,adc
	b	envlp
fndenv	equ	*
	ais	r1,adc
	sta	r1,2*adc(sp)	clobber orig argc
	sta	r1,environ
* profile buffer size = program text size / 4
	la	r1,etext
	si	r1,eprol
	ais	r1,15
	srls	r1,4
* get storage for profile buffer
	shi	sp,5*adc
	lhi	r2,cbufs
	sta	r2,4*adc(sp)
	slls	r2,1
	ais	r2,3
	ar	r1,r2
	sta	r1,3*adc(sp)
	slls	r1,2
	sta	r1,0(sp)
	bal	rf,sbrk
	chi	r0,-1
	be	nocore
* start profiling
	sta	r0,2*adc(sp)
	ais	r0,3*adc
	sta	r0,countbas
	la	r0,etext
	sta	r0,1*adc(sp)
	la	r0,eprol
	sta	r0,0(sp)
	bal	rf,monitor
	ahi	sp,5*adc
* call main program
	bal	rf,main
* if main routine returns, exit 
	sta	r0,0(sp)
	bal	rf,exit
	b	_exit
*
* no core for monitor buffer
*
nocore	equ	*
	lis	r0,2
	svc	14,write
	dc	mesg
	dc	emesg-mesg
	svc	14,1
mesg	db	c'No space for monitor buffer',x'0a'
emesg	equ	*
	align	2
*
* Exit routine -- write out mon.out file and exit
*
_exit	equ	*
	sis	sp,adc
	lis	r0,0
	sta	r0,0(sp)
	bal	rf,monitor
	lda	r0,adc(sp)
	svc	14,1
* end of prologue
eprol	equ	*
	bss
environ	das	1
	end
E 1
