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