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[64])
102 static char white[] = "\t ";
111 while((*p = getc()) == 0)
116 else if(*p == '\b' && p > buf){
120 }else if(read(f, p, 1) <= 0)
122 if(strchr("\r\n", *p) != nil)
124 if(p == buf && strchr(white, *p) != nil)
125 continue; /* whitespace on start of line */
132 continue; /* line full do not advance */
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)
164 getconf(char *s, char *buf)
170 for(p = BOOTARGS; p < confend; p = e+1){
171 for(e = p+1; e < confend; e++)
174 if(memcmp(p, s, n) == 0){
190 for(p = BOOTARGS; p < confend; p = e){
191 for(e = p+1; e < confend; e++){
197 if(memcmp(p, s, strlen(s)) == 0){
198 memmove(p, e, confend - e);
208 configure(void *f, char *path)
210 char line[64], *kern, *s, *p;
211 int inblock, nowait, n;
217 memset(BOOTLINE, 0, BOOTLINELEN);
220 memset(confend, 0, BOOTARGSLEN);
226 while(readline(f, line) > 0){
227 if(*line == 0 || strchr("#;=", *line) != nil)
230 inblock = memcmp("[common]", line, 8) != 0;
233 if(memcmp("boot", line, 5) == 0){
237 if(memcmp("wait", line, 5) == 0){
241 if(memcmp("show", line, 5) == 0){
245 if(memcmp("clear", line, 5) == 0){
249 } else if(line[5] == ' ' && delconf(line+6))
253 if(inblock != 0 || (p = strchr(line, '=')) == nil)
258 memmove(confend, line, n = strlen(line)); confend += n;
260 memmove(confend, p, n = strlen(p)); confend += n;
265 kern = getconf("bootfile=", path);
271 if(kern != nil && (nowait==0 || timeout(1000)))
276 print("no bootfile\n");
279 while((p = strchr(kern, '!')) != nil)
286 numfmt(char *s, ulong b, ulong i, ulong a)
311 hexfmt(char *s, int i, uvlong a)
314 s = numfmt(s, 16, i-8, a>>32);
317 return numfmt(s, 16, i, a);
321 decfmt(char *s, int i, ulong a)
323 return numfmt(s, 10, i, a);
329 uchar *p = (uchar*)&l;
330 return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
340 if(readn(f, &ex, sizeof(ex)) != sizeof(ex))
343 e = (uchar*)(beswal(ex.entry) & ~0xF0000000UL);
344 switch(beswal(ex.magic)){
346 if(readn(f, e, 8) != 8)
356 if(readn(f, t, n) != n)
359 d = (uchar*)PGROUND((uintptr)t);
362 if(readn(f, d, n) != n)
365 t = (uchar*)PGROUND((uintptr)d);
366 t += PGROUND(beswal(ex.bss));