6 char hex[] = "0123456789abcdef";
19 readn(void *f, void *data, int len)
27 if(((ulong)p & 0xF000) == 0){
29 putc(hex[((ulong)p>>16)&0xF]);
31 if((len = read(f, p, e - p)) <= 0)
37 return p - (uchar*)data;
41 memmove(void *dst, void *src, int n)
58 memcmp(void *src, void *dst, int n)
85 strchr(char *s, int c)
95 memset(void *dst, int v, int n)
106 readline(void *f, char buf[64])
108 static char white[] = "\t ";
117 while((*p = getc()) == 0)
122 else if(*p == '\b' && p > buf){
126 }else if(read(f, p, 1) <= 0)
128 if(strchr("\r\n", *p) != nil)
130 if(p == buf && strchr(white, *p) != nil)
131 continue; /* whitespace on start of line */
138 continue; /* line full do not advance */
142 while(p > buf && strchr(white, p[-1]))
162 #define BOOTLINE ((char*)CONFADDR)
163 #define BOOTLINELEN 64
164 #define BOOTARGS ((char*)(CONFADDR+BOOTLINELEN))
165 #define BOOTARGSLEN (4096-0x200-BOOTLINELEN)
170 getconf(char *s, char *buf)
176 for(p = BOOTARGS; p < confend; p = e+1){
177 for(e = p+1; e < confend; e++)
180 if(memcmp(p, s, n) == 0){
196 for(p = BOOTARGS; p < confend; p = e){
197 for(e = p+1; e < confend; e++){
203 if(memcmp(p, s, strlen(s)) == 0){
204 memmove(p, e, confend - e);
214 configure(void *f, char *path)
216 char line[64], *kern, *s, *p;
217 int inblock, nowait, n;
223 memset(BOOTLINE, 0, BOOTLINELEN);
226 memset(confend, 0, BOOTARGSLEN);
232 while(readline(f, line) > 0){
233 if(*line == 0 || strchr("#;=", *line) != nil)
236 inblock = memcmp("[common]", line, 8) != 0;
239 if(memcmp("boot", line, 5) == 0){
243 if(memcmp("wait", line, 5) == 0){
247 if(memcmp("show", line, 5) == 0){
251 if(memcmp("clear", line, 5) == 0){
255 } else if(line[5] == ' ' && delconf(line+6))
259 if(inblock != 0 || (p = strchr(line, '=')) == nil)
264 memmove(confend, line, n = strlen(line)); confend += n;
266 memmove(confend, p, n = strlen(p)); confend += n;
271 kern = getconf("bootfile=", path);
277 if(kern != nil && (nowait==0 || timeout(1000)))
282 print("no bootfile\n");
285 while((p = strchr(kern, '!')) != nil)
292 numfmt(char *s, ulong b, ulong i, ulong a)
317 hexfmt(char *s, int i, uvlong a)
320 s = numfmt(s, 16, i-8, a>>32);
323 return numfmt(s, 16, i, a);
327 decfmt(char *s, int i, ulong a)
329 return numfmt(s, 10, i, a);
335 uchar *p = (uchar*)&l;
336 return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
346 if(readn(f, &ex, sizeof(ex)) != sizeof(ex))
349 e = (uchar*)(beswal(ex.entry) & ~0xF0000000UL);
350 switch(beswal(ex.magic)){
352 if(readn(f, e, 8) != 8)
362 if(readn(f, t, n) != n)
365 d = (uchar*)PGROUND((ulong)t);
368 if(readn(f, d, n) != n)
371 t = (uchar*)PGROUND((ulong)d);
372 t += PGROUND(beswal(ex.bss));