xref: /minix3/sys/arch/i386/stand/lib/comio.S (revision 58a2b0008e28f606a7f7f5faaeaba4faac57a1ea)
1*58a2b000SEvgeniy Ivanov/*	$NetBSD: comio.S,v 1.4 2003/04/16 14:23:11 dsl Exp $	*/
2*58a2b000SEvgeniy Ivanov
3*58a2b000SEvgeniy Ivanov/* serial console handling
4*58a2b000SEvgeniy Ivanov  modelled after code in FreeBSD:sys/i386/boot/netboot/start2.S
5*58a2b000SEvgeniy Ivanov */
6*58a2b000SEvgeniy Ivanov
7*58a2b000SEvgeniy Ivanov#include <machine/asm.h>
8*58a2b000SEvgeniy Ivanov
9*58a2b000SEvgeniy Ivanov	.text
10*58a2b000SEvgeniy Ivanov
11*58a2b000SEvgeniy Ivanov/**************************************************************************
12*58a2b000SEvgeniy IvanovINIT - Initialization (com number)
13*58a2b000SEvgeniy Ivanov**************************************************************************/
14*58a2b000SEvgeniy IvanovENTRY(cominit)
15*58a2b000SEvgeniy Ivanov	push	%ebp
16*58a2b000SEvgeniy Ivanov	mov	%esp,%ebp
17*58a2b000SEvgeniy Ivanov	push	%ebx
18*58a2b000SEvgeniy Ivanov	push	%edx
19*58a2b000SEvgeniy Ivanov	push	%esi
20*58a2b000SEvgeniy Ivanov	push	%edi
21*58a2b000SEvgeniy Ivanov
22*58a2b000SEvgeniy Ivanov	movl	8(%ebp), %edx
23*58a2b000SEvgeniy Ivanov
24*58a2b000SEvgeniy Ivanov	call	_C_LABEL(prot_to_real)	# enter real mode
25*58a2b000SEvgeniy Ivanov	.code16
26*58a2b000SEvgeniy Ivanov
27*58a2b000SEvgeniy Ivanov	# Initialize the serial port (dl) to 9600 baud, 8N1.
28*58a2b000SEvgeniy Ivanov	movb	$0xe3, %al
29*58a2b000SEvgeniy Ivanov	movb	$0, %ah
30*58a2b000SEvgeniy Ivanov	int	$0x14
31*58a2b000SEvgeniy Ivanov	mov	%ax,%bx
32*58a2b000SEvgeniy Ivanov
33*58a2b000SEvgeniy Ivanov	calll	_C_LABEL(real_to_prot) # back to protected mode
34*58a2b000SEvgeniy Ivanov	.code32
35*58a2b000SEvgeniy Ivanov
36*58a2b000SEvgeniy Ivanov	xor	%eax,%eax
37*58a2b000SEvgeniy Ivanov	mov	%bx,%ax
38*58a2b000SEvgeniy Ivanov
39*58a2b000SEvgeniy Ivanov	pop	%edi
40*58a2b000SEvgeniy Ivanov	pop	%esi
41*58a2b000SEvgeniy Ivanov	pop	%edx
42*58a2b000SEvgeniy Ivanov	pop	%ebx
43*58a2b000SEvgeniy Ivanov	pop	%ebp
44*58a2b000SEvgeniy Ivanov	ret
45*58a2b000SEvgeniy Ivanov
46*58a2b000SEvgeniy Ivanov/**************************************************************************
47*58a2b000SEvgeniy IvanovPUTC - Print a character (char, com number)
48*58a2b000SEvgeniy Ivanov**************************************************************************/
49*58a2b000SEvgeniy IvanovENTRY(computc)
50*58a2b000SEvgeniy Ivanov	push	%ebp
51*58a2b000SEvgeniy Ivanov	mov	%esp,%ebp
52*58a2b000SEvgeniy Ivanov	push	%ecx
53*58a2b000SEvgeniy Ivanov	push	%ebx
54*58a2b000SEvgeniy Ivanov	push	%edx
55*58a2b000SEvgeniy Ivanov	push	%esi
56*58a2b000SEvgeniy Ivanov	push	%edi
57*58a2b000SEvgeniy Ivanov
58*58a2b000SEvgeniy Ivanov	movb	8(%ebp),%cl
59*58a2b000SEvgeniy Ivanov	movl	12(%ebp),%edx
60*58a2b000SEvgeniy Ivanov
61*58a2b000SEvgeniy Ivanov	call	_C_LABEL(prot_to_real)	# enter real mode
62*58a2b000SEvgeniy Ivanov	.code16
63*58a2b000SEvgeniy Ivanov
64*58a2b000SEvgeniy Ivanov	movb	%cl,%al
65*58a2b000SEvgeniy Ivanov	movb	$0x01, %ah
66*58a2b000SEvgeniy Ivanov	int	$0x14
67*58a2b000SEvgeniy Ivanov
68*58a2b000SEvgeniy Ivanov	movb	%ah,%bl
69*58a2b000SEvgeniy Ivanov
70*58a2b000SEvgeniy Ivanov	calll	_C_LABEL(real_to_prot) # back to protected mode
71*58a2b000SEvgeniy Ivanov	.code32
72*58a2b000SEvgeniy Ivanov
73*58a2b000SEvgeniy Ivanov	xor	%eax,%eax
74*58a2b000SEvgeniy Ivanov	movb	%bl,%al
75*58a2b000SEvgeniy Ivanov
76*58a2b000SEvgeniy Ivanov	pop	%edi
77*58a2b000SEvgeniy Ivanov	pop	%esi
78*58a2b000SEvgeniy Ivanov	pop	%edx
79*58a2b000SEvgeniy Ivanov	pop	%ebx
80*58a2b000SEvgeniy Ivanov	pop	%ecx
81*58a2b000SEvgeniy Ivanov	pop	%ebp
82*58a2b000SEvgeniy Ivanov	ret
83*58a2b000SEvgeniy Ivanov
84*58a2b000SEvgeniy Ivanov/**************************************************************************
85*58a2b000SEvgeniy IvanovGETC - Get a character (com number)
86*58a2b000SEvgeniy Ivanov**************************************************************************/
87*58a2b000SEvgeniy IvanovENTRY(comgetc)
88*58a2b000SEvgeniy Ivanov	push	%ebp
89*58a2b000SEvgeniy Ivanov	mov	%esp,%ebp
90*58a2b000SEvgeniy Ivanov	push	%ebx
91*58a2b000SEvgeniy Ivanov	push	%edx
92*58a2b000SEvgeniy Ivanov	push	%esi
93*58a2b000SEvgeniy Ivanov	push	%edi
94*58a2b000SEvgeniy Ivanov
95*58a2b000SEvgeniy Ivanov	movl	8(%ebp),%edx
96*58a2b000SEvgeniy Ivanov
97*58a2b000SEvgeniy Ivanov	call	_C_LABEL(prot_to_real)	# enter real mode
98*58a2b000SEvgeniy Ivanov	.code16
99*58a2b000SEvgeniy Ivanov
100*58a2b000SEvgeniy Ivanov	movb	$0x02, %ah
101*58a2b000SEvgeniy Ivanov	int	$0x14
102*58a2b000SEvgeniy Ivanov	mov	%ax, %bx
103*58a2b000SEvgeniy Ivanov
104*58a2b000SEvgeniy Ivanov	calll	_C_LABEL(real_to_prot) # back to protected mode
105*58a2b000SEvgeniy Ivanov	.code32
106*58a2b000SEvgeniy Ivanov
107*58a2b000SEvgeniy Ivanov	xor	%eax,%eax
108*58a2b000SEvgeniy Ivanov	mov	%bx,%ax
109*58a2b000SEvgeniy Ivanov
110*58a2b000SEvgeniy Ivanov	pop	%edi
111*58a2b000SEvgeniy Ivanov	pop	%esi
112*58a2b000SEvgeniy Ivanov	pop	%edx
113*58a2b000SEvgeniy Ivanov	pop	%ebx
114*58a2b000SEvgeniy Ivanov	pop	%ebp
115*58a2b000SEvgeniy Ivanov	ret
116*58a2b000SEvgeniy Ivanov
117*58a2b000SEvgeniy Ivanov/**************************************************************************
118*58a2b000SEvgeniy IvanovISKEY - Check for keyboard interrupt (com number)
119*58a2b000SEvgeniy Ivanov**************************************************************************/
120*58a2b000SEvgeniy IvanovENTRY(comstatus)
121*58a2b000SEvgeniy Ivanov	push	%ebp
122*58a2b000SEvgeniy Ivanov	mov	%esp,%ebp
123*58a2b000SEvgeniy Ivanov	push	%ebx
124*58a2b000SEvgeniy Ivanov	push	%edx
125*58a2b000SEvgeniy Ivanov	push	%esi
126*58a2b000SEvgeniy Ivanov	push	%edi
127*58a2b000SEvgeniy Ivanov
128*58a2b000SEvgeniy Ivanov	movl	8(%ebp),%edx
129*58a2b000SEvgeniy Ivanov
130*58a2b000SEvgeniy Ivanov	call	_C_LABEL(prot_to_real)	# enter real mode
131*58a2b000SEvgeniy Ivanov	.code16
132*58a2b000SEvgeniy Ivanov
133*58a2b000SEvgeniy Ivanov	movb	$0x03, %ah
134*58a2b000SEvgeniy Ivanov	int	$0x14
135*58a2b000SEvgeniy Ivanov	mov	%ax,%bx
136*58a2b000SEvgeniy Ivanov
137*58a2b000SEvgeniy Ivanov	calll	_C_LABEL(real_to_prot) # back to protected mode
138*58a2b000SEvgeniy Ivanov	.code32
139*58a2b000SEvgeniy Ivanov
140*58a2b000SEvgeniy Ivanov	xor	%eax,%eax
141*58a2b000SEvgeniy Ivanov	mov	%bx,%ax
142*58a2b000SEvgeniy Ivanov
143*58a2b000SEvgeniy Ivanov	pop	%edi
144*58a2b000SEvgeniy Ivanov	pop	%esi
145*58a2b000SEvgeniy Ivanov	pop	%edx
146*58a2b000SEvgeniy Ivanov	pop	%ebx
147*58a2b000SEvgeniy Ivanov	pop	%ebp
148*58a2b000SEvgeniy Ivanov	ret
149