2 * Mach Operating System
3 * Copyright (c) 1992, 1991 Carnegie Mellon University
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.
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.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
26 * from: Mach, Revision 2.2 92/04/04 11:35:57 rpd
27 * $FreeBSD: src/sys/i386/boot/biosboot/io.c,v 1.26 1999/08/28 00:43:13 peter Exp $
31 #include <machine/cpufunc.h>
32 #include <sys/reboot.h>
34 #define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
35 #define K_STATUS 0x64 /* keyboard status */
36 #define K_CMD 0x64 /* keybd ctlr command (write-only) */
38 #define K_OBUF_FUL 0x01 /* output buffer full */
39 #define K_IBUF_FUL 0x02 /* input buffer full */
41 #define KC_CMD_WIN 0xd0 /* read output port */
42 #define KC_CMD_WOUT 0xd1 /* write output port */
43 #define KB_A20 0xdf /* enable A20,
44 enable output buffer full interrupt
49 static int getchar(int in_buf);
52 * Gate A20 for high memory
60 while (inb(K_STATUS) & K_IBUF_FUL);
61 while (inb(K_STATUS) & K_OBUF_FUL)
64 outb(K_CMD, KC_CMD_WOUT);
65 while (inb(K_STATUS) & K_IBUF_FUL);
67 while (inb(K_STATUS) & K_IBUF_FUL);
71 /* printf - only handles %d as decimal, %c as char, %s as string */
74 printf(const char *format, ...)
76 int *dataptr = (int *)&format;
80 while ((c = *format++))
84 switch (c = *format++) {
87 char buf[10], *ptr = buf;
101 unsigned int num = *dataptr++, dig;
102 char buf[8], *ptr = buf;
104 *ptr++ = (dig=(num&0xf)) > 9?
113 case 'c': putchar((*dataptr++)&0xff); break;
115 char *ptr = (char *)*dataptr++;
128 if (loadflags & RB_DUAL) {
131 } else if (loadflags & RB_SERIAL)
143 if (loadflags & RB_DUAL) {
146 else if (serial_ischar())
150 } else if (loadflags & RB_SERIAL)
169 * This routine uses an inb to an unused port, the time to execute that
170 * inb is approximately 1.25uS. This value is pretty constant across
171 * all CPU's and all buses, with the exception of some PCI implentations
172 * that do not forward this I/O adress to the ISA bus as they know it
173 * is not a valid ISA bus address, those machines execute this inb in
176 * XXX this should be converted to use bios_tick.
192 * Checking the keyboard has the side effect of enabling clock
193 * interrupts so that bios_tick works. Check the keyboard to
194 * get this side effect even if we only want the serial status.
198 if (loadflags & RB_DUAL) {
201 } else if (!(loadflags & RB_SERIAL))
203 return (serial_ischar());
206 static __inline unsigned
207 pword(unsigned physaddr)
212 * Give the fs prefix separately because gas omits it for
213 * "movl %fs:0x46c, %eax".
215 __asm __volatile("fs; movl %1, %0" : "=r" (result)
216 : "m" (*(unsigned *)physaddr));
223 #define bios_tick pword(0x46c)
224 #define BIOS_TICK_MS 55
225 unsigned initial_bios_tick;
229 for (initial_bios_tick = bios_tick;
230 bios_tick - initial_bios_tick < BOOTWAIT / BIOS_TICK_MS;)
234 switch(*ptr = getchar(ptr - buf) & 0xff) {
240 if (ptr > buf) ptr--;
247 #error "TIMEOUT without BOOTWAIT"
249 for (initial_bios_tick = bios_tick;;) {
252 if (bios_tick - initial_bios_tick >=
253 TIMEOUT / BIOS_TICK_MS)
262 strcmp(const char *s1, const char *s2)
274 strcasecmp(const char *s1, const char *s2)
277 * We only consider ASCII chars and don't anticipate
278 * control characters (they are invalid in filenames
281 while ((*s1 & 0x5f) == (*s2 & 0x5f)) {
291 bcopy(const void *from, void *to, size_t len)
293 char *fp = (char *)from;
294 char *tp = (char *)to;
300 /* To quote Ken: "You are not expected to understand this." :) */
305 putchar((char)tw_chars);
306 tw_chars = (tw_chars >> 8) | ((tw_chars & (unsigned long)0xFF) << 24);