1 /**************************************************************************
3 **************************************************************************/
7 /**************************************************************************
9 **************************************************************************/
14 for (tmo
= currticks()+secs
*TICKS_PER_SEC
; currticks() < tmo
; )
18 /**************************************************************************
20 **************************************************************************/
23 static unsigned long lastticks
= 0;
25 static const char tiddles
[]="-\\|/";
27 if ((ticks
= currticks()) == lastticks
)
30 putchar(tiddles
[(count
++)&3]);
34 /**************************************************************************
35 STRCASECMP (not entirely correct, but this will do for our purposes)
36 **************************************************************************/
40 while (*a
&& *b
&& (*a
& ~0x20) == (*b
& ~0x20)) {a
++; b
++; }
41 return((*a
& ~0x20) - (*b
& ~0x20));
44 /**************************************************************************
48 %[#]X - 4 bytes long (8 hex digits)
49 %[#]x - 2 bytes int (4 hex digits)
50 - optional # prefixes 0x
51 %b - 1 byte int (2 hex digits)
55 %I - Internet address in x.x.x.x notation
56 Note: width specification not supported
57 **************************************************************************/
58 static char *do_printf(char *buf
, const char *fmt
, const int *dp
)
63 static const char hex
[]="0123456789ABCDEF";
66 if (*fmt
== '%') { /* switch() uses more space */
74 const long *lp
= (const long *)dp
;
75 register long h
= *lp
++;
81 *(buf
++) = hex
[(h
>>28)& 0x0F];
82 *(buf
++) = hex
[(h
>>24)& 0x0F];
83 *(buf
++) = hex
[(h
>>20)& 0x0F];
84 *(buf
++) = hex
[(h
>>16)& 0x0F];
85 *(buf
++) = hex
[(h
>>12)& 0x0F];
86 *(buf
++) = hex
[(h
>>8)& 0x0F];
87 *(buf
++) = hex
[(h
>>4)& 0x0F];
88 *(buf
++) = hex
[h
& 0x0F];
91 register int h
= *(dp
++);
96 *(buf
++) = hex
[(h
>>12)& 0x0F];
97 *(buf
++) = hex
[(h
>>8)& 0x0F];
98 *(buf
++) = hex
[(h
>>4)& 0x0F];
99 *(buf
++) = hex
[h
& 0x0F];
102 register int h
= *(dp
++);
103 *(buf
++) = hex
[(h
>>4)& 0x0F];
104 *(buf
++) = hex
[h
& 0x0F];
107 register int dec
= *(dp
++);
114 *(p
++) = '0' + (dec
%10);
117 while ((--p
) >= tmp
) *(buf
++) = *p
;
124 const long *lp
= (const long *)dp
;
126 dp
= (const int *)lp
;
127 buf
= sprintf(buf
,"%d.%d.%d.%d",
128 u
.c
[0], u
.c
[1], u
.c
[2], u
.c
[3]);
134 while (*p
) *(buf
++) = *p
++;
136 } else *(buf
++) = *fmt
;
143 char *sprintf(char *buf
, const char *fmt
, ...)
145 return do_printf(buf
, fmt
, ((const int *)&fmt
)+1);
148 void printf(const char *fmt
, ...)
153 do_printf(buf
, fmt
, ((const int *)&fmt
)+1);
154 while (*p
) putchar(*p
++);
158 /**************************************************************************
159 INET_ATON - Convert an ascii x.x.x.x to binary form
160 **************************************************************************/
161 int inet_aton(char *p
, in_addr
*i
)
163 unsigned long ip
= 0;
165 if (((val
= getdec(&p
)) < 0) || (val
> 255)) return(0);
166 if (*p
!= '.') return(0);
169 if (((val
= getdec(&p
)) < 0) || (val
> 255)) return(0);
170 if (*p
!= '.') return(0);
172 ip
= (ip
<< 8) | val
;
173 if (((val
= getdec(&p
)) < 0) || (val
> 255)) return(0);
174 if (*p
!= '.') return(0);
176 ip
= (ip
<< 8) | val
;
177 if (((val
= getdec(&p
)) < 0) || (val
> 255)) return(0);
178 i
->s_addr
= htonl((ip
<< 8) | val
);
182 #endif /* IMAGE_MENU */
184 int getdec(char **ptr
)
188 if ((*p
< '0') || (*p
> '9')) return(-1);
189 while ((*p
>= '0') && (*p
<= '9')) {
190 ret
= ret
*10 + (*p
- '0');
197 #define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
198 #define K_STATUS 0x64 /* keyboard status */
199 #define K_CMD 0x64 /* keybd ctlr command (write-only) */
201 #define K_OBUF_FUL 0x01 /* output buffer full */
202 #define K_IBUF_FUL 0x02 /* input buffer full */
204 #define KC_CMD_WIN 0xd0 /* read output port */
205 #define KC_CMD_WOUT 0xd1 /* write output port */
206 #define KB_SET_A20 0xdf /* enable A20,
207 enable output buffer full interrupt
209 disable clock line */
210 #define KB_UNSET_A20 0xdd /* enable A20,
211 enable output buffer full interrupt
213 disable clock line */
215 static void empty_8042(void)
220 time
= currticks() + TICKS_PER_SEC
; /* max wait of 1 second */
221 while ((((st
= inb(K_CMD
)) & K_OBUF_FUL
) ||
222 (st
& K_IBUF_FUL
)) &&
229 * Gate A20 for high memory
231 void gateA20_set(void)
237 outb(KC_CMD_WOUT
, K_CMD
);
239 outb(KB_SET_A20
, K_RDWR
);
246 * Unset Gate A20 for high memory - some operating systems (mainly old 16 bit
247 * ones) don't expect it to be set by the boot loader.
249 void gateA20_unset(void)
255 outb(KC_CMD_WOUT
, K_CMD
);
257 outb(KB_UNSET_A20
, K_RDWR
);
264 /* Serial console is only implemented in ETHERBOOT32 for now */
280 #ifdef CONSOLE_SERIAL
289 /**************************************************************************
290 GETCHAR - Read the next character from the console WITHOUT ECHO
291 **************************************************************************/
297 #if defined CONSOLE_CRT || defined CONSOLE_SERIAL
303 #ifdef CONSOLE_SERIAL
321 #ifdef CONSOLE_SERIAL
327 #endif /* ETHERBOOT32 */
339 unsigned long currticks(void)
341 register unsigned long l
, h
;
342 long long unsigned p
;
343 long long unsigned hh
,ll
;
348 p
= (ll
+ hh
* 0x100000000LL
) * 182 / (CPUCLOCK
* 100000LL);