/*
 * apm1.S
 *
 * Copyright 2004, Minoru Murashima. All rights reserved.
 * Distributed under the terms of the BSD License.
 */


#define ASM_FILE


#include"segment.h"
#include"apm.h"


.text

/*
 * int invokeApmFunction(int fnum,APM_FUNC_ARGS *args)
 * return : 0 or error=error number
 */
.globl invokeApmFunction
invokeApmFunction:
	pushl	%ebx
	pushl	%esi
	pushl	%edi
	pushl	%ebp

	movl	24(%esp),%eax			/* args address. */
	movw	2(%eax),%bx
	movw	4(%eax),%cx
	movw	6(%eax),%dx
	movw	8(%eax),%si
	movw	10(%eax),%di

	movl	$APM_DATA_DES,%eax
	movl	%eax,%ds
	movl	%eax,%es
	movl	20(%esp),%eax			/* function number. */
	movb	$APM_FUNC,%ah

	lcall	*%ss:apmfarCall			/* Invoke APM function. */
	movl	$KERNEL_DATA_DES,%ebp
	movl	%ebp,%ds
	movl	%ebp,%es
	jc		1f

	movl	24(%esp),%eax			/* args address. */
	movw	%ax,(%eax)
	movw	%bx,2(%eax)
	movw	%cx,4(%eax)
	movw	%dx,6(%eax)
	movw	%si,8(%eax)
	movw	%di,10(%eax)
	xorl	%eax,%eax

1:	shrl	$8,%eax
	andl	$0xff,%eax
	popl	%ebp
	popl	%edi
	popl	%esi
	popl	%ebx
	ret
