xref: /illumos-gate/usr/src/boot/i386/gptzfsboot/sio.S (revision ceb3ef19)
1199767f8SToomas Soome/*
2199767f8SToomas Soome * Copyright (c) 1998 Robert Nordier
3199767f8SToomas Soome * All rights reserved.
4199767f8SToomas Soome *
5199767f8SToomas Soome * Redistribution and use in source and binary forms are freely
6199767f8SToomas Soome * permitted provided that the above copyright notice and this
7199767f8SToomas Soome * paragraph and the following disclaimer are duplicated in all
8199767f8SToomas Soome * such forms.
9199767f8SToomas Soome *
10199767f8SToomas Soome * This software is provided "AS IS" and without any express or
11199767f8SToomas Soome * implied warranties, including, without limitation, the implied
12199767f8SToomas Soome * warranties of merchantability and fitness for a particular
13199767f8SToomas Soome * purpose.
14199767f8SToomas Soome */
15199767f8SToomas Soome
16199767f8SToomas Soome		.set SIO_FMT,SIOFMT		# 8N1
17199767f8SToomas Soome
18*ceb3ef19SToomas Soome/* int sio_port */
19*ceb3ef19SToomas Soomesio_port:	.long SIOPRT			# Base port
20*ceb3ef19SToomas Soome
21*ceb3ef19SToomas Soome		.globl sio_port
22199767f8SToomas Soome		.globl sio_init
23199767f8SToomas Soome		.globl sio_flush
24199767f8SToomas Soome		.globl sio_putc
25199767f8SToomas Soome		.globl sio_getc
26199767f8SToomas Soome		.globl sio_ischar
27199767f8SToomas Soome
28199767f8SToomas Soome/* int sio_init(int div) */
29199767f8SToomas Soome
30199767f8SToomas Soomesio_init:	pushl %eax
31*ceb3ef19SToomas Soome		movl (sio_port),%edx
32*ceb3ef19SToomas Soome		addl $0x3,%edx			# Data format reg
33199767f8SToomas Soome		movb $SIO_FMT|0x80,%al		# Set format
34199767f8SToomas Soome		outb %al,(%dx)			#  and DLAB
35199767f8SToomas Soome		subb $0x3,%dl			# Divisor latch reg
36199767f8SToomas Soome		popl %eax
37199767f8SToomas Soome		outw %ax,(%dx)			#  BPS
38*ceb3ef19SToomas Soome		movl (sio_port),%edx
39*ceb3ef19SToomas Soome		addl $0x3,%edx			# Data format reg
40199767f8SToomas Soome		movb $SIO_FMT,%al		# Clear
41199767f8SToomas Soome		outb %al,(%dx)			#  DLAB
42199767f8SToomas Soome		incl %edx			# Modem control reg
43199767f8SToomas Soome		movb $0x3,%al			# Set RTS,
44199767f8SToomas Soome		outb %al,(%dx)			#  DTR
45199767f8SToomas Soome		incl %edx			# Line status reg
46199767f8SToomas Soome		# Fallthrough
47199767f8SToomas Soome
48199767f8SToomas Soome/* int sio_flush(void) */
49199767f8SToomas Soome
50199767f8SToomas Soomesio_flush:	xorl %ecx,%ecx			# Timeout
51199767f8SToomas Soome		movb $0x80,%ch			#  counter
52199767f8SToomas Soomesio_flush.1:	call sio_ischar 		# Check for character
53199767f8SToomas Soome		jz sio_flush.2			# Till none
54199767f8SToomas Soome		loop sio_flush.1		#  or counter is zero
55199767f8SToomas Soome		movb $1, %al			# Exhausted all tries
56199767f8SToomas Soomesio_flush.2:	ret				# To caller
57199767f8SToomas Soome
58199767f8SToomas Soome/* void sio_putc(int c) */
59199767f8SToomas Soome
60199767f8SToomas Soomesio_putc:	pushl %eax
61*ceb3ef19SToomas Soome		movl (sio_port),%edx
62*ceb3ef19SToomas Soome		addl $0x5,%edx			# Line status reg
63199767f8SToomas Soome		xor %ecx,%ecx			# Timeout
64199767f8SToomas Soome		movb $0x40,%ch			#  counter
65199767f8SToomas Soomesio_putc.1:	inb (%dx),%al			# Transmitter
66199767f8SToomas Soome		testb $0x20,%al 		#  buffer empty?
67199767f8SToomas Soome		loopz sio_putc.1		# No
68199767f8SToomas Soome		jz sio_putc.2			# If timeout
69199767f8SToomas Soome		popl %eax                       # Get the character
70199767f8SToomas Soome		subb $0x5,%dl			# Transmitter hold reg
71199767f8SToomas Soome		outb %al,(%dx)			# Write character
72199767f8SToomas Soomesio_putc.2:	ret				# To caller
73199767f8SToomas Soome
74199767f8SToomas Soome/* int sio_getc(void) */
75199767f8SToomas Soome
76199767f8SToomas Soomesio_getc:	call sio_ischar 		# Character available?
77199767f8SToomas Soome		jz sio_getc			# No
78199767f8SToomas Soomesio_getc.1:	subb $0x5,%dl			# Receiver buffer reg
79199767f8SToomas Soome		inb (%dx),%al			# Read character
80199767f8SToomas Soome		ret				# To caller
81199767f8SToomas Soome
82199767f8SToomas Soome/* int sio_ischar(void) */
83199767f8SToomas Soome
84*ceb3ef19SToomas Soomesio_ischar:	movl (sio_port),%edx
85*ceb3ef19SToomas Soome		addl $0x5,%edx			# Line status register
86199767f8SToomas Soome		xorl %eax,%eax			# Zero
87199767f8SToomas Soome		inb (%dx),%al			# Received data
88199767f8SToomas Soome		andb $0x1,%al			#  ready?
89199767f8SToomas Soome		ret				# To caller
90