17c478bd9Sstevel@tonic-gate #ifndef GRUB_H
27c478bd9Sstevel@tonic-gate #define GRUB_H
37c478bd9Sstevel@tonic-gate 
47c478bd9Sstevel@tonic-gate #include "osdep.h"
57c478bd9Sstevel@tonic-gate #include "byteswap.h"
67c478bd9Sstevel@tonic-gate #include "in.h"
77c478bd9Sstevel@tonic-gate #include "ip.h"
87c478bd9Sstevel@tonic-gate #include "udp.h"
97c478bd9Sstevel@tonic-gate #include "if_ether.h"
107c478bd9Sstevel@tonic-gate #include "latch.h"
117c478bd9Sstevel@tonic-gate #include "io.h"
127c478bd9Sstevel@tonic-gate #include "nic.h"
137c478bd9Sstevel@tonic-gate #include <shared.h>
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #define K_ESC		'\033'
167c478bd9Sstevel@tonic-gate #define K_EOF		'\04'  /* Ctrl-D */
177c478bd9Sstevel@tonic-gate #define K_INTR		'\03'  /* Ctrl-C */
187c478bd9Sstevel@tonic-gate 
197c478bd9Sstevel@tonic-gate #ifndef	MAX_RPC_RETRIES
207c478bd9Sstevel@tonic-gate #define MAX_RPC_RETRIES		20
217c478bd9Sstevel@tonic-gate #endif
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate /* Inter-packet retry in ticks */
257c478bd9Sstevel@tonic-gate #ifndef TIMEOUT
267c478bd9Sstevel@tonic-gate #define TIMEOUT			(10*TICKS_PER_SEC)
277c478bd9Sstevel@tonic-gate #endif
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	NULL
307c478bd9Sstevel@tonic-gate #define NULL	((void *)0)
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #define ARP_CLIENT	0
357c478bd9Sstevel@tonic-gate #define ARP_SERVER	1
367c478bd9Sstevel@tonic-gate #define ARP_GATEWAY	2
377c478bd9Sstevel@tonic-gate #define MAX_ARP		ARP_GATEWAY+1
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #define IGMP_SERVER	0
407c478bd9Sstevel@tonic-gate #define MAX_IGMP	IGMP_SERVER+1
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	RARP_REQUEST	3
437c478bd9Sstevel@tonic-gate #define	RARP_REPLY	4
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #define MULTICAST_MASK    0xF0000000
477c478bd9Sstevel@tonic-gate #define MULTICAST_NETWORK 0xE0000000
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate struct arptable_t {
507c478bd9Sstevel@tonic-gate 	in_addr ipaddr;
517c478bd9Sstevel@tonic-gate 	uint8_t node[6];
527c478bd9Sstevel@tonic-gate };
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate struct igmptable_t {
557c478bd9Sstevel@tonic-gate 	in_addr group;
567c478bd9Sstevel@tonic-gate 	unsigned long time;
577c478bd9Sstevel@tonic-gate };
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #define	KERNEL_BUF	(BOOTP_DATA_ADDR->bootp_reply.bp_file)
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #define	FLOPPY_BOOT_LOCATION	0x7c00
627c478bd9Sstevel@tonic-gate /* Must match offsets in loader.S */
637c478bd9Sstevel@tonic-gate #define ROM_SEGMENT		0x1fa
647c478bd9Sstevel@tonic-gate #define ROM_LENGTH		0x1fc
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #define	ROM_INFO_LOCATION	(FLOPPY_BOOT_LOCATION+ROM_SEGMENT)
677c478bd9Sstevel@tonic-gate /* at end of floppy boot block */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /* Define a type for passing info to a loaded program */
727c478bd9Sstevel@tonic-gate struct ebinfo {
737c478bd9Sstevel@tonic-gate 	uint8_t  major, minor;	/* Version */
747c478bd9Sstevel@tonic-gate 	uint16_t flags;		/* Bit flags */
757c478bd9Sstevel@tonic-gate };
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /***************************************************************************
787c478bd9Sstevel@tonic-gate External prototypes
797c478bd9Sstevel@tonic-gate ***************************************************************************/
807c478bd9Sstevel@tonic-gate extern void rx_qdrain P((void));
817c478bd9Sstevel@tonic-gate extern int tftp P((const char *name, int (*)(unsigned char *, unsigned int, unsigned int, int)));
827c478bd9Sstevel@tonic-gate extern int ip_transmit P((int len, const void *buf));
837c478bd9Sstevel@tonic-gate extern void build_ip_hdr P((unsigned long destip, int ttl, int protocol,
847c478bd9Sstevel@tonic-gate 	int option_len, int len, const void *buf));
857c478bd9Sstevel@tonic-gate extern void build_udp_hdr P((unsigned long destip,
867c478bd9Sstevel@tonic-gate 	unsigned int srcsock, unsigned int destsock, int ttl,
877c478bd9Sstevel@tonic-gate 	int len, const void *buf));
887c478bd9Sstevel@tonic-gate extern int udp_transmit P((unsigned long destip, unsigned int srcsock,
897c478bd9Sstevel@tonic-gate 	unsigned int destsock, int len, const void *buf));
907c478bd9Sstevel@tonic-gate typedef int (*reply_t)(int ival, void *ptr, unsigned short ptype, struct iphdr *ip, struct udphdr *udp);
917c478bd9Sstevel@tonic-gate extern int await_reply P((reply_t reply,	int ival, void *ptr, long timeout));
927c478bd9Sstevel@tonic-gate extern int decode_rfc1533 P((unsigned char *, unsigned int, unsigned int, int));
937c478bd9Sstevel@tonic-gate extern void join_group(int slot, unsigned long group);
947c478bd9Sstevel@tonic-gate extern void leave_group(int slot);
957c478bd9Sstevel@tonic-gate #define RAND_MAX 2147483647L
967c478bd9Sstevel@tonic-gate extern uint16_t ipchksum P((const void *ip, unsigned long len));
977c478bd9Sstevel@tonic-gate extern uint16_t add_ipchksums P((unsigned long offset, uint16_t sum, uint16_t new));
987c478bd9Sstevel@tonic-gate extern int32_t random P((void));
997c478bd9Sstevel@tonic-gate extern long rfc2131_sleep_interval P((long base, int exp));
1007c478bd9Sstevel@tonic-gate extern long rfc1112_sleep_interval P((long base, int exp));
1017c478bd9Sstevel@tonic-gate #ifndef DOWNLOAD_PROTO_TFTP
1027c478bd9Sstevel@tonic-gate #define	tftp(fname, load_block) 0
1037c478bd9Sstevel@tonic-gate #endif
1047c478bd9Sstevel@tonic-gate extern void cleanup P((void));
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /* misc.c */
1077c478bd9Sstevel@tonic-gate extern void twiddle P((void));
1087c478bd9Sstevel@tonic-gate extern void sleep P((int secs));
1097c478bd9Sstevel@tonic-gate extern void interruptible_sleep P((int secs));
1107c478bd9Sstevel@tonic-gate extern void poll_interruptions P((void));
1117c478bd9Sstevel@tonic-gate extern int strcasecmp P((const char *a, const char *b));
1127c478bd9Sstevel@tonic-gate extern char *substr P((const char *a, const char *b));
1137c478bd9Sstevel@tonic-gate extern unsigned long strtoul P((const char *p, const char **, int base));
1147c478bd9Sstevel@tonic-gate extern void printf P((const char *, ...));
1157c478bd9Sstevel@tonic-gate extern int sprintf P((char *, const char *, ...));
1167c478bd9Sstevel@tonic-gate extern int inet_aton P((char *p, in_addr *i));
1177c478bd9Sstevel@tonic-gate extern void putchar P((int));
1187c478bd9Sstevel@tonic-gate extern int getchar P((void));
1197c478bd9Sstevel@tonic-gate extern int iskey P((void));
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate extern void grub_printf(const char *, ...);
1227c478bd9Sstevel@tonic-gate extern char config_file[128];
1237c478bd9Sstevel@tonic-gate extern void etherboot_printf(const char *,  ...);
1247c478bd9Sstevel@tonic-gate extern int etherboot_sprintf(char *, const char *, ...);
1257c478bd9Sstevel@tonic-gate extern int getdec(char **s);
1267c478bd9Sstevel@tonic-gate extern void cleanup_net(void);
1277c478bd9Sstevel@tonic-gate extern void print_network_configuration (void);
1287c478bd9Sstevel@tonic-gate extern int ifconfig (char *, char *, char *, char *);
1297c478bd9Sstevel@tonic-gate extern struct arptable_t arptable[MAX_ARP];
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate #undef printf
1327c478bd9Sstevel@tonic-gate #undef sprintf
1337c478bd9Sstevel@tonic-gate #define printf etherboot_printf
1347c478bd9Sstevel@tonic-gate #define sprintf etherboot_sprintf
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate #ifdef DEBUG
1377c478bd9Sstevel@tonic-gate #define EnterFunction(func) printf("Enter: " func "\n");
1387c478bd9Sstevel@tonic-gate #define LeaveFunction(func) printf("Leave: " func "\n");
1397c478bd9Sstevel@tonic-gate #else
1407c478bd9Sstevel@tonic-gate #define EnterFunction(func)
1417c478bd9Sstevel@tonic-gate #define LeaveFunction(func)
1427c478bd9Sstevel@tonic-gate #endif
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate  * Some codes from etherboot use a level in DEBUG. Define it to be
1467c478bd9Sstevel@tonic-gate  * zero means no debug info output, that will make them silence in
1477c478bd9Sstevel@tonic-gate  * compiling. Up it as you want.
1487c478bd9Sstevel@tonic-gate  */
1497c478bd9Sstevel@tonic-gate #ifndef DEBUG
1507c478bd9Sstevel@tonic-gate #  define DEBUG 0
1517c478bd9Sstevel@tonic-gate #endif
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*#define RPC_DEBUG*/
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate extern char *hostname;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate extern int hostnamelen;
1587c478bd9Sstevel@tonic-gate /* Whether network is ready */
1597c478bd9Sstevel@tonic-gate extern int network_ready;
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /* User aborted in await_reply if not zero */
1627c478bd9Sstevel@tonic-gate extern int user_abort;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate extern int rarp(void);
1657c478bd9Sstevel@tonic-gate extern int grub_eth_probe(void);
1667c478bd9Sstevel@tonic-gate extern int bootp(void);
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate extern int dhcp(void);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate extern struct nic nic;
1717c478bd9Sstevel@tonic-gate #endif /* GRUB_H */
172