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);
176 while((n = readline(f, line)) > 0){
177 if(*line == 0 || strchr("#;=", *line))
180 inblock = memcmp("[common]", line, 8);
183 if(!memcmp("clear", line, 6)){
187 if(!memcmp("boot", line, 5))
189 if(inblock || !strrchr(line, '='))
191 if(!memcmp("bootfile=", line, 9))
192 memmove(kern = path, line+9, 1 + n-9);
193 if(!memcmp("apm", line, 3) && line[4]=='='){
194 apmconf('0' - line[3]);
197 memmove(confend, line, n); confend += n;
199 print(line); print(crnl);
207 if(kern && timeout(1000))
212 print("no bootfile\r\n");
215 if(p = strrchr(kern, '!'))
223 hexfmt(char *s, int i, ulong a)
234 addconfx(char *s, int w, ulong v)
239 memmove(confend, s, n);
240 hexfmt(confend+n, w, v);
253 a = (uchar*)CONFADDR;
257 if(memcmp(a, "APM", 4))
262 addconfx("apm", 1, id);
263 addconfx("=ax=", 4, *((ushort*)(a+4)));
264 addconfx(" ebx=", 8, *((ulong*)(a+12)));
265 addconfx(" cx=", 4, *((ushort*)(a+6)));
266 addconfx(" dx=", 4, *((ushort*)(a+8)));
267 addconfx(" di=", 4, *((ushort*)(a+10)));
268 addconfx(" esi=", 8, *((ulong*)(a+16)));
270 print(s); print(crnl);
275 ulong e820(ulong bx, void *p);
290 memset(&e, 0, sizeof(e));
291 if((bx = e820(0, &e)) == 0)
295 memmove(confend, "e820=", 5);
299 if(e.typ == 1 && (e.ext & 1) == 0 && e.len){
301 addconfx("", 8, v>>32);
302 addconfx("", 8, v&0xffffffff);
304 addconfx(" ", 8, v>>32);
305 addconfx("", 8, v&0xffffffff);
309 memset(&e, 0, sizeof(e));
310 } while(bx = e820(bx, &e));
313 print(s); print(crnl);
324 return (p[0]<<8) | p[1];
333 return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
347 if(readn(f, &ex, sizeof(ex)) != sizeof(ex))
349 if(beswal(ex.magic) != I_MAGIC)
352 e = (uchar*)(beswal(ex.entry) & ~0xF0000000UL);
356 if(readn(f, t, n) != n)
358 d = (uchar*)PGROUND((ulong)t + n);
361 if(readn(f, d, n) != n)