#! /bin/csh -f
#$Header:gmon.ex 12.0$
#$ACIS:gmon.ex 12.0$
#$Source: /ibm/acis/usr/src/lib/libc/ca/csu/RCS/gmon.ex,v $
#
# 5799-WZQ (C) COPYRIGHT IBM CORPORATION 1986,1988
# LICENSED MATERIALS - PROPERTY OF IBM
# REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
#
# decide which compiler is used  
#
# IMPORTANT NOTE:
#
# This file is referenced from the kernel makefile when profiling is
# used. Please make sure that any changes are compatible with this
# kernel use.
#
switch (`egrep 'globl.*(oVpcc|oVhc1|oVhc2)' $1 | awk '{print substr($2,4,3)}'`)

case pcc:

	ex - $1 <<"+"
"	@(#)mon.ex	4.4 (Berkeley) 7/26/83"
"	fix funny things done by mcount()"
"	fix its name, make it jsb'able, change registers to protect the caller"
set magic
"/the beginning of mcount()/mark a"
/_.mcount/mark a
'a;/ cas /s/cas.*/get r14,$_mcount/
'a;/ stm /a
 mr r2,r0	# frompcindex
 mr r3,r15	# selfpc = return address
.
/DF[0-9,A-F]8/s//DF28/
/.set \LOWREGVAR/s;, [0-9]*;, 2 ;
/.set \LOWREG/s;, r[0-9]*;, r2 ;
/.set \LREGSPACE/s;, [0-9]*;, 84 ;
""
"fix the name"
g/_.mcount/s//mcount/
"	fix funny name for minbrk used by monstartup() to limit brk()"
g/_minbrk/s//minbrk/
w
q
"+"
	breaksw

case hc1:

	ex - $1 <<"+"
"	@(#)mon.ex	4.4 (Berkeley) 7/26/83"
"	fix funny things done by mcount()"
"	fix its name, make it jsb'able, change registers to protect the caller"
set magic
"/the beginning of mcount()/mark a"
/_.mcount/mark a
" change the stack space size for reg save "
'a;/	stm[	 ]*/c1
	stm  	r2,-92(r1)
.
/	cal[	 ]*/c1
	cal	r1,-92(r1)
.
/	lm[	 ]*/c1
	lm	r2,-92(r1)
.
'a;/	stm[	 ]*/a
	mr	r2,r0		# frompcindex
	mr	r3,r15		# selfpc = return address
.
/	mr[	 ]*/c1
	get	r14,$_mcount
.
" set trace data to show first gpr saved 				"
/DF[0-9,A-F]8/s//DF28/
""
"fix the name"
g/_.mcount/s//mcount/
"	fix funny name for minbrk used by monstartup() to limit brk()"
g/_minbrk/s//minbrk/
w
q
"+"
	breaksw

case hc2:

	ex - $1 <<"+"
"	Massage output of compiler for mcount() "
set magic
"/the beginning of mcount()/mark a"
/.globl[	 ]*_.mcount/mark a
'a;/	stm[	 ]*/c1
	stm	r2,-92(sp)
.
/	cal[	 ]*/c1
	cal	sp,-92(sp)
.
/	lm[	 ]*/c1
	lm	r2,0(sp)
.
/	cal[	 ]*/c1
	cal	sp,92(sp)
.
'a;/	stm[	 ]*/a
	mr	r2,r0		# frompcindex
	mr	r3,r15		# selfpc = return address
.
/	mr[	 ]*/c1
	get	r14,$_mcount
.
" set trace data to show first gpr saved "
/0x[0-9,a-f]8/s//0x28/
s/$/ now r2/
/lcl_offset/s/0x[0-9,a-f]/0x17/
s/$/ now 92/
" fix the name "
g/_.mcount/s//mcount/
" fix funny name for minbrk used by monstartup() to limit brk() "
g/_minbrk/s//minbrk/
w
q
"+"
	breaksw
endsw
