/* vim: set filetype=c:
 *
 * osload.h86  -  Definitions for loading a new boot image
 *
 * 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: osload.h86,v 1.7 2007/01/06 18:31:38 gkminix Exp $
 */

#ifndef HEADERS_OSLOAD_H86
#define HEADERS_OSLOAD_H86


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



/*
 * The runtime module loads a new boot image at address 0x00100000, e.g. at
 * the beginning of extended memory. It then analyzes the boot image header
 * and creates an array of copy records, which define what part of the boot
 * image has to be copied at what memory address. This array gets stored at
 * 0x00007000. It then returns to the MGL loader, which then copies a small
 * copy program at 0x00007400, and jumps to the image copy program. This
 * copy program then places every part of the boot image where it belongs,
 * and jumps into the new image.
 * Before the image copy program gets called, the stack and the register values
 * have to be set so as the image expects them. Then, when the image copy
 * program finally calls the image, it just has to switch the stack and every-
 * thing is setup properly.
 * The following definitions are used for the interfacing between the various
 * parts of the MGL boot image loader.
 */

/* Structure size values */
#define COPY_REC_NUM	16		/* max. number of copy records */
#define IMAGE_REC_ADDR	0x00007000	/* address where to load image record */
#define OSLOAD_ADDR	0x00007100	/* address where to copy os loader */
#define OSLOAD_END	0x00007B00	/* address where os loader has to end */
#define OSLOAD_STACK	0x00007C00	/* intermediate top of stack */
#define IMAGE_ADDR	0x00110000	/* address where to load new image */


#ifndef _ASSEMBLY_

struct copy_rec {
  __lptr	srcaddr;		/* linear source copy address */
  __lptr	destaddr;		/* linear destination address */
  __lptr	copysize;		/* size of memory block to copy */
};

struct image_rec {
  __fptr	startaddr;		/* start address of image */
  __u8		hflags1;		/* hflags1 from netboot image header */
  __u8		hflags2;		/* hflags2 from netboot image header */
  __u16		addrnum;		/* number of copy adress records */
  struct copy_rec addrs[COPY_REC_NUM];	/* array with copy addresses */
  __u16		reg_ax;			/* register values when calling image */
  __u16		reg_bx;
  __u16		reg_cx;
  __u16		reg_dx;
  __u16		reg_ds;
  __u16		reg_es;
  __u16		reg_si;
  __u16		reg_di;
  __u32		stack[2];		/* pointers to put onto the stack */
};

#else

			.struct	0
copy_srcaddr:		.struct	.+4	/* linear source copy address */
copy_destaddr:		.struct	.+4	/* linear destination address */
copy_copysize:		.struct	.+4	/* size of memory block to copy */

#define COPY_STRUCT_SIZE	12


			.struct	0
image_startaddr:	.struct	.+4	/* start address of image */
image_hflags1:		.struct	.+1	/* hflags1 from netboot image header */
image_hflags2:		.struct	.+1	/* hflags2 from netboot image header */
image_addrnum:		.struct	.+2	/* number of copy address records */
image_addrs:		.struct	.+(COPY_REC_NUM * COPY_STRUCT_SIZE)
image_reg_ax:		.struct	.+2
image_reg_bx:		.struct	.+2
image_reg_cx:		.struct	.+2
image_reg_dx:		.struct	.+2
image_reg_ds:		.struct	.+2
image_reg_es:		.struct	.+2
image_reg_si:		.struct	.+2
image_reg_di:		.struct	.+2
image_stack:		.struct	.+(4 * 2)

#define IMAGE_STRUCT_SIZE	224

#endif /* _ASSEMBLY_ */

#endif

