25 readn(void *f, void *data, int len)
33 if(((ulong)p & 0xF000) == 0){
35 putc(hex[((ulong)p>>16)&0xF]);
37 if((len = read(f, p, e - p)) <= 0)
43 return p - (uchar*)data;
47 memmove(void *dst, void *src, int n)
64 memcmp(void *src, void *dst, int n)
91 strchr(char *s, int c)
101 memset(void *dst, int v, int n)
117 if(c == 0 && uart != -1)
123 readline(void *f, char *buf)
125 static char white[] = "\t ";
134 while((*p = getc()) == 0)
136 if(p == buf && (*p == '\b' || strchr(white, *p) != nil))
147 }else if(read(f, p, 1) <= 0)
149 if(strchr("\r\n", *p) != nil)
151 if(p == buf && strchr(white, *p) != nil)
152 continue; /* whitespace on start of line */
155 while(p > buf && strchr(white, p[-1]))
175 #define BOOTLINE ((char*)CONFADDR)
176 #define BOOTLINELEN 64
177 #define BOOTARGS ((char*)(CONFADDR+BOOTLINELEN))
178 #define BOOTARGSLEN (4096-0x200-BOOTLINELEN)
182 static void apmconf(int);
183 static void e820conf(void);
184 static void ramdiskconf(int);
185 static void uartconf(char*);
188 getconf(char *s, char *buf)
194 for(p = BOOTARGS; p < confend; p = e+1){
195 for(e = p+1; e < confend; e++)
198 if(memcmp(p, s, n) == 0){
214 for(p = BOOTARGS; p < confend; p = e){
215 for(e = p+1; e < confend; e++){
221 if(memcmp(p, s, strlen(s)) == 0){
222 memmove(p, e, confend - e);
232 configure(void *f, char *path)
234 char *line, *kern, *s, *p;
235 int inblock, nowait, n;
241 memset(BOOTLINE, 0, BOOTLINELEN);
244 memset(confend, 0, BOOTARGSLEN);
252 while(readline(f, line = confend+1) > 0){
253 if(*line == 0 || strchr("#;=", *line) != nil)
256 inblock = memcmp("[common]", line, 8) != 0;
259 if(memcmp("boot", line, 5) == 0){
263 if(memcmp("wait", line, 5) == 0){
267 if(memcmp("show", line, 5) == 0){
271 if(memcmp("clear", line, 5) == 0){
275 } else if(line[5] == ' ' && delconf(line+6))
279 if(inblock != 0 || (p = strchr(line, '=')) == nil)
283 if(memcmp("apm", line, 3) == 0){
284 apmconf(line[3] - '0');
287 if(memcmp("console", line, 8) == 0)
291 memmove(confend, line, n = strlen(line)); confend += n;
293 memmove(confend, p, n = strlen(p)); confend += n;
298 kern = getconf("bootfile=", path);
304 if(kern != nil && (nowait==0 || timeout(1000)))
309 print("no bootfile\n");
312 while((p = strchr(kern, '!')) != nil)
320 hexfmt(char *s, int i, ulong a)
331 addconfx(char *s, int w, ulong v)
336 memmove(confend, s, n);
337 hexfmt(confend+n, w, v);
348 a = (uchar*)CONFADDR;
352 if(memcmp(a, "APM", 4) != 0)
357 addconfx("apm", 1, id);
358 addconfx("=ax=", 4, *((ushort*)(a+4)));
359 addconfx(" ebx=", 8, *((ulong*)(a+12)));
360 addconfx(" cx=", 4, *((ushort*)(a+6)));
361 addconfx(" dx=", 4, *((ushort*)(a+8)));
362 addconfx(" di=", 4, *((ushort*)(a+10)));
363 addconfx(" esi=", 8, *((ulong*)(a+16)));
389 if(e.len != 0 && (e.ext & 3) == 1){
391 /* single entry <= 1MB is useless */
392 if(bx == 0 && e.typ == 1 && e.len <= 0x100000)
394 memmove(confend, "*e820=", 6);
397 addconfx("", 1, e.typ);
399 addconfx(" 0x", 8, v>>32);
400 addconfx("", 8, v&0xffffffff);
402 addconfx(" 0x", 8, v>>32);
403 addconfx("", 8, v&0xffffffff);
418 checksum(void *v, int n)
439 char oem_table_id[8];
441 char asl_compiler_id[4];
442 u32int asl_compiler_revision;
463 #define BDA ((uchar*)0x400)
464 mbft = (void*)((((BDA[0x14]<<8) | BDA[0x13])<<10) - 1024);
465 for(; (ulong)&mbft->sector_shift < 0xA0000; mbft = (void*)((ulong)mbft + 16)){
466 if(memcmp("mBFT", mbft, 4) == 0
467 && mbft->len < 1024 && (uchar*)mbft + mbft->len > &mbft->sector_shift
468 && checksum(mbft, mbft->len) == 0)
473 shift = mbft->sector_shift;
478 addconfx("ramdisk", 1, id);
479 addconfx("=0x", 8, mbft->diskbuf);
480 addconfx(" 0x", 8, mbft->disksize<<shift);
481 addconfx(" 0x", 8, 1UL<<shift);
492 if(*s >= '0' && *s <= '3'){
494 uartinit(uart, (7<<5) | 3); /* b9660 l8 s1 */
502 uchar *p = (uchar*)&l;
503 return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
514 print("a20 enable failed\n");
516 if(readn(f, &ex, sizeof(ex)) != sizeof(ex))
519 e = (uchar*)(beswal(ex.entry) & ~0xF0000000UL);
520 switch(beswal(ex.magic)){
522 if(readn(f, e, 8) != 8)
532 if(readn(f, t, n) != n)
535 d = (uchar*)PGROUND((ulong)t);
538 if(readn(f, d, n) != n)
541 t = (uchar*)PGROUND((ulong)d);
542 t += PGROUND(beswal(ex.bss));