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 .set SIO_FMT,SIOFMT # 8N1 17 18/* int sio_port */ 19sio_port: .long SIOPRT # Base port 20 21 .globl sio_port 22 .globl sio_init 23 .globl sio_flush 24 .globl sio_putc 25 .globl sio_getc 26 .globl sio_ischar 27 28/* int sio_init(int div) */ 29 30sio_init: pushl %eax 31 movl (sio_port),%edx 32 addl $0x3,%edx # Data format reg 33 movb $SIO_FMT|0x80,%al # Set format 34 outb %al,(%dx) # and DLAB 35 subb $0x3,%dl # Divisor latch reg 36 popl %eax 37 outw %ax,(%dx) # BPS 38 movl (sio_port),%edx 39 addl $0x3,%edx # Data format reg 40 movb $SIO_FMT,%al # Clear 41 outb %al,(%dx) # DLAB 42 incl %edx # Modem control reg 43 movb $0x3,%al # Set RTS, 44 outb %al,(%dx) # DTR 45 incl %edx # Line status reg 46 # Fallthrough 47 48/* int sio_flush(void) */ 49 50sio_flush: xorl %ecx,%ecx # Timeout 51 movb $0x80,%ch # counter 52sio_flush.1: call sio_ischar # Check for character 53 jz sio_flush.2 # Till none 54 loop sio_flush.1 # or counter is zero 55 movb $1, %al # Exhausted all tries 56sio_flush.2: ret # To caller 57 58/* void sio_putc(int c) */ 59 60sio_putc: pushl %eax 61 movl (sio_port),%edx 62 addl $0x5,%edx # Line status reg 63 xor %ecx,%ecx # Timeout 64 movb $0x40,%ch # counter 65sio_putc.1: inb (%dx),%al # Transmitter 66 testb $0x20,%al # buffer empty? 67 loopz sio_putc.1 # No 68 jz sio_putc.2 # If timeout 69 popl %eax # Get the character 70 subb $0x5,%dl # Transmitter hold reg 71 outb %al,(%dx) # Write character 72sio_putc.2: ret # To caller 73 74/* int sio_getc(void) */ 75 76sio_getc: call sio_ischar # Character available? 77 jz sio_getc # No 78sio_getc.1: subb $0x5,%dl # Receiver buffer reg 79 inb (%dx),%al # Read character 80 ret # To caller 81 82/* int sio_ischar(void) */ 83 84sio_ischar: movl (sio_port),%edx 85 addl $0x5,%edx # Line status register 86 xorl %eax,%eax # Zero 87 inb (%dx),%al # Received data 88 andb $0x1,%al # ready? 89 ret # To caller 90