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)
92 if(((ulong)p & 0xF000) == 0){
94 putc(hex[((ulong)p>>16)&0xF]);
96 if((len = read(f, p, e - p)) <= 0)
101 return p - (uchar*)data;
105 readline(void *f, char buf[64])
107 static char white[] = "\t ";
114 while(p < buf + 64-1){
119 else if(*p == '\b' && p > buf){
123 }else if(read(f, p, 1) <= 0)
125 if(p == buf && strchr(white, *p))
131 while(p > buf && strchr(white, p[-1]))
150 #define BOOTLINE ((char*)CONFADDR)
151 #define BOOTLINELEN 64
152 #define BOOTARGS ((char*)(CONFADDR+BOOTLINELEN))
153 #define BOOTARGSLEN (4096-0x200-BOOTLINELEN)
157 static void apmconf(int);
158 static void e820conf(void);
161 configure(void *f, char *path)
163 char line[64], *kern, *p;
169 memset(BOOTLINE, 0, BOOTLINELEN);
172 memset(confend, 0, BOOTARGSLEN);
174 while((n = readline(f, line)) > 0){
175 if(*line == 0 || strchr("#;=", *line))
178 inblock = memcmp("[common]", line, 8);
181 if(!memcmp("clear", line, 6)){
185 if(!memcmp("boot", line, 5))
187 if(inblock || !strrchr(line, '='))
189 if(!memcmp("bootfile=", line, 9))
190 memmove(kern = path, line+9, 1 + n-9);
191 if(!memcmp("apm", line, 3) && line[4]=='='){
192 apmconf('0' - line[3]);
195 memmove(confend, line, n); confend += n;
197 print(line); print(crnl);
206 if(kern && timeout(500))
211 print("no bootfile\r\n");
214 if(p = strrchr(kern, '!'))
227 return (p[0]<<8) | p[1];
236 return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
240 hexfmt(char *s, int i, ulong a)
251 addconfx(char *s, int w, ulong v)
256 memmove(confend, s, n);
257 hexfmt(confend+n, w, v);
270 a = (uchar*)CONFADDR;
274 if(memcmp(a, "APM", 4))
279 addconfx("apm", 1, id);
280 addconfx("=ax=", 4, *((ushort*)(a+4)));
281 addconfx(" ebx=", 8, *((ulong*)(a+12)));
282 addconfx(" cx=", 4, *((ushort*)(a+6)));
283 addconfx(" dx=", 4, *((ushort*)(a+8)));
284 addconfx(" di=", 4, *((ushort*)(a+10)));
285 addconfx(" esi=", 8, *((ulong*)(a+16)));
287 print(s); print(crnl);
292 ulong e820(ulong bx, void *p);
307 memset(&e, 0, sizeof(e));
308 if((bx = e820(0, &e)) == 0)
312 memmove(confend, "e820=", 5);
316 if(e.typ == 1 && (e.ext & 1) == 0 && e.len){
318 addconfx("", 8, v>>32);
319 addconfx("", 8, v&0xffffffff);
321 addconfx(" ", 8, v>>32);
322 addconfx("", 8, v&0xffffffff);
326 memset(&e, 0, sizeof(e));
327 } while(bx = e820(bx, &e));
330 print(s); print(crnl);
349 if(readn(f, &ex, sizeof(ex)) != sizeof(ex))
351 if(beswal(ex.magic) != I_MAGIC)
354 e = (uchar*)(beswal(ex.entry) & ~0xF0000000UL);
358 if(readn(f, t, n) != n)
360 d = (uchar*)PGROUND((ulong)t + n);
363 if(readn(f, d, n) != n)