|
|
1.1 root 1: /*
2: * Ported to boot 386BSD by Julian Elischer ([email protected]) Sept 1992
3: *
4: * Mach Operating System
5: * Copyright (c) 1992, 1991 Carnegie Mellon University
6: * All Rights Reserved.
7: *
8: * Permission to use, copy, modify and distribute this software and its
9: * documentation is hereby granted, provided that both the copyright
10: * notice and this permission notice appear in all copies of the
11: * software, derivative works or modified versions, and any portions
12: * thereof, and that both notices appear in supporting documentation.
13: *
14: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17: *
18: * Carnegie Mellon requests users of this software to return to
19: *
20: * Software Distribution Coordinator or [email protected]
21: * School of Computer Science
22: * Carnegie Mellon University
23: * Pittsburgh PA 15213-3890
24: *
25: * any improvements or extensions that they make and grant Carnegie Mellon
26: * the rights to redistribute these changes.
27: */
28:
29: /*
30: * HISTORY
1.1.1.2 ! root 31: * io.c,v
! 32: * Revision 1.3 1993/07/11 12:02:24 andrew
! 33: * Fixes from bde, including support for loading @ any MB boundary (e.g. a
! 34: * kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead
! 35: * buffering to speed booting from floppies. Also works with aha174x
! 36: * controllers in enhanced mode.
! 37: *
! 38: * Revision 1.2 1993/06/18 02:28:59 cgd
! 39: * make it *do* something when loading the kernel, a la sun twiddling-thing
! 40: *
! 41: * Revision 1.1 1993/03/21 18:08:38 cgd
1.1 root 42: * after 0.2.2 "stable" patches applied
43: *
44: * Revision 2.2 92/04/04 11:35:57 rpd
45: * Fixed for IBM L40's A20 initialization.
46: * [92/03/30 rvb]
47: *
48: * Created.
49: * [92/03/30 mg32]
50: *
51: */
52:
53: #include <i386/include/pio.h>
54:
55: #define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
56: #define K_STATUS 0x64 /* keyboard status */
57: #define K_CMD 0x64 /* keybd ctlr command (write-only) */
58:
59: #define K_OBUF_FUL 0x01 /* output buffer full */
60: #define K_IBUF_FUL 0x02 /* input buffer full */
61:
62: #define KC_CMD_WIN 0xd0 /* read output port */
63: #define KC_CMD_WOUT 0xd1 /* write output port */
64: #define KB_A20 0x9f /* enable A20,
65: enable output buffer full interrupt
66: enable data line
67: disable clock line */
68:
69: /*
70: * Gate A20 for high memory
71: */
72: unsigned char x_20 = KB_A20;
73: gateA20()
74: {
75: #ifdef IBM_L40
76: outb(0x92, 0x2);
77: #else IBM_L40
78: while (inb(K_STATUS) & K_IBUF_FUL);
79: while (inb(K_STATUS) & K_OBUF_FUL)
80: (void)inb(K_RDWR);
81:
82: outb(K_CMD, KC_CMD_WOUT);
83: while (inb(K_STATUS) & K_IBUF_FUL);
84: outb(K_RDWR, x_20);
85: while (inb(K_STATUS) & K_IBUF_FUL);
86: #endif IBM_L40
87: }
88:
89: /* printf - only handles %d as decimal, %c as char, %s as string */
90:
91: printf(format,data)
92: char *format;
93: int data;
94: {
95: int *dataptr = &data;
96: char c;
1.1.1.2 ! root 97:
! 98: reset_twiddle();
1.1 root 99: while (c = *format++)
100: if (c != '%')
101: putchar(c);
102: else
103: switch (c = *format++) {
104: case 'd': {
105: int num = *dataptr++;
106: char buf[10], *ptr = buf;
107: if (num<0) {
108: num = -num;
109: putchar('-');
110: }
111: do
112: *ptr++ = '0'+num%10;
113: while (num /= 10);
114: do
115: putchar(*--ptr);
116: while (ptr != buf);
117: break;
118: }
119: case 'x': {
120: int num = *dataptr++, dig;
121: char buf[8], *ptr = buf;
122: do
123: *ptr++ = (dig=(num&0xf)) > 9?
124: 'a' + dig - 10 :
125: '0' + dig;
126: while (num >>= 4);
127: do
128: putchar(*--ptr);
129: while (ptr != buf);
130: break;
131: }
132: case 'c': putchar((*dataptr++)&0xff); break;
133: case 's': {
134: char *ptr = (char *)*dataptr++;
135: while (c = *ptr++)
136: putchar(c);
137: break;
138: }
139: }
140: }
141:
142: putchar(c)
143: {
144: if (c == '\n')
145: putc('\r');
146: putc(c);
147: }
148:
149: getchar()
150: {
151: int c;
152:
153: if ((c=getc()) == '\r')
154: c = '\n';
155: if (c == '\b') {
156: putchar('\b');
157: putchar(' ');
158: }
159: putchar(c);
160: return(c);
161: }
162:
163: gets(buf)
164: char *buf;
165: {
166: int i;
167: char *ptr=buf;
168:
169: for (i = 240000; i>0; i--)
170: if (ischar())
171: for (;;)
172: switch(*ptr = getchar() & 0xff) {
173: case '\n':
174: case '\r':
175: *ptr = '\0';
176: return 1;
177: case '\b':
178: if (ptr > buf) ptr--;
179: continue;
180: default:
181: ptr++;
182: }
183: return 0;
184: }
185:
186: strcmp(s1, s2)
187: char *s1, *s2;
188: {
189: while (*s1 == *s2) {
190: if (!*s1++)
191: return 0;
192: s2++;
193: }
194: return 1;
195: }
196:
197: bcopy(from, to, len)
198: char *from, *to;
199: int len;
200: {
201: while (len-- > 0)
202: *to++ = *from++;
203: }
1.1.1.2 ! root 204:
! 205: static int tw_on;
! 206: static int tw_pos;
! 207: static char tw_chars[] = "|/-\\";
! 208:
! 209: reset_twiddle()
! 210: {
! 211: if (tw_on)
! 212: putchar('\b');
! 213: tw_on = 0;
! 214: tw_pos = 0;
! 215: }
! 216:
! 217: twiddle()
! 218: {
! 219: if (tw_on)
! 220: putchar('\b');
! 221: else
! 222: tw_on = 1;
! 223: putchar(tw_chars[tw_pos++]);
! 224: tw_pos %= (sizeof(tw_chars) - 1);
! 225: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.