xref: /freebsd/stand/i386/boot2/sio.S (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
1/*
2 * Copyright (c) 1998 Robert Nordier
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are freely
6 * permitted provided that the above copyright notice and this
7 * paragraph and the following disclaimer are duplicated in all
8 * such forms.
9 *
10 * This software is provided "AS IS" and without any express or
11 * implied warranties, including, without limitation, the implied
12 * warranties of merchantability and fitness for a particular
13 * purpose.
14 */
15
16		.set SIO_PRT,SIOPRT		# Base port
17		.set SIO_FMT,SIOFMT		# 8N1
18
19		.globl sio_init
20		.globl sio_flush
21		.globl sio_putc
22		.globl sio_getc
23		.globl sio_ischar
24
25/* int sio_init(int div) */
26
27sio_init:	pushl %eax
28		movw $SIO_PRT+0x3,%dx		# Data format reg
29		movb $SIO_FMT|0x80,%al		# Set format
30		outb %al,(%dx)			#  and DLAB
31		subb $0x3,%dl			# Divisor latch reg
32		popl %eax
33		outw %ax,(%dx)			#  BPS
34		movw $SIO_PRT+0x3,%dx		# Data format reg
35		movb $SIO_FMT,%al		# Clear
36		outb %al,(%dx)			#  DLAB
37		incl %edx			# Modem control reg
38		movb $0x3,%al			# Set RTS,
39		outb %al,(%dx)			#  DTR
40		incl %edx			# Line status reg
41		# Fallthrough
42
43/* int sio_flush(void) */
44
45sio_flush:	xorl %ecx,%ecx			# Timeout
46		movb $0x80,%ch			#  counter
47sio_flush.1:	call sio_ischar 		# Check for character
48		jz sio_flush.2			# Till none
49		loop sio_flush.1		#  or counter is zero
50		movb $1, %al			# Exhausted all tries
51sio_flush.2:	ret				# To caller
52
53/* void sio_putc(int c) */
54
55sio_putc:	pushl %eax
56		movw $SIO_PRT+0x5,%dx		# Line status reg
57		xor %ecx,%ecx			# Timeout
58		movb $0x40,%ch			#  counter
59sio_putc.1:	inb (%dx),%al			# Transmitter
60		testb $0x20,%al 		#  buffer empty?
61		loopz sio_putc.1		# No
62		jz sio_putc.2			# If timeout
63		popl %eax                       # Get the character
64		subb $0x5,%dl			# Transmitter hold reg
65		outb %al,(%dx)			# Write character
66sio_putc.2:	ret				# To caller
67
68/* int sio_getc(void) */
69
70sio_getc:	call sio_ischar 		# Character available?
71		jz sio_getc			# No
72sio_getc.1:	subb $0x5,%dl			# Receiver buffer reg
73		inb (%dx),%al			# Read character
74		ret				# To caller
75
76/* int sio_ischar(void) */
77
78sio_ischar:	movw $SIO_PRT+0x5,%dx		# Line status register
79		xorl %eax,%eax			# Zero
80		inb (%dx),%al			# Received data
81		andb $0x1,%al			#  ready?
82		ret				# To caller
83