diff options
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/i386/stand/libsa/bioscons.c | 116 |
1 files changed, 55 insertions, 61 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 |