extension=S

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		'#include "asmoff.def"'
	print		".align 4"
	print		".global ${name}"
	print		"${name}:"
	print		"#if defined(VARIANT_p)"
	print		"  pushl	%ebp"
	print		"  movl		%esp,%ebp"
	print		"  .data"
	print		"  .align 4"
	print		"  .LP1:"
	print		"  .long 0"
	print		"  .text"
	print		"  movl \$.LP1,%edx"
	print		"  call	_mcount"
	print		"  popl %ebp"
	print		"#endif"
	for neg in $neglist; do
		let "off = $neg * 4"
		print	"negl $off(%esp)"
	done  
	print		"movl	\$${kcnum},%eax"
	print		"#if defined(__PIC__)"
	print		"  call .L1"
	print		"  .L1:"
	print		"  popl	%edx"
	print		"  movl	%edx,%ecx"
	print		"  addl	\$_GLOBAL_OFFSET_TABLE_+[.-.L1],%ecx"
	print		"  addl	\$(.L2-.L1),%edx"
	print		"  testl \$X86_CPU_SEP,__cpu_flags@GOTOFF(%ecx)"
	print		"#else"
	print		"  testl \$X86_CPU_SEP,__cpu_flags"
	print		"  movl	\$.L2,%edx"
	print		"#endif"
	print		"jz	1f"
	print		"movl	%esp,%ecx"
	print		"sysenter"
	print		".L2:"
	print		"ret"
	print		"2:"
	case ${rent} in
	NONE)
		print	".extern __ker_err"
		print	"#if defined(__PIC__)"
		print	"  addl	\$_GLOBAL_OFFSET_TABLE_+[.-.L2],%edx"
		print	"  movl __ker_err@GOT(%edx),%edx"
		print	"  jmp	*%edx"
		print	"#else"
		print	"  jmp	__ker_err"
		print	"#endif"
		;;
	NORMAL)
		print	"ret"
		;;
	NEGATIVE)
		print	"negl	%eax"
		print	"ret"
		;;
	esac
	print		"1:"
	print		"int	\$0x28"
	print		"ret"
	case ${rent} in
	NONE)
		print	"#if defined(__PIC__)"
		print	"  jmp	2b"
		print	"#else"
		print	"  jmp	__ker_err"
		print	"#endif"
		;;
	NORMAL)
		print	"ret"
		;;
	NEGATIVE)
		print	"negl	%eax"
		print	"ret"
		;;
	esac
	print		".type ${name},@function"
	print		".size ${name},.-${name}"
}
