/* Copyright 1984 by the Massachusetts Institute of Technology */

/* Structure definitions for system datatypes.
 */

/*
 *------------------------------------------------------------------
 *
 * $Source: /mit/cgw/src/sys/include/RCS/sys.h,v $
 * $Revision: 1.4 $
 * $Date: 88/06/05 22:23:42 $
 * $State: Exp $
 * $Author: jon $
 *
 *------------------------------------------------------------------
 */

#ifdef mc68000
#include	"../src.68/68.h"
#endif
#ifdef vax
#include	"../src.vax/vax.h"
#endif
#ifdef ibm032
#include       "../src.rt/rt.h" 
#endif

/* I/O request block */

#define	iorb	struct	iorbstr
#define	dct	struct	dctstr

iorb {	iorb	*i_link;	/* 00  Link to next iorb */
	dct	*i_devp;	/* 04   */
	void	(*i_cmp)();	/* 08  I/O completion routine */
	byte	*i_addr;	/* 0c  Start of data */
	byte	i_usr1;		/* 10  Use by SLIP byte stuffing */
	unss	i_breq;		/* 12  Bytes requested */
	bits	i_stat;		/* 14  Status */
	unss	i_bxfr;		/* 16  Bytes transfered */
	word	i_usr2;		/* 18  netp */
	word	i_usr3;		/* 1c   */
	word	i_usr4;		/* 20  time pkt was rcvd (not used) */
	word	i_usr5;		/* 24   */
	word	i_usr6;		/* 28   */
	};

#define	mkiorb(x)	((iorb *) (x))

/* IORB Status bits */
#define	I_ERR	0x000f		/* the low 4 bits can be used to pass
				 * an error code if desired */
#define	I_BRD	0x10		/* set if pkt was broadcast */
#define I_USR1	0x20
#define I_USR2	0x40
#define	I_DONE	0x80

/* Device control table */

dct {	md_ihx	d_ihx;
	void	(* d_iha)();
	iorb	*d_qhd;
	iorb	*d_qtl;
	dct	*d_lnk;
	word	*d_iva;
	void	(* d_ina)();
	word	d_csr;
	word	d_buf;
	void	(* d_strt)();
	bits	d_flg;
	byte	*d_addr;
	unss	d_breq;
	word	d_dev1;		/* Used by the DEQNA for its buffer
				 * list and statistics, used by VII
				 * for statistics. */
	word	d_dev2;		/* Used for statistics copy routine. */
	word	d_dev3;		/* (struct async_conf *) for async lines */
	unsb	d_crf;		/* device numbering in the DHV */
	byte	d_null;
	unsw	d_rc;		/* see NOTE 1 below */
	byte	*d_rfnt;	/* Used by the SLIP framing code */
	byte	*d_rend;	/* Used by the SLIP framing code */
	byte	*d_rhd;
	byte	*d_rtl;
	byte	d_rbuf[20];
	};

#define	mkdct(x)	((dct *) (x))
/*
 * inth		interrupt handler
 * init		device initialization routine
 * start	driver xfer start routine
 * csr		device control/status register
 * iva		device interrupt vector address
 * link		link to associated device
 */
#define	DCTMAC(inth, init, start, csr, iva, link) \
  { MD_IHD, inth, 0, 0, link, (word *)iva, init, csr, 0, start }
#define DCTMAC2(inth, init, start, csr, iva, link, d3) \
  { MD_IHD, inth, 0, 0, link, (word *)iva, init, csr, 0, start, \
    0, 0, 0, 0, 0, (word)d3 }

#define	D_HLD	01
#define	D_STP	02
#define	D_DWN	04
#define	D_RUN	040
#define	D_ACT	0100
#define	D_DV1	01000
#define	D_DV2	02000
#define	D_INI	040000
#define	D_OFL	0100000

#define NO_IVEC ((word *)-1)

/*
 * NOTE 1:
 *	d_rc is used for async serial line devices.  It is set
 * (usually in a network initialization routine) to point to an
 * interrupt level routine which does the per character protocol
 * specific actions such as byte stuffing and packet framing.
 *	Receive: Called as devp->d_rc((dct *)devp, (unss)c); where c
 * is the received character.  Currently the format of c is the value
 * as returned in the receive silo on a DHV-11.  See gw/dev.vax/dhv.h.
 *	Transmit: Called as devp->d_rc((dct *)devp).  Returns the
 * number of characters to send (zero means end of packet) and having
 * set devp->d_rfnt to point to the data to send.
 */

/* Initialization list definition. */
struct inittbl	{
	int	(*init_routine)();
	word	init_data;
};

#define	tskblk	struct	tskstr

tskblk	{	tskblk	*tsk_link;
		unsb	tsk_pri;
		unsb	tsk_spare;
		word	tsk_data;
		void	(* tsk_hndlr)();
	};		


#define	hndlre	struct	hndstr

hndlre	{	tskblk	*h_twait;
		tskblk	*h_tfree;		
	};
