summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/i386/stand/libsa/bioscons.c116
-rw-r--r--sys/lib/libsa/stand.h3
-rw-r--r--sys/stand/boot/cmd.c29
3 files changed, 77 insertions, 71 deletions
diff --git a/sys/arch/i386/stand/libsa/bioscons.c b/sys/arch/i386/stand/libsa/bioscons.c
index d5a88ea58de..18bd40a1b96 100644
--- a/sys/arch/i386/stand/libsa/bioscons.c
+++ b/sys/arch/i386/stand/libsa/bioscons.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bioscons.c,v 1.10 1997/09/24 06:02:44 mickey Exp $ */
+/* $OpenBSD: bioscons.c,v 1.11 1997/10/07 07:59:59 mickey Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
@@ -43,6 +43,19 @@
#include <dev/cons.h>
#include <lib/libsa/stand.h>
+int comspeed __P((dev_t, int));
+
+int
+cnspeed(dev, sp)
+ dev_t dev;
+ int sp;
+{
+ if (major(dev) == 8) /* comN */
+ return comspeed(dev, sp);
+ /* pc0 and anything else */
+ return 9600;
+}
+
/* XXX cannot trust NVRAM on this. Maybe later we make a real probe. */
#if 0
#define PRESENT_MASK (NVRAM_EQUIPMENT_KBD|NVRAM_EQUIPMENT_DISPLAY)
@@ -51,7 +64,6 @@
#endif
int com_setsp __P((int));
-static int com_speed = 9600; /* default speed is 9600 baud */
static const int comports[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
void
@@ -128,8 +140,6 @@ com_init(cn)
/* let bios do necessary init first, 9600-N-1 */
__asm __volatile(DOINT(0x14) : : "a" (0xe3), "d" (unit) :
"%ecx", "cc" );
- /* now just set the speed */
- (void)com_setsp(com_speed);
}
int
@@ -152,75 +162,59 @@ com_getc(dev)
return (rv & 0xff);
}
-/* ripped screaming from dev/ic/com.c */
-static int
-comspeed(speed)
- int speed;
+/* call with sp == 0 to query the current speed */
+int
+comspeed(dev, sp)
+ dev_t dev;
+ int sp;
{
-#define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */
- int x, err;
+ static int com_speed = 9600; /* default speed is 9600 baud */
+ int i, newsp;
+ time_t tt;
+ int err;
- if (speed == 0)
- return 0;
- if (speed < 0)
+ if (sp <= 0)
+ return com_speed;
+ /* valid baud rate? */
+ if (sp > 38400 || sp < 75)
return -1;
- x = divrnd((COM_FREQ / 16), speed);
- if (x <= 0)
+
+ for (i = sp; i != 75; i >>= 1)
+ if (i & 1)
+ return -1;
+
+/* ripped screaming from dev/ic/com.c */
+#define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */
+ newsp = divrnd((COM_FREQ / 16), sp);
+ if (newsp <= 0)
return -1;
- err = divrnd((COM_FREQ / 16) * 1000, speed * x) - 1000;
+ err = divrnd((COM_FREQ / 16) * 1000, sp * newsp) - 1000;
if (err < 0)
err = -err;
if (err > COM_TOLERANCE)
return -1;
- return x;
#undef divrnd(n, q)
-}
-
-/* call with sp == 0 to query the current speed */
-int
-com_setsp(sp)
- int sp;
-{
- int unit, i, newsp = comspeed(sp);
- if (sp == 0)
- return com_speed;
- /* valid baud rate? */
- if (sp > 38400 || sp < 75)
- {
- badspeed:
- printf("invalid terminal speed %d\n", sp);
- return 0;
- }
- for (i=sp; i != 75; i >>= 1)
- if (i & 1)
- goto badspeed;
- /* is current console a com device? */
- if (cn_tab && cn_tab->cn_getc == com_getc)
+ if (cn_tab && cn_tab->cn_dev == dev && com_speed != sp)
{
- time_t tt;
- unit = minor(cn_tab->cn_dev);
- if (com_speed != sp)
- {
- printf("com%d: changing speed from %d to %d\n"
- "com%d: change your terminal to match!\n"
- "com%d: will change speed in 5 seconds....\n",
- unit, com_speed, sp,
- unit, unit);
- /* let the \n get out and the
- user change the terminal */
- for (tt = getsecs() + 5; getsecs() < tt;);
- }
- outb(comports[unit] + com_cfcr, LCR_DLAB);
- outb(comports[unit] + com_dlbl, newsp);
- outb(comports[unit] + com_dlbh, newsp>>8);
- outb(comports[unit] + com_cfcr, LCR_8BITS);
- printf("using com%d console at %d baud\n", unit, sp);
- } else {
- printf("speed on next com device will be %d\n"
- "change your terminal to match!\n", sp);
+ printf("com%d: changing speed to %d baud\n\a"
+ "com%d: change your terminal to match!\n\a"
+ "com%d: will change speed in 5 seconds....\n\a",
+ minor(dev), sp, minor(dev), minor(dev));
+ /* let the \n get out and the
+ user change the terminal */
+ for (tt = getsecs() + 5; getsecs() < tt;);
}
- return com_speed = sp;
+
+ outb(comports[minor(dev)] + com_cfcr, LCR_DLAB);
+ outb(comports[minor(dev)] + com_dlbl, newsp);
+ outb(comports[minor(dev)] + com_dlbh, newsp>>8);
+ outb(comports[minor(dev)] + com_cfcr, LCR_8BITS);
+ printf("com%d: console is at %d baud\n", minor(dev), sp);
+
+ newsp = com_speed;
+ com_speed = sp;
+ return newsp;
}
void
diff --git a/sys/lib/libsa/stand.h b/sys/lib/libsa/stand.h
index 0fd9ca0cc8f..c67bcd9b44f 100644
--- a/sys/lib/libsa/stand.h
+++ b/sys/lib/libsa/stand.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: stand.h,v 1.29 1997/08/13 14:18:10 niklas Exp $ */
+/* $OpenBSD: stand.h,v 1.30 1997/10/07 07:59:58 mickey Exp $ */
/* $NetBSD: stand.h,v 1.18 1996/11/30 04:35:51 gwr Exp $ */
/*-
@@ -186,6 +186,7 @@ int cnset __P((dev_t));
void cnputc __P((int));
int cngetc __P((void));
int cnischar __P((void));
+int cnspeed __P((dev_t, int));
u_int sleep __P((u_int));
void usleep __P((u_int));
diff --git a/sys/stand/boot/cmd.c b/sys/stand/boot/cmd.c
index 114af576393..087ef07445c 100644
--- a/sys/stand/boot/cmd.c
+++ b/sys/stand/boot/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.33 1997/09/20 22:40:37 flipk Exp $ */
+/* $OpenBSD: cmd.c,v 1.34 1997/10/07 07:59:57 mickey Exp $ */
/*
* Copyright (c) 1997 Michael Shalayeff
@@ -34,7 +34,6 @@
#include <sys/param.h>
#include <libsa.h>
-#include <biosdev.h>
#include <sys/reboot.h>
#include "cmd.h"
@@ -372,15 +371,27 @@ Xset()
static int
Xstty()
{
- int sp;
- char *cp;
+ register int sp;
+ register char *cp;
+ dev_t dev;
+
if (cmd.argc == 1)
- printf("com speed is %d\n", com_setsp(0));
+ printf("%s speed is %d\n", ttyname(0), cnspeed(0, -1));
else {
- sp = 0;
- for (cp = cmd.argv[1]; *cp && isdigit(*cp); cp++)
- sp = sp*10 + (*cp - '0');
- com_setsp(sp);
+ dev = ttydev(cmd.argv[1]);
+ if (dev == NODEV)
+ printf("%s not a console device\n", cmd.argv[1]);
+ else {
+ if (cmd.argc == 2)
+ printf("%s speed is %d\n", cmd.argv[1],
+ cnspeed(dev, -1));
+ else {
+ sp = 0;
+ for (cp = cmd.argv[2]; *cp && isdigit(*cp); cp++)
+ sp = sp * 10 + (*cp - '0');
+ cnspeed(dev, sp);
+ }
+ }
}
return 0;