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