2 * Copyright (c) 1998 Robert Nordier
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
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
15 * $FreeBSD: src/sys/boot/i386/boot2/sio.s,v 1.4 1999/08/28 00:40:02 peter Exp $
16 * $DragonFly: src/sys/boot/pc32/boot2/sio.S,v 1.8 2006/08/12 05:42:26 swildner Exp $
18 .set SIO_PRT,SIOPRT # Base port
19 .set SIO_FMT,SIOFMT # 8N1
20 .set SIO_DIV,(115200/SIOSPD) # 115200 / SPD
31 * returns non-zero if we couldn't init, which can happen if
32 * the serial port is unmapped and the inb's all return
33 * 0xFF (we fail to flush the input).
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
39 movw $SIO_DIV,%ax # divisor
40 outw %ax,(%dx) # BASE+0 (divisor w/ DLAB set)
42 movb $0x01,%al # Enable FIFO
45 * DISABLED - apparently many new laptops only implement
46 * 8250s, this might crash them? XXX
48 /* outb %al,(%dx) */ # BASE+2
50 movb $SIO_FMT,%al # Clear DLAB
51 outb %al,(%dx) # BASE+3
53 movb $0x3,%al # RTS+DTR
54 outb %al,(%dx) # BASE+4
55 incl %edx # BASE+5 Line status reg
58 * fall through to io_flush
60 * sio_flush: flush pending data in the serial port,
61 * return non-zero if we were unable to flush (aka
62 * ischar always returned true)
64 sio_flush: movb $1,%ch # let %cl be garbage
71 * void sio_putc(int c)
73 sio_putc: movw $SIO_PRT+0x5,%dx # Line status reg
74 movb $0x40,%ch # Timeout counter. Allow %cl
76 sio_putc.1: inb (%dx),%al # Transmitter buffer empty?
79 jz sio_putc.2 # If timeout
80 movb 0x4(%esp,1),%al # Get character
81 subb $0x5,%dl # Transmitter hold reg
82 outb %al,(%dx) # Write character
88 sio_getc: call sio_ischar # Character available?
90 sio_getc.1: subb $0x5,%dl # Receiver buffer reg
91 inb (%dx),%al # Read character
95 * int sio_ischar(void)
97 sio_ischar: movw $SIO_PRT+0x5,%dx # Line status register
99 inb (%dx),%al # Received data ready?
104 inbser: movw $SIO_PRT+5,%dx