/* vim: set filetype=c:
 *
 * general.h86  -  Common PXE definitions
 *
 * 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: general.h86,v 1.11 2007/01/06 18:31:04 gkminix Exp $
 */

#ifndef PXE_GENERAL_H86
#define PXE_GENERAL_H86


/*
 * Include the main header file
 */
#define GCC_INCLUDE
#include <pxe/general.h>



/*
 **************************************************************************
 *
 * This file contains the Preboot API common definitions as
 * per Intels PXE specification version 2.1.
 *
 **************************************************************************
 *
 * Result codes returned in AX by a PXENV API service:
 */
#define PXENV_EXIT_SUCCESS	0x0000
#define PXENV_EXIT_FAILURE	0x0001



/*
 **************************************************************************
 *
 * Status codes returned in the status word of the PXENV API parameter
 * structure. Some of these codes are also used to return status
 * information from a boot image loader back to the bootrom.
 */

/* Generic API errors that are reported by the loader */
#define PXENV_STATUS_SUCCESS		0x00
#define PXENV_STATUS_FAILURE		0x01	/* general failure */
#define PXENV_STATUS_BAD_FUNC		0x02	/* invalid function number */
#define PXENV_STATUS_UNSUPPORTED	0x03	/* function not yet supported */
#define PXENV_STATUS_KEEP_UNDI		0x04	/* keep UNDI in memory */
#define PXENV_STATUS_KEEP_ALL		0x05	/* keep everything in memory */

/* ARP/UDP errors (0x10 to 0x1F) */
#define PXENV_STATUS_ARP_CANCELED	0x10	/* ARP canceled by keystroke */
#define PXENV_STATUS_ARP_TIMEOUT	0x11	/* ARP timeout */
#define PXENV_STATUS_UDP_CLOSED		0x18	/* UDP closed */
#define PXENV_STATUS_UDP_OPEN		0x19	/* UDP already open */
#define PXENV_STATUS_TFTP_CLOSED	0x1A	/* TFTP closed */
#define PXENV_STATUS_TFTP_OPEN		0x1B	/* TFTP already opened */

/* BIOS/system errors (0x20 to 0x2F) */
#define PXENV_STATUS_MCOPY_PROBLEM	0x20	/* unable to copy into memory */

/* TFP errors (0x30 to 0x3F) */
#define PXENV_STATUS_TFTP_CANNOT_ARP	0x30	/* TFTP ARP problem */
#define PXENV_STATUS_TFTP_OPEN_CANCELED	0x31	/* TFTP open canceled by key */
#define PXENV_STATUS_TFTP_OPEN_TIMEOUT	0x32	/* timeout during TFTP open */
#define PXENV_STATUS_TFTP_UNKNOWN_OP	0x33	/* unknown TFTP opcode */
#define PXENV_STATUS_TFTP_READ_CANCELED	0x34	/* TFTP read canceled by key */
#define PXENV_STATUS_TFTP_READ_TIMEOUT	0x35	/* timeout during TFTP read */
#define PXENV_STATUS_TFTP_ERROR_OP	0x36	/* bad TFTP opcode */
#define PXENV_STATUS_TFTP_CANNOT_OPEN	0x38	/* error during TFTP open */
#define PXENV_STATUS_TFTP_CANNOT_READ	0x39	/* error during TFTP read */
#define PXENV_STATUS_TFTP_TOO_MANY	0x3A	/* too many packages */
#define PXENV_STATUS_TFTP_INVALID_FILE	0x3B	/* file not found */
#define PXENV_STATUS_TFTP_ACCESS	0x3C	/* access violation */
#define PXENV_STATUS_TFTP_NO_MCAST	0x3D	/* no multicast address */
#define PXENV_STATUS_TFTP_NO_FILESIZE	0x3E	/* unable to get file size */
#define PXENV_STATUS_TFTP_INV_PACKET	0x3F	/* invalid packet size */

/* BOOTP errors (0x40 to 0x4F) */
#define PXENV_STATUS_BOOTP_CANCELED	0x40	/* BOOTP canceled by key */
#define PXENV_STATUS_BOOTP_TIMEOUT	0x41	/* timeout during BOOTP */
#define PXENV_STATUS_BOOTP_NO_FILE	0x42	/* missing bootfile name */

/* DHCP errors (0x50 to 0x5F) */
#define PXENV_STATUS_DHCP_CANCELED	0x50	/* DHCP canceled by key */
#define PXENV_STATUS_DHCP_TIMEOUT	0x51	/* timeout during DHCP */
#define PXENV_STATUS_DHCP_NO_IP_ADDR	0x52	/* missing IP address */
#define PXENV_STATUS_DHCP_NO_FILE	0x53	/* missing bootfile name */
#define PXENV_STATUS_DHCP_BAD_IP	0x54	/* invalid IP address */

/* Driver errors (0x60 to 0x6F) */
#define PXENV_STATUS_UNDI_INVFUNC	0x60	/* invalid UNDI function */
#define PXENV_STATUS_UNDI_MEDIATEST	0x61	/* media test failed */
#define PXENV_STATUS_UNDI_MCAST		0x62	/* cannot init for multicast */
#define PXENV_STATUS_UNDI_NIC_INIT	0x63	/* cannot init NIC */
#define PXENV_STATUS_UNDI_PHY_INIT	0x64	/* cannot init hardware */
#define PXENV_STATUS_UNDI_CONFIG_DATA	0x65	/* cannot read config data */
#define PXENV_STATUS_UNDI_INIT_DATA	0x66	/* cannot read init data */
#define PXENV_STATUS_UNDI_INV_HWADDR	0x67	/* invalid hardware address */
#define PXENV_STATUS_UNDI_EEPROM	0x68	/* invalid EEPROM checksum */
#define PXENV_STATUS_UNDI_RESOURCES	0x69	/* out of resources */
#define PXENV_STATUS_UNDI_INVALID_STATE	0x6A	/* invalid UNDI state */
#define PXENV_STATUS_UNDI_TRANSMIT	0x6B	/* UNDI transmit error */

/* Bootstrap (.1) errors (0x70 to 0x7F) */
#define PXENV_STATUS_BSTRAP_MENU	0x74	/* invalid bootstrap menu */
#define PXENV_STATUS_BSTRAP_MCAST_ADDR	0x76	/* missing multicast address */
#define PXENV_STATUS_BSTRAP_LIST	0x77	/* missing file list */
#define PXENV_STATUS_BSTRAP_NO_RESPONSE	0x78	/* no response from server */
#define PXENV_STATUS_BSTRAP_BIG_FILE	0x79	/* next file too big */

/* Environment (.2) errors (0x80 to 0x8F) */

/* MTFTP errors (0x90 to 0x9F) */
#define PXENV_STATUS_MTFTP_OPEN_CANCEL	0x91	/* MTFTP open canceled by key */
#define PXENV_STATUS_MTFTP_OPEN_TIMEOUT	0x92	/* timeout during MTFTP open */
#define PXENV_STATUS_MTFTP_UNKNOWN_OP	0x93	/* unknown TFTP opcode */
#define PXENV_STATUS_MTFTP_READ_CANCEL	0x94	/* MTFTP read canceled by key */
#define PXENV_STATUS_MTFTP_READ_TIMEOUT	0x95	/* timeout during MTFTP read */
#define PXENV_STATUS_MTFTP_ERROR_OP	0x96	/* bad TFTP opcode */
#define PXENV_STATUS_MTFTP_CANNOT_OPEN	0x98	/* error during MTFTP open */
#define PXENV_STATUS_MTFTP_CANNOT_READ	0x99	/* error during MTFTP read */
#define PXENV_STATUS_MTFTP_TOO_MANY	0x9A	/* too many packages */
#define PXENV_STATUS_MTFTP_PACK_SIZE	0x9B	/* invalid package size */

/* Misc. errors (0xA0 to 0xAF) */
#define PXENV_STATUS_BINL_CANCELED	0xA0	/* BINL canceled by key */
#define PXENV_STATUS_BINL_NO_SERVER	0xA1	/* no BINL server found */
#define PXENV_STATUS_PMODE		0xA2	/* not available in prot mode */
#define PXENV_STATUS_RMODE		0xA3	/* not available in real mode */

/* BUSD errors (0xB0 to 0xBF) */
#define PXENV_STATUS_BUSD_BUS_ENABLE	0xB0	/* BUSD services not enabled */
#define PXENV_STATUS_BUSD_DEV_ENABLE	0xB1	/* BUSD device not enabled */

/* Loader errors (0xC0 to 0xCF) */
#define PXENV_STATUS_LOADER_NO_FBM	0xC0	/* no free base memory */
#define PXENV_STATUS_LOADER_NO_BC	0xC1	/* no base code rom ID */
#define PXENV_STATUS_LOADER_BAD_BC_ID	0xC2	/* bad base code rom ID */
#define PXENV_STATUS_LOADER_BC_IMG	0xC3	/* bad base code image */
#define PXENV_STATUS_LOADER_NO_UNDI	0xC4	/* no UNDI rom ID */
#define PXENV_STATUS_LOADER_BAD_UNDI	0xC5	/* bad UNDI rom ID */
#define PXENV_STATUS_LOADER_UNDI_IMG	0xC6	/* bad UNDI runtime image */
#define PXENV_STATUS_LOADER_NO_PXE	0xC8	/* missing !PXE struct */
#define PXENV_STATUS_LOADER_NO_PXENV	0xC9	/* missing PXENV+ struct */
#define PXENV_STATUS_LOADER_UNDI_START	0xCA	/* UNDI not started */
#define PXENV_STATUS_LOADER_BC_START	0xCB	/* base code not started */

/* Reserved errors (0xD0 to 0xFF) */
#define PXENV_STATUS_IMAGE_INVALID	0xD0	/* invalid boot image */
#define PXENV_STATUS_STOP_BASE		0xD1	/* error stopping base code */
#define PXENV_STATUS_UNLOAD_BASE	0xD2	/* error unloading base code */
#define PXENV_STATUS_STOP_UNDI		0xD3	/* error stopping UNDI */
#define PXENV_STATUS_CLEANUP_UNDI	0xD4	/* error cleaning up UNDI */



/*
 **************************************************************************
 *
 * Define calls to the target runtime library. These routines should not be
 * used by the bootrom.
 */
#if COMPILE_SYSTEM == COMPILER_TARGET_GCC && !defined(_BOOTROM_)

/* Routine to call a PXE API runtime function */
__nb_inline__ unsigned short pxe(unsigned short func, void *params)
{
  __u16 ret;
  __u16 d0, d1;

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

#endif

#endif

