sio.S revision 128707
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 * $FreeBSD: head/sys/boot/i386/boot2/sio.S 128707 2004-04-28 09:49:22Z ru $
16 */
17
18		.set SIO_PRT,SIOPRT		# Base port
19		.set SIO_FMT,SIOFMT		# 8N1
20		.set SIO_DIV,(115200/SIOSPD)	# 115200 / SPD
21
22		.globl sio_init
23		.globl sio_flush
24		.globl sio_putc
25		.globl sio_getc
26		.globl sio_ischar
27
28/* void sio_init(void) */
29
30sio_init:	movw $SIO_PRT+0x3,%dx		# Data format reg
31		movb $SIO_FMT|0x80,%al		# Set format
32		outb %al,(%dx)			#  and DLAB
33		pushl %edx			# Save
34		subb $0x3,%dl			# Divisor latch reg
35		movw $SIO_DIV,%ax		# Set
36		outw %ax,(%dx)			#  BPS
37		popl %edx			# Restore
38		movb $SIO_FMT,%al		# Clear
39		outb %al,(%dx)			#  DLAB
40		incl %edx			# Modem control reg
41		movb $0x3,%al			# Set RTS,
42		outb %al,(%dx)			#  DTR
43		incl %edx			# Line status reg
44
45/* void sio_flush(void) */
46
47sio_flush.0:	call sio_getc.1 		# Get character
48sio_flush:	call sio_ischar 		# Check for character
49		jnz sio_flush.0 		# Till none
50		ret				# To caller
51
52/* void sio_putc(int c) */
53
54sio_putc:	movw $SIO_PRT+0x5,%dx		# Line status reg
55		xor %ecx,%ecx			# Timeout
56		movb $0x40,%ch			#  counter
57sio_putc.1:	inb (%dx),%al			# Transmitter
58		testb $0x20,%al 		#  buffer empty?
59		loopz sio_putc.1		# No
60		jz sio_putc.2			# If timeout
61		movb 0x4(%esp,1),%al		# Get character
62		subb $0x5,%dl			# Transmitter hold reg
63		outb %al,(%dx)			# Write character
64sio_putc.2:	ret $0x4			# To caller
65
66/* int sio_getc(void) */
67
68sio_getc:	call sio_ischar 		# Character available?
69		jz sio_getc			# No
70sio_getc.1:	subb $0x5,%dl			# Receiver buffer reg
71		inb (%dx),%al			# Read character
72		ret				# To caller
73
74/* int sio_ischar(void) */
75
76sio_ischar:	movw $SIO_PRT+0x5,%dx		# Line status register
77		xorl %eax,%eax			# Zero
78		inb (%dx),%al			# Received data
79		andb $0x1,%al			#  ready?
80		ret				# To caller
81