Fix a minor bug in the auto-console selection (handle the -m mute option
[dragonfly.git] / sys / boot / i386 / boot2 / sio.S
1 #
2 # Copyright (c) 1998 Robert Nordier
3 # All rights reserved.
4 #
5 # Redistribution and use in source and binary forms are freely
6 # permitted provided that the above copyright notice and this
7 # paragraph and the following disclaimer are duplicated in all
8 # such forms.
9 #
10 # This software is provided "AS IS" and without any express or
11 # implied warranties, including, without limitation, the implied
12 # warranties of merchantability and fitness for a particular
13 # purpose.
14 #
15
16 # $FreeBSD: src/sys/boot/i386/boot2/sio.s,v 1.4 1999/08/28 00:40:02 peter Exp $
17 # $DragonFly: src/sys/boot/i386/boot2/Attic/sio.S,v 1.5 2004/06/27 08:00:46 dillon Exp $
18
19                 .set SIO_PRT,SIOPRT             # Base port
20                 .set SIO_FMT,SIOFMT             # 8N1
21                 .set SIO_DIV,(115200/SIOSPD)    # 115200 / SPD
22
23                 .globl sio_init
24                 .globl sio_flush
25                 .globl sio_putc
26                 .globl sio_getc
27                 .globl sio_ischar
28
29 # int sio_init(void)
30
31 # returns non-zero if we couldn't init, which can happen if the
32 # serial port is unmapped and the inb's all return 0xFF (we fail
33 # to flush the input).
34
35 sio_init:       movw $SIO_PRT+0x3,%dx           # Data format reg
36                 movb $SIO_FMT|0x80,%al          # Set format and DLAB
37                 outb %al,(%dx)                  # BASE+3
38                 subb $0x3,%dl
39                 movw $SIO_DIV,%ax               # divisor
40                 outw %ax,(%dx)                  # BASE+0 (divisor w/ DLAB set)
41                 movw $SIO_PRT+0x2,%dx
42                 movb $0x01,%al                  # Enable FIFO
43                 # DISABLED - apparently many new laptops only implement 
44                 # 8250s, this might crash them? XXX
45                 # outb %al,(%dx)                        # BASE+2
46                 incl %edx
47                 movb $SIO_FMT,%al               # Clear DLAB
48                 outb %al,(%dx)                  # BASE+3
49                 incl %edx
50                 movb $0x3,%al                   # RTS+DTR
51                 outb %al,(%dx)                  # BASE+4
52                 incl %edx                       # BASE+5 Line status reg
53
54                 # fall through to io_flush
55                 #
56                 # sio_flush: flush pending data in the serial port,
57                 # return non-zero if we were unable to flush (aka
58                 # ischar always returned true)
59
60 sio_flush:      movb $1,%ch                     # let %cl be garbage
61 1:              call sio_getc.1
62                 call sio_ischar
63                 loopnz 1b
64                 ret
65
66 # void sio_putc(int c)
67
68 sio_putc:       movw $SIO_PRT+0x5,%dx           # Line status reg
69                 movb $0x40,%ch                  # Timeout counter.  Allow %cl
70                                                 # to contain garbage.
71 sio_putc.1:     inb (%dx),%al                   # Transmitter buffer empty?
72                 testb $0x20,%al
73                 loopz sio_putc.1                # No
74                 jz sio_putc.2                   # If timeout
75                 movb 0x4(%esp,1),%al            # Get character
76                 subb $0x5,%dl                   # Transmitter hold reg
77                 outb %al,(%dx)                  # Write character
78 sio_putc.2:     ret $0x4
79
80 # int sio_getc(void)
81
82 sio_getc:       call sio_ischar                 # Character available?
83                 jz sio_getc                     # No
84 sio_getc.1:     subb $0x5,%dl                   # Receiver buffer reg
85                 inb (%dx),%al                   # Read character
86                 ret
87
88 # int sio_ischar(void)
89
90 sio_ischar:     movw $SIO_PRT+0x5,%dx           # Line status register
91                 xorl %eax,%eax                  # Zero
92                 inb (%dx),%al                   # Received data ready?
93                 andb $0x1,%al
94                 ret
95
96                 .globl inbser
97 inbser: movw $SIO_PRT+5,%dx
98                 inb (%dx),%al
99                 ret