xref: /freebsd/usr.sbin/mptable/mptable.c (revision bc96366c864c07ef352edb92017357917c75b36c)
1 /*
2  * Copyright (c) 1996, by Steve Passe
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. The name of the developer may NOT be used to endorse or promote products
11  *    derived from this software without specific prior written permission.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25 
26 /*
27  * mptable.c
28  */
29 
30 #ifndef lint
31 static const char rcsid[] =
32   "$FreeBSD$";
33 #endif /* not lint */
34 
35 /*
36  * this will cause the raw mp table to be dumped to /tmp/mpdump
37  *
38 #define RAW_DUMP
39  */
40 
41 #define MP_SIG			0x5f504d5f	/* _MP_ */
42 #define EXTENDED_PROCESSING_READY
43 #define OEM_PROCESSING_READY_NOT
44 
45 #include <sys/param.h>
46 #include <sys/mman.h>
47 #include <x86/mptable.h>
48 #include <err.h>
49 #include <fcntl.h>
50 #include <paths.h>
51 #include <stdint.h>
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #include <unistd.h>
56 
57 #define SEP_LINE \
58 "\n-------------------------------------------------------------------------------\n"
59 
60 #define SEP_LINE2 \
61 "\n===============================================================================\n"
62 
63 /* EBDA is @ 40:0e in real-mode terms */
64 #define EBDA_POINTER		0x040e		/* location of EBDA pointer */
65 
66 /* CMOS 'top of mem' is @ 40:13 in real-mode terms */
67 #define TOPOFMEM_POINTER	0x0413		/* BIOS: base memory size */
68 
69 #define DEFAULT_TOPOFMEM	0xa0000
70 
71 #define BIOS_BASE		0xf0000
72 #define BIOS_BASE2		0xe0000
73 #define BIOS_SIZE		0x10000
74 #define ONE_KBYTE		1024
75 
76 #define GROPE_AREA1		0x80000
77 #define GROPE_AREA2		0x90000
78 #define GROPE_SIZE		0x10000
79 
80 #define MAXPNSTR		132
81 
82 typedef struct BUSTYPENAME {
83     u_char	type;
84     char	name[ 7 ];
85 } busTypeName;
86 
87 static const busTypeName busTypeTable[] =
88 {
89     { CBUS,		"CBUS"   },
90     { CBUSII,		"CBUSII" },
91     { EISA,		"EISA"   },
92     { UNKNOWN_BUSTYPE,	"---"    },
93     { UNKNOWN_BUSTYPE,	"---"    },
94     { ISA,		"ISA"    },
95     { UNKNOWN_BUSTYPE,	"---"    },
96     { UNKNOWN_BUSTYPE,	"---"    },
97     { UNKNOWN_BUSTYPE,	"---"    },
98     { UNKNOWN_BUSTYPE,	"---"    },
99     { UNKNOWN_BUSTYPE,	"---"    },
100     { UNKNOWN_BUSTYPE,	"---"    },
101     { PCI,		"PCI"    },
102     { UNKNOWN_BUSTYPE,	"---"    },
103     { UNKNOWN_BUSTYPE,	"---"    },
104     { UNKNOWN_BUSTYPE,	"---"    },
105     { UNKNOWN_BUSTYPE,	"---"    },
106     { UNKNOWN_BUSTYPE,	"---"    },
107     { UNKNOWN_BUSTYPE,	"---"    }
108 };
109 
110 static const char *whereStrings[] = {
111     "Extended BIOS Data Area",
112     "BIOS top of memory",
113     "Default top of memory",
114     "BIOS",
115     "Extended BIOS",
116     "GROPE AREA #1",
117     "GROPE AREA #2"
118 };
119 
120 static void apic_probe( u_int32_t* paddr, int* where );
121 
122 static void MPConfigDefault( int featureByte );
123 
124 static void MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfpsp );
125 static void MPConfigTableHeader( u_int32_t pap );
126 
127 static void seekEntry( u_int32_t addr );
128 static void readEntry( void* entry, int size );
129 static void *mapEntry( u_int32_t addr, int size );
130 
131 static void processorEntry( proc_entry_ptr entry );
132 static void busEntry( bus_entry_ptr entry );
133 static void ioApicEntry( io_apic_entry_ptr entry );
134 static void intEntry( int_entry_ptr entry );
135 
136 static void sasEntry( sas_entry_ptr entry );
137 static void bhdEntry( bhd_entry_ptr entry );
138 static void cbasmEntry( cbasm_entry_ptr entry );
139 
140 static void doDmesg( void );
141 static void pnstr( char* s, int c );
142 
143 /* global data */
144 static int	pfd;		/* physical /dev/mem fd */
145 
146 static int	busses[256];
147 static int	apics[256];
148 
149 static int	ncpu;
150 static int	nbus;
151 static int	napic;
152 static int	nintr;
153 
154 static int	dmesg;
155 static int	grope;
156 static int	verbose;
157 
158 static void
159 usage( void )
160 {
161     fprintf( stderr, "usage: mptable [-dmesg] [-verbose] [-grope] [-help]\n" );
162     exit( 0 );
163 }
164 
165 /*
166  *
167  */
168 int
169 main( int argc, char *argv[] )
170 {
171     u_int32_t	paddr;
172     int		where;
173     mpfps_t	mpfps;
174     int		defaultConfig;
175 
176     int		ch;
177 
178     /* announce ourselves */
179     puts( SEP_LINE2 );
180 
181     printf( "MPTable\n" );
182 
183     while ((ch = getopt(argc, argv, "d:g:h:v:")) != -1) {
184 	switch(ch) {
185 	case 'd':
186 	    if ( strcmp( optarg, "mesg") == 0 )
187 	        dmesg = 1;
188 	    else
189 	        dmesg = 0;
190 	    break;
191 	case 'h':
192 	    if ( strcmp( optarg, "elp") == 0 )
193 	        usage();
194 	    break;
195 	case 'g':
196 	    if ( strcmp( optarg, "rope") == 0 )
197 	        grope = 1;
198 	    break;
199 	case 'v':
200 	    if ( strcmp( optarg, "erbose") == 0 )
201 	        verbose = 1;
202 	    break;
203 	default:
204 	    usage();
205 	}
206 	argc -= optind;
207 	argv += optind;
208 	optreset = 1;
209 	optind = 0;
210     }
211 
212     /* open physical memory for access to MP structures */
213     if ( (pfd = open( _PATH_MEM, O_RDONLY )) < 0 )
214         err( 1, "mem open" );
215 
216     /* probe for MP structures */
217     apic_probe( &paddr, &where );
218     if ( where <= 0 ) {
219         fprintf( stderr, "\n MP FPS NOT found,\n" );
220         fprintf( stderr, " suggest trying -grope option!!!\n\n" );
221         return 1;
222     }
223 
224     if ( verbose )
225         printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n",
226 	      whereStrings[ where - 1 ], paddr );
227 
228     puts( SEP_LINE );
229 
230     /* analyze the MP Floating Pointer Structure */
231     MPFloatingPointer( paddr, where, &mpfps );
232 
233     puts( SEP_LINE );
234 
235     /* check whether an MP config table exists */
236     if ( (defaultConfig = mpfps->config_type) )
237         MPConfigDefault( defaultConfig );
238     else
239 	MPConfigTableHeader( mpfps->pap );
240 
241     /* do a dmesg output */
242     if ( dmesg )
243         doDmesg();
244 
245     puts( SEP_LINE2 );
246 
247     return 0;
248 }
249 
250 
251 /*
252  * set PHYSICAL address of MP floating pointer structure
253  */
254 #define NEXT(X)		((X) += 4)
255 static void
256 apic_probe( u_int32_t* paddr, int* where )
257 {
258     /*
259      * c rewrite of apic_probe() by Jack F. Vogel
260      */
261 
262     int		x;
263     u_short	segment;
264     u_int32_t	target;
265     u_int	buffer[ BIOS_SIZE / sizeof( int ) ];
266 
267     if ( verbose )
268         printf( "\n" );
269 
270     /* search Extended Bios Data Area, if present */
271     if ( verbose )
272         printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER );
273     seekEntry( (u_int32_t)EBDA_POINTER );
274     readEntry( &segment, 2 );
275     if ( segment ) {		    /* search EBDA */
276         target = (u_int32_t)segment << 4;
277 	if ( verbose )
278 	    printf( "found, searching EBDA @ 0x%08x\n", target );
279         seekEntry( target );
280         readEntry( buffer, ONE_KBYTE );
281 
282         for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
283             if ( buffer[ x ] == MP_SIG ) {
284                 *where = 1;
285                 *paddr = (x * sizeof( unsigned int )) + target;
286                 return;
287             }
288         }
289     }
290     else {
291 	if ( verbose )
292 	    printf( "NOT found\n" );
293     }
294 
295     /* read CMOS for real top of mem */
296     seekEntry( (u_int32_t)TOPOFMEM_POINTER );
297     readEntry( &segment, 2 );
298     --segment;						/* less ONE_KBYTE */
299     target = segment * 1024;
300     if ( verbose )
301         printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n",
302 	        target, segment );
303     seekEntry( target );
304     readEntry( buffer, ONE_KBYTE );
305 
306     for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
307         if ( buffer[ x ] == MP_SIG ) {
308             *where = 2;
309             *paddr = (x * sizeof( unsigned int )) + target;
310             return;
311         }
312     }
313 
314     /* we don't necessarily believe CMOS, check base of the last 1K of 640K */
315     if ( target != (DEFAULT_TOPOFMEM - 1024)) {
316 	target = (DEFAULT_TOPOFMEM - 1024);
317 	if ( verbose )
318 	    printf( " searching default 'top of mem' @ 0x%08x (%dK)\n",
319 		    target, (target / 1024) );
320 	seekEntry( target );
321 	readEntry( buffer, ONE_KBYTE );
322 
323 	for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
324 	    if ( buffer[ x ] == MP_SIG ) {
325 		*where = 3;
326 		*paddr = (x * sizeof( unsigned int )) + target;
327 		return;
328 	    }
329 	}
330     }
331 
332     /* search the BIOS */
333     if ( verbose )
334         printf( " searching BIOS @ 0x%08x\n", BIOS_BASE );
335     seekEntry( BIOS_BASE );
336     readEntry( buffer, BIOS_SIZE );
337 
338     for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
339         if ( buffer[ x ] == MP_SIG ) {
340             *where = 4;
341             *paddr = (x * sizeof( unsigned int )) + BIOS_BASE;
342             return;
343         }
344     }
345 
346     /* search the extended BIOS */
347     if ( verbose )
348         printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 );
349     seekEntry( BIOS_BASE2 );
350     readEntry( buffer, BIOS_SIZE );
351 
352     for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
353         if ( buffer[ x ] == MP_SIG ) {
354             *where = 5;
355             *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2;
356             return;
357         }
358     }
359 
360     if ( grope ) {
361 	/* search additional memory */
362 	target = GROPE_AREA1;
363 	if ( verbose )
364 	    printf( " groping memory @ 0x%08x\n", target );
365 	seekEntry( target );
366 	readEntry( buffer, GROPE_SIZE );
367 
368 	for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
369 	    if ( buffer[ x ] == MP_SIG ) {
370 		*where = 6;
371 		*paddr = (x * sizeof( unsigned int )) + GROPE_AREA1;
372 		return;
373 	    }
374 	}
375 
376 	target = GROPE_AREA2;
377 	if ( verbose )
378 	    printf( " groping memory @ 0x%08x\n", target );
379 	seekEntry( target );
380 	readEntry( buffer, GROPE_SIZE );
381 
382 	for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
383 	    if ( buffer[ x ] == MP_SIG ) {
384 		*where = 7;
385 		*paddr = (x * sizeof( unsigned int )) + GROPE_AREA2;
386 		return;
387 	    }
388 	}
389     }
390 
391     *where = 0;
392     *paddr = (u_int32_t)0;
393 }
394 
395 
396 /*
397  *
398  */
399 static void
400 MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfpsp )
401 {
402     mpfps_t mpfps;
403 
404     /* map in mpfps structure*/
405     *mpfpsp = mpfps = mapEntry( paddr, sizeof( *mpfps ) );
406 
407     /* show its contents */
408     printf( "MP Floating Pointer Structure:\n\n" );
409 
410     printf( "  location:\t\t\t" );
411     switch ( where )
412     {
413     case 1:
414 	printf( "EBDA\n" );
415 	break;
416     case 2:
417 	printf( "BIOS base memory\n" );
418 	break;
419     case 3:
420 	printf( "DEFAULT base memory (639K)\n" );
421 	break;
422     case 4:
423 	printf( "BIOS\n" );
424 	break;
425     case 5:
426 	printf( "Extended BIOS\n" );
427 	break;
428 
429     case 0:
430 	printf( "NOT found!\n" );
431 	exit( 1 );
432     default:
433 	printf( "BOGUS!\n" );
434 	exit( 1 );
435     }
436     printf( "  physical address:\t\t0x%08x\n", paddr );
437 
438     printf( "  signature:\t\t\t'" );
439     pnstr( mpfps->signature, 4 );
440     printf( "'\n" );
441 
442     printf( "  length:\t\t\t%d bytes\n", mpfps->length * 16 );
443     printf( "  version:\t\t\t1.%1d\n", mpfps->spec_rev );
444     printf( "  checksum:\t\t\t0x%02x\n", mpfps->checksum );
445 
446     /* bits 0:6 are RESERVED */
447     if ( mpfps->mpfb2 & 0x7f ) {
448         printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 );
449     }
450 
451     /* bit 7 is IMCRP */
452     printf( "  mode:\t\t\t\t%s\n", (mpfps->mpfb2 & MPFB2_IMCR_PRESENT) ?
453             "PIC" : "Virtual Wire" );
454 
455     /* MP feature bytes 3-5 are expected to be ZERO */
456     if ( mpfps->mpfb3 )
457         printf( " warning, MP feature byte 3 NONZERO!\n" );
458     if ( mpfps->mpfb4 )
459         printf( " warning, MP feature byte 4 NONZERO!\n" );
460     if ( mpfps->mpfb5 )
461         printf( " warning, MP feature byte 5 NONZERO!\n" );
462 }
463 
464 
465 /*
466  *
467  */
468 static void
469 MPConfigDefault( int featureByte )
470 {
471     printf( "  MP default config type: %d\n\n", featureByte );
472     switch ( featureByte ) {
473     case 1:
474 	printf( "   bus: ISA, APIC: 82489DX\n" );
475 	break;
476     case 2:
477 	printf( "   bus: EISA, APIC: 82489DX\n" );
478 	break;
479     case 3:
480 	printf( "   bus: EISA, APIC: 82489DX\n" );
481 	break;
482     case 4:
483 	printf( "   bus: MCA, APIC: 82489DX\n" );
484 	break;
485     case 5:
486 	printf( "   bus: ISA+PCI, APIC: Integrated\n" );
487 	break;
488     case 6:
489 	printf( "   bus: EISA+PCI, APIC: Integrated\n" );
490 	break;
491     case 7:
492 	printf( "   bus: MCA+PCI, APIC: Integrated\n" );
493 	break;
494     default:
495 	printf( "   future type\n" );
496 	break;
497     }
498 
499     switch ( featureByte ) {
500     case 1:
501     case 2:
502     case 3:
503     case 4:
504 	nbus = 1;
505 	break;
506     case 5:
507     case 6:
508     case 7:
509 	nbus = 2;
510 	break;
511     default:
512 	printf( "   future type\n" );
513 	break;
514     }
515 
516     ncpu = 2;
517     napic = 1;
518     nintr = 16;
519 }
520 
521 
522 /*
523  *
524  */
525 static void
526 MPConfigTableHeader( u_int32_t pap )
527 {
528     mpcth_t	cth;
529     int		x;
530     int		totalSize;
531     int		c;
532     int		oldtype, entrytype;
533     u_int8_t	*entry;
534 
535     if ( pap == 0 ) {
536 	printf( "MP Configuration Table Header MISSING!\n" );
537         exit( 1 );
538     }
539 
540     /* map in cth structure */
541     cth = mapEntry( pap, sizeof( *cth ) );
542 
543     printf( "MP Config Table Header:\n\n" );
544 
545     printf( "  physical address:\t\t0x%08x\n", pap );
546 
547     printf( "  signature:\t\t\t'" );
548     pnstr( cth->signature, 4 );
549     printf( "'\n" );
550 
551     printf( "  base table length:\t\t%d\n", cth->base_table_length );
552 
553     printf( "  version:\t\t\t1.%1d\n", cth->spec_rev );
554     printf( "  checksum:\t\t\t0x%02x\n", cth->checksum );
555 
556     printf( "  OEM ID:\t\t\t'" );
557     pnstr( cth->oem_id, 8 );
558     printf( "'\n" );
559 
560     printf( "  Product ID:\t\t\t'" );
561     pnstr( cth->product_id, 12 );
562     printf( "'\n" );
563 
564     printf( "  OEM table pointer:\t\t0x%08x\n", cth->oem_table_pointer );
565     printf( "  OEM table size:\t\t%d\n", cth->oem_table_size );
566 
567     printf( "  entry count:\t\t\t%d\n", cth->entry_count );
568 
569     printf( "  local APIC address:\t\t0x%08x\n", cth->apic_address );
570 
571     printf( "  extended table length:\t%d\n", cth->extended_table_length );
572     printf( "  extended table checksum:\t%d\n", cth->extended_table_checksum );
573 
574     totalSize = cth->base_table_length - sizeof( struct MPCTH );
575 
576     puts( SEP_LINE );
577 
578     printf( "MP Config Base Table Entries:\n\n" );
579 
580     /* initialize tables */
581     for (x = 0; x < (int)nitems(busses); x++)
582 	busses[x] = 0xff;
583 
584     for (x = 0; x < (int)nitems(apics); x++)
585 	apics[x] = 0xff;
586 
587     ncpu = 0;
588     nbus = 0;
589     napic = 0;
590     nintr = 0;
591 
592     oldtype = -1;
593     entry = mapEntry(pap + sizeof(*cth), cth->base_table_length);
594     for (c = cth->entry_count; c; c--) {
595 	entrytype = *entry;
596 	if (entrytype != oldtype)
597 	    printf("--\n");
598 	if (entrytype < oldtype)
599 	    printf("MPTABLE OUT OF ORDER!\n");
600 	switch (entrytype) {
601 	case MPCT_ENTRY_PROCESSOR:
602 	    if (oldtype != MPCT_ENTRY_PROCESSOR)
603 		printf( "Processors:\tAPIC ID\tVersion\tState"
604 			"\t\tFamily\tModel\tStep\tFlags\n" );
605 	    processorEntry((proc_entry_ptr)entry);
606 	    entry += sizeof(struct PROCENTRY);
607 	    break;
608 
609 	case MPCT_ENTRY_BUS:
610 	    if (oldtype != MPCT_ENTRY_BUS)
611 		printf( "Bus:\t\tBus ID\tType\n" );
612 	    busEntry((bus_entry_ptr)entry);
613 	    entry += sizeof(struct BUSENTRY);
614 	    break;
615 
616 	case MPCT_ENTRY_IOAPIC:
617 	    if (oldtype != MPCT_ENTRY_IOAPIC)
618 		printf( "I/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" );
619 	    ioApicEntry((io_apic_entry_ptr)entry);
620 	    entry += sizeof(struct IOAPICENTRY);
621 	    break;
622 
623 	case MPCT_ENTRY_INT:
624 	    if (oldtype != MPCT_ENTRY_INT)
625 		printf( "I/O Ints:\tType\tPolarity    Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
626 	    intEntry((int_entry_ptr)entry);
627 	    entry += sizeof(struct INTENTRY);
628 	    break;
629 
630 	case MPCT_ENTRY_LOCAL_INT:
631 	    if (oldtype != MPCT_ENTRY_LOCAL_INT)
632 		printf( "Local Ints:\tType\tPolarity    Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
633 	    intEntry((int_entry_ptr)entry);
634 	    entry += sizeof(struct INTENTRY);
635 	    break;
636 
637 	default:
638 	    printf("MPTABLE HOSED! record type = %d\n", entrytype);
639 	    exit(1);
640 	}
641 	oldtype = entrytype;
642     }
643 
644 
645 #if defined( EXTENDED_PROCESSING_READY )
646     /* process any extended data */
647     if ( cth->extended_table_length ) {
648 	ext_entry_ptr ext_entry, end;
649 
650 	puts( SEP_LINE );
651 
652         printf( "MP Config Extended Table Entries:\n\n" );
653 
654 	ext_entry = mapEntry(pap + cth->base_table_length,
655 	    cth->extended_table_length);
656 	end = (ext_entry_ptr)((char *)ext_entry + cth->extended_table_length);
657 	while (ext_entry < end) {
658 	    switch (ext_entry->type) {
659             case MPCT_EXTENTRY_SAS:
660 		sasEntry((sas_entry_ptr)ext_entry);
661 		break;
662             case MPCT_EXTENTRY_BHD:
663 		bhdEntry((bhd_entry_ptr)ext_entry);
664 		break;
665             case MPCT_EXTENTRY_CBASM:
666 		cbasmEntry((cbasm_entry_ptr)ext_entry);
667 		break;
668             default:
669                 printf( "Extended Table HOSED!\n" );
670                 exit( 1 );
671             }
672 
673 	    ext_entry = (ext_entry_ptr)((char *)ext_entry + ext_entry->length);
674         }
675     }
676 #endif  /* EXTENDED_PROCESSING_READY */
677 
678     /* process any OEM data */
679     if ( cth->oem_table_pointer && (cth->oem_table_size > 0) ) {
680 #if defined( OEM_PROCESSING_READY )
681 # error your on your own here!
682         /* map in oem table structure */
683 	oemdata = mapEntry( cth->oem_table_pointer, cth->oem_table_size);
684 
685         /** process it */
686 #else
687         printf( "\nyou need to modify the source to handle OEM data!\n\n" );
688 #endif  /* OEM_PROCESSING_READY */
689     }
690 
691     fflush( stdout );
692 
693 #if defined( RAW_DUMP )
694 {
695     int		ofd;
696     void	*dumpbuf;
697 
698     ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR, 0666 );
699 
700     dumpbuf = mapEntry( paddr, 1024 );
701     write( ofd, dumpbuf, 1024 );
702     close( ofd );
703 }
704 #endif /* RAW_DUMP */
705 }
706 
707 
708 /*
709  *
710  */
711 static void
712 seekEntry( u_int32_t addr )
713 {
714     if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 )
715         err( 1, "%s seek", _PATH_MEM );
716 }
717 
718 
719 /*
720  *
721  */
722 static void
723 readEntry( void* entry, int size )
724 {
725     if ( read( pfd, entry, size ) != size )
726         err( 1, "readEntry" );
727 }
728 
729 static void *
730 mapEntry( u_int32_t addr, int size )
731 {
732     void	*p;
733 
734     p = mmap( NULL, size, PROT_READ, MAP_SHARED, pfd, addr );
735     if (p == MAP_FAILED)
736 	err( 1, "mapEntry" );
737     return (p);
738 }
739 
740 static void
741 processorEntry( proc_entry_ptr entry )
742 {
743 
744     /* count it */
745     ++ncpu;
746 
747     printf( "\t\t%2d", entry->apic_id );
748     printf( "\t 0x%2x", entry->apic_version );
749 
750     printf( "\t %s, %s",
751             (entry->cpu_flags & PROCENTRY_FLAG_BP) ? "BSP" : "AP",
752             (entry->cpu_flags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" );
753 
754     printf( "\t %d\t %d\t %d",
755             (entry->cpu_signature >> 8) & 0x0f,
756             (entry->cpu_signature >> 4) & 0x0f,
757             entry->cpu_signature & 0x0f );
758 
759     printf( "\t 0x%04x\n", entry->feature_flags );
760 }
761 
762 
763 /*
764  *
765  */
766 static int
767 lookupBusType( char* name )
768 {
769     int x;
770 
771     for ( x = 0; x < MAX_BUSTYPE; ++x )
772 	if ( strcmp( busTypeTable[ x ].name, name ) == 0 )
773 	    return busTypeTable[ x ].type;
774 
775     return UNKNOWN_BUSTYPE;
776 }
777 
778 
779 static void
780 busEntry( bus_entry_ptr entry )
781 {
782     int		x;
783     char	name[ 8 ];
784     char	c;
785 
786     /* count it */
787     ++nbus;
788 
789     printf( "\t\t%2d", entry->bus_id );
790     printf( "\t " ); pnstr( entry->bus_type, 6 ); printf( "\n" );
791 
792     for ( x = 0; x < 6; ++x ) {
793 	if ( (c = entry->bus_type[ x ]) == ' ' )
794 	    break;
795 	name[ x ] = c;
796     }
797     name[ x ] = '\0';
798     busses[ entry->bus_id ] = lookupBusType( name );
799 }
800 
801 
802 static void
803 ioApicEntry( io_apic_entry_ptr entry )
804 {
805 
806     /* count it */
807     ++napic;
808 
809     printf( "\t\t%2d", entry->apic_id );
810     printf( "\t 0x%02x", entry->apic_version );
811     printf( "\t %s",
812             (entry->apic_flags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" );
813     printf( "\t\t 0x%x\n", entry->apic_address );
814 
815     apics[ entry->apic_id ] = entry->apic_id;
816 }
817 
818 
819 static const char *intTypes[] = {
820     "INT", "NMI", "SMI", "ExtINT"
821 };
822 
823 static const char *polarityMode[] = {
824     "conforms", "active-hi", "reserved", "active-lo"
825 };
826 static const char *triggerMode[] = {
827     "conforms", "edge", "reserved", "level"
828 };
829 
830 static void
831 intEntry( int_entry_ptr entry )
832 {
833 
834     /* count it */
835     if ( entry->type == MPCT_ENTRY_INT )
836 	++nintr;
837 
838     printf( "\t\t%s", intTypes[ entry->int_type ] );
839 
840     printf( "\t%9s", polarityMode[ entry->int_flags & INTENTRY_FLAGS_POLARITY ] );
841     printf( "%12s", triggerMode[ (entry->int_flags & INTENTRY_FLAGS_TRIGGER) >> 2 ] );
842 
843     printf( "\t %5d", entry->src_bus_id );
844     if ( busses[ entry->src_bus_id ] == PCI )
845 	printf( "\t%2d:%c",
846 	        (entry->src_bus_irq >> 2) & 0x1f,
847 	        (entry->src_bus_irq & 0x03) + 'A' );
848     else
849 	printf( "\t %3d", entry->src_bus_irq );
850     printf( "\t %6d", entry->dst_apic_id );
851     printf( "\t %3d\n", entry->dst_apic_int );
852 }
853 
854 
855 static void
856 sasEntry( sas_entry_ptr entry )
857 {
858 
859     printf( "--\nSystem Address Space\n");
860     printf( " bus ID: %d", entry->bus_id );
861     printf( " address type: " );
862     switch ( entry->address_type ) {
863     case SASENTRY_TYPE_IO:
864 	printf( "I/O address\n" );
865 	break;
866     case SASENTRY_TYPE_MEMORY:
867 	printf( "memory address\n" );
868 	break;
869     case SASENTRY_TYPE_PREFETCH:
870 	printf( "prefetch address\n" );
871 	break;
872     default:
873 	printf( "UNKNOWN type\n" );
874 	break;
875     }
876 
877     printf( " address base: 0x%jx\n", (uintmax_t)entry->address_base );
878     printf( " address range: 0x%jx\n", (uintmax_t)entry->address_length );
879 }
880 
881 
882 static void
883 bhdEntry( bhd_entry_ptr entry )
884 {
885 
886     printf( "--\nBus Hierarchy\n" );
887     printf( " bus ID: %d", entry->bus_id );
888     printf( " bus info: 0x%02x", entry->bus_info );
889     printf( " parent bus ID: %d\n", entry->parent_bus );
890 }
891 
892 
893 static void
894 cbasmEntry( cbasm_entry_ptr entry )
895 {
896 
897     printf( "--\nCompatibility Bus Address\n" );
898     printf( " bus ID: %d", entry->bus_id );
899     printf( " address modifier: %s\n",
900 	(entry->address_mod & CBASMENTRY_ADDRESS_MOD_SUBTRACT) ?
901 	"subtract" : "add" );
902     printf( " predefined range: 0x%08x\n", entry->predefined_range );
903 }
904 
905 
906 /*
907  * do a dmesg output
908  */
909 static void
910 doDmesg( void )
911 {
912     puts( SEP_LINE );
913 
914     printf( "dmesg output:\n\n" );
915     fflush( stdout );
916     system( "dmesg" );
917 }
918 
919 
920 /*
921  *
922  */
923 static void
924 pnstr( char* s, int c )
925 {
926     char string[ MAXPNSTR + 1 ];
927 
928     if ( c > MAXPNSTR )
929         c = MAXPNSTR;
930     strncpy( string, s, c );
931     string[ c ] = '\0';
932     printf( "%s", string );
933 }
934