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

/* System definition */

#include	<types.h>
#include	<sys.h>

#include	<gw/dev.vax/async.h>
#include	<gw/dev.vax/dhv.h>

#define	NULL	0

/* definitions of packet sizes */
#define	MX_PKT	3000		/* Size of largest packet */
#define	MX_SH	4		/* software header (MPW) */
#define	MX_HH	14		/* hardware header (10 Mb EtherNet) */
#define	MX_ST	0		/* software trailer */
#define	MX_HT	6		/* hardware trailer (chaos) */

/*
 * System initialization routines
 */

ext void log_init(), opcon_register();
ext word log_cmd, test_cmd;
ext void time_init(), io_init(), bus_int();
ext void initgw();
ext void INNET(), CHNET(), ARP(), RIP(), EGP(), /* TIME(),*/ SNMP(), snmpinit();
ext void TIMING(), NIP();
ext void OPCON(), STAT();
ext void restart_init();
ext void tcp_Init(), SUPDUP();
ext void KEEP_ALIVE();

void fixmem()
{
    ext long himem;

/*    himem = 1024 * 1024 * 2; */
}

struct inittbl	INITTBL[] = {
			/* system initialization */
      fixmem, 0,     /* too much memory is bad ... */
	log_init, 0,		/* logging */
	time_init, 0,		/* timers */
	io_init, 0,		/* devices */
	OPCON, 0,		/* command interpreter */
	STAT, 0,		/* status */
	opcon_register, (word)(&log_cmd), /* init logging commands */
#ifdef ndef
	opcon_register, (word)(&test_cmd),
#endif
	initgw, 0,	/* gateway initialization */
		
			/* protocol initialization */
	INNET, 0,		/* internet */
/*	CHNET, 0,		/* chaos net */
        NIP, 0,                /* Network Information Protocol */
	ARP, 0,			/* address resolution protocol */
        EGP, 0,		/* exterior gateway protocol */
	RIP, 0,    		/* routing information protocol */
/*        TIME, 0,*/        /* time (RFC868) protocol    */
/*        snmpinit, 0, */
	tcp_Init, 0,		/* TCP */
	SUPDUP, 0,		/* SUPDUP server */
/* only for skit 
	KEEP_ALIVE, 2,		/* DEQNA keep alive */
	/* TIMING, 0,		/* print timing info */
	restart_init, 0, /* Sets up restart parameter block */
	0, 0
};


/*
 * Device definitions
 */

#ifdef ndef
ext void viiii(), viioi(), viiin(), viiot(), vii_up();
ext void dmaii(), dmaoi(), dmain(), dmaot(), dma_up();
#endif
ext void qna_in_up(), qna_out_up(), qna_out(), qna_in(), qna_int();
ext void dlii(), dloi(), dlup(), dlin(), dlot();
ext void dhii(), dhoi(), dhup(), dhin(), dhot();
ext void con_rup(), con_tup(), con_out(), con_rint(), con_tint();
ext void sd_tup(), sd_write();
ext void null();

#ifdef ndef
dct viidct[2] = {
    DCTMAC(viiii, vii_up, viiin, 0x20001a80, 0x2b0, &viidct[1]),
    DCTMAC(viioi, vii_up, viiot, 0x20001a88, 0x2b4, &viidct[0]),
};
dct dmadct[2] = {
    DCTMAC(dmaii, dma_up, dmain, 0x20001dc0, 0x260, &dmadct[1]),
    DCTMAC(dmaoi, dma_up, dmaot, 0x20001dc8, 0x264, &dmadct[0]),
};
#endif

dct qnadct[2] = {
    DCTMAC(qna_int, qna_in_up, qna_in, 0x20001920, 0x3f8, &qnadct[1]),
    DCTMAC(qna_int, qna_out_up, qna_out, 0x20001920, 0x3fc, &qnadct[0]),
};


dct nulldct[2] = {
    DCTMAC(null, null, null, 0x20001920, 0x3f8, &nulldct[1]),
    DCTMAC(null, null, null, 0x20001920, 0x3fc, &nulldct[0]),
};

dct condct[2] = {
    DCTMAC(con_rint, con_rup, NULL, 0, 0xf8, &condct[1]),
    DCTMAC(con_tint, con_tup, con_out, 0, 0xfc, &condct[0]),
};

dct sddct[1] = {
    DCTMAC(NULL, sd_tup, sd_write, 0, 0, &sddct[0]),
};

/*
dct dldct[2] = {
    DCTMAC(dlii, dlup, dlin, VAX_CSR(0777560), VAX_INT(0460), &dldct[1]),
    DCTMAC(dloi, dlup, dlot, VAX_CSR(0777560), VAX_INT(0464), &dldct[0]),
};
*/

struct async_conf modem_19200 = {
    PARITY_OFF,
    CHAR_LEN_8,
    STOP1,
    NO_MODEM,
    BAUD_19200,
    BAUD_19200,
    FC_NONE
};

struct async_conf modem_9600 = {
    PARITY_OFF,
    CHAR_LEN_8,
    STOP1,
    NO_MODEM,
    BAUD_9600,
    BAUD_9600,
    FC_NONE
};

struct async_conf modem_2400 = {
    PARITY_OFF,
    CHAR_LEN_8,
    STOP1,
    MODEM,
    BAUD_2400,
    BAUD_2400,
    FC_NONE
};

struct async_conf modem_1200 = {
    PARITY_OFF,
    CHAR_LEN_8,
    STOP1,
    MODEM,
    BAUD_1200,
    BAUD_1200,
    FC_NONE
};

struct async_conf CTS_9600 = {
    PARITY_OFF,
    CHAR_LEN_8,
    STOP1,
    MODEM,
    BAUD_9600,
    BAUD_9600,
    FC_NONE
};

extern dct dhodct[];
/* CSR used to be 0760440 */
dct dhidct[8] = {
    DCTMAC2(dhii, dhup, dhin, VAX_CSR(0760460), VAX_INT(0310), &dhodct[0], &modem_1200),
    DCTMAC2(dhii, dhup, dhin, VAX_CSR(0760460), NO_IVEC, &dhodct[1], &modem_2400),
    DCTMAC2(dhii, dhup, dhin, VAX_CSR(0760460), NO_IVEC, &dhodct[2], &modem_9600),
    DCTMAC2(dhii, dhup, dhin, VAX_CSR(0760460), NO_IVEC, &dhodct[3], &modem_19200),
    DCTMAC2(dhii, dhup, dhin, VAX_CSR(0760460), NO_IVEC, &dhodct[4], NULL),
    DCTMAC2(dhii, dhup, dhin, VAX_CSR(0760460), NO_IVEC, &dhodct[5], NULL),
    DCTMAC2(dhii, dhup, dhin, VAX_CSR(0760460), NO_IVEC, &dhodct[6], NULL),
    DCTMAC2(dhii, dhup, dhin, VAX_CSR(0760460), NO_IVEC, &dhodct[7], NULL),
};

dct dhodct[8] = {
    DCTMAC(dhoi, NULL, dhot, VAX_CSR(0760460), VAX_INT(0314), &dhidct[0]),
    DCTMAC(dhoi, NULL, dhot, VAX_CSR(0760460), NO_IVEC, &dhidct[1]),
    DCTMAC(dhoi, NULL, dhot, VAX_CSR(0760460), NO_IVEC, &dhidct[2]),
    DCTMAC(dhoi, NULL, dhot, VAX_CSR(0760460), NO_IVEC, &dhidct[3]),
    DCTMAC(dhoi, NULL, dhot, VAX_CSR(0760460), NO_IVEC, &dhidct[4]),
    DCTMAC(dhoi, NULL, dhot, VAX_CSR(0760460), NO_IVEC, &dhidct[5]),
    DCTMAC(dhoi, NULL, dhot, VAX_CSR(0760460), NO_IVEC, &dhidct[6]),
    DCTMAC(dhoi, NULL, dhot, VAX_CSR(0760460), NO_IVEC, &dhidct[7]),
};

dct *DCTVT[] =	{
#ifdef ndef
                        &dmadct[0],
			&dmadct[1],
			&viidct[0],
			&viidct[1],
#endif
			&qnadct[0],
			&qnadct[1],
			&dhidct[0], &dhidct[1], &dhidct[2], &dhidct[3],
			&dhidct[4], &dhidct[5], &dhidct[6], &dhidct[7],
			&dhodct[0], &dhodct[1], &dhodct[2], &dhodct[3],
			&dhodct[4], &dhodct[5], &dhodct[6], &dhodct[7],
#ifdef ndef
			&dldct[0],
#endif
			&condct[0],
			&condct[1],
			&sddct[0],
			NULL
		};

dct *log_dev = &condct[1];

/*
 * Global Variables defined per configuration
 *
 *	These should really be set from the net structure at runtime.
 */

word	pktsiz = MX_PKT + MX_SH + MX_HH + MX_ST + MX_HT;
word	hdrsiz = MX_SH + MX_HH;
word	tlrsiz = MX_ST + MX_HT;
word	bufsiz = sizeof(iorb) + MX_PKT + MX_SH + MX_HH + MX_ST + MX_HT;
word	pktoff = sizeof(iorb) + MX_SH + MX_HH;

null_in ()
{
  return;
}

word null_out ()
{
  return(0);
}

null_prinit()
{
  return;
}
