xref: /illumos-gate/usr/src/boot/i386/gptzfsboot/sio.S (revision ceb3ef19)
122028508SToomas Soome/*
222028508SToomas Soome * Copyright (c) 1998 Robert Nordier
322028508SToomas Soome * All rights reserved.
422028508SToomas Soome *
522028508SToomas Soome * Redistribution and use in source and binary forms are freely
622028508SToomas Soome * permitted provided that the above copyright notice and this
722028508SToomas Soome * paragraph and the following disclaimer are duplicated in all
822028508SToomas Soome * such forms.
922028508SToomas Soome *
1022028508SToomas Soome * This software is provided "AS IS" and without any express or
1122028508SToomas Soome * implied warranties, including, without limitation, the implied
1222028508SToomas Soome * warranties of merchantability and fitness for a particular
1322028508SToomas Soome * purpose.
1422028508SToomas Soome */
1522028508SToomas Soome
1622028508SToomas Soome		.set SIO_FMT,SIOFMT		# 8N1
1722028508SToomas Soome
18*ceb3ef19SToomas Soome/* int sio_port */
19*ceb3ef19SToomas Soomesio_port:	.long SIOPRT			# Base port
20*ceb3ef19SToomas Soome
21*ceb3ef19SToomas Soome		.globl sio_port
2222028508SToomas Soome		.globl sio_init
2322028508SToomas Soome		.globl sio_flush
2422028508SToomas Soome		.globl sio_putc
2522028508SToomas Soome		.globl sio_getc
2622028508SToomas Soome		.globl sio_ischar
2722028508SToomas Soome
2822028508SToomas Soome/* int sio_init(int div) */
2922028508SToomas Soome
3022028508SToomas Soomesio_init:	pushl %eax
31*ceb3ef19SToomas Soome		movl (sio_port),%edx
32*ceb3ef19SToomas Soome		addl $0x3,%edx			# Data format reg
3322028508SToomas Soome		movb $SIO_FMT|0x80,%al		# Set format
3422028508SToomas Soome		outb %al,(%dx)			#  and DLAB
3522028508SToomas Soome		subb $0x3,%dl			# Divisor latch reg
3622028508SToomas Soome		popl %eax
3722028508SToomas Soome		outw %ax,(%dx)			#  BPS
38*ceb3ef19SToomas Soome		movl (sio_port),%edx
39*ceb3ef19SToomas Soome		addl $0x3,%edx			# Data format reg
4022028508SToomas Soome		movb $SIO_FMT,%al		# Clear
4122028508SToomas Soome		outb %al,(%dx)			#  DLAB
4222028508SToomas Soome		incl %edx			# Modem control reg
4322028508SToomas Soome		movb $0x3,%al			# Set RTS,
4422028508SToomas Soome		outb %al,(%dx)			#  DTR
4522028508SToomas Soome		incl %edx			# Line status reg
4622028508SToomas Soome		# Fallthrough
4722028508SToomas Soome
4822028508SToomas Soome/* int sio_flush(void) */
4922028508SToomas Soome
5022028508SToomas Soomesio_flush:	xorl %ecx,%ecx			# Timeout
5122028508SToomas Soome		movb $0x80,%ch			#  counter
5222028508SToomas Soomesio_flush.1:	call sio_ischar 		# Check for character
5322028508SToomas Soome		jz sio_flush.2			# Till none
5422028508SToomas Soome		loop sio_flush.1		#  or counter is zero
5522028508SToomas Soome		movb $1, %al			# Exhausted all tries
5622028508SToomas Soomesio_flush.2:	ret				# To caller
5722028508SToomas Soome
5822028508SToomas Soome/* void sio_putc(int c) */
5922028508SToomas Soome
6022028508SToomas Soomesio_putc:	pushl %eax
61*ceb3ef19SToomas Soome		movl (sio_port),%edx
62*ceb3ef19SToomas Soome		addl $0x5,%edx			# Line status reg
6322028508SToomas Soome		xor %ecx,%ecx			# Timeout
6422028508SToomas Soome		movb $0x40,%ch			#  counter
6522028508SToomas Soomesio_putc.1:	inb (%dx),%al			# Transmitter
6622028508SToomas Soome		testb $0x20,%al 		#  buffer empty?
6722028508SToomas Soome		loopz sio_putc.1		# No
6822028508SToomas Soome		jz sio_putc.2			# If timeout
6922028508SToomas Soome		popl %eax                       # Get the character
7022028508SToomas Soome		subb $0x5,%dl			# Transmitter hold reg
7122028508SToomas Soome		outb %al,(%dx)			# Write character
7222028508SToomas Soomesio_putc.2:	ret				# To caller
7322028508SToomas Soome
7422028508SToomas Soome/* int sio_getc(void) */
7522028508SToomas Soome
7622028508SToomas Soomesio_getc:	call sio_ischar 		# Character available?
7722028508SToomas Soome		jz sio_getc			# No
7822028508SToomas Soomesio_getc.1:	subb $0x5,%dl			# Receiver buffer reg
7922028508SToomas Soome		inb (%dx),%al			# Read character
8022028508SToomas Soome		ret				# To caller
8122028508SToomas Soome
8222028508SToomas Soome/* int sio_ischar(void) */
8322028508SToomas Soome
84*ceb3ef19SToomas Soomesio_ischar:	movl (sio_port),%edx
85*ceb3ef19SToomas Soome		addl $0x5,%edx			# Line status register
8622028508SToomas Soome		xorl %eax,%eax			# Zero
8722028508SToomas Soome		inb (%dx),%al			# Received data
8822028508SToomas Soome		andb $0x1,%al			#  ready?
8922028508SToomas Soome		ret				# To caller
90