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)
91 if((len = read(f, p, e - p)) <= 0)
95 return p - (uchar*)data;
99 readline(void *f, char buf[64])
101 static char white[] = "\t ";
108 while(p < buf + 64-1){
113 else if(*p == 0x08 && p > buf){
117 }else if(read(f, p, 1) <= 0)
119 if(p == buf && strchr(white, *p))
125 while(p > buf && strchr(white, p[-1]))
132 #define BOOTLINE ((char*)CONFADDR)
133 #define BOOTLINELEN 64
134 #define BOOTARGS ((char*)(CONFADDR+BOOTLINELEN))
135 #define BOOTARGSLEN (4096-0x200-BOOTLINELEN)
139 static void apmconf(int);
142 configure(void *f, char *path)
144 char line[64], *kern, *p;
150 confend = (char*)BOOTARGS;
151 memset(confend, 0, BOOTARGSLEN);
153 while((n = readline(f, line)) > 0){
154 if(*line == 0 || strchr("#;=", *line))
157 inblock = memcmp("[common]", line, 8);
160 if(!memcmp("clear", line, 6)){
164 if(!memcmp("boot", line, 5))
166 if(inblock || !strrchr(line, '='))
168 if(!memcmp("bootfile=", line, 9))
169 memmove(kern = path, line+9, 1 + n-9);
170 if(!memcmp("apm", line, 3) && line[4]=='='){
171 apmconf('0' - line[3]);
174 memmove(confend, line, n); confend += n;
176 print(line); print(crnl);
184 print("no bootfile\r\n");
187 for(n=0; n<10000; n++)
190 if(p = strrchr(kern, '!'))
203 return (p[0]<<8) | p[1];
212 return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
216 hexfmt(char *s, int i, ulong a)
227 addconfx(char *s, int w, ulong v)
232 memmove(confend, s, n);
233 hexfmt(confend+n, w, v);
244 a = (uchar*)CONFADDR;
248 if(memcmp(a, "APM", 4))
253 addconfx("apm", 1, id);
254 addconfx("=ax=", 4, *((ushort*)(a+4)));
255 addconfx(" ebx=", 8, *((ulong*)(a+12)));
256 addconfx(" cx=", 4, *((ushort*)(a+6)));
257 addconfx(" dx=", 4, *((ushort*)(a+8)));
258 addconfx(" di=", 4, *((ushort*)(a+10)));
259 addconfx(" esi=", 8, *((ulong*)(a+16)));
261 print(s); print(crnl);
274 if(readn(f, &ex, sizeof(ex)) != sizeof(ex))
276 if(beswal(ex.magic) != I_MAGIC)
279 e = (uchar*)(beswal(ex.entry) & ~0xF0000000UL);
282 if(readn(f, t, n) != n)
284 d = (uchar*)PGROUND((ulong)t + n);
286 if(readn(f, d, n) != n)
290 memset(BOOTLINE, 0, BOOTLINELEN);