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