/* vim: set filetype=c:
 *
 **************************************************************************
 *
 * Boot-ROM-Code to load an operating system across a TCP/IP network.
 *
 * Module:  pxe.h86
 * Purpose: Definitions for PXE function calling
 * Entries: none
 *
 **************************************************************************
 *
 * Copyright (C) 2003-2007 Gero Kuhlmann <gero@gkminix.han.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: pxe.h86,v 1.5 2007/01/06 18:30:47 gkminix Exp $
 */

#ifndef HEADERS_PXE_H86
#define HEADERS_PXE_H86


/*
 **************************************************************************
 *
 * This file can only get included into target C source files.
 */
#if defined(_ASSEMBLY_) || !defined(_TARGET_) || !defined(_BOOTROM_)
# error This file can only get included into target C source files
#endif



/*
 **************************************************************************
 *
 * We need some includes before we can include this file
 */
#include <common.h86>



/*
 **************************************************************************
 *
 * Global variables
 */

/* Far pointer to PXENV structure */
extern __fptr pxenvptr asm("pxenvptr");

/* Far pointer to !PXE structure */
extern __fptr pxeptr asm("pxeptr");

/* Far pointer to status callout function */
extern __fptr statuscallout asm("statcallout");



/*
 **************************************************************************
 * 
 * Call the PXE function handler
 */
static inline unsigned short pxe(unsigned short func, void *params)
{
  __u16 ret;
  __u16 d0;

  __asm__ __volatile__(
	"call callpxe"
	: "=&a" (ret), "=&b" (d0)
	: "0" ((__u16)func), "1" ((__u16)((int)params & 0xFFFF))
	: "memory", "cc");
  return((unsigned short)ret);
}



/*
 **************************************************************************
 *
 * Call PXE status callout function
 *
 * Input: param = 0      Inside time-out loop
 *        param = 1 - n  TFTP packet number
 *
 * Output: non-zero if to cancel the transfer
 */
static inline short callout(unsigned short param)
{
  __u16 d0, d1, d2, d3;

  __asm__ __volatile__(
	"pushw %%ax\n\t"
	"lcall *(statcallout)\n\t"
	"addw $2,%%sp"
	: "=&a" (d0), "=&b" (d1), "=&c" (d2), "=&d" (d3)
	: "0" ((__u16)param)
	: "memory", "cc");
  return((short)d0);
}


#endif

