sio.S revision 220337
1132718Skan/* 2169689Skan * Copyright (c) 1998 Robert Nordier 3169689Skan * All rights reserved. 4132718Skan * 5132718Skan * Redistribution and use in source and binary forms are freely 6132718Skan * permitted provided that the above copyright notice and this 7132718Skan * paragraph and the following disclaimer are duplicated in all 8132718Skan * such forms. 9132718Skan * 10132718Skan * This software is provided "AS IS" and without any express or 11132718Skan * implied warranties, including, without limitation, the implied 12132718Skan * warranties of merchantability and fitness for a particular 13132718Skan * purpose. 14132718Skan * 15132718Skan * $FreeBSD: head/sys/boot/i386/boot2/sio.S 220337 2011-04-04 18:23:55Z rdivacky $ 16132718Skan */ 17132718Skan 18132718Skan .set SIO_PRT,SIOPRT # Base port 19132718Skan .set SIO_FMT,SIOFMT # 8N1 20132718Skan 21169689Skan .globl sio_init 22169689Skan .globl sio_flush 23132718Skan .globl sio_putc 24132718Skan .globl sio_getc 25132718Skan .globl sio_ischar 26132718Skan 27132718Skan/* void sio_init(int div) */ 28132718Skan 29132718Skansio_init: pushl %eax 30132718Skan movw $SIO_PRT+0x3,%dx # Data format reg 31132718Skan movb $SIO_FMT|0x80,%al # Set format 32132718Skan outb %al,(%dx) # and DLAB 33132718Skan subb $0x3,%dl # Divisor latch reg 34132718Skan popl %eax 35132718Skan outw %ax,(%dx) # BPS 36132718Skan movw $SIO_PRT+0x3,%dx # Data format reg 37132718Skan movb $SIO_FMT,%al # Clear 38132718Skan outb %al,(%dx) # DLAB 39132718Skan incl %edx # Modem control reg 40132718Skan movb $0x3,%al # Set RTS, 41132718Skan outb %al,(%dx) # DTR 42132718Skan incl %edx # Line status reg 43132718Skan call sio_flush 44132718Skan ret 45132718Skan 46132718Skan/* void sio_flush(void) */ 47132718Skan 48132718Skansio_flush.0: call sio_getc.1 # Get character 49132718Skansio_flush: call sio_ischar # Check for character 50132718Skan jnz sio_flush.0 # Till none 51132718Skan ret # To caller 52132718Skan 53132718Skan/* void sio_putc(int c) */ 54132718Skan 55132718Skansio_putc: pushl %eax 56132718Skan movw $SIO_PRT+0x5,%dx # Line status reg 57132718Skan xor %ecx,%ecx # Timeout 58132718Skan movb $0x40,%ch # counter 59132718Skansio_putc.1: inb (%dx),%al # Transmitter 60132718Skan testb $0x20,%al # buffer empty? 61132718Skan loopz sio_putc.1 # No 62132718Skan jz sio_putc.2 # If timeout 63132718Skan popl %eax # Get the character 64132718Skan subb $0x5,%dl # Transmitter hold reg 65132718Skan outb %al,(%dx) # Write character 66132718Skansio_putc.2: ret # To caller 67132718Skan 68132718Skan/* int sio_getc(void) */ 69132718Skan 70132718Skansio_getc: call sio_ischar # Character available? 71132718Skan jz sio_getc # No 72132718Skansio_getc.1: subb $0x5,%dl # Receiver buffer reg 73132718Skan inb (%dx),%al # Read character 74132718Skan ret # To caller 75132718Skan 76132718Skan/* int sio_ischar(void) */ 77169689Skan 78132718Skansio_ischar: movw $SIO_PRT+0x5,%dx # Line status register 79132718Skan xorl %eax,%eax # Zero 80132718Skan inb (%dx),%al # Received data 81132718Skan andb $0x1,%al # ready? 82132718Skan ret # To caller 83132718Skan