/* vim: set filetype=c:
 *
 * entry.h86  -  Definitions for PXE entry functions and installation check
 *
 * 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: entry.h86,v 1.9 2007/01/06 18:31:03 gkminix Exp $
 */

#ifndef PXE_ENTRY_H86
#define PXE_ENTRY_H86


/*
 * This file can only get included into target C or assembler source files.
 */
#define GCC_INCLUDE
#include <compiler.h>



/*
 **************************************************************************
 *
 * This file contains the Preboot API installation check definitions
 * as per Intels PXE specification version 2.0.
 *
 **************************************************************************
 *
 * Preboot API Installation check definitions:
 */
#ifndef INT_PXE
#define INT_PXE		0x1A		/* PXE installation check interrupt */
#endif
#define	PXE_IN_MAGIC	0x5650		/* Magic ID into PXE interrupt */
#define PXE_OUT_MAGIC	0x564E		/* Magic ID coming from PXE interrupt */



/*
 **************************************************************************
 *
 * Definition of PXENV+ API Entry Point Structure
 */
#ifndef _ASSEMBLY_

typedef struct s_pxenv_entry {
	__u8   signature[6];		/* entry point structure signature */
	__u16  version;			/* API version */
	__u8   length;			/* length of this structure */
	__u8   checksum;		/* makes checksum of struct zero */
	__fptr rm_entry;		/* 16-bit real mode API entry point */
	__fptr pm_entry;		/* 16-bit protected mode entry point */
	__u16  bc_stk_sel;		/* base code stack segment */
	__u16  bc_stk_size;		/* size of base code stack */
	__u16  bc_cs_sel;		/* base code code segment */
	__u16  bc_cs_size;		/* size of base code code segment */
	__u16  bc_ds_sel;		/* base code data segment */
	__u16  bc_ds_size;		/* size of base code data segment */
	__u16  net_ds_sel;		/* network driver data segment */
	__u16  net_ds_size;		/* size of network driver data seg */
	__u16  net_cs_sel;		/* network driver code segment */
	__u16  net_cs_size;		/* size of network driver code seg */
	__fptr pxeptr;			/* far ptr to !PXE structure */
} t_pxenv_entry;

#else

			.struct	0
o_pe_sig:		.struct	.+6	/* entry point structure signature */
o_pe_version:		.struct	.+2	/* API version */
o_pe_length:		.struct	.+1	/* length of this structure */
o_pe_checksum:		.struct	.+1	/* makes checksum of struct zero */
o_pe_rm_entry:		.struct	.+4	/* 16-bit real mode entry point */
o_pe_pm_entry:		.struct	.+4	/* 16-bit protected mode entry point */
o_pe_bc_ss_sel:		.struct	.+2	/* base code stack segment */
o_pe_bc_ss_size:	.struct	.+2	/* size of base code stack */
o_pe_bc_cs_sel:		.struct	.+2	/* base code code segment */
o_pe_bc_cs_size:	.struct	.+2	/* size of base code code segment */
o_pe_bc_ds_sel:		.struct	.+2	/* base code data segment */
o_pe_bc_ds_size:	.struct	.+2	/* size of base code data segment */
o_pe_net_ds_sel:	.struct	.+2	/* network driver data segment */
o_pe_net_ds_size:	.struct	.+2	/* size of network driver data seg */
o_pe_net_cs_sel:	.struct	.+2	/* network driver code segment */
o_pe_net_cs_size:	.struct	.+2	/* size of network driver code seg */
o_pe_pxe_ptr:		.struct	.+4	/* far pointer to !PXE structure */

#define pxentry_size		42	/* size of entry point structure */

#endif



/*
 **************************************************************************
 *
 * Definition of !PXE API Entry Point Structure
 */

/* Segment descriptor numbers */
#define PXE_DESC_STACK		0	/* stack segment */
#define PXE_DESC_UNDI_DATA	1	/* UNDI data segment */
#define PXE_DESC_UNDI_CODE	2	/* UNDI code segment */
#define PXE_DESC_UNDI_WRITE	3	/* UNDI code write segment */
#define PXE_DESC_BASE_DATA	4	/* base data segment */
#define PXE_DESC_BASE_CODE	5	/* base code segment */
#define PXE_DESC_BASE_WRITE	6	/* base code write segment */

#define PXE_DESC_DEF_UNDI	4	/* default # of desc with only UNDI */
#define PXE_DESC_DEF_BASE	7	/* default # of desc with UNDI & base */
#define PXE_DESC_DEF_NUM	7	/* total # of descriptors in struct */


#ifndef _ASSEMBLY_

/* Segment descriptor definition */
typedef struct s_desc {
	__u16  segment;			/* segment or selector */
	__u32  addr;			/* physical base address */
	__u16  size;			/* size of segment */
} t_desc;


/* !PXE API entry point structure */
typedef struct s_pxe_struct {
	__u8   signature[4];		/* entry point structure signature */
	__u8   length;			/* length of this structure */
	__u8   checksum;		/* makes checksum of this struct zero */
	__u8   revision;		/* structure definition revision */
	__u8   resvd1;			/* reserved */
	__fptr undiromid;		/* far ptr to UNDI ROM ID structure */
	__fptr baseromid;		/* far ptr to base ROM ID structure */
	__fptr pxentry16;		/* far ptr to 16-bit PXE entry point */
	__fptr pxentry32;		/* far ptr to 32-bit PXE entry point */
	__fptr statuscallout;		/* far ptr to status callout routine */
	__u8   resvd2;			/* reserved */
	__u8   descnum;			/* number of segment descriptors */
	__u16  firstsel;		/* first protected mode selector */
	t_desc desc[PXE_DESC_DEF_NUM];	/* segment descriptors */
} t_pxe_struct;

#else

			.struct	0
o_desc_segment:		.struct	.+2	/* segment or selector */
o_desc_addr:		.struct	.+4	/* physical base address */
o_desc_size:		.struct	.+2	/* size of segment */

#define desc_size		8	/* size of descriptor structure */
					/* total size of descriptor table */
#define pxe_desc_size		(PXE_DESC_DEF_NUM * desc_size)


			.struct	0
o_ps_sig:		.struct	.+4	/* entry point structure signature */
o_ps_length:		.struct	.+1	/* length of this structure */
o_ps_checksum:		.struct	.+1	/* makes checksum of this struct zero */
o_ps_revision:		.struct	.+1	/* structure definition revision */
			.struct	.+1	/* reserved */
o_ps_undiromid:		.struct	.+4	/* far ptr to UNDI ROM ID structure */
o_ps_baseromid:		.struct	.+4	/* far ptr to base ROM ID structure */
o_ps_pxentry16:		.struct	.+4	/* far ptr to 16-bit PXE entry point */
o_ps_pxentry32:		.struct	.+4	/* far ptr to 32-bit PXE entry point */
o_ps_statuscallout:	.struct	.+4	/* far ptr to status callout routine */
			.struct	.+1	/* reserved */
o_ps_descnum:		.struct	.+1	/* number of segment descriptors */
o_ps_firstsel:		.struct	.+2	/* first protected mode selector */
o_ps_desc:		.struct	.+pxe_desc_size

#define pxe_struct_size		32
#define pxe_def_size		(pxe_struct_size + pxe_desc_size)

#define pxe_stack_sel		(pxe_struct_size + (PXE_DESC_STACK * desc_size))
#define pxe_undi_data_sel	(pxe_struct_size + (PXE_DESC_UNDI_DATA * desc_size))
#define pxe_undi_text_sel	(pxe_struct_size + (PXE_DESC_UNDI_WRITE * desc_size))
#define pxe_base_data_sel	(pxe_struct_size + (PXE_DESC_BASE_DATA * desc_size))
#define pxe_base_text_sel	(pxe_struct_size + (PXE_DESC_BASE_WRITE * desc_size))

#endif



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

/* External data structures */
extern __fptr pxestruct asm ("pxestruct");	/* Pointer to !PXE structure */
extern __fptr pxenvstruct asm ("pxenvstruct");	/* Pointer to PXENV+ struct */

#endif

#endif

