Deleted Added
full compact
comconsole.c (40211) comconsole.c (41285)
1/*
2 * Copyright (c) 1998 Michael Smith (msmith@freebsd.org)
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 8 unchanged lines hidden (view full) ---

17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 *
1/*
2 * Copyright (c) 1998 Michael Smith (msmith@freebsd.org)
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 8 unchanged lines hidden (view full) ---

17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 *
25 * From Id: probe_keyboard.c,v 1.13 1997/06/09 05:10:55 bde Exp
26 *
27 * $Id: comconsole.c,v 1.3 1998/10/02 16:32:45 msmith Exp $
25 * $Id: comconsole.c,v 1.4 1998/10/11 10:05:13 peter Exp $
28 */
29
30#include <stand.h>
31#include <bootstrap.h>
26 */
27
28#include <stand.h>
29#include <bootstrap.h>
32#include <btxv86.h>
30#include <machine/cpufunc.h>
33#include "libi386.h"
34
31#include "libi386.h"
32
33/* selected defines from ns16550.h */
34#define com_data 0 /* data register (R/W) */
35#define com_dlbl 0 /* divisor latch low (W) */
36#define com_dlbh 1 /* divisor latch high (W) */
37#define com_ier 1 /* interrupt enable (W) */
38#define com_iir 2 /* interrupt identification (R) */
39#define com_fifo 2 /* FIFO control (W) */
40#define com_lctl 3 /* line control register (R/W) */
41#define com_cfcr 3 /* line control register (R/W) */
42#define com_mcr 4 /* modem control register (R/W) */
43#define com_lsr 5 /* line status register (R/W) */
44#define com_msr 6 /* modem status register (R/W) */
45
46/* selected defines from sioreg.h */
47#define CFCR_DLAB 0x80
48#define MCR_RTS 0x02
49#define MCR_DTR 0x01
50#define LSR_TXRDY 0x20
51#define LSR_RXRDY 0x01
52
53#define COMC_FMT 0x3 /* 8N1 */
54#define COMC_TXWAIT 0x40000 /* transmit timeout */
55#define COMC_BPS(x) (115200 / (x)) /* speed to DLAB divisor */
56
57#define COMPORT 0x3f8
58#define COMSPEED 9600
59
35static void comc_probe(struct console *cp);
36static int comc_init(int arg);
37static void comc_putchar(int c);
38static int comc_getchar(void);
39static int comc_ischar(void);
40
41static int comc_started;
42
43struct console comconsole = {
44 "comconsole",
60static void comc_probe(struct console *cp);
61static int comc_init(int arg);
62static void comc_putchar(int c);
63static int comc_getchar(void);
64static int comc_ischar(void);
65
66static int comc_started;
67
68struct console comconsole = {
69 "comconsole",
45 "BIOS serial port",
70 "serial port",
46 0,
47 comc_probe,
48 comc_init,
49 comc_putchar,
50 comc_getchar,
51 comc_ischar
52};
53
71 0,
72 comc_probe,
73 comc_init,
74 comc_putchar,
75 comc_getchar,
76 comc_ischar
77};
78
54#define BIOS_COMPORT 0
55
56static void
57comc_probe(struct console *cp)
58{
59 /* XXX check the BIOS equipment list? */
60 cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
61}
62
63static int
64comc_init(int arg)
65{
79static void
80comc_probe(struct console *cp)
81{
82 /* XXX check the BIOS equipment list? */
83 cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
84}
85
86static int
87comc_init(int arg)
88{
66 int i;
67
68 if (comc_started && arg == 0)
69 return 0;
70 comc_started = 1;
89 if (comc_started && arg == 0)
90 return 0;
91 comc_started = 1;
71 v86.ctl = 0;
72 v86.addr = 0x14;
73 v86.eax = 0xe3; /* 9600N81 */
74 v86.edx = BIOS_COMPORT; /* XXX take as arg, or use env var? */
75 v86int();
76
92
77 for(i = 0; i < 10 && comc_ischar(); i++)
78 (void)comc_getchar();
93 outb(COMPORT + com_cfcr, CFCR_DLAB | COMC_FMT);
94 outb(COMPORT + com_dlbl, COMC_BPS(COMSPEED) & 0xff);
95 outb(COMPORT + com_dlbh, COMC_BPS(COMSPEED) >> 8);
96 outb(COMPORT + com_cfcr, COMC_FMT);
97 outb(COMPORT + com_mcr, MCR_RTS | MCR_DTR);
79
98
99 do
100 inb(COMPORT + com_data);
101 while (inb(COMPORT + com_lsr) & LSR_RXRDY);
102
80 return(0);
81}
82
83static void
84comc_putchar(int c)
85{
103 return(0);
104}
105
106static void
107comc_putchar(int c)
108{
86 v86.ctl = 0;
87 v86.addr = 0x14;
88 v86.eax = 0x100 | c; /* Function 1 = write */
89 v86.edx = BIOS_COMPORT; /* XXX take as arg, or use env var? */
90 v86int();
109 int wait;
110
111 for (wait = COMC_TXWAIT; wait > 0; wait--)
112 if (inb(COMPORT + com_lsr) & LSR_TXRDY) {
113 outb(COMPORT + com_data, c);
114 break;
115 }
91}
92
93static int
94comc_getchar(void)
95{
116}
117
118static int
119comc_getchar(void)
120{
96 if (comc_ischar()) {
97 v86.ctl = 0;
98 v86.addr = 0x14;
99 v86.eax = 0x200; /* Function 2 = read */
100 v86.edx = BIOS_COMPORT; /* XXX take as arg, or use env var? */
101 v86int();
102 return(v86.eax & 0xff);
103 } else {
104 return(-1);
105 }
121 return(comc_ischar() ? inb(COMPORT + com_data) : -1);
106}
107
108static int
109comc_ischar(void)
110{
122}
123
124static int
125comc_ischar(void)
126{
111 v86.ctl = 0;
112 v86.addr = 0x14;
113 v86.eax = 0x300; /* Function 3 = status */
114 v86.edx = BIOS_COMPORT; /* XXX take as arg, or use env var? */
115 v86int();
116 return(v86.eax & 0x100); /* AH bit 1 is "receive data ready" */
127 return(inb(COMPORT + com_lsr) & LSR_RXRDY);
117}
128}