Make sc0 the default to match our GENERIC* kernels.
[unix-history] / sys / i386 / netboot / misc.c
CommitLineData
db4d0741
MR
1/**************************************************************************
2MISC Support Routines
3**************************************************************************/
4
5#include "netboot.h"
6
7#define NO_SWITCH /* saves space */
8
9/**************************************************************************
10TWIDDLE
11**************************************************************************/
12twiddle()
13{
14 static int count=0;
15 char tiddles[]="-\\|/";
16 putchar(tiddles[(count++)&3]);
17 putchar('\b');
18}
19
20/**************************************************************************
21BCOPY
22**************************************************************************/
23bcopy(s,d,n)
24 char *s, *d;
25 int n;
26{
27 while ((n--) > 0) {
28 *(d++) = *(s++);
29 }
30}
31
32/**************************************************************************
33BZERO
34**************************************************************************/
35bzero(d,n)
36 char *d;
37 int n;
38{
39 while ((n--) > 0) {
40 *(d++) = 0;
41 }
42}
43
44/**************************************************************************
45BCOMPARE
46**************************************************************************/
47bcompare(d,s,n)
48 char *d,*s;
49 int n;
50{
51 while ((n--) > 0) {
52 if (*(d++) != *(s++)) return(0);
53 }
54 return(1);
55}
56
57
58/**************************************************************************
59PRINTF
60**************************************************************************/
61printf(fmt, data)
62 char *fmt;
63 int data;
64{
65 char *p;
66 int *dp = &data;
67 while (*fmt) {
68 if (*fmt == '%') { /* switch() uses more space */
69 fmt++;
70 if (*fmt == 'X')
71 printhl(*dp++);
72 if (*fmt == 'x')
73 printhw(*dp++);
74 if (*fmt == 'd')
75 printdec(*dp++);
76 if (*fmt == 'I')
77 printip(*dp++);
78 if (*fmt == 'c')
79 putchar(*(dp++) & 0x00FF);
80 if (*fmt == 's') {
81 p = (char *)*dp++;
82 while (*p) putchar(*p++);
83 }
84 } else putchar(*fmt);
85 fmt++;
86 }
87 return(0);
88}
89
90
91/**************************************************************************
92PRINTDEC - Print a number in decimal
93**************************************************************************/
94printdec(n)
95 int n;
96{
97 char buf[16], *p;
98 p = buf;
99 if (n < 0) {
100 putchar('-');
101 n = -n;
102 }
103 do {
104 *(p++) = '0' + (n%10);
105 n = n/10;
106 } while(n);
107 while ((--p) >= buf) putchar(*p);
108}
109
110char *putdec(p, n)
111 char *p;
112 int n;
113{
114 n = n & 0x00FF;
115 if (n/100) *(p++) = '0' + (n/100);
116 if (n/10) *(p++) = '0' + ((n/10) % 10);
117 *(p++) = '0' + (n%10);
118 return(p);
119}
120
121/**************************************************************************
122PRINTDEC - Print a number in decimal
123**************************************************************************/
124static char hex[]="0123456789ABCDEF";
125printhl(h) {
126 printhw(h>>16);
127 printhw(h);
128}
129printhw(h) {
130 printhb(h>>8);
131 printhb(h);
132}
133printhb(h) {
134 putchar(hex[(h>>4)& 0x0F]);
135 putchar(hex[h &0x0F]);
136}
137
138/**************************************************************************
139PRINTIP - Print an IP address in x.x.x.x notation
140**************************************************************************/
141printip(i)
142 unsigned i;
143{
144 printdec((i>>24) & 0x0FF);
145 putchar('.');
146 printdec((i>>16) & 0x0FF);
147 putchar('.');
148 printdec((i>>8) & 0x0FF);
149 putchar('.');
150 printdec(i & 0x0FF);
151}
152
153/**************************************************************************
154SETIP - Convert an ascii x.x.x.x to binary form
155**************************************************************************/
156setip(p, i)
157 char *p;
158 unsigned *i;
159{
160 unsigned ip = 0;
161 int val;
162 if (((val = getdec(&p)) < 0) || (val > 255)) return(0);
163 if (*p != '.') return(0);
164 p++;
165 ip = val;
166 if (((val = getdec(&p)) < 0) || (val > 255)) return(0);
167 if (*p != '.') return(0);
168 p++;
169 ip = (ip << 8) | val;
170 if (((val = getdec(&p)) < 0) || (val > 255)) return(0);
171 if (*p != '.') return(0);
172 p++;
173 ip = (ip << 8) | val;
174 if (((val = getdec(&p)) < 0) || (val > 255)) return(0);
175 *i = (ip << 8) | val;
176 return(1);
177}
178
179getdec(ptr)
180 char **ptr;
181{
182 char *p = *ptr;
183 int ret=0;
184 if ((*p < '0') || (*p > '9')) return(-1);
185 while ((*p >= '0') && (*p <= '9')) {
186 ret = ret*10 + (*p - '0');
187 p++;
188 }
189 *ptr = p;
190 return(ret);
191}
192
193
194#define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
195#define K_STATUS 0x64 /* keyboard status */
196#define K_CMD 0x64 /* keybd ctlr command (write-only) */
197
198#define K_OBUF_FUL 0x01 /* output buffer full */
199#define K_IBUF_FUL 0x02 /* input buffer full */
200
201#define KC_CMD_WIN 0xd0 /* read output port */
202#define KC_CMD_WOUT 0xd1 /* write output port */
203#define KB_A20 0x9f /* enable A20,
204 enable output buffer full interrupt
205 enable data line
206 disable clock line */
207
208/*
209 * Gate A20 for high memory
210 */
211unsigned char x_20 = KB_A20;
212gateA20()
213{
214#ifdef IBM_L40
215 outb(0x92, 0x2);
216#else IBM_L40
217 while (inb(K_STATUS) & K_IBUF_FUL);
218 while (inb(K_STATUS) & K_OBUF_FUL)
219 (void)inb(K_RDWR);
220
221 outb(K_CMD, KC_CMD_WOUT);
222 while (inb(K_STATUS) & K_IBUF_FUL);
223 outb(K_RDWR, x_20);
224 while (inb(K_STATUS) & K_IBUF_FUL);
225#endif IBM_L40
226}
227