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