1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
typedef struct List {
void *next;
} List;
typedef struct Alarm Alarm;
typedef struct Alarm {
List;
int busy;
long dt;
void (*f)(Alarm*);
void *arg;
} Alarm;
typedef struct Apminfo {
int haveinfo;
int ax;
int cx;
int dx;
int di;
int ebx;
int esi;
} Apminfo;
typedef struct Block Block;
struct Block {
Block* next;
uchar* rp; /* first unconsumed byte */
uchar* wp; /* first empty byte */
uchar* lim; /* 1 past the end of the buffer */
uchar* base; /* start of the buffer */
ulong flag;
};
#define BLEN(s) ((s)->wp - (s)->rp)
typedef struct IOQ IOQ;
typedef struct IOQ {
uchar buf[4096];
uchar *in;
uchar *out;
int state;
int (*getc)(IOQ*);
int (*putc)(IOQ*, int);
void *ptr;
};
enum {
Eaddrlen = 6,
/* next two exclude 4-byte ether CRC */
ETHERMINTU = 60, /* minimum transmit size */
ETHERMAXTU = 1514, /* maximum transmit size */
ETHERHDRSIZE = 14, /* size of an ethernet header */
MaxEther = 6,
};
typedef struct {
uchar d[Eaddrlen];
uchar s[Eaddrlen];
uchar type[2];
uchar data[1500];
uchar crc[4];
} Etherpkt;
extern uchar broadcast[Eaddrlen];
typedef struct Ureg Ureg;
#pragma incomplete Ureg
typedef struct Segdesc {
ulong d0;
ulong d1;
} Segdesc;
typedef struct Mach {
ulong ticks; /* of the clock since boot time */
void *alarm; /* alarms bound to this clock */
} Mach;
extern Mach *m;
#define I_MAGIC ((((4*11)+0)*11)+7)
typedef struct Exec Exec;
struct Exec
{
uchar magic[4]; /* magic number */
uchar text[4]; /* size of text segment */
uchar data[4]; /* size of initialized data */
uchar bss[4]; /* size of uninitialized data */
uchar syms[4]; /* size of symbol table */
uchar entry[4]; /* entry point */
uchar spsz[4]; /* size of sp/pc offset table */
uchar pcsz[4]; /* size of pc/line number table */
};
/*
* a parsed .ini line
*/
#define ISAOPTLEN 32
#define NISAOPT 8
typedef struct ISAConf {
char type[NAMELEN];
ulong port;
ulong irq;
ulong mem;
ulong size;
uchar ea[6];
int nopt;
char opt[NISAOPT][ISAOPTLEN];
} ISAConf;
typedef struct Pcidev Pcidev;
typedef struct PCMmap PCMmap;
typedef struct PCMslot PCMslot;
#define BOOTLINE ((char*)CONFADDR)
enum {
MB = (1024*1024),
};
#define ROUND(s, sz) (((s)+((sz)-1))&~((sz)-1))
typedef struct Type Type;
typedef struct Medium Medium;
typedef struct Boot Boot;
enum { /* type */
Tnil = 0x00,
Tfloppy = 0x01,
Tsd = 0x02,
Tether = 0x03,
Tcd = 0x04,
Tbios = 0x05,
Tany = -1,
};
enum { /* name and flag */
Fnone = 0x00,
Nfs = 0x00,
Ffs = (1<<Nfs),
Nboot = 0x01,
Fboot = (1<<Nboot),
Nbootp = 0x02,
Fbootp = (1<<Nbootp),
NName = 3,
Fany = Fbootp|Fboot|Ffs,
Fini = 0x10,
Fprobe = 0x80,
};
typedef struct Type {
int type;
int flag;
int (*init)(void);
void (*initdev)(int, char*);
void* (*getfspart)(int, char*, int); /* actually returns Dos* */
void (*addconf)(int);
int (*boot)(int, char*, Boot*);
void (*printdevs)(int);
char** parts;
char** inis;
int mask;
Medium* media;
} Type;
extern void (*etherdetach)(void);
extern void (*floppydetach)(void);
extern void (*sddetach)(void);
typedef struct Lock { /* for ilock, iunlock */
int locked;
int spl;
} Lock;
enum { /* returned by bootpass */
MORE, ENOUGH, FAIL
};
enum {
INITKERNEL,
READEXEC,
READ9TEXT,
READ9DATA,
READGZIP,
READEHDR,
READPHDR,
READEPAD,
READEDATA,
TRYBOOT,
INIT9LOAD,
READ9LOAD,
FAILED
};
struct Boot {
int state;
Exec exec;
char *bp; /* base ptr */
char *wp; /* write ptr */
char *ep; /* end ptr */
};
extern int debug;
extern int debugload;
extern Apminfo apm;
extern char *defaultpartition;
extern int iniread;
extern int pxe;
extern int vga;
extern int onlybios0;
extern int biosinited;
extern int biosload;
|