#!/bin/sh

aout=vmlinux
start=

while [ $# != 0 ]
do
    case "$1:$2" in
	-f:?*) aout=$2; shift 2;;
	-*) usage;;
	*) start=$1; shift 1;;
    esac
done

case $(file /bin/ls) in
    *64-bit*PA-RISC*) mhost=hppa64-linux- ;;
    *32-bit*PA-RISC*) mhost=hppa-linux- ;;
    *) mhost=other ;;
esac

case $(file $aout) in
    *64-bit*PA-RISC*) maout=hppa64-linux- ;;
    *32-bit*PA-RISC*) maout=hppa-linux- ;;
    *) maout=other ;;
esac

prefix=
[ $mhost != $maout ] && prefix=$maout

if [ -z "$start" ]
then
    ${prefix}objdump -d --reloc $aout
else
    case "$start" in
	0x*) true;;
	[0-9]*) start=0x$start;;
	[a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
		start=0x$start ;;
	*) start=$(${prefix}nm -n $aout | grep " $start\$" | awk '{print $1}')
	   if [ -z "$start" ]
	   then
	       echo "symbol $start not found in $aout" >&2
	       exit 2
	   fi
	   start=0x$start
	   ;;
    esac
    ${prefix}objdump -d --reloc $aout --start-address $start
fi | ${PAGER:-less}
