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
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
33 #include <machine/cpufunc.h>
34 #include <sys/reboot.h>
35 #include <pc98/pc98/pc98_machdep.h>
37 static int getchar(int in_buf);
40 * Gate A20 for high memory
49 /* printf - only handles %d as decimal, %c as char, %s as string */
52 printf(const char *format, ...)
54 int *dataptr = (void *)&format;
58 while ((c = *format++))
62 switch (c = *format++) {
65 char buf[10], *ptr = buf;
79 unsigned int num = *dataptr++, dig;
80 char buf[8], *ptr = buf;
82 *ptr++ = (dig=(num&0xf)) > 9?
91 case 'c': putchar((*dataptr++)&0xff); break;
93 char *ptr = (char *)*dataptr++;
106 if (loadflags & RB_DUAL) {
109 } else if (loadflags & RB_SERIAL)
121 if (loadflags & RB_DUAL) {
124 else if (serial_ischar())
128 } else if (loadflags & RB_SERIAL)
147 * This routine uses an inb to an unused port, the time to execute that
148 * inb is approximately 1.25uS. This value is pretty constant across
149 * all CPU's and all buses, with the exception of some PCI implentations
150 * that do not forward this I/O address to the ISA bus as they know it
151 * is not a valid ISA bus address, those machines execute this inb in
154 * XXX this should be converted to use bios_tick.
162 (void)outb(0x5f,0); /* about 600ns */
171 * Checking the keyboard has the side effect of enabling clock
172 * interrupts so that bios_tick works. Check the keyboard to
173 * get this side effect even if we only want the serial status.
177 if (loadflags & RB_DUAL) {
180 } else if (!(loadflags & RB_SERIAL))
182 return (serial_ischar());
185 static __inline unsigned
186 pword(unsigned physaddr)
188 static int counter = 0;
191 for (i = 0; i < 512; i++)
200 #define bios_tick pword(0x46c)
201 #define BIOS_TICK_MS 1
202 unsigned initial_bios_tick;
206 for (initial_bios_tick = bios_tick;
207 bios_tick - initial_bios_tick < BOOTWAIT / BIOS_TICK_MS;)
211 switch(*ptr = getchar(ptr - buf) & 0xff) {
217 if (ptr > buf) ptr--;
224 #error "TIMEOUT without BOOTWAIT"
226 for (initial_bios_tick = bios_tick;;) {
229 if (bios_tick - initial_bios_tick >=
230 TIMEOUT / BIOS_TICK_MS)
239 strcmp(const char *s1, const char *s2)
251 strcasecmp(const char *s1, const char *s2)
254 * We only consider ASCII chars and don't anticipate
255 * control characters (they are invalid in filenames
258 while ((*s1 & 0x5f) == (*s2 & 0x5f)) {
268 memcpy(const void *from, void *to, size_t len)
270 const char *fp = (const char *)from;
271 char *tp = (char *)to;
277 /* To quote Ken: "You are not expected to understand this." :) */
282 putchar((char)tw_chars);
283 tw_chars = (tw_chars >> 8) | ((tw_chars & (unsigned long)0xFF) << 24);
287 static unsigned short *Crtat = (unsigned short *)0;
293 static unsigned short *crtat;
294 unsigned char sys_type;
299 sys_type = *(unsigned char *)V(0xA1501);
300 if (sys_type & 0x08) {
301 Crtat = (unsigned short *)V(0xE0000);
306 Crtat = (unsigned short *)V(0xA0000);
317 } while ((int)crtat % 16);
323 crtat -= (crtat - Crtat) % col;
329 *crtat = (c == 0x5c ? 0xfc : c);
330 *(crtat++ + 0x1000) = 0xe1;
334 if (crtat >= Crtat + col * row) {
336 for (i = 1; i < row; i++) {
337 memcpy((void *)(cp+col), (void *)cp, col*2);
340 for (i = 0; i < col; i++) {
346 while((inb(0x60) & 0x04) == 0) {}
348 outb(0x60, pos & 0xff);
349 outb(0x60, pos >> 8);
352 void machine_check(void)
358 /* PC98_SYSTEM_PARAMETER(0x501) */
359 ret = ((*(unsigned char*)V(0xA1501)) & 0x08) >> 3;
362 while (inb(0x60) & 0x20) {}
363 while (!(inb(0x60) & 0x20)) {}
369 /* M_NORMAL, use CG window (all NEC OK) */
371 for (i = 0; i < 4; i++) {
372 data += *((unsigned long*)V(0xA4000) + i);/* 0xa4000 */
374 if (data == 0x6efc58fc) { /* DA data */
379 ret |= (inb(0x42) & 0x20) ? M_8M : 0;
381 /* PC98_SYSTEM_PARAMETER(0x400) */
382 if ((*(unsigned char*)V(0xA1400)) & 0x80) {
385 if (ret & M_NEC_PC98) {
386 /* PC98_SYSTEM_PARAMETER(0x458) */
387 if ((*(unsigned char*)V(0xA1458)) & 0x80) {
395 (*(unsigned long *)V(0xA1620)) = ret;