what the heck one last one before i go take a nap...
[dragonfly.git] / sys / i386 / boot / biosboot / serial.S
1 /*
2  * Mach Operating System
3  * Copyright (c) 1992, 1991 Carnegie Mellon University
4  * All Rights Reserved.
5  * 
6  * Permission to use, copy, modify and distribute this software and its
7  * documentation is hereby granted, provided that both the copyright
8  * notice and this permission notice appear in all copies of the
9  * software, derivative works or modified versions, and any portions
10  * thereof, and that both notices appear in supporting documentation.
11  * 
12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15  * 
16  * Carnegie Mellon requests users of this software to return to
17  * 
18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
19  *  School of Computer Science
20  *  Carnegie Mellon University
21  *  Pittsburgh PA 15213-3890
22  * 
23  * any improvements or extensions that they make and grant Carnegie Mellon
24  * the rights to redistribute these changes.
25  *
26  *      from: Mach, Revision 2.2  92/04/04  11:34:26  rpd
27  * $FreeBSD: src/sys/i386/boot/biosboot/serial.S,v 1.13 1999/08/28 00:43:14 peter Exp $
28  * $DragonFly: src/sys/i386/boot/biosboot/Attic/serial.S,v 1.3 2003/08/07 21:17:20 dillon Exp $
29  */
30
31 /*
32   Copyright 1988, 1989, 1990, 1991, 1992 
33    by Intel Corporation, Santa Clara, California.
34
35                 All Rights Reserved
36
37 Permission to use, copy, modify, and distribute this software and
38 its documentation for any purpose and without fee is hereby
39 granted, provided that the above copyright notice appears in all
40 copies and that both the copyright notice and this permission notice
41 appear in supporting documentation, and that the name of Intel
42 not be used in advertising or publicity pertaining to distribution
43 of the software without specific, written prior permission.
44
45 INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
46 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
47 IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
48 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
49 LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
50 NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
51 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
52 */
53
54 /*
55  * Serial bootblock interface routines
56  * Copyright (c) 1994, J"org Wunsch
57  *
58  * Permission to use, copy, modify and distribute this software and its
59  * documentation is hereby granted, provided that both the copyright
60  * notice and this permission notice appear in all copies of the
61  * software, derivative works or modified versions, and any portions
62  * thereof, and that both notices appear in supporting documentation.
63  *
64  * THE AUTHOR ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
65  * CONDITION.  THE AUTHOR DISCLAIMS ANY LIABILITY OF ANY KIND FOR
66  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
67  */ 
68
69         .file   "serial.S"
70
71 #include <dev/serial/sio/sioreg.h>
72 #include "asm.h"
73
74         .text
75
76 /*
77  * The serial port interface routines implement a simple polled i/o
78  * interface to a standard serial port.  Due to the space restrictions
79  * for the boot blocks, no BIOS support is used (since BIOS requires
80  * expensive real/protected mode switches), instead the rudimentary
81  * BIOS support is duplicated here.
82  *
83  * The base address and speed for the i/o port are passed from the
84  * Makefile in the COMCONSOLE and CONSPEED preprocessor macros.  The
85  * line control parameters are currently hard-coded to 8 bits, no
86  * parity, 1 stop bit (8N1).  This can be changed in init_serial().
87  */
88
89 /*
90  * void serial_putc(int ch);
91  *      Write character `ch' to port COMCONSOLE.
92  */
93 ENTRY(serial_putc)
94         movl    $10000, %ecx    # timeout
95         movl    $COMCONSOLE + 5, %edx   # line status reg
96 1:
97         decl    %ecx
98         je      2f
99         inb     %dx, %al
100         testb   $0x20, %al
101         je      1b              # TX buffer not empty
102
103         movb    4(%esp), %al
104
105         subl    $5, %edx        # TX output reg
106         outb    %al, %dx        # send this one
107
108 2:
109         ret
110
111 /*
112  * int serial_getc(void);
113  *      Read a character from port COMCONSOLE.
114  */
115 ENTRY(serial_getc)
116         mov     $COMCONSOLE + 5, %edx   # line status reg
117 1:
118         inb     %dx, %al
119         testb   $0x01, %al
120         je      1b              # no rx char available
121
122         xorl    %eax, %eax
123         subl    $5, %edx        # rx buffer reg
124         inb     %dx, %al        # fetch (first) character
125
126         andb    $0x7F, %al      # remove any parity bits we get
127         cmpb    $0x7F, %al      # make DEL...
128         jne     2f
129         movb    $0x08, %al      # look like BS
130 2:
131         ret
132
133 /*
134  * int serial_ischar(void);
135  *       If there is a character in the input buffer of port COMCONSOLE,
136  *       return nonzero; otherwise return 0.
137  */
138 ENTRY(serial_ischar)
139         xorl    %eax, %eax
140         movl    $COMCONSOLE + 5, %edx   # line status reg
141         inb     %dx, %al
142         andb    $0x01, %al              # rx char available?
143         ret
144
145 /*
146  * void init_serial(void);
147  *      Initialize port COMCONSOLE to speed CONSPEED, line settings 8N1.
148  */
149 ENTRY(init_serial)
150         movl    $COMCONSOLE + 3, %edx   # line control reg
151         movb    $0x80, %al
152         outb    %al, %dx        # enable DLAB
153
154         subl    $3, %edx        # divisor latch, low byte
155         movb    $COMBRD(CONSPEED) & 0xff, %al
156         outb    %al, %dx
157         incl    %edx            # divisor latch, high byte
158         movb    $COMBRD(CONSPEED) >> 8, %al
159         outb    %al, %dx
160
161         incl    %edx            # fifo control register (if any)
162         xorl    %eax,%eax
163         outb    %al, %dx        # disable fifo to reduce worst-case busy-wait
164
165         incl    %edx            # line control reg
166         movb    $0x03, %al
167         outb    %al, %dx        # 8N1
168
169         incl    %edx            # modem control reg
170         outb    %al, %dx        # enable DTR/RTS
171
172         /* Flush the input buffer. */
173         incl    %edx            # line status reg
174 1:
175         subl    $5, %edx        # rx buffer reg
176         inb     %dx, %al        # throw away (unconditionally the first time)
177         addl    $5, %edx        # line status reg
178         inb     %dx, %al
179         testb   $0x01, %al
180         jne     1b              # more
181
182         ret