6 char hex[] = "0123456789abcdef";
19 readn(void *f, void *data, int len)
26 if((len = read(f, p, e - p)) <= 0)
31 return p - (uchar*)data;
35 memmove(void *dst, void *src, int n)
52 memcmp(void *src, void *dst, int n)
79 strchr(char *s, int c)
89 memset(void *dst, int v, int n)
100 readline(void *f, char *buf)
102 static char white[] = "\t ";
111 while((*p = getc()) == 0)
113 if(p == buf && (*p == '\b' || strchr(white, *p) != nil))
124 }else if(read(f, p, 1) <= 0)
126 if(strchr("\r\n", *p) != nil)
128 if(p == buf && strchr(white, *p) != nil)
129 continue; /* whitespace on start of line */
132 while(p > buf && strchr(white, p[-1]))
152 #define BOOTLINE ((char*)CONFADDR)
153 #define BOOTLINELEN 64
154 #define BOOTARGS ((char*)(CONFADDR+BOOTLINELEN))
155 #define BOOTARGSLEN (4096-0x200-BOOTLINELEN)
160 getconf(char *s, char *buf)
166 for(p = BOOTARGS; p < confend; p = e+1){
167 for(e = p+1; e < confend; e++)
170 if(memcmp(p, s, n) == 0){
186 for(p = BOOTARGS; p < confend; p = e){
187 for(e = p+1; e < confend; e++){
193 if(memcmp(p, s, strlen(s)) == 0){
194 memmove(p, e, confend - e);
204 configure(void *f, char *path)
206 char *line, *kern, *s, *p;
207 int inblock, nowait, n;
213 memset(BOOTLINE, 0, BOOTLINELEN);
216 memset(confend, 0, BOOTARGSLEN);
222 while(readline(f, line = confend+1) > 0){
223 if(*line == 0 || strchr("#;=", *line) != nil)
226 inblock = memcmp("[common]", line, 8) != 0;
229 if(memcmp("boot", line, 5) == 0){
233 if(memcmp("wait", line, 5) == 0){
237 if(memcmp("show", line, 5) == 0){
241 if(memcmp("clear", line, 5) == 0){
245 } else if(line[5] == ' ' && delconf(line+6))
249 if(inblock != 0 || (p = strchr(line, '=')) == nil)
254 memmove(confend, line, n = strlen(line)); confend += n;
256 memmove(confend, p, n = strlen(p)); confend += n;
261 kern = getconf("bootfile=", path);
267 if(kern != nil && (nowait==0 || timeout(1000)))
272 print("no bootfile\n");
275 while((p = strchr(kern, '!')) != nil)
282 numfmt(char *s, ulong b, ulong i, ulong a)
307 hexfmt(char *s, int i, uvlong a)
310 s = numfmt(s, 16, i-8, a>>32);
313 return numfmt(s, 16, i, a);
317 decfmt(char *s, int i, ulong a)
319 return numfmt(s, 10, i, a);
325 uchar *p = (uchar*)&l;
326 return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
336 if(readn(f, &ex, sizeof(ex)) != sizeof(ex))
339 e = (uchar*)(beswal(ex.entry) & ~0xF0000000UL);
340 switch(beswal(ex.magic)){
342 if(readn(f, e, 8) != 8)
352 if(readn(f, t, n) != n)
355 d = (uchar*)PGROUND((uintptr)t);
358 if(readn(f, d, n) != n)
361 t = (uchar*)PGROUND((uintptr)d);
362 t += PGROUND(beswal(ex.bss));