This commit was manufactured by cvs2svn to create tag 'FreeBSD-release/1.0'.
[unix-history] / sys / i386 / boot / io.c
CommitLineData
15637ed4 1/*
15637ed4
RG
2 * Mach Operating System
3 * Copyright (c) 1992, 1991 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
78ed81a3 25 *
26 * from: Mach, Revision 2.2 92/04/04 11:35:57 rpd
27 * $Id$
15637ed4
RG
28 */
29
30#include <i386/include/pio.h>
31
32#define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
33#define K_STATUS 0x64 /* keyboard status */
34#define K_CMD 0x64 /* keybd ctlr command (write-only) */
35
36#define K_OBUF_FUL 0x01 /* output buffer full */
37#define K_IBUF_FUL 0x02 /* input buffer full */
38
39#define KC_CMD_WIN 0xd0 /* read output port */
40#define KC_CMD_WOUT 0xd1 /* write output port */
41#define KB_A20 0x9f /* enable A20,
42 enable output buffer full interrupt
43 enable data line
44 disable clock line */
45
46/*
47 * Gate A20 for high memory
48 */
49unsigned char x_20 = KB_A20;
50gateA20()
51{
52#ifdef IBM_L40
53 outb(0x92, 0x2);
54#else IBM_L40
55 while (inb(K_STATUS) & K_IBUF_FUL);
56 while (inb(K_STATUS) & K_OBUF_FUL)
57 (void)inb(K_RDWR);
58
59 outb(K_CMD, KC_CMD_WOUT);
60 while (inb(K_STATUS) & K_IBUF_FUL);
61 outb(K_RDWR, x_20);
62 while (inb(K_STATUS) & K_IBUF_FUL);
63#endif IBM_L40
64}
65
66/* printf - only handles %d as decimal, %c as char, %s as string */
67
68printf(format,data)
69 char *format;
70 int data;
71{
72 int *dataptr = &data;
73 char c;
78ed81a3 74
75 reset_twiddle();
15637ed4
RG
76 while (c = *format++)
77 if (c != '%')
78 putchar(c);
79 else
80 switch (c = *format++) {
81 case 'd': {
82 int num = *dataptr++;
83 char buf[10], *ptr = buf;
84 if (num<0) {
85 num = -num;
86 putchar('-');
87 }
88 do
89 *ptr++ = '0'+num%10;
90 while (num /= 10);
91 do
92 putchar(*--ptr);
93 while (ptr != buf);
94 break;
95 }
96 case 'x': {
97 int num = *dataptr++, dig;
98 char buf[8], *ptr = buf;
99 do
100 *ptr++ = (dig=(num&0xf)) > 9?
101 'a' + dig - 10 :
102 '0' + dig;
103 while (num >>= 4);
104 do
105 putchar(*--ptr);
106 while (ptr != buf);
107 break;
108 }
109 case 'c': putchar((*dataptr++)&0xff); break;
110 case 's': {
111 char *ptr = (char *)*dataptr++;
112 while (c = *ptr++)
113 putchar(c);
114 break;
115 }
116 }
117}
118
119putchar(c)
120{
121 if (c == '\n')
122 putc('\r');
123 putc(c);
124}
125
126getchar()
127{
128 int c;
129
130 if ((c=getc()) == '\r')
131 c = '\n';
132 if (c == '\b') {
133 putchar('\b');
134 putchar(' ');
135 }
136 putchar(c);
137 return(c);
138}
139
140gets(buf)
141char *buf;
142{
143 int i;
144 char *ptr=buf;
145
146 for (i = 240000; i>0; i--)
147 if (ischar())
148 for (;;)
149 switch(*ptr = getchar() & 0xff) {
150 case '\n':
151 case '\r':
152 *ptr = '\0';
153 return 1;
154 case '\b':
155 if (ptr > buf) ptr--;
156 continue;
157 default:
158 ptr++;
159 }
160 return 0;
161}
162
163strcmp(s1, s2)
164char *s1, *s2;
165{
166 while (*s1 == *s2) {
167 if (!*s1++)
168 return 0;
169 s2++;
170 }
171 return 1;
172}
173
174bcopy(from, to, len)
175char *from, *to;
176int len;
177{
178 while (len-- > 0)
179 *to++ = *from++;
180}
78ed81a3 181
182static int tw_on;
183static int tw_pos;
184static char tw_chars[] = "|/-\\";
185
186reset_twiddle()
187{
188 if (tw_on)
189 putchar('\b');
190 tw_on = 0;
191 tw_pos = 0;
192}
193
194twiddle()
195{
196 if (tw_on)
197 putchar('\b');
198 else
199 tw_on = 1;
200 putchar(tw_chars[tw_pos++]);
201 tw_pos %= (sizeof(tw_chars) - 1);
202}