sio.S revision 129240
1128707Sru/*
2128707Sru * Copyright (c) 1998 Robert Nordier
3128707Sru * All rights reserved.
4128707Sru *
5128707Sru * Redistribution and use in source and binary forms are freely
6128707Sru * permitted provided that the above copyright notice and this
7128707Sru * paragraph and the following disclaimer are duplicated in all
8128707Sru * such forms.
9128707Sru *
10128707Sru * This software is provided "AS IS" and without any express or
11128707Sru * implied warranties, including, without limitation, the implied
12128707Sru * warranties of merchantability and fitness for a particular
13128707Sru * purpose.
14128707Sru *
15128707Sru * $FreeBSD: head/sys/boot/i386/boot2/sio.S 129240 2004-05-14 20:29:30Z ru $
16128707Sru */
17125932Sru
18129240Sru		.set SIO_PRT,SIOPRT		# Base port
19129240Sru		.set SIO_FMT,SIOFMT		# 8N1
20129240Sru		.set SIO_DIV,(115200/SIOSPD)	# 115200 / SPD
21125932Sru
22125932Sru		.globl sio_init
23125932Sru		.globl sio_flush
24125932Sru		.globl sio_putc
25125932Sru		.globl sio_getc
26125932Sru		.globl sio_ischar
27125932Sru
28128707Sru/* void sio_init(void) */
29125932Sru
30129240Srusio_init:	movw $SIO_PRT+0x3,%dx		# Data format reg
31129240Sru		movb $SIO_FMT|0x80,%al		# Set format
32129240Sru		outb %al,(%dx)			#  and DLAB
33129240Sru		pushl %edx			# Save
34129240Sru		subb $0x3,%dl			# Divisor latch reg
35129240Sru		movw $SIO_DIV,%ax		# Set
36129240Sru		outw %ax,(%dx)			#  BPS
37129240Sru		popl %edx			# Restore
38129240Sru		movb $SIO_FMT,%al		# Clear
39129240Sru		outb %al,(%dx)			#  DLAB
40129240Sru		incl %edx			# Modem control reg
41129240Sru		movb $0x3,%al			# Set RTS,
42129240Sru		outb %al,(%dx)			#  DTR
43129240Sru		incl %edx			# Line status reg
44125932Sru
45128707Sru/* void sio_flush(void) */
46125932Sru
47129240Srusio_flush.0:	call sio_getc.1 		# Get character
48129240Srusio_flush:	call sio_ischar 		# Check for character
49129240Sru		jnz sio_flush.0 		# Till none
50129240Sru		ret				# To caller
51125932Sru
52128707Sru/* void sio_putc(int c) */
53125932Sru
54129240Srusio_putc:	movw $SIO_PRT+0x5,%dx		# Line status reg
55129240Sru		xor %ecx,%ecx			# Timeout
56129240Sru		movb $0x40,%ch			#  counter
57129240Srusio_putc.1:	inb (%dx),%al			# Transmitter
58129240Sru		testb $0x20,%al 		#  buffer empty?
59129240Sru		loopz sio_putc.1		# No
60129240Sru		jz sio_putc.2			# If timeout
61129240Sru		movb 0x4(%esp,1),%al		# Get character
62129240Sru		subb $0x5,%dl			# Transmitter hold reg
63129240Sru		outb %al,(%dx)			# Write character
64129240Srusio_putc.2:	ret $0x4			# To caller
65125932Sru
66128707Sru/* int sio_getc(void) */
67125932Sru
68129240Srusio_getc:	call sio_ischar 		# Character available?
69129240Sru		jz sio_getc			# No
70129240Srusio_getc.1:	subb $0x5,%dl			# Receiver buffer reg
71129240Sru		inb (%dx),%al			# Read character
72129240Sru		ret				# To caller
73125932Sru
74128707Sru/* int sio_ischar(void) */
75125932Sru
76129240Srusio_ischar:	movw $SIO_PRT+0x5,%dx		# Line status register
77129240Sru		xorl %eax,%eax			# Zero
78129240Sru		inb (%dx),%al			# Received data
79129240Sru		andb $0x1,%al			#  ready?
80129240Sru		ret				# To caller
81