sio.S revision 125932
1305153Sjkim#
2305153Sjkim# Copyright (c) 1998 Robert Nordier
3238405Sjkim# All rights reserved.
4238405Sjkim#
5290207Sjkim# Redistribution and use in source and binary forms are freely
6238405Sjkim# permitted provided that the above copyright notice and this
7238405Sjkim# paragraph and the following disclaimer are duplicated in all
8238405Sjkim# such forms.
9238405Sjkim#
10299481Sjkim# This software is provided "AS IS" and without any express or
11299481Sjkim# implied warranties, including, without limitation, the implied
12299481Sjkim# warranties of merchantability and fitness for a particular
13299481Sjkim# purpose.
14299481Sjkim#
15299481Sjkim
16299481Sjkim# $FreeBSD: head/sys/boot/i386/boot2/sio.S 125932 2004-02-17 07:13:04Z ru $
17299481Sjkim
18299481Sjkim		.set SIO_PRT,SIOPRT		# Base port
19299481Sjkim		.set SIO_FMT,SIOFMT		# 8N1
20299481Sjkim		.set SIO_DIV,(115200/SIOSPD)	# 115200 / SPD
21299481Sjkim
22299481Sjkim		.globl sio_init
23299481Sjkim		.globl sio_flush
24238405Sjkim		.globl sio_putc
25238405Sjkim		.globl sio_getc
26238405Sjkim		.globl sio_ischar
27238405Sjkim
28238405Sjkim# void sio_init(void)
29238405Sjkim
30238405Sjkimsio_init:	movw $SIO_PRT+0x3,%dx		# Data format reg
31238405Sjkim		movb $SIO_FMT|0x80,%al		# Set format
32238405Sjkim		outb %al,(%dx)			#  and DLAB
33238405Sjkim		pushl %edx			# Save
34238405Sjkim		subb $0x3,%dl			# Divisor latch reg
35238405Sjkim		movw $SIO_DIV,%ax		# Set
36238405Sjkim		outw %ax,(%dx)			#  BPS
37238405Sjkim		popl %edx			# Restore
38238405Sjkim		movb $SIO_FMT,%al		# Clear
39238405Sjkim		outb %al,(%dx)			#  DLAB
40238405Sjkim		incl %edx			# Modem control reg
41238405Sjkim		movb $0x3,%al			# Set RTS,
42238405Sjkim		outb %al,(%dx)			#  DTR
43238405Sjkim		incl %edx			# Line status reg
44238405Sjkim
45238405Sjkim# void sio_flush(void)
46238405Sjkim
47238405Sjkimsio_flush.0:	call sio_getc.1 		# Get character
48238405Sjkimsio_flush:	call sio_ischar 		# Check for character
49238405Sjkim		jnz sio_flush.0 		# Till none
50238405Sjkim		ret				# To caller
51238405Sjkim
52238405Sjkim# void sio_putc(int c)
53290207Sjkim
54290207Sjkimsio_putc:	movw $SIO_PRT+0x5,%dx		# Line status reg
55290207Sjkim		xor %ecx,%ecx			# Timeout
56238405Sjkim		movb $0x40,%ch			#  counter
57238405Sjkimsio_putc.1:	inb (%dx),%al			# Transmitter
58238405Sjkim		testb $0x20,%al 		#  buffer empty?
59238405Sjkim		loopz sio_putc.1		# No
60238405Sjkim		jz sio_putc.2			# If timeout
61238405Sjkim		movb 0x4(%esp,1),%al		# Get character
62238405Sjkim		subb $0x5,%dl			# Transmitter hold reg
63290207Sjkim		outb %al,(%dx)			# Write character
64238405Sjkimsio_putc.2:	ret $0x4			# To caller
65238405Sjkim
66238405Sjkim# int sio_getc(void)
67290207Sjkim
68290207Sjkimsio_getc:	call sio_ischar 		# Character available?
69290207Sjkim		jz sio_getc			# No
70290207Sjkimsio_getc.1:	subb $0x5,%dl			# Receiver buffer reg
71238405Sjkim		inb (%dx),%al			# Read character
72238405Sjkim		ret				# To caller
73290207Sjkim
74238405Sjkim# int sio_ischar(void)
75238405Sjkim
76238405Sjkimsio_ischar:	movw $SIO_PRT+0x5,%dx		# Line status register
77290207Sjkim		xorl %eax,%eax			# Zero
78238405Sjkim		inb (%dx),%al			# Received data
79290207Sjkim		andb $0x1,%al			#  ready?
80290207Sjkim		ret				# To caller
81238405Sjkim