7 memset(void *dst, int v, int n)
18 memmove(void *dst, void *src, int n)
35 memcmp(void *src, void *dst, int n)
60 strchr(char *s, int c)
70 strrchr(char *s, int c)
74 while(s = strchr(s, c))
88 readn(void *f, void *data, int len)
96 if(((ulong)p & 0xF000) == 0){
98 putc(hex[((ulong)p>>16)&0xF]);
100 if((len = read(f, p, e - p)) <= 0)
106 return p - (uchar*)data;
110 readline(void *f, char buf[64])
112 static char white[] = "\t ";
119 while(p < buf + 64-1){
124 else if(*p == '\b' && p > buf){
128 }else if(read(f, p, 1) <= 0)
130 if(p == buf && strchr(white, *p))
136 while(p > buf && strchr(white, p[-1]))
156 #define BOOTLINE ((char*)CONFADDR)
157 #define BOOTLINELEN 64
158 #define BOOTARGS ((char*)(CONFADDR+BOOTLINELEN))
159 #define BOOTARGSLEN (4096-0x200-BOOTLINELEN)
163 static void apmconf(int);
164 static void e820conf(void);
171 for(p = BOOTARGS; p < confend; p = e){
172 for(e = p+1; e < confend; e++){
178 if(!memcmp(p, s, strlen(s))){
179 memmove(p, e, confend - e);
189 configure(void *f, char *path)
191 char line[64], *kern, *s, *p;
198 memset(BOOTLINE, 0, BOOTLINELEN);
201 memset(confend, 0, BOOTARGSLEN);
205 while(readline(f, line) > 0){
206 if(*line == 0 || strchr("#;=", *line))
209 inblock = memcmp("[common]", line, 8);
212 if(!memcmp("boot", line, 5))
214 if(!memcmp("clear", line, 5)){
219 } else if(line[5] == ' ' && delconf(line+6)){
225 if(inblock || (p = strchr(line, '=')) == nil)
229 if(!memcmp("apm", line, 3)){
230 apmconf('0' - line[3]);
233 if(!memcmp("bootfile", line, 8))
234 memmove(kern = path, p, strlen(p)+1);
237 memmove(confend, line, n = strlen(line)); confend += n;
239 memmove(confend, p, n = strlen(p)); confend += n;
242 print(s); print(crnl);
252 if(kern && timeout(1000))
257 print("no bootfile\r\n");
260 if(p = strrchr(kern, '!'))
268 hexfmt(char *s, int i, ulong a)
279 addconfx(char *s, int w, ulong v)
284 memmove(confend, s, n);
285 hexfmt(confend+n, w, v);
298 a = (uchar*)CONFADDR;
302 if(memcmp(a, "APM", 4))
307 addconfx("apm", 1, id);
308 addconfx("=ax=", 4, *((ushort*)(a+4)));
309 addconfx(" ebx=", 8, *((ulong*)(a+12)));
310 addconfx(" cx=", 4, *((ushort*)(a+6)));
311 addconfx(" dx=", 4, *((ushort*)(a+8)));
312 addconfx(" di=", 4, *((ushort*)(a+10)));
313 addconfx(" esi=", 8, *((ulong*)(a+16)));
315 print(s); print(crnl);
321 ulong e820(ulong bx, void *p);
336 memset(&e, 0, sizeof(e));
337 if((bx = e820(0, &e)) == 0)
341 memmove(confend, "e820=", 5);
345 if(e.typ == 1 && (e.ext & 1) == 0 && e.len){
347 addconfx("", 8, v>>32);
348 addconfx("", 8, v&0xffffffff);
350 addconfx(" ", 8, v>>32);
351 addconfx("", 8, v&0xffffffff);
355 memset(&e, 0, sizeof(e));
356 } while(bx = e820(bx, &e));
359 print(s); print(crnl);
371 return (p[0]<<8) | p[1];
380 return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
394 if(readn(f, &ex, sizeof(ex)) != sizeof(ex))
396 if(beswal(ex.magic) != I_MAGIC)
399 e = (uchar*)(beswal(ex.entry) & ~0xF0000000UL);
403 if(readn(f, t, n) != n)
405 d = (uchar*)PGROUND((ulong)t + n);
408 if(readn(f, d, n) != n)