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/boot/pc98/boot2/io.c,v 1.2.2.1 2001/10/07 13:22:38 nyan Exp $
31 #include <machine/cpufunc.h>
32 #include <sys/reboot.h>
34 #include <pc98/pc98/pc98.h>
38 static int getchar(int in_buf);
41 * Gate A20 for high memory
50 /* printf - only handles %d as decimal, %c as char, %s as string */
53 printf(const char *format, ...)
55 int *dataptr = (int *)&format;
59 while ((c = *format++))
63 switch (c = *format++) {
66 char buf[10], *ptr = buf;
80 unsigned int num = *dataptr++, dig;
81 char buf[8], *ptr = buf;
83 *ptr++ = (dig=(num&0xf)) > 9?
92 case 'c': putchar((*dataptr++)&0xff); break;
94 char *ptr = (char *)*dataptr++;
107 if (loadflags & RB_DUAL) {
110 } else if (loadflags & RB_SERIAL)
122 if (loadflags & RB_DUAL) {
125 else if (serial_ischar())
129 } else if (loadflags & RB_SERIAL)
148 * This routine uses an inb to an unused port, the time to execute that
149 * inb is approximately 1.25uS. This value is pretty constant across
150 * all CPU's and all buses, with the exception of some PCI implentations
151 * that do not forward this I/O address to the ISA bus as they know it
152 * is not a valid ISA bus address, those machines execute this inb in
155 * XXX this should be converted to use bios_tick.
163 (void)outb(0x5f,0); /* about 600ns */
177 * Checking the keyboard has the side effect of enabling clock
178 * interrupts so that bios_tick works. Check the keyboard to
179 * get this side effect even if we only want the serial status.
183 if (loadflags & RB_DUAL) {
186 } else if (!(loadflags & RB_SERIAL))
188 return (serial_ischar());
191 static __inline unsigned
192 pword(unsigned physaddr)
195 static int counter = 0;
198 for (i = 0; i < 512; i++)
206 * Give the fs prefix separately because gas omits it for
207 * "movl %fs:0x46c, %eax".
209 __asm __volatile("fs; movl %1, %0" : "=r" (result)
210 : "m" (*(unsigned *)physaddr));
218 #define bios_tick pword(0x46c)
220 #define BIOS_TICK_MS 1
222 #define BIOS_TICK_MS 55
224 unsigned initial_bios_tick;
228 for (initial_bios_tick = bios_tick;
229 bios_tick - initial_bios_tick < BOOTWAIT / BIOS_TICK_MS;)
233 switch(*ptr = getchar(ptr - buf) & 0xff) {
239 if (ptr > buf) ptr--;
246 #error "TIMEOUT without BOOTWAIT"
248 for (initial_bios_tick = bios_tick;;) {
251 if (bios_tick - initial_bios_tick >=
252 TIMEOUT / BIOS_TICK_MS)
261 strcmp(const char *s1, const char *s2)
273 strcasecmp(const char *s1, const char *s2)
276 * We only consider ASCII chars and don't anticipate
277 * control characters (they are invalid in filenames
280 while ((*s1 & 0x5f) == (*s2 & 0x5f)) {
290 bcopy(const void *from, void *to, size_t len)
292 char *fp = (char *)from;
293 char *tp = (char *)to;
299 /* To quote Ken: "You are not expected to understand this." :) */
304 putchar((char)tw_chars);
305 tw_chars = (tw_chars >> 8) | ((tw_chars & (unsigned long)0xFF) << 24);
309 static unsigned short *Crtat = (unsigned short *)0;
315 static unsigned short *crtat;
316 unsigned char sys_type;
321 sys_type = *(unsigned char *)V(0xA1501);
322 if (sys_type & 0x08) {
323 Crtat = (unsigned short *)V(0xE0000);
328 Crtat = (unsigned short *)V(0xA0000);
339 } while ((int)crtat % 16);
345 crtat -= (crtat - Crtat) % col;
351 *crtat = (c == 0x5c ? 0xfc : c);
352 *(crtat++ + 0x1000) = 0xe1;
356 if (crtat >= Crtat + col * row) {
358 for (i = 1; i < row; i++) {
359 bcopy((void *)(cp+col), (void *)cp, col*2);
362 for (i = 0; i < col; i++) {
368 while((inb(0x60) & 0x04) == 0) {}
370 outb(0x60, pos & 0xff);
371 outb(0x60, pos >> 8);
374 void machine_check(void)
379 u_char epson_machine_id = *(unsigned char *)V(0xA1624);
381 /* PC98_SYSTEM_PARAMETER(0x501) */
382 ret = ((*(unsigned char*)V(0xA1501)) & 0x08) >> 3;
385 while (inb(0x60) & 0x20) {}
386 while (!(inb(0x60) & 0x20)) {}
392 /* M_NORMAL, use CG window (all NEC OK) */
394 for (i = 0; i < 4; i++) {
395 data += *((unsigned long*)V(0xA4000) + i);/* 0xa4000 */
397 if (data == 0x6efc58fc) { /* DA data */
402 ret |= (inb(0x42) & 0x20) ? M_8M : 0;
404 /* PC98_SYSTEM_PARAMETER(0x400) */
405 if ((*(unsigned char*)V(0xA1400)) & 0x80) {
408 if (ret & M_NEC_PC98) {
409 /* PC98_SYSTEM_PARAMETER(0x458) */
410 if ((*(unsigned char*)V(0xA1458)) & 0x80) {
417 switch (epson_machine_id) {
418 case 0x20: /* note A */
419 case 0x22: /* note W */
420 case 0x27: /* note AE */
421 case 0x2a: /* note WR */
428 (*(unsigned long *)V(0xA1620)) = ret;