]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/boot/pc/sub.c
9boot: increase timeout, do less printing
[plan9front.git] / sys / src / boot / pc / sub.c
index 205cace13e94e458933c1efb14540a8740150d5d..ddeeba9cf09acc1deabed96fda5f6f2cb110e38a 100644 (file)
@@ -85,13 +85,19 @@ readn(void *f, void *data, int len)
 {
        uchar *p, *e;
 
+       putc(' ');
        p = data;
        e = p + len;
        while(p < e){
+               if(((ulong)p & 0xF000) == 0){
+                       putc('\b');
+                       putc(hex[((ulong)p>>16)&0xF]);
+               }
                if((len = read(f, p, e - p)) <= 0)
                        break;
                p += len;
        }
+       putc('\b');
        return p - (uchar*)data;
 }
 
@@ -110,7 +116,7 @@ readline(void *f, char buf[64])
                                putc(*p = getc());
                                if(*p == '\r')
                                        putc('\n');
-                               else if(*p == 0x08 && p > buf){
+                               else if(*p == '\b' && p > buf){
                                        p--;
                                        continue;
                                }
@@ -129,6 +135,18 @@ readline(void *f, char buf[64])
        return p - buf;
 }
 
+static int
+timeout(int ms)
+{
+       while(ms > 0){
+               if(gotc())
+                       return 1;
+               usleep(100000);
+               ms -= 100;
+       }
+       return 0;
+}
+
 #define BOOTLINE       ((char*)CONFADDR)
 #define BOOTLINELEN    64
 #define BOOTARGS       ((char*)(CONFADDR+BOOTLINELEN))
@@ -137,6 +155,7 @@ readline(void *f, char buf[64])
 char *confend;
 
 static void apmconf(int);
+static void e820conf(void);
 
 char*
 configure(void *f, char *path)
@@ -147,8 +166,12 @@ Clear:
        kern = 0;
        inblock = 0;
 
-       confend = (char*)BOOTARGS;
+       memset(BOOTLINE, 0, BOOTLINELEN);
+
+       confend = BOOTARGS;
        memset(confend, 0, BOOTARGSLEN);
+
+       e820conf();
 Loop:
        while((n = readline(f, line)) > 0){
                if(*line == 0 || strchr("#;=", *line))
@@ -176,17 +199,19 @@ Loop:
                print(line); print(crnl);
        }
        *confend = 0;
+
        if(f){
                close(f);
                f = 0;
+
+               if(kern && timeout(1000))
+                       goto Loop;
        }
+
        if(!kern){
                print("no bootfile\r\n");
                goto Loop;
        }
-       for(n=0; n<10000; n++)
-               if(gotc())
-                       goto Loop;
        if(p = strrchr(kern, '!'))
                kern = p+1;
 
@@ -194,24 +219,6 @@ Loop:
 }
 
 
-static ushort
-beswab(ushort s)
-{
-       uchar *p;
-
-       p = (uchar*)&s;
-       return (p[0]<<8) | p[1];
-}
-
-static ulong
-beswal(ulong l)
-{
-       uchar *p;
-
-       p = (uchar*)&l;
-       return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
-}
-
 static void
 hexfmt(char *s, int i, ulong a)
 {
@@ -284,50 +291,46 @@ e820conf(void)
        if((bx = e820(0, &e)) == 0)
                return;
 
+       s = confend;
        memmove(confend, "e820=", 5);
        confend += 5;
 
        do{
-               s = confend;
-               v = e.base;
-               addconfx("", 8, v>>32);
-               addconfx("", 8, v&0xffffffff);
-               v = e.base + e.len;
-               addconfx(" ", 8, v>>32);
-               addconfx("", 8, v&0xffffffff);
-
-               print(s);
-
-               switch(e.typ){
-               case 1:
-                       print(" ram");
-                       break;
-               case 2:
-                       print(" reserved");
-                       break;
-               case 3:
-                       print(" acpi reclaim");
-                       break;
-               case 4:
-                       print(" acpi nvs");
-                       break;
-               case 5:
-                       print(" bad");
-                       break;
-               default:
-                       print(" ???");
+               if(e.typ == 1 && (e.ext & 1) == 0 && e.len){
+                       v = e.base;
+                       addconfx("", 8, v>>32);
+                       addconfx("", 8, v&0xffffffff);
+                       v = e.base + e.len;
+                       addconfx(" ", 8, v>>32);
+                       addconfx("", 8, v&0xffffffff);
+                       *confend++ = ' ';
                }
-               print(crnl);
 
-               if(e.typ == 1 && (e.ext & 1) == 0)
-                       *confend++ = ' ';
-               else
-                       confend = s;
                memset(&e, 0, sizeof(e));
        } while(bx = e820(bx, &e));
 
-       *confend++ = '\n';
        *confend = 0;
+       print(s); print(crnl);
+
+       *confend++ = '\n';
+}
+
+static ushort
+beswab(ushort s)
+{
+       uchar *p;
+
+       p = (uchar*)&s;
+       return (p[0]<<8) | p[1];
+}
+
+static ulong
+beswal(ulong l)
+{
+       uchar *p;
+
+       p = (uchar*)&l;
+       return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3];
 }
 
 void a20(void);
@@ -339,9 +342,8 @@ bootkern(void *f)
        ulong n;
        Exec ex;
 
-       e820conf();
-
        a20();
+
        if(readn(f, &ex, sizeof(ex)) != sizeof(ex))
                return "bad header";
        if(beswal(ex.magic) != I_MAGIC)
@@ -350,16 +352,22 @@ bootkern(void *f)
        e = (uchar*)(beswal(ex.entry) & ~0xF0000000UL);
        t = e;
        n = beswal(ex.text);
+
        if(readn(f, t, n) != n)
                goto Error;
        d = (uchar*)PGROUND((ulong)t + n);
        n = beswal(ex.data);
+
        if(readn(f, d, n) != n)
                goto Error;
        close(f);
        unload();
-       memset(BOOTLINE, 0, BOOTLINELEN);
+
+       print("boot");
+       print(crnl);
+
        jump(e);
+
 Error:         
        return "i/o error";
 }