|
|
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
31: * $Log: io.c,v $
32: * Revision 1.1 1993/03/21 18:08:38 cgd
33: * after 0.2.2 "stable" patches applied
34: *
35: * Revision 2.2 92/04/04 11:35:57 rpd
36: * Fixed for IBM L40's A20 initialization.
37: * [92/03/30 rvb]
38: *
39: * Created.
40: * [92/03/30 mg32]
41: *
42: */
43:
44: #include <i386/include/pio.h>
45:
46: #define K_RDWR 0x60 /* keyboard data & cmds (read/write) */
47: #define K_STATUS 0x64 /* keyboard status */
48: #define K_CMD 0x64 /* keybd ctlr command (write-only) */
49:
50: #define K_OBUF_FUL 0x01 /* output buffer full */
51: #define K_IBUF_FUL 0x02 /* input buffer full */
52:
53: #define KC_CMD_WIN 0xd0 /* read output port */
54: #define KC_CMD_WOUT 0xd1 /* write output port */
55: #define KB_A20 0x9f /* enable A20,
56: enable output buffer full interrupt
57: enable data line
58: disable clock line */
59:
60: /*
61: * Gate A20 for high memory
62: */
63: unsigned char x_20 = KB_A20;
64: gateA20()
65: {
66: #ifdef IBM_L40
67: outb(0x92, 0x2);
68: #else IBM_L40
69: while (inb(K_STATUS) & K_IBUF_FUL);
70: while (inb(K_STATUS) & K_OBUF_FUL)
71: (void)inb(K_RDWR);
72:
73: outb(K_CMD, KC_CMD_WOUT);
74: while (inb(K_STATUS) & K_IBUF_FUL);
75: outb(K_RDWR, x_20);
76: while (inb(K_STATUS) & K_IBUF_FUL);
77: #endif IBM_L40
78: }
79:
80: /* printf - only handles %d as decimal, %c as char, %s as string */
81:
82: printf(format,data)
83: char *format;
84: int data;
85: {
86: int *dataptr = &data;
87: char c;
88: while (c = *format++)
89: if (c != '%')
90: putchar(c);
91: else
92: switch (c = *format++) {
93: case 'd': {
94: int num = *dataptr++;
95: char buf[10], *ptr = buf;
96: if (num<0) {
97: num = -num;
98: putchar('-');
99: }
100: do
101: *ptr++ = '0'+num%10;
102: while (num /= 10);
103: do
104: putchar(*--ptr);
105: while (ptr != buf);
106: break;
107: }
108: case 'x': {
109: int num = *dataptr++, dig;
110: char buf[8], *ptr = buf;
111: do
112: *ptr++ = (dig=(num&0xf)) > 9?
113: 'a' + dig - 10 :
114: '0' + dig;
115: while (num >>= 4);
116: do
117: putchar(*--ptr);
118: while (ptr != buf);
119: break;
120: }
121: case 'c': putchar((*dataptr++)&0xff); break;
122: case 's': {
123: char *ptr = (char *)*dataptr++;
124: while (c = *ptr++)
125: putchar(c);
126: break;
127: }
128: }
129: }
130:
131: putchar(c)
132: {
133: if (c == '\n')
134: putc('\r');
135: putc(c);
136: }
137:
138: getchar()
139: {
140: int c;
141:
142: if ((c=getc()) == '\r')
143: c = '\n';
144: if (c == '\b') {
145: putchar('\b');
146: putchar(' ');
147: }
148: putchar(c);
149: return(c);
150: }
151:
152: gets(buf)
153: char *buf;
154: {
155: int i;
156: char *ptr=buf;
157:
158: for (i = 240000; i>0; i--)
159: if (ischar())
160: for (;;)
161: switch(*ptr = getchar() & 0xff) {
162: case '\n':
163: case '\r':
164: *ptr = '\0';
165: return 1;
166: case '\b':
167: if (ptr > buf) ptr--;
168: continue;
169: default:
170: ptr++;
171: }
172: return 0;
173: }
174:
175: strcmp(s1, s2)
176: char *s1, *s2;
177: {
178: while (*s1 == *s2) {
179: if (!*s1++)
180: return 0;
181: s2++;
182: }
183: return 1;
184: }
185:
186: bcopy(from, to, len)
187: char *from, *to;
188: int len;
189: {
190: while (len-- > 0)
191: *to++ = *from++;
192: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.