
function gen_call {
	typeset name="$1"
	typeset kcnum="$2"
	typeset nparms="$3"
	typeset rent="$4"
	typeset neglist="$5"

	print		'# DO NOT EDIT THIS FILE, IT IS GENERATED BY "mkkercalls"'
	print		".text"
	print		".global ${name}"
	print		"${name}:"
	print		".align 1"
	if [ ${nparms} -ge 7 ]; then
		echo "Too many parms to handle for ${name}" >&2
		exit 1
	fi
	if [ ${nparms} -eq 6 ]; then
		print	"mov.l	r8,@-r15"
		print	"mov.l	r9,@-r15"
		print	"mov.l	@(8,r15),r8"
		print	"mov.l	@(12,r15),r9"
	elif [ ${nparms} -eq 5 ]; then
		print	"mov.l	r8,@-r15"
		print	"mov.l	@(4,r15),r8"
	fi	
	# save frame pointer
	print		"mov.l	r14,@-r15"
	print		"mov	r15,r14"
	for neg in $neglist; do
		let "reg = $neg + 3"
		print	"neg	r${reg},r${reg}"
	done
	print		"trapa	#${kcnum}"
	# work around for a chip bug (see Hitachi technical update TN-SH7-456A/E)
	print		"bra	1f"
	print		"nop"
	print		"nop"
	print		"bra	2f"
	print		"nop"

	print		"nop"
	print		"nop"
	print		"nop"
	print		"1:"
	if [ ${nparms} -eq 6 ]; then
		print	"mov.l	@r15+,r14"
		print	"mov.l	@r15+,r9"
		print	"rts"
		print	" mov.l	@r15+,r8"
		print	"2:"
		print	"mov.l	@r15+,r14"
		print	"mov.l	@r15+,r9"
		print	"mov.l	@r15+,r8"
	elif [ ${nparms} -eq 5 ]; then
		print	"mov.l	@r15+,r14"
		print	"rts"
		print	" mov.l	@r15+,r8"
		print	"2:"
		print	"mov.l	@r15+,r14"
		print	"mov.l	@r15+,r8"
	else
		print	"rts"
		print	" mov.l	@r15+,r14"
		print	"nop"
		print	"2:"
		print	"mov.l	@r15+,r14"
	fi	
	
	case ${rent} in
	NONE)
		print	".ifdef __PIC__"
		print	"  mov		r0,r4"
		print	"  mova		__got,r0"
		print	"  mov.l	__got,r2"
		print	"  add		r0,r2"
		print	"  mov.l	ker_err_a,r0"
		print	"  mov.l	@(r0,r2),r1"
		print	"  jmp		@r1"
		print	"   nop"
		print	" .align 2"
		print	" __got: .long _GLOBAL_OFFSET_TABLE_"
		print	" ker_err_a: .long  __ker_err@GOT"
		print	".else"
		print	"  mov.l	ker_err_a,r1"
		print	"  jmp		@r1"
		print	"   mov		r0,r4"
		print	" .align 2"
		print	" ker_err_a: .long  __ker_err"
		print	".endif"
		;;
	NORMAL)
		print	"rts"
		print	" nop"
		;;
	NEGATIVE)
		print	"rts"
		print	" neg r0,r0"
		;;
	esac
	print		".type ${name},@function"
	print		".size ${name},.-${name}"
}
