You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #ifndef ETHERBOOT_H
  2. #define ETHERBOOT_H
  3. /*
  4. * Standard includes that we always want
  5. *
  6. */
  7. #include "compiler.h"
  8. #include "stddef.h"
  9. #include "stdint.h"
  10. /*
  11. * IMPORTANT!!!!!!!!!!!!!!
  12. *
  13. * Everything below this point is cruft left over from older versions
  14. * of Etherboot. Do not add *anything* below this point. Things are
  15. * gradually being moved to individual header files.
  16. *
  17. */
  18. #include <stdarg.h>
  19. #include "osdep.h"
  20. #ifndef BOOT_FIRST
  21. #define BOOT_FIRST BOOT_NIC
  22. #endif
  23. #ifndef BOOT_SECOND
  24. #define BOOT_SECOND BOOT_NOTHING
  25. #endif
  26. #ifndef BOOT_THIRD
  27. #define BOOT_THIRD BOOT_NOTHING
  28. #endif
  29. #define DEFAULT_BOOT_ORDER ( \
  30. (BOOT_FIRST << (0*BOOT_BITS)) | \
  31. (BOOT_SECOND << (1*BOOT_BITS)) | \
  32. (BOOT_THIRD << (2*BOOT_BITS)) | \
  33. (BOOT_NOTHING << (3*BOOT_BITS)) | \
  34. 0)
  35. #ifdef BOOT_INDEX
  36. #define DEFAULT_BOOT_INDEX BOOT_INDEX
  37. #else
  38. #define DEFAULT_BOOT_INDEX 0
  39. #endif
  40. #if !defined(TAGGED_IMAGE) && !defined(AOUT_IMAGE) && !defined(ELF_IMAGE) && !defined(ELF64_IMAGE) && !defined(COFF_IMAGE) && !defined(RAW_IMAGE)
  41. #define TAGGED_IMAGE /* choose at least one */
  42. #endif
  43. #define K_ESC '\033'
  44. #define K_EOF '\04' /* Ctrl-D */
  45. #define K_INTR '\03' /* Ctrl-C */
  46. /* Edit this to change the path to hostspecific kernel image
  47. kernel.<client_ip_address> in RARP boot */
  48. #ifndef DEFAULT_KERNELPATH
  49. #define DEFAULT_KERNELPATH "/tftpboot/kernel.%@"
  50. #endif
  51. #ifdef FREEBSD_PXEEMU
  52. #undef DEFAULT_BOOTFILE
  53. #ifndef PXENFSROOTPATH
  54. #define PXENFSROOTPATH ""
  55. #endif
  56. #define DEFAULT_BOOTFILE PXENFSROOTPATH "/boot/pxeboot"
  57. #endif
  58. #ifndef MAX_TFTP_RETRIES
  59. #define MAX_TFTP_RETRIES 20
  60. #endif
  61. #ifndef MAX_BOOTP_RETRIES
  62. #define MAX_BOOTP_RETRIES 20
  63. #endif
  64. #define MAX_BOOTP_EXTLEN (ETH_MAX_MTU-sizeof(struct bootpip_t))
  65. #ifndef MAX_ARP_RETRIES
  66. #define MAX_ARP_RETRIES 20
  67. #endif
  68. #ifndef MAX_RPC_RETRIES
  69. #define MAX_RPC_RETRIES 20
  70. #endif
  71. /* Link configuration time in tenths of a second */
  72. #ifndef VALID_LINK_TIMEOUT
  73. #define VALID_LINK_TIMEOUT 100 /* 10.0 seconds */
  74. #endif
  75. /* Inter-packet retry in ticks */
  76. #ifndef TIMEOUT
  77. #define TIMEOUT (10*TICKS_PER_SEC)
  78. #endif
  79. #ifndef BOOTP_TIMEOUT
  80. #define BOOTP_TIMEOUT (2*TICKS_PER_SEC)
  81. #endif
  82. /* Max interval between IGMP packets */
  83. #define IGMP_INTERVAL (10*TICKS_PER_SEC)
  84. #define IGMPv1_ROUTER_PRESENT_TIMEOUT (400*TICKS_PER_SEC)
  85. /* These settings have sense only if compiled with -DCONGESTED */
  86. /* total retransmission timeout in ticks */
  87. #define TFTP_TIMEOUT (30*TICKS_PER_SEC)
  88. /* packet retransmission timeout in ticks */
  89. #ifdef CONGESTED
  90. #define TFTP_REXMT (3*TICKS_PER_SEC)
  91. #else
  92. #define TFTP_REXMT TIMEOUT
  93. #endif
  94. #ifndef NULL
  95. #define NULL ((void *)0)
  96. #endif
  97. #include "if_ether.h"
  98. enum {
  99. ARP_CLIENT, ARP_SERVER, ARP_GATEWAY,
  100. ARP_NAMESERVER,
  101. #ifdef PXE_EXPORT
  102. ARP_PROXYDHCP,
  103. #endif
  104. MAX_ARP
  105. };
  106. #define RARP_REQUEST 3
  107. #define RARP_REPLY 4
  108. #include <gpxe/in.h>
  109. /* Helper macros used to identify when DHCP options are valid/invalid in/outside of encapsulation */
  110. #define NON_ENCAP_OPT in_encapsulated_options == 0 &&
  111. #ifdef ALLOW_ONLY_ENCAPSULATED
  112. #define ENCAP_OPT in_encapsulated_options == 1 &&
  113. #else
  114. #define ENCAP_OPT
  115. #endif
  116. #include "if_arp.h"
  117. #include "ip.h"
  118. #include "udp.h"
  119. #include "old_tcp.h"
  120. #include "bootp.h"
  121. #include "igmp.h"
  122. #include "nfs.h"
  123. #include "console.h"
  124. #include "stdlib.h"
  125. struct arptable_t {
  126. struct in_addr ipaddr;
  127. uint8_t node[6];
  128. } PACKED;
  129. #define KERNEL_BUF (bootp_data.bootp_reply.bp_file)
  130. #define FLOPPY_BOOT_LOCATION 0x7c00
  131. struct rom_info {
  132. unsigned short rom_segment;
  133. unsigned short rom_length;
  134. };
  135. extern inline int rom_address_ok(struct rom_info *rom, int assigned_rom_segment)
  136. {
  137. return (assigned_rom_segment < 0xC000
  138. || assigned_rom_segment == rom->rom_segment);
  139. }
  140. /* Define a type for passing info to a loaded program */
  141. struct ebinfo {
  142. uint8_t major, minor; /* Version */
  143. uint16_t flags; /* Bit flags */
  144. };
  145. /***************************************************************************
  146. External prototypes
  147. ***************************************************************************/
  148. /* main.c */
  149. struct Elf_Bhdr;
  150. extern int main();
  151. extern char as_main_program;
  152. /* nic.c */
  153. extern void rx_qdrain P((void));
  154. extern int ip_transmit P((int len, const void *buf));
  155. extern void build_ip_hdr P((unsigned long destip, int ttl, int protocol,
  156. int option_len, int len, const void *buf));
  157. extern void build_udp_hdr P((unsigned long destip,
  158. unsigned int srcsock, unsigned int destsock, int ttl,
  159. int len, const void *buf));
  160. extern int udp_transmit P((unsigned long destip, unsigned int srcsock,
  161. unsigned int destsock, int len, const void *buf));
  162. extern int tcp_transmit(unsigned long destip, unsigned int srcsock,
  163. unsigned int destsock, long send_seq, long recv_seq,
  164. int window, int flags, int len, const void *buf);
  165. int tcp_reset(struct iphdr *ip);
  166. typedef int (*reply_t)(int ival, void *ptr, unsigned short ptype, struct iphdr *ip, struct udphdr *udp, struct tcphdr *tcp);
  167. extern int await_reply P((reply_t reply, int ival, void *ptr, long timeout));
  168. extern int decode_rfc1533 P((unsigned char *, unsigned int, unsigned int, int));
  169. #define RAND_MAX 2147483647L
  170. extern uint16_t ipchksum P((const void *ip, unsigned long len));
  171. extern uint16_t add_ipchksums P((unsigned long offset, uint16_t sum, uint16_t new));
  172. extern int32_t random P((void));
  173. extern long rfc2131_sleep_interval P((long base, int exp));
  174. extern void cleanup P((void));
  175. /* osloader.c */
  176. /* Be careful with sector_t it is an unsigned long long on x86 */
  177. typedef uint64_t sector_t;
  178. typedef sector_t (*os_download_t)(unsigned char *data, unsigned int len, int eof);
  179. extern os_download_t probe_image(unsigned char *data, unsigned int len);
  180. extern int load_block P((unsigned char *, unsigned int, unsigned int, int ));
  181. /* misc.c */
  182. extern void twiddle P((void));
  183. extern void sleep P((int secs));
  184. extern void interruptible_sleep P((int secs));
  185. extern void poll_interruptions P((void));
  186. extern int strcasecmp P((const char *a, const char *b));
  187. extern char *substr P((const char *a, const char *b));
  188. extern unsigned long get_boot_order(unsigned long order, unsigned *index);
  189. extern void disk_init P((void));
  190. extern unsigned int pcbios_disk_read P((int drv,int c,int h,int s,char *buf));
  191. /* start32.S */
  192. struct os_entry_regs {
  193. /* Be careful changing this structure
  194. * as it is used by assembly language code.
  195. */
  196. uint32_t edi; /* 0 */
  197. uint32_t esi; /* 4 */
  198. uint32_t ebp; /* 8 */
  199. uint32_t esp; /* 12 */
  200. uint32_t ebx; /* 16 */
  201. uint32_t edx; /* 20 */
  202. uint32_t ecx; /* 24 */
  203. uint32_t eax; /* 28 */
  204. uint32_t saved_ebp; /* 32 */
  205. uint32_t saved_esi; /* 36 */
  206. uint32_t saved_edi; /* 40 */
  207. uint32_t saved_ebx; /* 44 */
  208. uint32_t saved_eip; /* 48 */
  209. uint32_t saved_esp; /* 52 */
  210. };
  211. struct regs {
  212. /* Be careful changing this structure
  213. * as it is used by assembly language code.
  214. */
  215. uint32_t edi; /* 0 */
  216. uint32_t esi; /* 4 */
  217. uint32_t ebp; /* 8 */
  218. uint32_t esp; /* 12 */
  219. uint32_t ebx; /* 16 */
  220. uint32_t edx; /* 20 */
  221. uint32_t ecx; /* 24 */
  222. uint32_t eax; /* 28 */
  223. };
  224. extern struct os_entry_regs os_regs;
  225. extern struct regs initial_regs;
  226. extern int xstart32(unsigned long entry_point, ...);
  227. extern int xstart_lm(unsigned long entry_point, unsigned long params);
  228. extern void xend32 P((void));
  229. struct Elf_Bhdr *prepare_boot_params(void *header);
  230. extern int elf_start(unsigned long machine, unsigned long entry, unsigned long params);
  231. extern unsigned long currticks P((void));
  232. extern void exit P((int status));
  233. /***************************************************************************
  234. External variables
  235. ***************************************************************************/
  236. /* main.c */
  237. extern struct rom_info rom;
  238. extern char *hostname;
  239. extern int hostnamelen;
  240. extern unsigned char *addparam;
  241. extern int addparamlen;
  242. extern jmp_buf restart_etherboot;
  243. extern int url_port;
  244. extern struct arptable_t arptable[MAX_ARP];
  245. #ifdef IMAGE_MENU
  246. extern int menutmo,menudefault;
  247. extern unsigned char *defparams;
  248. extern int defparams_max;
  249. #endif
  250. #ifdef MOTD
  251. extern unsigned char *motd[RFC1533_VENDOR_NUMOFMOTD];
  252. #endif
  253. extern struct bootpd_t bootp_data;
  254. #define BOOTP_DATA_ADDR (&bootp_data)
  255. extern unsigned char *end_of_rfc1533;
  256. #ifdef IMAGE_FREEBSD
  257. extern int freebsd_howto;
  258. #define FREEBSD_KERNEL_ENV_SIZE 256
  259. extern char freebsd_kernel_env[FREEBSD_KERNEL_ENV_SIZE];
  260. #endif
  261. /*
  262. * Local variables:
  263. * c-basic-offset: 8
  264. * End:
  265. */
  266. #endif /* ETHERBOOT_H */