#include "mem.h"
void
-memset(void *p, int v, int n)
+memset(void *dst, int v, int n)
{
- uchar *d = p;
+ uchar *d = dst;
+
while(n > 0){
*d++ = v;
n--;
uchar *s = src;
if(d < s){
- while(n > 0){
+ while(n-- > 0)
*d++ = *s++;
- n--;
- }
- } if(d > s){
+ } else if(d > s){
s += n;
d += n;
- while(n > 0){
+ while(n-- > 0)
*--d = *--s;
- n--;
- }
}
}
uchar *d = dst;
uchar *s = src;
int r = 0;
- while((n > 0) && (r = (*d++ - *s++)) == 0)
- n--;
+
+ while(n-- > 0)
+ if(r = (*d++ - *s++))
+ break;
+
return r;
}
strlen(char *s)
{
char *p = s;
+
while(*p)
p++;
+
return p - s;
}
for(; *s; s++)
if(*s == c)
return s;
- return 0;
-}
-char*
-strrchr(char *s, int c)
-{
- char *r;
- r = 0;
- while(s = strchr(s, c))
- r = s++;
- return r;
+ return 0;
}
void
p += len;
}
putc('\b');
+
return p - (uchar*)data;
}
p--;
}while(p == buf);
*p = 0;
+
return p - buf;
}
static void apmconf(int);
static void e820conf(void);
+static int
+delconf(char *s)
+{
+ char *p, *e;
+
+ for(p = BOOTARGS; p < confend; p = e){
+ for(e = p+1; e < confend; e++){
+ if(*e == '\n'){
+ e++;
+ break;
+ }
+ }
+ if(!memcmp(p, s, strlen(s))){
+ memmove(p, e, confend - e);
+ confend -= e - p;
+ *confend = 0;
+ return 1;
+ }
+ }
+ return 0;
+}
+
char*
configure(void *f, char *path)
{
- char line[64], *kern, *p;
- int inblock, n;
+ char line[64], *kern, *s, *p;
+ int inblock, nowait, n;
+
Clear:
kern = 0;
+ nowait = 1;
inblock = 0;
memset(BOOTLINE, 0, BOOTLINELEN);
e820conf();
Loop:
- while((n = readline(f, line)) > 0){
+ while(readline(f, line) > 0){
if(*line == 0 || strchr("#;=", *line))
continue;
if(*line == '['){
inblock = memcmp("[common]", line, 8);
continue;
}
- if(!memcmp("clear", line, 6)){
- print("ok\r\n");
- goto Clear;
- }
- if(!memcmp("boot", line, 5))
+ if(!memcmp("boot", line, 5)){
+ nowait=1;
break;
- if(inblock || !strrchr(line, '='))
+ }
+ if(!memcmp("wait", line, 5)){
+ nowait=0;
+ continue;
+ }
+ if(!memcmp("clear", line, 5)){
+ if(line[5] == 0){
+ print("ok");
+ print(crnl);
+ goto Clear;
+ } else if(line[5] == ' ' && delconf(line+6)){
+ print("ok");
+ print(crnl);
+ }
continue;
- if(!memcmp("bootfile=", line, 9))
- memmove(kern = path, line+9, 1 + n-9);
- if(!memcmp("apm", line, 3) && line[4]=='='){
+ }
+ if(inblock || (p = strchr(line, '=')) == nil)
+ continue;
+ *p++ = 0;
+ delconf(line);
+ if(!memcmp("apm", line, 3)){
apmconf('0' - line[3]);
continue;
}
- memmove(confend, line, n); confend += n;
+ if(!memcmp("bootfile", line, 8))
+ memmove(kern = path, p, strlen(p)+1);
+
+ s = confend;
+ memmove(confend, line, n = strlen(line)); confend += n;
+ *confend++ = '=';
+ memmove(confend, p, n = strlen(p)); confend += n;
+ *confend = 0;
+
+ print(s); print(crnl);
+
*confend++ = '\n';
- print(line); print(crnl);
+ *confend = 0;
}
- *confend = 0;
if(f){
close(f);
f = 0;
- if(kern && timeout(1000))
+ if(kern && (nowait==0 || timeout(1000)))
goto Loop;
}
print("no bootfile\r\n");
goto Loop;
}
- if(p = strrchr(kern, '!'))
+ while(p = strchr(kern, '!'))
kern = p+1;
return kern;
print(s); print(crnl);
*confend++ = '\n';
+ *confend = 0;
}
ulong e820(ulong bx, void *p);
ulong bx;
char *s;
- memset(&e, 0, sizeof(e));
- if((bx = e820(0, &e)) == 0)
- return;
-
+ bx=0;
s = confend;
- memmove(confend, "e820=", 5);
- confend += 5;
do{
- if(e.typ == 1 && (e.ext & 1) == 0 && e.len){
+ bx = e820(bx, &e);
+ if(e.typ == 1 && e.len != 0 && (e.ext & 3) == 1){
+ if(confend == s){
+ /* single entry <= 1MB is useless */
+ if(bx == 0 && e.len <= 0x100000)
+ break;
+ memmove(confend, "e820=", 5);
+ confend += 5;
+ }
v = e.base;
addconfx("", 8, v>>32);
addconfx("", 8, v&0xffffffff);
- v = e.base + e.len;
+ v += e.len;
addconfx(" ", 8, v>>32);
addconfx("", 8, v&0xffffffff);
*confend++ = ' ';
}
+ } while(bx);
- memset(&e, 0, sizeof(e));
- } while(bx = e820(bx, &e));
+ if(confend == s)
+ return;
*confend = 0;
print(s); print(crnl);
*confend++ = '\n';
+ *confend = 0;
}
static ushort