sio.S revision 220337
1118824Sharti/*
2118824Sharti * Copyright (c) 1998 Robert Nordier
3118824Sharti * All rights reserved.
4119075Sobrien *
5118824Sharti * Redistribution and use in source and binary forms are freely
6118824Sharti * permitted provided that the above copyright notice and this
7119075Sobrien * paragraph and the following disclaimer are duplicated in all
8265420Simp * such forms.
9226440Scognet *
10118824Sharti * This software is provided "AS IS" and without any express or
11270027Sngie * implied warranties, including, without limitation, the implied
12118824Sharti * warranties of merchantability and fitness for a particular
13290083Sbdrewery * purpose.
14129215Scognet *
15133565Sharti * $FreeBSD: head/sys/boot/i386/boot2/sio.S 220337 2011-04-04 18:23:55Z rdivacky $
16133565Sharti */
17270027Sngie
18270027Sngie		.set SIO_PRT,SIOPRT		# Base port
19270027Sngie		.set SIO_FMT,SIOFMT		# 8N1
20275030Sbapt
21226440Scognet		.globl sio_init
22275030Sbapt		.globl sio_flush
23226440Scognet		.globl sio_putc
24133565Sharti		.globl sio_getc
25133565Sharti		.globl sio_ischar
26133565Sharti
27133565Sharti/* void sio_init(int div) */
28211725Simp
29211725Simpsio_init:	pushl %eax
30129215Scognet		movw $SIO_PRT+0x3,%dx		# Data format reg
31129215Scognet		movb $SIO_FMT|0x80,%al		# Set format
32118824Sharti		outb %al,(%dx)			#  and DLAB
33133565Sharti		subb $0x3,%dl			# Divisor latch reg
34290083Sbdrewery		popl %eax
35118824Sharti		outw %ax,(%dx)			#  BPS
36133565Sharti		movw $SIO_PRT+0x3,%dx		# Data format reg
37143617Sharti		movb $SIO_FMT,%al		# Clear
38133565Sharti		outb %al,(%dx)			#  DLAB
39270027Sngie		incl %edx			# Modem control reg
40133565Sharti		movb $0x3,%al			# Set RTS,
41270027Sngie		outb %al,(%dx)			#  DTR
42133565Sharti		incl %edx			# Line status reg
43118824Sharti		call sio_flush
44		ret
45
46/* void sio_flush(void) */
47
48sio_flush.0:	call sio_getc.1 		# Get character
49sio_flush:	call sio_ischar 		# Check for character
50		jnz sio_flush.0 		# Till none
51		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