dat.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. typedef struct List {
  10. void *next;
  11. } List;
  12. typedef struct Alarm Alarm;
  13. typedef struct Alarm {
  14. List;
  15. int busy;
  16. long dt;
  17. void (*f)(Alarm*);
  18. void *arg;
  19. } Alarm;
  20. typedef struct Apminfo {
  21. int haveinfo;
  22. int ax;
  23. int cx;
  24. int dx;
  25. int di;
  26. int ebx;
  27. int esi;
  28. } Apminfo;
  29. typedef struct Block Block;
  30. struct Block {
  31. Block* next;
  32. uchar* rp; /* first unconsumed byte */
  33. uchar* wp; /* first empty byte */
  34. uchar* lim; /* 1 past the end of the buffer */
  35. uchar* base; /* start of the buffer */
  36. uint32_t flag;
  37. };
  38. #define BLEN(s) ((s)->wp - (s)->rp)
  39. typedef struct IOQ IOQ;
  40. typedef struct IOQ {
  41. uchar buf[4096];
  42. uchar *in;
  43. uchar *out;
  44. int state;
  45. int (*getc)(IOQ*);
  46. int (*putc)(IOQ*, int);
  47. void *ptr;
  48. };
  49. enum {
  50. Eaddrlen = 6,
  51. /* next two exclude 4-byte ether CRC */
  52. ETHERMINTU = 60, /* minimum transmit size */
  53. ETHERMAXTU = 1514, /* maximum transmit size */
  54. ETHERHDRSIZE = 14, /* size of an ethernet header */
  55. MaxEther = 6,
  56. };
  57. typedef struct {
  58. uchar d[Eaddrlen];
  59. uchar s[Eaddrlen];
  60. uchar type[2];
  61. uchar data[1500];
  62. uchar crc[4];
  63. } Etherpkt;
  64. extern uchar broadcast[Eaddrlen];
  65. typedef struct Ureg Ureg;
  66. typedef struct Segdesc {
  67. uint32_t d0;
  68. uint32_t d1;
  69. } Segdesc;
  70. typedef struct Mach {
  71. int machno; /* physical id of processor (KNOWN TO ASSEMBLY) */
  72. uint32_t splpc; /* pc of last caller to splhi */
  73. uint32_t* pdb; /* page directory base for this processor (va) */
  74. Segdesc *gdt; /* gdt for this processor */
  75. uint32_t ticks; /* of the clock since boot time */
  76. void *alarm; /* alarms bound to this clock */
  77. } Mach;
  78. extern Mach *m;
  79. #define I_MAGIC ((((4*11)+0)*11)+7) /* intel 386 */
  80. #define S_MAGIC (0x8000|((((4*26)+0)*26)+7)) /* amd64 */
  81. typedef struct Exec Exec;
  82. struct Exec
  83. {
  84. uchar magic[4]; /* magic number */
  85. uchar text[4]; /* size of text segment */
  86. uchar data[4]; /* size of initialized data */
  87. uchar bss[4]; /* size of uninitialized data */
  88. uchar syms[4]; /* size of symbol table */
  89. uchar entry[4]; /* entry point */
  90. uchar spsz[4]; /* size of sp/pc offset table */
  91. uchar pcsz[4]; /* size of pc/line number table */
  92. };
  93. /*
  94. * a parsed .ini line
  95. */
  96. #define ISAOPTLEN 32
  97. #define NISAOPT 8
  98. typedef struct ISAConf {
  99. char* type;
  100. uint32_t port;
  101. uint32_t irq;
  102. uint32_t dma;
  103. uint32_t mem;
  104. uint32_t size;
  105. uint32_t freq;
  106. uchar ea[6];
  107. int nopt;
  108. char opt[NISAOPT][ISAOPTLEN];
  109. } ISAConf;
  110. typedef struct Pcidev Pcidev;
  111. typedef struct PCMmap PCMmap;
  112. typedef struct PCMslot PCMslot;
  113. #define BOOTLINE ((char*)CONFADDR)
  114. #define ROUND(s, sz) (((s)+((sz)-1))&~((sz)-1))
  115. typedef struct Type Type;
  116. typedef struct Medium Medium;
  117. typedef struct Boot Boot;
  118. enum { /* type */
  119. Tnil = 0x00,
  120. Tfloppy = 0x01,
  121. Tsd = 0x02,
  122. Tether = 0x03,
  123. Tcd = 0x04,
  124. Tany = -1,
  125. };
  126. enum { /* name and flag */
  127. Fnone = 0x00,
  128. Nfs = 0x00,
  129. Ffs = (1<<Nfs),
  130. Nboot = 0x01,
  131. Fboot = (1<<Nboot),
  132. Nbootp = 0x02,
  133. Fbootp = (1<<Nbootp),
  134. NName = 3,
  135. Fany = Fbootp|Fboot|Ffs,
  136. Fini = 0x10,
  137. Fprobe = 0x80,
  138. };
  139. typedef struct Type {
  140. int type;
  141. int flag;
  142. int (*init)(void);
  143. void (*initdev)(int, char*);
  144. void* (*getfspart)(int, char*, int); /* actually returns Dos* */
  145. void (*addconf)(int);
  146. int (*boot)(int, char*, Boot*);
  147. void (*printdevs)(int);
  148. char** parts;
  149. char** inis;
  150. int mask;
  151. Medium* media;
  152. } Type;
  153. extern void (*etherdetach)(void);
  154. extern void (*floppydetach)(void);
  155. extern void (*sddetach)(void);
  156. typedef struct Lock { /* for ilock, iunlock */
  157. int locked;
  158. int spl;
  159. } Lock;
  160. enum { /* returned by bootpass */
  161. MORE, ENOUGH, FAIL
  162. };
  163. enum {
  164. INITKERNEL,
  165. READEXEC,
  166. READ9TEXT,
  167. READ9DATA,
  168. READGZIP,
  169. READEHDR,
  170. READPHDR,
  171. READEPAD,
  172. READEDATA,
  173. TRYBOOT,
  174. TRYEBOOT,
  175. INIT9LOAD,
  176. READ9LOAD,
  177. FAILED
  178. };
  179. typedef struct {
  180. Exec;
  181. uvlong uvl[1];
  182. } Hdr;
  183. struct Boot {
  184. int state;
  185. Hdr hdr;
  186. char *bp; /* base ptr */
  187. char *wp; /* write ptr */
  188. char *ep; /* end ptr */
  189. };
  190. /*
  191. * Multiboot grot.
  192. */
  193. typedef struct Mbi Mbi;
  194. struct Mbi {
  195. u32int flags;
  196. u32int memlower;
  197. u32int memupper;
  198. u32int bootdevice;
  199. u32int cmdline;
  200. u32int modscount;
  201. u32int modsaddr;
  202. u32int syms[4];
  203. u32int mmaplength;
  204. u32int mmapaddr;
  205. u32int driveslength;
  206. u32int drivesaddr;
  207. u32int configtable;
  208. u32int bootloadername;
  209. u32int apmtable;
  210. u32int vbe[6];
  211. };
  212. enum { /* flags */
  213. Fmem = 0x00000001, /* mem* valid */
  214. Fbootdevice = 0x00000002, /* bootdevice valid */
  215. Fcmdline = 0x00000004, /* cmdline valid */
  216. Fmods = 0x00000008, /* mod* valid */
  217. Fsyms = 0x00000010, /* syms[] has a.out info */
  218. Felf = 0x00000020, /* syms[] has ELF info */
  219. Fmmap = 0x00000040, /* mmap* valid */
  220. Fdrives = 0x00000080, /* drives* valid */
  221. Fconfigtable = 0x00000100, /* configtable* valid */
  222. Fbootloadername = 0x00000200, /* bootloadername* valid */
  223. Fapmtable = 0x00000400, /* apmtable* valid */
  224. Fvbe = 0x00000800, /* vbe[] valid */
  225. };
  226. typedef struct Mod Mod;
  227. struct Mod {
  228. u32int modstart;
  229. u32int modend;
  230. u32int string;
  231. u32int reserved;
  232. };
  233. typedef struct MMap MMap;
  234. struct MMap {
  235. u32int size;
  236. u32int base[2];
  237. u32int length[2];
  238. u32int type;
  239. };
  240. extern int debug;
  241. extern Apminfo apm;
  242. extern int vflag;
  243. extern u32int memstart;
  244. extern MMap mmap[20];
  245. extern int nmmap;
  246. extern char *defaultpartition;
  247. extern int iniread;
  248. extern int pxe;
  249. /*
  250. * Compatibility hacks.
  251. */
  252. typedef struct QLock {
  253. int r;
  254. } QLock;
  255. #define qlock(i) {/* nothing to do */;}
  256. #define qunlock(i) {/* nothing to do */;}
  257. #define READSTR 0
  258. #define waserror() (0)
  259. #define nexterror()
  260. #define poperror()
  261. #define mallocalign(n, a, o, s) ialloc((n), (a))
  262. #define iprint print
  263. #define readstr(offset, a, n, p) 0; USED(offset, a, n, p)
  264. #define wmb() coherence()
  265. #define addethercard(a, b)
  266. typedef struct Netif Netif;
  267. typedef struct Ether Ether;
  268. struct Netif {
  269. /* Ether */
  270. long (*ifstat)(Ether*, void*, long, uint32_t);
  271. long (*ctl)(Ether*, void*, long);
  272. /* Netif */
  273. int mbps;
  274. void *arg;
  275. void (*promiscuous)(void*, int);
  276. void (*multicast)(void*, uchar*, int);
  277. };