/* vim: set filetype=c:
 *
 * bios.h86  -  Definitions for acessing the system BIOS
 *
 * 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: bios.h86,v 1.12 2007/01/06 18:31:07 gkminix Exp $
 */

#ifndef SYSTEM_BIOS_H86
#define SYSTEM_BIOS_H86


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



/*
 * BIOS data segment
 */
#define BIOS_SEG	0x0040		/* BIOS data segment */

#define BIOS_SYSCNF	0x0010		/* System configuration */
#define BIOS_BASEMEM	0x0013		/* Free base memory in kB */
#define BIOS_FDSTAT	0x0041		/* Floppy disk status byte */
#define BIOS_COLUMNS	0x004A		/* Number of screen columns */
#define BIOS_VIDSIZE	0x004C		/* Size of video buffer in bytes */
#define BIOS_RSTFLAG	0x0072		/* BIOS reset flag */
#define BIOS_HDSTAT	0x0074		/* Hard disk status byte */
#define BIOS_VDSFLAG	0x007B		/* Virtual DMA status flag */
#define BIOS_LINES	0x0084		/* Number of screen lines - 1 */



/*
 * BIOS reset vector
 */
#define BIOS_RESET_SEG	0xF000		/* BIOS segment */
#define BIOS_RESET_OFS	0xFFF0		/* BIOS reset entry point */



/*
 * BIOS bootstrap vector
 */
#define BIOS_BOOT_SEG	0xF000		/* BIOS segment */
#define BIOS_BOOT_OFS	0xE6F2		/* BIOS bootstrap entry point */



/*
 * BIOS system type ID byte
 */
#define BIOS_MODEL_SEG	0xF000		/* BIOS segment */
#define BIOS_MODEL_OFS	0xFFFE		/* BIOS model ID offset */

#define BIOS_MODEL_PC	0xFF		/* Original IBM PC */
#define BIOS_MODEL_XT	0xFE		/* Original IBM PC/XT */
#define BIOS_MODEL_JR	0xFD		/* Original IBM PC/Jr */
#define BIOS_MODEL_AT	0xFC		/* 286+ processor system */
#define BIOS_MODEL_86	0xFB		/* other 8-/16-bit PC systems */
#define BIOS_MODEL_OPS2	0xFA		/* Original IBM PS/2 86+ */
#define BIOS_MODEL_CONV	0xF9		/* Original IBM Convertible */
#define BIOS_MODEL_PS2	0xF8		/* Original IBM PS/2 286+ */



/*
 * BIOS interrupt vectors:
 */
#define INT_VIDEO	0x10		/* BIOS screen vector */
#define INT_EQUIP	0x11		/* BIOS equipment flags */
#define INT_MEMORY	0x12		/* BIOS determine amount of base memory */
#define INT_DISK	0x13		/* BIOS disk vector */
#define INT_AUX		0x14		/* BIOS aux I/O vector */
#define INT_MISC	0x15		/* BIOS misc function vector */
#define INT_KBD		0x16		/* BIOS keyboard vector */
#define INT_PRINT	0x17		/* BIOS printer output vector */
#define INT_BOOTROM	0x18		/* ROM entry interrupt */
#define INT_BOOTFAIL	0x18		/* PnP BIOS boot fail interrupt */
#define INT_BOOTSTRAP	0x19		/* Bootstrap interrupt */
#define INT_TIME	0x1A		/* BIOS time/date vector */
#define INT_PCI		0x1A		/* PCI BIOS interface */
#define INT_DPB		0x1E		/* BIOS diskette parameter block */



/*
 * Get an interrupt vector
 */
#ifndef _ASSEMBLY_
__nb_inline__ __fptr getint(unsigned short intnum)
{
  __u16 d0, d1;
  __u32 ret;

  __asm__ __volatile__(
	"push %%es\n\t"
	"movw %0,%%es\n\t"
	"movl %%es:(%1),%2\n\t"
	"pop %%es"
	: "=&r" (d0), "=&b" (d1), "=r" (ret)
	: "0" ((__u16)0), "1" ((__u16)(intnum * 4))
	: "memory");
  return((__fptr)ret);
}
#endif



/*
 * Definitions for accessing a BIOS Diskette Parameter Block (DPB)
 */
#define DPB_SIZE	11		/* size of disk parameter block */
#define DPB_VECT	(INT_DPB * 4)	/* vector address of interrupt 0x1E */

#ifndef _ASSEMBLY_

struct bios_dpb {
  __u16         specify;		/* step rate, head un-/load time */
  __u8          motordelay;		/* ticks until motor turned off */
  __u8          sectsize;		/* bytes per sector */
  __u8          sptrack;		/* sectors per track */
  __u8          gaplength;		/* gap length in bytes */
  __u8          datalength;		/* data length in bytes */
  __u8          formatgap;		/* gap length for formatting */
  __u8          fillerbyte;		/* format filler byte */
  __u8          headsettle;		/* head settle time */
  __u8          motorstart;		/* motor start time */
} PACKED;

#else

			.struct	0
dpb_specify:		.struct	.+2	/* step rate, head un-/load time */
dpb_motordelay:		.struct	.+1	/* ticks until motor turned off */
dpb_sectsize:		.struct	.+1	/* bytes per sector */
dpb_sptrack:		.struct	.+1	/* sectors per track */
dpb_gaplength:		.struct	.+1	/* gap length in bytes */
dpb_datalength:		.struct	.+1	/* data length in bytes */
dpb_formatgap:		.struct	.+1	/* gap length for formatting */
dpb_fillerbyte:		.struct	.+1	/* format filler byte */
dpb_headsettle:		.struct	.+1	/* head settle time */
dpb_motorstart:		.struct	.+1	/* motor start time */

#endif /* _ASSEMBLY_ */

#endif

