7 memset(void *p, int v, int n)
17 memmove(void *dst, void *src, int n)
38 memcmp(void *src, void *dst, int n)
43 while((n > 0) && (r = (*d++ - *s++)) == 0)
58 strchr(char *s, int c)
67 strrchr(char *s, int c)
71 while(s = strchr(s, c))
84 readn(void *f, void *data, int len)
91 if((len = read(f, p, e - p)) <= 0)
95 return p - (uchar*)data;
99 readline(void *f, char buf[64])
101 static char white[] = "\t ";
108 while(p < buf + 64-1){
113 else if(*p == 0x08 && p > buf){
117 }else if(read(f, p, 1) <= 0)
119 if(p == buf && strchr(white, *p))
125 while(p > buf && strchr(white, p[-1]))
144 #define BOOTLINE ((char*)CONFADDR)
145 #define BOOTLINELEN 64
146 #define BOOTARGS ((char*)(CONFADDR+BOOTLINELEN))
147 #define BOOTARGSLEN (4096-0x200-BOOTLINELEN)
151 static void apmconf(int);
154 configure(void *f, char *path)
156 char line[64], *kern, *p;
162 confend = (char*)BOOTARGS;
163 memset(confend, 0, BOOTARGSLEN);
165 while((n = readline(f, line)) > 0){
166 if(*line == 0 || strchr("#;=", *line))
169 inblock = memcmp("[common]", line, 8);
172 if(!memcmp("clear", line, 6)){
176 if(!memcmp("boot", line, 5))
178 if(inblock || !strrchr(line, '='))
180 if(!memcmp("bootfile=", line, 9))
181 memmove(kern = path, line+9, 1 + n-9);
182 if(!memcmp("apm", line, 3) && line[4]=='='){
183 apmconf('0' - line[3]);
186 memmove(confend, line, n); confend += n;
188 print(line); print(crnl);
196 if(kern && timeout(500))
201 print("no bootfile\r\n");
204 if(p = strrchr(kern, '!'))
217 return (p[0]<<8) | p[1];
226 return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
230 hexfmt(char *s, int i, ulong a)
241 addconfx(char *s, int w, ulong v)
246 memmove(confend, s, n);
247 hexfmt(confend+n, w, v);
260 a = (uchar*)CONFADDR;
264 if(memcmp(a, "APM", 4))
269 addconfx("apm", 1, id);
270 addconfx("=ax=", 4, *((ushort*)(a+4)));
271 addconfx(" ebx=", 8, *((ulong*)(a+12)));
272 addconfx(" cx=", 4, *((ushort*)(a+6)));
273 addconfx(" dx=", 4, *((ushort*)(a+8)));
274 addconfx(" di=", 4, *((ushort*)(a+10)));
275 addconfx(" esi=", 8, *((ulong*)(a+16)));
277 print(s); print(crnl);
282 ulong e820(ulong bx, void *p);
297 memset(&e, 0, sizeof(e));
298 if((bx = e820(0, &e)) == 0)
302 memmove(confend, "e820=", 5);
306 if(e.typ == 1 && (e.ext & 1) == 0 && e.len){
308 addconfx("", 8, v>>32);
309 addconfx("", 8, v&0xffffffff);
311 addconfx(" ", 8, v>>32);
312 addconfx("", 8, v&0xffffffff);
316 memset(&e, 0, sizeof(e));
317 } while(bx = e820(bx, &e));
320 print(s); print(crnl);
337 if(readn(f, &ex, sizeof(ex)) != sizeof(ex))
339 if(beswal(ex.magic) != I_MAGIC)
342 e = (uchar*)(beswal(ex.entry) & ~0xF0000000UL);
345 if(readn(f, t, n) != n)
347 d = (uchar*)PGROUND((ulong)t + n);
349 if(readn(f, d, n) != n)
353 memset(BOOTLINE, 0, BOOTLINELEN);