#! /bin/sh

FILENAME_LEN=255
bootfile=/vmunix
karch=`arch -k`

case $karch in
	sun3)
		bootparam=c
		romp=fef0000
		;;
	sun3x)
		bootparam=c
		romp=fefe0000
		echo " this machine would crash using this romp ... exit"
		exit
		;;
	sun4)
		bootparam=c
		romp=ffe81000
		;;
	sun4c)
		bootparam=80
		romp=ffe80010
		;;
	sun386)
		bootparam=c
		romp=fffe0000
		;;
esac
#				*bootparam
cp /dev/null /tmp/args
adb /dev/kmem <<EOF >/tmp/foo
$romp+$bootparam?p
EOF
addr=`cat /tmp/foo | sed 's/^.*://'`

#				**bootparam
adb /dev/kmem <<EOF >/tmp/foo
$addr?p
EOF
addr=`cat /tmp/foo | sed 's/^.*://'`

#				b_args
adb /dev/kmem <<EOF >/tmp/foo
$addr?8p
EOF
addr=`cat /tmp/foo | sed 's/^.*://'`

#				argstrings
for i in $addr; do
if [ "$i" != 0 ]; then
adb /dev/kmem <<EOF >>/tmp/args
$i?s
EOF
fi
done
awk '{print $2}' /tmp/args > /tmp/args1
for arg in `cat /tmp/args1`; do
	len=`expr length $arg`
	cpind=`expr index $arg "\)"`
	if [ $cpind = 0 ]; then
		if [ $arg = -d ]; then
			bootfile=/$prev
			break
		else
			prev=$arg
			continue
		fi
	elif [ $cpind -lt $len ]; then
		cpind=`expr $cpind + 1`
		bootfile=/`expr substr $arg $cpind $FILENAME_LEN`
		break
	fi
done
echo $bootfile
