Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / boot / pc98 / boot2 / serial_8251.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/boot/pc98/boot2/serial_8251.S,v 1.1.2.1 2000/04/16 03:55:16 nyan 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 /*
69  * modified for PC-98 by KATO T. of Nagoya University
70  */
71
72         .file   "serial.S"
73
74 #include <isa/sioreg.h>
75 #include "asm.h"
76
77         .text
78
79 /*
80  * The serial port interface routines implement a simple polled i/o
81  * interface to a standard serial port.  Due to the space restrictions
82  * for the boot blocks, no BIOS support is used (since BIOS requires
83  * expensive real/protected mode switches), instead the rudimentary
84  * BIOS support is duplicated here.
85  *
86  * The base address for the i/o port is passed from the Makefile in
87  * the COMCONSOLE preprocessor macro.  Console parameters are currently
88  * hard-coded to 9600 Bd, 8 bit.  This can be changed in the
89  * init_serial() function.
90  */
91
92 /*
93  * void serial_putc(char ch)
94  *      send ch to serial port
95  *
96  */
97
98 ENTRY(serial_putc)
99         mov     $COMCONSOLE + 2, %edx   # line status reg
100 1:      inb     %dx, %al
101         testb   $0x01, %al
102         jz      1b              # TX buffer not empty
103
104         movb    0x4(%esp), %al
105
106         sub     $2, %edx        # TX output reg
107         outb    %al, %dx        # send this one
108
109         ret
110
111 /*
112  * int serial_getc(void)
113  *      read a character from serial port
114  */
115
116 ENTRY(serial_getc)
117         mov     $COMCONSOLE + 2, %edx   # line status reg
118 1:
119         inb     %dx, %al
120         testb   $0x02, %al
121         jz      1b              # no RX char available
122
123         xorb    %eax, %eax
124         subb    $2, %edx        # RX buffer reg
125         inb     %dx, %al        # fetch (first) character
126
127         cmp     $0x7F, %eax     # make DEL...
128         jne     2f
129         movb    $0x08, %eax     # look like BS
130 2:
131         ret
132
133 /*
134  * int serial_ischar(void)
135  *       if there is a character pending, return true; otherwise return 0
136  */
137 ENTRY(serial_ischar)
138         xorl    %eax, %eax
139         movl    $COMCONSOLE + 2, %edx   # line status reg
140         inb     %dx, %al
141         andb    $0x02, %al              # RX char available?
142
143         ret
144
145 /*
146  * void init_serial(void)
147  *      initialize the serial console port to 9600 Bd, 8 bpc
148  */
149 ENTRY(init_serial)
150         /* set 8253 */
151         movb    0xb6, %al
152         outb    %al, $0x77
153         movl    $COMCONSOLE_CLK, %eax
154         outb    %al, $0x75
155         inb     $0x5f, %al
156         movb    %ah, %al
157         outb    %al, $0x75
158
159         /* inhibit com int */
160         inb     $0x35, %al
161         andb    $0xf8, %al
162         movb    %al, %ah
163         inb     $0x5f, %al
164         movb    %ah, %al
165         outb    %al, $0x35
166
167         inb     $0x02, %al
168         orb     $0x10, %al
169         outb    %al, $0x02
170         
171         /* dummy command */
172         xorb    %al,%al
173         movl    $COMCONSOLE + 2, %edx
174         outb    %al, %dx
175         inb     $0x5f, %al
176         xorb    %al,%al
177         outb    %al, %dx
178         inb     $0x5f, %al
179         xorb    %al,%al
180         outb    %al, %dx
181         inb     $0x5f, %al
182
183         /* RESET 8251 */
184         movb    $0x40, %al
185         outb    %al, %dx
186
187         movb    $COMCONSOLE_MODE , %al
188         andb    $0xfc, %al
189         orb     $0x02, %al      /* factor = 1/16 */
190         outb    %al, %dx
191         inb     $0x5f, %al
192
193         /* start RS-232C */
194         movb    $0x37, %al
195         outb    %al, %dx
196
197         ret
198