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
18 .set SIO_PRT,SIOPRT # Base port
19 .set SIO_FMT,SIOFMT # 8N1
27 /* int sio_init(int div) */
30 movw $SIO_PRT+0x3,%dx # Data format reg
31 movb $SIO_FMT|0x80,%al # Set format
32 outb %al,(%dx) # and DLAB
33 subb $0x3,%dl # Divisor latch reg
36 movw $SIO_PRT+0x3,%dx # Data format reg
37 movb $SIO_FMT,%al # Clear
39 incl %edx # Modem control reg
40 movb $0x3,%al # Set RTS,
42 incl %edx # Line status reg
45 /* int sio_flush(void) */
47 sio_flush: xorl %ecx,%ecx # Timeout
48 movb $0x80,%ch # counter
49 sio_flush.1: call sio_ischar # Check for character
50 jz sio_flush.2 # Till none
51 loop sio_flush.1 # or counter is zero
52 movb $1, %al # Exhausted all tries
53 sio_flush.2: ret # To caller
55 /* void sio_putc(int c) */
58 movw $SIO_PRT+0x5,%dx # Line status reg
59 xor %ecx,%ecx # Timeout
60 movb $0x40,%ch # counter
61 sio_putc.1: inb (%dx),%al # Transmitter
62 testb $0x20,%al # buffer empty?
64 jz sio_putc.2 # If timeout
65 popl %eax # Get the character
66 subb $0x5,%dl # Transmitter hold reg
67 outb %al,(%dx) # Write character
68 sio_putc.2: ret # To caller
70 /* int sio_getc(void) */
72 sio_getc: call sio_ischar # Character available?
74 sio_getc.1: subb $0x5,%dl # Receiver buffer reg
75 inb (%dx),%al # Read character
78 /* int sio_ischar(void) */
80 sio_ischar: movw $SIO_PRT+0x5,%dx # Line status register
82 inb (%dx),%al # Received data
83 andb $0x1,%al # ready?