/*1* Copyright (c) 1998 Robert Nordier2* All rights reserved.3*4* Redistribution and use in source and binary forms are freely5* permitted provided that the above copyright notice and this6* paragraph and the following disclaimer are duplicated in all7* such forms.8*9* This software is provided "AS IS" and without any express or10* implied warranties, including, without limitation, the implied11* warranties of merchantability and fitness for a particular12* purpose.13*/1415.set SIO_PRT,SIOPRT # Base port16.set SIO_FMT,SIOFMT # 8N11718.globl sio_init19.globl sio_flush20.globl sio_putc21.globl sio_getc22.globl sio_ischar2324/* int sio_init(int div) */2526sio_init: pushl %eax27movw $SIO_PRT+0x3,%dx # Data format reg28movb $SIO_FMT|0x80,%al # Set format29outb %al,(%dx) # and DLAB30subb $0x3,%dl # Divisor latch reg31popl %eax32outw %ax,(%dx) # BPS33movw $SIO_PRT+0x3,%dx # Data format reg34movb $SIO_FMT,%al # Clear35outb %al,(%dx) # DLAB36incl %edx # Modem control reg37movb $0x3,%al # Set RTS,38outb %al,(%dx) # DTR39incl %edx # Line status reg40# Fallthrough4142/* int sio_flush(void) */4344sio_flush: xorl %ecx,%ecx # Timeout45movb $0x80,%ch # counter46sio_flush.1: call sio_ischar # Check for character47jz sio_flush.2 # Till none48loop sio_flush.1 # or counter is zero49movb $1, %al # Exhausted all tries50sio_flush.2: ret # To caller5152/* void sio_putc(int c) */5354sio_putc: pushl %eax55movw $SIO_PRT+0x5,%dx # Line status reg56xor %ecx,%ecx # Timeout57movb $0x40,%ch # counter58sio_putc.1: inb (%dx),%al # Transmitter59testb $0x20,%al # buffer empty?60loopz sio_putc.1 # No61jz sio_putc.2 # If timeout62popl %eax # Get the character63subb $0x5,%dl # Transmitter hold reg64outb %al,(%dx) # Write character65sio_putc.2: ret # To caller6667/* int sio_getc(void) */6869sio_getc: call sio_ischar # Character available?70jz sio_getc # No71sio_getc.1: subb $0x5,%dl # Receiver buffer reg72inb (%dx),%al # Read character73ret # To caller7475/* int sio_ischar(void) */7677sio_ischar: movw $SIO_PRT+0x5,%dx # Line status register78xorl %eax,%eax # Zero79inb (%dx),%al # Received data80andb $0x1,%al # ready?81ret # To caller828384