summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1995-12-26 20:27:57 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1995-12-26 20:27:57 +0000
commitab136f3b0281b670e205bb6668de0216921c1ac4 (patch)
tree57fc515e3425b93be3b43b2d72f919a6aa950146
parent1761d011b4a83a9818c0a207dae66dbcbf764e69 (diff)
from perry:
fix my own pr 1762, in which it was noted that boot2 used a busy loop to time out the boot prompt. Now uses a usleep() routine that calls the BIOS and the functionality is separate from gets(). Timeout is #defined to 5 seconds. Also did some minor cleanup in preparation to prototype/ANSIfy everything. (problem was originally reported by deraadt a number of years ago)
-rw-r--r--sys/arch/i386/boot/bios.S43
-rw-r--r--sys/arch/i386/boot/boot.c27
-rw-r--r--sys/arch/i386/boot/io.c93
-rw-r--r--sys/arch/i386/boot/version.c9
4 files changed, 135 insertions, 37 deletions
diff --git a/sys/arch/i386/boot/bios.S b/sys/arch/i386/boot/bios.S
index 21d07287aed..39cdb2fc382 100644
--- a/sys/arch/i386/boot/bios.S
+++ b/sys/arch/i386/boot/bios.S
@@ -1,4 +1,4 @@
-/* $NetBSD: bios.S,v 1.11 1995/03/12 00:10:56 mycroft Exp $ */
+/* $NetBSD: bios.S,v 1.12 1995/12/23 17:21:25 perry Exp $ */
/*
* Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
@@ -331,3 +331,44 @@ xdone:
popl %ebx
popl %ebp
ret
+
+/*
+# BIOS call "INT 15H Function 86H" to sleep for a set number of microseconds
+# Call with %ah = 0x86
+# %cx = time interval (high)
+# %dx = time interval (low)
+# Return:
+# If error
+# CF = set
+# else
+# CF = clear
+*/
+ENTRY(usleep)
+ pushl %ebp
+ movl %esp, %ebp
+ pushl %ebx
+ pushl %ecx # not clear if I need this.
+ pushl %edx # ...or this, but they are harmless. (perry)
+
+ movw 8(%ebp), %dx
+ movw 10(%ebp), %cx
+
+ call _C_LABEL(prot_to_real)
+
+ movb $0x86, %ah
+ int $0x15
+ setnc %ah
+
+ movb %ah, %bl # real_to_prot uses %eax
+
+ data32
+ call _C_LABEL(real_to_prot)
+
+ xorl %eax, %eax
+ movb %bl, %al
+
+ popl %edx
+ popl %ecx
+ popl %ebx
+ popl %ebp
+ ret
diff --git a/sys/arch/i386/boot/boot.c b/sys/arch/i386/boot/boot.c
index a3350b21001..ff5de40769a 100644
--- a/sys/arch/i386/boot/boot.c
+++ b/sys/arch/i386/boot/boot.c
@@ -1,4 +1,4 @@
-/* $NetBSD: boot.c,v 1.28 1995/03/12 00:10:57 mycroft Exp $ */
+/* $NetBSD: boot.c,v 1.29 1995/12/23 17:21:27 perry Exp $ */
/*
* Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
@@ -63,22 +63,29 @@ int cflag;
#endif
char *name;
char *names[] = {
- "/bsd", "/obsd", "/bsd.old",
+ "/netbsd", "/onetbsd", "/netbsd.old",
};
#define NUMNAMES (sizeof(names)/sizeof(char *))
-extern char *version;
+/* Number of seconds that prompt should wait during boot */
+#define PROMPTWAIT 5
+
+static void getbootdev __P((int *howto));
+static void loadprog __P((int howto));
+extern char *version;
extern int end;
+
+void
boot(drive)
-int drive;
+ int drive;
{
int loadflags, currname = 0;
char *t;
printf("\n"
- ">> OpenBSD BOOT: %d/%d k [%s]\n"
- "use hd(1,a)/bsd to boot sd0 when wd0 is also installed\n",
+ ">> NetBSD BOOT: %d/%d k [%s]\n"
+ "use hd(1,a)/netbsd to boot sd0 when wd0 is also installed\n",
argv[7] = memsize(0),
argv[8] = memsize(1),
version);
@@ -106,8 +113,9 @@ loadstart:
goto loadstart;
}
+static void
loadprog(howto)
- int howto;
+ int howto;
{
long int startaddr;
long int addr; /* physical address.. not directly useable */
@@ -265,17 +273,18 @@ nosyms:
startprog((int)startaddr, argv);
}
-char namebuf[100];
+static void
getbootdev(howto)
int *howto;
{
+ static char namebuf[100]; /* don't allocate on stack! */
char c, *ptr = namebuf;
printf("Boot: [[[%s(%d,%c)]%s][-adrs]] :- ",
devs[maj], unit, 'a'+part, name);
#ifdef CHECKSUM
cflag = 0;
#endif
- if (gets(namebuf)) {
+ if (awaitkey(PROMPTWAIT) && gets(namebuf)) {
while (c = *ptr) {
while (c == ' ')
c = *++ptr;
diff --git a/sys/arch/i386/boot/io.c b/sys/arch/i386/boot/io.c
index 0fdd7cabd50..30324242c19 100644
--- a/sys/arch/i386/boot/io.c
+++ b/sys/arch/i386/boot/io.c
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.17 1995/03/12 00:11:00 mycroft Exp $ */
+/* $NetBSD: io.c,v 1.18 1995/12/23 17:21:26 perry Exp $ */
/*
* Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
@@ -31,6 +31,15 @@
#include <sys/types.h>
#include <machine/pio.h>
+void gateA20 __P((int on));
+/*void printf __P((const char *format, int data));*/ /* not quite right XXX */
+void putchar __P((int c));
+int gets __P((char *buf));
+int strcmp __P((const char *s1, const char *s2));
+void bcopy __P((char *from, char *to, int len));
+int awaitkey __P((int seconds));
+void twiddle __P((void));
+
#define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
#define K_STATUS 0x64 /* keyboard status */
#define K_CMD 0x64 /* keybd ctlr command (write-only) */
@@ -48,6 +57,7 @@
/*
* Gate A20 for high memory
*/
+void
gateA20(on)
int on;
{
@@ -74,9 +84,9 @@ gateA20(on)
}
/* printf - only handles %d as decimal, %c as char, %s as string */
-
+void
printf(format, data)
- char *format;
+ const char *format;
int data;
{
int *dataptr = &data;
@@ -124,6 +134,7 @@ printf(format, data)
}
}
+void
putchar(c)
int c;
{
@@ -132,37 +143,37 @@ putchar(c)
putc(c);
}
+int
gets(buf)
char *buf;
{
- int i;
char *ptr = buf;
- for (i = 240000; i > 0; i--)
- if (ischar())
- for (;;) {
- register int c = getc();
- if (c == '\n' || c == '\r') {
- putchar('\n');
- *ptr = '\0';
- return 1;
- } else if (c == '\b' || c == '\177') {
- if (ptr > buf) {
- putchar('\b');
- putchar(' ');
- putchar('\b');
- ptr--;
- }
- } else {
- putchar(c);
- *ptr++ = c;
- }
+ for (;;) {
+ register int c = getc();
+ if (c == '\n' || c == '\r') {
+ putchar('\n');
+ *ptr = '\0';
+ return 1;
+ } else if (c == '\b' || c == '\177') {
+ if (ptr > buf) {
+ putchar('\b');
+ putchar(' ');
+ putchar('\b');
+ ptr--;
}
- return 0;
+ } else {
+ putchar(c);
+ *ptr++ = c;
+ }
+ }
+
+ /* shouldn't ever be reached; we have to return in the loop. */
}
+int
strcmp(s1, s2)
- char *s1, *s2;
+ const char *s1, *s2;
{
while (*s1 == *s2) {
if (!*s1++)
@@ -172,6 +183,7 @@ strcmp(s1, s2)
return 1;
}
+void
bcopy(from, to, len)
char *from, *to;
int len;
@@ -187,6 +199,37 @@ bcopy(from, to, len)
}
}
+/* Number of milliseconds to sleep during each microsleep */
+#define NAPTIME 50
+
+/*
+ * awaitkey takes a number of seconds to wait for a key to be
+ * struck. If a key is struck during the period, it returns true, else
+ * it returns false. It returns (nearly) as soon as the key is
+ * hit. Note that it does something only slightly smarter than busy waiting.
+ */
+int
+awaitkey(seconds)
+ int seconds;
+{
+ int i;
+
+ /*
+ * We sleep for brief periods (typically 50 milliseconds, set
+ * by NAPTIME), polling the input buffer at the end of
+ * each period.
+ */
+ for (i = ((seconds*1000)/NAPTIME); i > 0; i--) {
+ /* multiply by 1000 to get microseconds. */
+ usleep(NAPTIME*1000);
+ if (ischar())
+ break;
+ }
+
+ /* If a character was hit, "i" will still be non-zero. */
+ return (i != 0);
+}
+
void
twiddle()
{
diff --git a/sys/arch/i386/boot/version.c b/sys/arch/i386/boot/version.c
index 10d0ce0a614..3d40a95b061 100644
--- a/sys/arch/i386/boot/version.c
+++ b/sys/arch/i386/boot/version.c
@@ -1,8 +1,13 @@
-/* $NetBSD: version.c,v 1.27 1995/03/12 00:13:47 mycroft Exp $ */
+/* $NetBSD: version.c,v 1.28 1995/12/23 17:21:23 perry Exp $ */
/*
* NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE.
*
+ * 1.27 -> 1.28
+ * fix gets to use real timeout instead of loop and do
+ * a little cleanup, and add some prototypes. A lot more
+ * needs to be done here. (perry)
+ *
* 1.26 -> 1.27
* size reduction and code cleanup. (mycroft)
*
@@ -49,4 +54,4 @@
* look in boot.c revision logs
*/
-char *version = "1.27";
+char *version = "1.28";