125265Sfsmp/*
225265Sfsmp * Copyright (c) 1996, by Steve Passe
325265Sfsmp * All rights reserved.
425265Sfsmp *
525265Sfsmp * Redistribution and use in source and binary forms, with or without
625265Sfsmp * modification, are permitted provided that the following conditions
725265Sfsmp * are met:
825265Sfsmp * 1. Redistributions of source code must retain the above copyright
925265Sfsmp *    notice, this list of conditions and the following disclaimer.
1025265Sfsmp * 2. The name of the developer may NOT be used to endorse or promote products
1125265Sfsmp *    derived from this software without specific prior written permission.
1225265Sfsmp *
1325265Sfsmp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1425265Sfsmp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1525265Sfsmp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1625265Sfsmp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1725265Sfsmp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1825265Sfsmp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1925265Sfsmp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2025265Sfsmp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2125265Sfsmp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2225265Sfsmp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2325265Sfsmp * SUCH DAMAGE.
2425265Sfsmp */
2525265Sfsmp
2625265Sfsmp/*
2725265Sfsmp * mptable.c
2825265Sfsmp */
2925265Sfsmp
3029850Scharnier#ifndef lint
3129850Scharnierstatic const char rcsid[] =
3250479Speter  "$FreeBSD$";
3329850Scharnier#endif /* not lint */
3429850Scharnier
3525265Sfsmp/*
3625265Sfsmp * this will cause the raw mp table to be dumped to /tmp/mpdump
3725265Sfsmp *
3825265Sfsmp#define RAW_DUMP
3925265Sfsmp */
4025265Sfsmp
4125265Sfsmp#define MP_SIG			0x5f504d5f	/* _MP_ */
4225265Sfsmp#define EXTENDED_PROCESSING_READY
4325265Sfsmp#define OEM_PROCESSING_READY_NOT
4425265Sfsmp
45244530Sneel#include <sys/param.h>
4629850Scharnier#include <err.h>
4729850Scharnier#include <fcntl.h>
4869793Sobrien#include <paths.h>
4925265Sfsmp#include <stdio.h>
5029850Scharnier#include <stdlib.h>
5129850Scharnier#include <string.h>
5225265Sfsmp#include <unistd.h>
5325265Sfsmp
5425265Sfsmp#define SEP_LINE \
5525265Sfsmp"\n-------------------------------------------------------------------------------\n"
5625265Sfsmp
5725265Sfsmp#define SEP_LINE2 \
5825265Sfsmp"\n===============================================================================\n"
5925265Sfsmp
6025265Sfsmp/* EBDA is @ 40:0e in real-mode terms */
6125265Sfsmp#define EBDA_POINTER		0x040e		/* location of EBDA pointer */
6225265Sfsmp
6325265Sfsmp/* CMOS 'top of mem' is @ 40:13 in real-mode terms */
6425265Sfsmp#define TOPOFMEM_POINTER	0x0413		/* BIOS: base memory size */
6525265Sfsmp
6625265Sfsmp#define DEFAULT_TOPOFMEM	0xa0000
6725265Sfsmp
6825265Sfsmp#define BIOS_BASE		0xf0000
6925265Sfsmp#define BIOS_BASE2		0xe0000
7025265Sfsmp#define BIOS_SIZE		0x10000
7125265Sfsmp#define ONE_KBYTE		1024
7225265Sfsmp
7325265Sfsmp#define GROPE_AREA1		0x80000
7425265Sfsmp#define GROPE_AREA2		0x90000
7525265Sfsmp#define GROPE_SIZE		0x10000
7625265Sfsmp
7725265Sfsmp#define PROCENTRY_FLAG_EN	0x01
7825265Sfsmp#define PROCENTRY_FLAG_BP	0x02
7925265Sfsmp#define IOAPICENTRY_FLAG_EN	0x01
8025265Sfsmp
8125265Sfsmp#define MAXPNSTR		132
8225265Sfsmp
8325265Sfsmpenum busTypes {
8425265Sfsmp    CBUS = 1,
8525265Sfsmp    CBUSII = 2,
8625265Sfsmp    EISA = 3,
8725265Sfsmp    ISA = 6,
8825265Sfsmp    PCI = 13,
8925265Sfsmp    XPRESS = 18,
9025265Sfsmp    MAX_BUSTYPE = 18,
9125265Sfsmp    UNKNOWN_BUSTYPE = 0xff
9225265Sfsmp};
9325265Sfsmp
9425265Sfsmptypedef struct BUSTYPENAME {
9525265Sfsmp    u_char	type;
9625265Sfsmp    char	name[ 7 ];
9725265Sfsmp} busTypeName;
9825265Sfsmp
99227224Sedstatic const busTypeName busTypeTable[] =
10025265Sfsmp{
10125265Sfsmp    { CBUS,		"CBUS"   },
10225265Sfsmp    { CBUSII,		"CBUSII" },
10325265Sfsmp    { EISA,		"EISA"   },
10425265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
10525265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
10625265Sfsmp    { ISA,		"ISA"    },
10725265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
10825265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
10925265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
11025265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
11125265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
11225265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
11325265Sfsmp    { PCI,		"PCI"    },
11425265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
11525265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
11625265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
11725265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
11825265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    },
11925265Sfsmp    { UNKNOWN_BUSTYPE,	"---"    }
12025265Sfsmp};
12125265Sfsmp
122227224Sedstatic const char *whereStrings[] = {
12325265Sfsmp    "Extended BIOS Data Area",
12425265Sfsmp    "BIOS top of memory",
12525265Sfsmp    "Default top of memory",
12625265Sfsmp    "BIOS",
12725265Sfsmp    "Extended BIOS",
12825265Sfsmp    "GROPE AREA #1",
12925265Sfsmp    "GROPE AREA #2"
13025265Sfsmp};
13125265Sfsmp
13225265Sfsmptypedef struct TABLE_ENTRY {
13325265Sfsmp    u_char	type;
13425265Sfsmp    u_char	length;
13525265Sfsmp    char	name[ 32 ];
13625265Sfsmp} tableEntry;
13725265Sfsmp
138227224Sedstatic const tableEntry extendedtableEntryTypes[] =
13925265Sfsmp{
14025265Sfsmp    { 128, 20, "System Address Space" },
141204085Sjhb    { 129,  8, "Bus Hierarchy" },
14225265Sfsmp    { 130,  8, "Compatibility Bus Address" }
14325265Sfsmp};
14425265Sfsmp
14525265Sfsmp/* MP Floating Pointer Structure */
14625265Sfsmptypedef struct MPFPS {
14725265Sfsmp    char	signature[ 4 ];
148120590Speter    u_int32_t	pap;
14925265Sfsmp    u_char	length;
15025265Sfsmp    u_char	spec_rev;
15125265Sfsmp    u_char	checksum;
15225265Sfsmp    u_char	mpfb1;
15325265Sfsmp    u_char	mpfb2;
15425265Sfsmp    u_char	mpfb3;
15525265Sfsmp    u_char	mpfb4;
15625265Sfsmp    u_char	mpfb5;
15725265Sfsmp} mpfps_t;
15825265Sfsmp
15925265Sfsmp/* MP Configuration Table Header */
16025265Sfsmptypedef struct MPCTH {
16125265Sfsmp    char	signature[ 4 ];
16225265Sfsmp    u_short	base_table_length;
16325265Sfsmp    u_char	spec_rev;
16425265Sfsmp    u_char	checksum;
16525265Sfsmp    u_char	oem_id[ 8 ];
16625265Sfsmp    u_char	product_id[ 12 ];
167120590Speter    u_int32_t	oem_table_pointer;
16825265Sfsmp    u_short	oem_table_size;
16925265Sfsmp    u_short	entry_count;
170120590Speter    u_int32_t	apic_address;
17125265Sfsmp    u_short	extended_table_length;
17225265Sfsmp    u_char	extended_table_checksum;
17325265Sfsmp    u_char	reserved;
17425265Sfsmp} mpcth_t;
17525265Sfsmp
17625265Sfsmp
17725265Sfsmptypedef struct PROCENTRY {
17825265Sfsmp    u_char	type;
17925265Sfsmp    u_char	apicID;
18025265Sfsmp    u_char	apicVersion;
18125265Sfsmp    u_char	cpuFlags;
182120590Speter    u_int32_t	cpuSignature;
183120590Speter    u_int32_t	featureFlags;
184120590Speter    u_int32_t	reserved1;
185120590Speter    u_int32_t	reserved2;
18625265Sfsmp} ProcEntry;
18725265Sfsmp
18825265Sfsmptypedef struct BUSENTRY {
18925265Sfsmp    u_char	type;
19025265Sfsmp    u_char	busID;
19125265Sfsmp    char	busType[ 6 ];
19225265Sfsmp} BusEntry;
19325265Sfsmp
19425265Sfsmptypedef struct IOAPICENTRY {
19525265Sfsmp    u_char	type;
19625265Sfsmp    u_char	apicID;
19725265Sfsmp    u_char	apicVersion;
19825265Sfsmp    u_char	apicFlags;
199120590Speter    u_int32_t	apicAddress;
20025265Sfsmp} IOApicEntry;
20125265Sfsmp
20225265Sfsmptypedef struct INTENTRY {
20325265Sfsmp    u_char	type;
20425265Sfsmp    u_char	intType;
20525265Sfsmp    u_short	intFlags;
20625265Sfsmp    u_char	srcBusID;
20725265Sfsmp    u_char	srcBusIRQ;
20825265Sfsmp    u_char	dstApicID;
20925265Sfsmp    u_char	dstApicINT;
21025265Sfsmp} IntEntry;
21125265Sfsmp
21225265Sfsmp
21325265Sfsmp/*
21425265Sfsmp * extended entry type structures
21525265Sfsmp */
21625265Sfsmp
21725265Sfsmptypedef struct SASENTRY {
21825265Sfsmp    u_char	type;
21925265Sfsmp    u_char	length;
22025265Sfsmp    u_char	busID;
22125265Sfsmp    u_char	addressType;
22225265Sfsmp    u_int64_t	addressBase;
22325265Sfsmp    u_int64_t	addressLength;
224120590Speter} __attribute__((__packed__)) SasEntry;
22525265Sfsmp
22625265Sfsmp
22725265Sfsmptypedef struct BHDENTRY {
22825265Sfsmp    u_char	type;
22925265Sfsmp    u_char	length;
23025265Sfsmp    u_char	busID;
23125265Sfsmp    u_char	busInfo;
23225265Sfsmp    u_char	busParent;
23325265Sfsmp    u_char	reserved[ 3 ];
23425265Sfsmp} BhdEntry;
23525265Sfsmp
23625265Sfsmp
23725265Sfsmptypedef struct CBASMENTRY {
23825265Sfsmp    u_char	type;
23925265Sfsmp    u_char	length;
24025265Sfsmp    u_char	busID;
24125265Sfsmp    u_char	addressMod;
24225265Sfsmp    u_int	predefinedRange;
24325265Sfsmp} CbasmEntry;
24425265Sfsmp
24525265Sfsmp
24625265Sfsmp
247120590Speterstatic void apic_probe( u_int32_t* paddr, int* where );
24825265Sfsmp
24925265Sfsmpstatic void MPConfigDefault( int featureByte );
25025265Sfsmp
251120590Speterstatic void MPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfps );
252120590Speterstatic void MPConfigTableHeader( u_int32_t pap );
25325265Sfsmp
25425265Sfsmpstatic int readType( void );
255120590Speterstatic void seekEntry( u_int32_t addr );
25625265Sfsmpstatic void readEntry( void* entry, int size );
25725265Sfsmp
25825265Sfsmpstatic void processorEntry( void );
25925265Sfsmpstatic void busEntry( void );
26025265Sfsmpstatic void ioApicEntry( void );
26125265Sfsmpstatic void intEntry( void );
26225265Sfsmp
26325265Sfsmpstatic void sasEntry( void );
26425265Sfsmpstatic void bhdEntry( void );
26525265Sfsmpstatic void cbasmEntry( void );
26625265Sfsmp
26725265Sfsmpstatic void doDmesg( void );
26825265Sfsmpstatic void pnstr( char* s, int c );
26925265Sfsmp
27025265Sfsmp/* global data */
271227224Sedstatic int	pfd;		/* physical /dev/mem fd */
27225265Sfsmp
273244526Sneelstatic int	busses[256];
274244526Sneelstatic int	apics[256];
27525265Sfsmp
276227224Sedstatic int	ncpu;
277227224Sedstatic int	nbus;
278227224Sedstatic int	napic;
279227224Sedstatic int	nintr;
28025265Sfsmp
281227224Sedstatic int	dmesg;
282227224Sedstatic int	grope;
283227224Sedstatic int	verbose;
28425265Sfsmp
28525265Sfsmpstatic void
28625265Sfsmpusage( void )
28725265Sfsmp{
28829850Scharnier    fprintf( stderr, "usage: mptable [-dmesg] [-verbose] [-grope] [-help]\n" );
28925265Sfsmp    exit( 0 );
29025265Sfsmp}
29125265Sfsmp
29225265Sfsmp/*
29325265Sfsmp *
29425265Sfsmp */
29525265Sfsmpint
29625265Sfsmpmain( int argc, char *argv[] )
29725265Sfsmp{
298120590Speter    u_int32_t	paddr;
29925265Sfsmp    int		where;
30025265Sfsmp    mpfps_t	mpfps;
30125265Sfsmp    int		defaultConfig;
30225265Sfsmp
30325265Sfsmp    int		ch;
30425265Sfsmp
30525265Sfsmp    /* announce ourselves */
30625265Sfsmp    puts( SEP_LINE2 );
30725265Sfsmp
308141385Sobrien    printf( "MPTable\n" );
30925265Sfsmp
31047442Simp    while ((ch = getopt(argc, argv, "d:g:h:v:")) != -1) {
31125265Sfsmp	switch(ch) {
31225265Sfsmp	case 'd':
31325265Sfsmp	    if ( strcmp( optarg, "mesg") == 0 )
31425265Sfsmp	        dmesg = 1;
31525265Sfsmp	    else
31625265Sfsmp	        dmesg = 0;
31725265Sfsmp	    break;
31825265Sfsmp	case 'h':
31925265Sfsmp	    if ( strcmp( optarg, "elp") == 0 )
32025265Sfsmp	        usage();
32125265Sfsmp	    break;
32225265Sfsmp	case 'g':
32325326Sfsmp	    if ( strcmp( optarg, "rope") == 0 )
32425265Sfsmp	        grope = 1;
32525265Sfsmp	    break;
32625265Sfsmp	case 'v':
32725265Sfsmp	    if ( strcmp( optarg, "erbose") == 0 )
32825265Sfsmp	        verbose = 1;
32925265Sfsmp	    break;
33025265Sfsmp	default:
33125265Sfsmp	    usage();
33225265Sfsmp	}
33325265Sfsmp	argc -= optind;
33425265Sfsmp	argv += optind;
33525265Sfsmp	optreset = 1;
33625265Sfsmp	optind = 0;
33725265Sfsmp    }
33825265Sfsmp
33925265Sfsmp    /* open physical memory for access to MP structures */
34069793Sobrien    if ( (pfd = open( _PATH_MEM, O_RDONLY )) < 0 )
34129850Scharnier        err( 1, "mem open" );
34225265Sfsmp
34325265Sfsmp    /* probe for MP structures */
34425265Sfsmp    apic_probe( &paddr, &where );
34525265Sfsmp    if ( where <= 0 ) {
34625265Sfsmp        fprintf( stderr, "\n MP FPS NOT found,\n" );
34725265Sfsmp        fprintf( stderr, " suggest trying -grope option!!!\n\n" );
34825265Sfsmp        return 1;
34925265Sfsmp    }
35025265Sfsmp
35125265Sfsmp    if ( verbose )
35225265Sfsmp        printf( "\n MP FPS found in %s @ physical addr: 0x%08x\n",
35325265Sfsmp	      whereStrings[ where - 1 ], paddr );
35425265Sfsmp
35525265Sfsmp    puts( SEP_LINE );
35625265Sfsmp
35725265Sfsmp    /* analyze the MP Floating Pointer Structure */
35825265Sfsmp    MPFloatingPointer( paddr, where, &mpfps );
35925265Sfsmp
36025265Sfsmp    puts( SEP_LINE );
36125265Sfsmp
36225265Sfsmp    /* check whether an MP config table exists */
36329850Scharnier    if ( (defaultConfig = mpfps.mpfb1) )
36425265Sfsmp        MPConfigDefault( defaultConfig );
36525265Sfsmp    else
36625265Sfsmp	MPConfigTableHeader( mpfps.pap );
36725265Sfsmp
36825265Sfsmp    /* do a dmesg output */
36925265Sfsmp    if ( dmesg )
37025265Sfsmp        doDmesg();
37125265Sfsmp
37225265Sfsmp    puts( SEP_LINE2 );
37325265Sfsmp
37425265Sfsmp    return 0;
37525265Sfsmp}
37625265Sfsmp
37725265Sfsmp
37825265Sfsmp/*
37925265Sfsmp * set PHYSICAL address of MP floating pointer structure
38025265Sfsmp */
38125265Sfsmp#define NEXT(X)		((X) += 4)
38225265Sfsmpstatic void
383120590Speterapic_probe( u_int32_t* paddr, int* where )
38425265Sfsmp{
38525265Sfsmp    /*
38625265Sfsmp     * c rewrite of apic_probe() by Jack F. Vogel
38725265Sfsmp     */
38825265Sfsmp
38925265Sfsmp    int		x;
39025265Sfsmp    u_short	segment;
391120590Speter    u_int32_t	target;
39225265Sfsmp    u_int	buffer[ BIOS_SIZE / sizeof( int ) ];
39325265Sfsmp
39425265Sfsmp    if ( verbose )
39525265Sfsmp        printf( "\n" );
39625265Sfsmp
39725265Sfsmp    /* search Extended Bios Data Area, if present */
39825265Sfsmp    if ( verbose )
39925265Sfsmp        printf( " looking for EBDA pointer @ 0x%04x, ", EBDA_POINTER );
400120590Speter    seekEntry( (u_int32_t)EBDA_POINTER );
40125265Sfsmp    readEntry( &segment, 2 );
40225265Sfsmp    if ( segment ) {		    /* search EBDA */
403120590Speter        target = (u_int32_t)segment << 4;
40425265Sfsmp	if ( verbose )
40525265Sfsmp	    printf( "found, searching EBDA @ 0x%08x\n", target );
40625265Sfsmp        seekEntry( target );
40725265Sfsmp        readEntry( buffer, ONE_KBYTE );
40825265Sfsmp
409120590Speter        for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
41025265Sfsmp            if ( buffer[ x ] == MP_SIG ) {
41125265Sfsmp                *where = 1;
41225265Sfsmp                *paddr = (x * sizeof( unsigned int )) + target;
41325265Sfsmp                return;
41425265Sfsmp            }
41525265Sfsmp        }
41625265Sfsmp    }
41725265Sfsmp    else {
41825265Sfsmp	if ( verbose )
41925265Sfsmp	    printf( "NOT found\n" );
42025265Sfsmp    }
42125265Sfsmp
42225265Sfsmp    /* read CMOS for real top of mem */
423120590Speter    seekEntry( (u_int32_t)TOPOFMEM_POINTER );
42425265Sfsmp    readEntry( &segment, 2 );
42525265Sfsmp    --segment;						/* less ONE_KBYTE */
42625265Sfsmp    target = segment * 1024;
42725265Sfsmp    if ( verbose )
42825265Sfsmp        printf( " searching CMOS 'top of mem' @ 0x%08x (%dK)\n",
42925265Sfsmp	        target, segment );
43025265Sfsmp    seekEntry( target );
43125265Sfsmp    readEntry( buffer, ONE_KBYTE );
43225265Sfsmp
433120590Speter    for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
43425265Sfsmp        if ( buffer[ x ] == MP_SIG ) {
43525265Sfsmp            *where = 2;
43625265Sfsmp            *paddr = (x * sizeof( unsigned int )) + target;
43725265Sfsmp            return;
43825265Sfsmp        }
43925265Sfsmp    }
44025265Sfsmp
44125265Sfsmp    /* we don't necessarily believe CMOS, check base of the last 1K of 640K */
44225265Sfsmp    if ( target != (DEFAULT_TOPOFMEM - 1024)) {
44325265Sfsmp	target = (DEFAULT_TOPOFMEM - 1024);
44425265Sfsmp	if ( verbose )
44525265Sfsmp	    printf( " searching default 'top of mem' @ 0x%08x (%dK)\n",
44625265Sfsmp		    target, (target / 1024) );
44725265Sfsmp	seekEntry( target );
44825265Sfsmp	readEntry( buffer, ONE_KBYTE );
44925265Sfsmp
450120590Speter	for ( x = 0; x < ONE_KBYTE / (int)sizeof ( unsigned int ); NEXT(x) ) {
45125265Sfsmp	    if ( buffer[ x ] == MP_SIG ) {
45225265Sfsmp		*where = 3;
45325265Sfsmp		*paddr = (x * sizeof( unsigned int )) + target;
45425265Sfsmp		return;
45525265Sfsmp	    }
45625265Sfsmp	}
45725265Sfsmp    }
45825265Sfsmp
45925265Sfsmp    /* search the BIOS */
46025265Sfsmp    if ( verbose )
46125265Sfsmp        printf( " searching BIOS @ 0x%08x\n", BIOS_BASE );
46225265Sfsmp    seekEntry( BIOS_BASE );
46325265Sfsmp    readEntry( buffer, BIOS_SIZE );
46425265Sfsmp
465120590Speter    for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
46625265Sfsmp        if ( buffer[ x ] == MP_SIG ) {
46725265Sfsmp            *where = 4;
46825265Sfsmp            *paddr = (x * sizeof( unsigned int )) + BIOS_BASE;
46925265Sfsmp            return;
47025265Sfsmp        }
47125265Sfsmp    }
47225265Sfsmp
47325265Sfsmp    /* search the extended BIOS */
47425265Sfsmp    if ( verbose )
47525265Sfsmp        printf( " searching extended BIOS @ 0x%08x\n", BIOS_BASE2 );
47625265Sfsmp    seekEntry( BIOS_BASE2 );
47725265Sfsmp    readEntry( buffer, BIOS_SIZE );
47825265Sfsmp
479120590Speter    for ( x = 0; x < BIOS_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
48025265Sfsmp        if ( buffer[ x ] == MP_SIG ) {
48125265Sfsmp            *where = 5;
48225265Sfsmp            *paddr = (x * sizeof( unsigned int )) + BIOS_BASE2;
48325265Sfsmp            return;
48425265Sfsmp        }
48525265Sfsmp    }
48625265Sfsmp
48725265Sfsmp    if ( grope ) {
48825265Sfsmp	/* search additional memory */
48925265Sfsmp	target = GROPE_AREA1;
49025265Sfsmp	if ( verbose )
49125265Sfsmp	    printf( " groping memory @ 0x%08x\n", target );
49225265Sfsmp	seekEntry( target );
49325265Sfsmp	readEntry( buffer, GROPE_SIZE );
49425265Sfsmp
495120590Speter	for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
49625265Sfsmp	    if ( buffer[ x ] == MP_SIG ) {
49725265Sfsmp		*where = 6;
49825265Sfsmp		*paddr = (x * sizeof( unsigned int )) + GROPE_AREA1;
49925265Sfsmp		return;
50025265Sfsmp	    }
50125265Sfsmp	}
50225265Sfsmp
50325265Sfsmp	target = GROPE_AREA2;
50425265Sfsmp	if ( verbose )
50525265Sfsmp	    printf( " groping memory @ 0x%08x\n", target );
50625265Sfsmp	seekEntry( target );
50725265Sfsmp	readEntry( buffer, GROPE_SIZE );
50825265Sfsmp
509120590Speter	for ( x = 0; x < GROPE_SIZE / (int)sizeof( unsigned int ); NEXT(x) ) {
51025265Sfsmp	    if ( buffer[ x ] == MP_SIG ) {
51125265Sfsmp		*where = 7;
51225265Sfsmp		*paddr = (x * sizeof( unsigned int )) + GROPE_AREA2;
51325265Sfsmp		return;
51425265Sfsmp	    }
51525265Sfsmp	}
51625265Sfsmp    }
51725265Sfsmp
51825265Sfsmp    *where = 0;
519120590Speter    *paddr = (u_int32_t)0;
52025265Sfsmp}
52125265Sfsmp
52225265Sfsmp
52325265Sfsmp/*
52425265Sfsmp *
52525265Sfsmp */
52629850Scharnierstatic void
527120590SpeterMPFloatingPointer( u_int32_t paddr, int where, mpfps_t* mpfps )
52825265Sfsmp{
52925265Sfsmp
53025265Sfsmp    /* read in mpfps structure*/
53125265Sfsmp    seekEntry( paddr );
53225265Sfsmp    readEntry( mpfps, sizeof( mpfps_t ) );
53325265Sfsmp
53425265Sfsmp    /* show its contents */
53525265Sfsmp    printf( "MP Floating Pointer Structure:\n\n" );
53625265Sfsmp
53729850Scharnier    printf( "  location:\t\t\t" );
53825265Sfsmp    switch ( where )
53925265Sfsmp    {
54025265Sfsmp    case 1:
54125265Sfsmp	printf( "EBDA\n" );
54225265Sfsmp	break;
54325265Sfsmp    case 2:
54425265Sfsmp	printf( "BIOS base memory\n" );
54525265Sfsmp	break;
54625265Sfsmp    case 3:
54725265Sfsmp	printf( "DEFAULT base memory (639K)\n" );
54825265Sfsmp	break;
54925265Sfsmp    case 4:
55025265Sfsmp	printf( "BIOS\n" );
55125265Sfsmp	break;
55225265Sfsmp    case 5:
55325265Sfsmp	printf( "Extended BIOS\n" );
55425265Sfsmp	break;
55525265Sfsmp
55625265Sfsmp    case 0:
55725265Sfsmp	printf( "NOT found!\n" );
55825265Sfsmp	exit( 1 );
55925265Sfsmp    default:
56025265Sfsmp	printf( "BOGUS!\n" );
56125265Sfsmp	exit( 1 );
56225265Sfsmp    }
56325265Sfsmp    printf( "  physical address:\t\t0x%08x\n", paddr );
56425265Sfsmp
56525265Sfsmp    printf( "  signature:\t\t\t'" );
56625265Sfsmp    pnstr( mpfps->signature, 4 );
56725265Sfsmp    printf( "'\n" );
56825265Sfsmp
56925265Sfsmp    printf( "  length:\t\t\t%d bytes\n", mpfps->length * 16 );
57025265Sfsmp    printf( "  version:\t\t\t1.%1d\n", mpfps->spec_rev );
57125265Sfsmp    printf( "  checksum:\t\t\t0x%02x\n", mpfps->checksum );
57225265Sfsmp
57325265Sfsmp    /* bits 0:6 are RESERVED */
57425265Sfsmp    if ( mpfps->mpfb2 & 0x7f ) {
57529850Scharnier        printf( " warning, MP feature byte 2: 0x%02x\n", mpfps->mpfb2 );
57625265Sfsmp    }
57725265Sfsmp
57825265Sfsmp    /* bit 7 is IMCRP */
57925265Sfsmp    printf( "  mode:\t\t\t\t%s\n", (mpfps->mpfb2 & 0x80) ?
58025265Sfsmp            "PIC" : "Virtual Wire" );
58125265Sfsmp
58225265Sfsmp    /* MP feature bytes 3-5 are expected to be ZERO */
58325265Sfsmp    if ( mpfps->mpfb3 )
58425265Sfsmp        printf( " warning, MP feature byte 3 NONZERO!\n" );
58525265Sfsmp    if ( mpfps->mpfb4 )
58625265Sfsmp        printf( " warning, MP feature byte 4 NONZERO!\n" );
58725265Sfsmp    if ( mpfps->mpfb5 )
58825265Sfsmp        printf( " warning, MP feature byte 5 NONZERO!\n" );
58925265Sfsmp}
59025265Sfsmp
59125265Sfsmp
59225265Sfsmp/*
59325265Sfsmp *
59425265Sfsmp */
59525265Sfsmpstatic void
59625265SfsmpMPConfigDefault( int featureByte )
59725265Sfsmp{
59825265Sfsmp    printf( "  MP default config type: %d\n\n", featureByte );
59925265Sfsmp    switch ( featureByte ) {
60025265Sfsmp    case 1:
60125265Sfsmp	printf( "   bus: ISA, APIC: 82489DX\n" );
60225265Sfsmp	break;
60325265Sfsmp    case 2:
60425265Sfsmp	printf( "   bus: EISA, APIC: 82489DX\n" );
60525265Sfsmp	break;
60625265Sfsmp    case 3:
60725265Sfsmp	printf( "   bus: EISA, APIC: 82489DX\n" );
60825265Sfsmp	break;
60925265Sfsmp    case 4:
61025265Sfsmp	printf( "   bus: MCA, APIC: 82489DX\n" );
61125265Sfsmp	break;
61225265Sfsmp    case 5:
61325265Sfsmp	printf( "   bus: ISA+PCI, APIC: Integrated\n" );
61425265Sfsmp	break;
61525265Sfsmp    case 6:
61625265Sfsmp	printf( "   bus: EISA+PCI, APIC: Integrated\n" );
61725265Sfsmp	break;
61825265Sfsmp    case 7:
61925265Sfsmp	printf( "   bus: MCA+PCI, APIC: Integrated\n" );
62025265Sfsmp	break;
62125265Sfsmp    default:
62225265Sfsmp	printf( "   future type\n" );
62325265Sfsmp	break;
62425265Sfsmp    }
62525265Sfsmp
62625265Sfsmp    switch ( featureByte ) {
62725265Sfsmp    case 1:
62825265Sfsmp    case 2:
62925265Sfsmp    case 3:
63025265Sfsmp    case 4:
63125265Sfsmp	nbus = 1;
63225265Sfsmp	break;
63325265Sfsmp    case 5:
63425265Sfsmp    case 6:
63525265Sfsmp    case 7:
63625265Sfsmp	nbus = 2;
63725265Sfsmp	break;
63825265Sfsmp    default:
63925265Sfsmp	printf( "   future type\n" );
64025265Sfsmp	break;
64125265Sfsmp    }
64225265Sfsmp
64325265Sfsmp    ncpu = 2;
64425265Sfsmp    napic = 1;
64525265Sfsmp    nintr = 16;
64625265Sfsmp}
64725265Sfsmp
64825265Sfsmp
64925265Sfsmp/*
65025265Sfsmp *
65125265Sfsmp */
65225265Sfsmpstatic void
653120590SpeterMPConfigTableHeader( u_int32_t pap )
65425265Sfsmp{
655120590Speter    u_int32_t	paddr;
65625265Sfsmp    mpcth_t	cth;
65729850Scharnier    int		x;
65871209Speter    int		totalSize;
65925265Sfsmp    int		count, c;
66025265Sfsmp    int		type;
66171209Speter    int		oldtype, entrytype;
66225265Sfsmp
66325265Sfsmp    if ( pap == 0 ) {
66425265Sfsmp	printf( "MP Configuration Table Header MISSING!\n" );
66525265Sfsmp        exit( 1 );
66625265Sfsmp    }
66725265Sfsmp
66825265Sfsmp    /* convert physical address to virtual address */
669120590Speter    paddr = pap;
67025265Sfsmp
67125265Sfsmp    /* read in cth structure */
67225265Sfsmp    seekEntry( paddr );
67325265Sfsmp    readEntry( &cth, sizeof( cth ) );
67425265Sfsmp
67525265Sfsmp    printf( "MP Config Table Header:\n\n" );
67625265Sfsmp
67725265Sfsmp    printf( "  physical address:\t\t0x%08x\n", pap );
67825265Sfsmp
67925265Sfsmp    printf( "  signature:\t\t\t'" );
68025265Sfsmp    pnstr( cth.signature, 4 );
68125265Sfsmp    printf( "'\n" );
68225265Sfsmp
68325265Sfsmp    printf( "  base table length:\t\t%d\n", cth.base_table_length );
68425265Sfsmp
68525265Sfsmp    printf( "  version:\t\t\t1.%1d\n", cth.spec_rev );
68625265Sfsmp    printf( "  checksum:\t\t\t0x%02x\n", cth.checksum );
68725265Sfsmp
68825265Sfsmp    printf( "  OEM ID:\t\t\t'" );
68925265Sfsmp    pnstr( cth.oem_id, 8 );
69025265Sfsmp    printf( "'\n" );
69125265Sfsmp
69225265Sfsmp    printf( "  Product ID:\t\t\t'" );
69325265Sfsmp    pnstr( cth.product_id, 12 );
69425265Sfsmp    printf( "'\n" );
69525265Sfsmp
69625265Sfsmp    printf( "  OEM table pointer:\t\t0x%08x\n", cth.oem_table_pointer );
69725265Sfsmp    printf( "  OEM table size:\t\t%d\n", cth.oem_table_size );
69825265Sfsmp
69925265Sfsmp    printf( "  entry count:\t\t\t%d\n", cth.entry_count );
70025265Sfsmp
70125265Sfsmp    printf( "  local APIC address:\t\t0x%08x\n", cth.apic_address );
70225265Sfsmp
70325265Sfsmp    printf( "  extended table length:\t%d\n", cth.extended_table_length );
70425265Sfsmp    printf( "  extended table checksum:\t%d\n", cth.extended_table_checksum );
70525265Sfsmp
70625265Sfsmp    totalSize = cth.base_table_length - sizeof( struct MPCTH );
70725265Sfsmp    count = cth.entry_count;
70825265Sfsmp
70925265Sfsmp    puts( SEP_LINE );
71025265Sfsmp
71125265Sfsmp    printf( "MP Config Base Table Entries:\n\n" );
71225265Sfsmp
713244530Sneel    /* initialize tables */
714244530Sneel    for (x = 0; x < (int)nitems(busses); x++)
715244530Sneel	busses[x] = 0xff;
71625265Sfsmp
717244530Sneel    for (x = 0; x < (int)nitems(apics); x++)
718244530Sneel	apics[x] = 0xff;
719244530Sneel
72025265Sfsmp    ncpu = 0;
72125265Sfsmp    nbus = 0;
72225265Sfsmp    napic = 0;
72325265Sfsmp    nintr = 0;
72425265Sfsmp
72571209Speter    oldtype = -1;
72671209Speter    for (c = count; c; c--) {
72771209Speter	entrytype = readType();
72871209Speter	if (entrytype != oldtype)
72971209Speter	    printf("--\n");
73071209Speter	if (entrytype < oldtype)
73171209Speter	    printf("MPTABLE OUT OF ORDER!\n");
73271209Speter	switch (entrytype) {
73371209Speter	case 0:
73471209Speter	    if (oldtype != 0)
73571209Speter		printf( "Processors:\tAPIC ID\tVersion\tState"
73671209Speter			"\t\tFamily\tModel\tStep\tFlags\n" );
73771209Speter	    oldtype = 0;
73825265Sfsmp	    processorEntry();
73971209Speter	    break;
74025265Sfsmp
74171209Speter	case 1:
74271209Speter	    if (oldtype != 1)
74371209Speter		printf( "Bus:\t\tBus ID\tType\n" );
74471209Speter	    oldtype = 1;
74525265Sfsmp	    busEntry();
74671209Speter	    break;
74725265Sfsmp
74871209Speter	case 2:
74971209Speter	    if (oldtype != 2)
75071209Speter		printf( "I/O APICs:\tAPIC ID\tVersion\tState\t\tAddress\n" );
75171209Speter	    oldtype = 2;
75225265Sfsmp	    ioApicEntry();
75371209Speter	    break;
75425265Sfsmp
75571209Speter	case 3:
75671209Speter	    if (oldtype != 3)
75771209Speter		printf( "I/O Ints:\tType\tPolarity    Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
75871209Speter	    oldtype = 3;
75925265Sfsmp	    intEntry();
76071209Speter	    break;
76125265Sfsmp
76271209Speter	case 4:
76371209Speter	    if (oldtype != 4)
76471209Speter		printf( "Local Ints:\tType\tPolarity    Trigger\tBus ID\t IRQ\tAPIC ID\tPIN#\n" );
76571209Speter	    oldtype = 4;
76625265Sfsmp	    intEntry();
76771209Speter	    break;
76871209Speter
76971209Speter	default:
77071209Speter	    printf("MPTABLE HOSED! record type = %d\n", entrytype);
77171209Speter	    exit(1);
77271209Speter	}
77325265Sfsmp    }
77425265Sfsmp
77525265Sfsmp
77625265Sfsmp#if defined( EXTENDED_PROCESSING_READY )
77725265Sfsmp    /* process any extended data */
77829850Scharnier    if ( (totalSize = cth.extended_table_length) ) {
77925265Sfsmp	puts( SEP_LINE );
78025265Sfsmp
78125265Sfsmp        printf( "MP Config Extended Table Entries:\n\n" );
78225265Sfsmp
78325265Sfsmp        while ( totalSize > 0 ) {
78425265Sfsmp            switch ( type = readType() ) {
78525265Sfsmp            case 128:
78625265Sfsmp		sasEntry();
78725265Sfsmp		break;
78825265Sfsmp            case 129:
78925265Sfsmp		bhdEntry();
79025265Sfsmp		break;
79125265Sfsmp            case 130:
79225265Sfsmp		cbasmEntry();
79325265Sfsmp		break;
79425265Sfsmp            default:
79525265Sfsmp                printf( "Extended Table HOSED!\n" );
79625265Sfsmp                exit( 1 );
79725265Sfsmp            }
79825265Sfsmp
79925265Sfsmp            totalSize -= extendedtableEntryTypes[ type-128 ].length;
80025265Sfsmp        }
80125265Sfsmp    }
80225265Sfsmp#endif  /* EXTENDED_PROCESSING_READY */
80325265Sfsmp
80425265Sfsmp    /* process any OEM data */
80525265Sfsmp    if ( cth.oem_table_pointer && (cth.oem_table_size > 0) ) {
80625265Sfsmp#if defined( OEM_PROCESSING_READY )
80725265Sfsmp# error your on your own here!
80825265Sfsmp        /* convert OEM table pointer to virtual address */
809120590Speter        poemtp = (u_int32_t)cth.oem_table_pointer;
81025265Sfsmp
81125265Sfsmp        /* read in oem table structure */
81229850Scharnier        if ( (oemdata = (void*)malloc( cth.oem_table_size )) == NULL )
81329850Scharnier            err( 1, "oem malloc" );
81425265Sfsmp
81525265Sfsmp        seekEntry( poemtp );
81625265Sfsmp        readEntry( oemdata, cth.oem_table_size );
81725265Sfsmp
81825265Sfsmp        /** process it */
81925265Sfsmp
82025265Sfsmp        free( oemdata );
82125265Sfsmp#else
82225265Sfsmp        printf( "\nyou need to modify the source to handle OEM data!\n\n" );
82325265Sfsmp#endif  /* OEM_PROCESSING_READY */
82425265Sfsmp    }
82525265Sfsmp
82625265Sfsmp    fflush( stdout );
82725265Sfsmp
82825265Sfsmp#if defined( RAW_DUMP )
82925265Sfsmp{
83025265Sfsmp    int		ofd;
83125265Sfsmp    u_char	dumpbuf[ 4096 ];
83225265Sfsmp
833229466Spjd    ofd = open( "/tmp/mpdump", O_CREAT | O_RDWR, 0666 );
83425265Sfsmp    seekEntry( paddr );
83525265Sfsmp    readEntry( dumpbuf, 1024 );
83625265Sfsmp    write( ofd, dumpbuf, 1024 );
83725265Sfsmp    close( ofd );
83825265Sfsmp}
83925265Sfsmp#endif /* RAW_DUMP */
84025265Sfsmp}
84125265Sfsmp
84225265Sfsmp
84325265Sfsmp/*
84425265Sfsmp *
84525265Sfsmp */
84625265Sfsmpstatic int
84725265SfsmpreadType( void )
84825265Sfsmp{
84925265Sfsmp    u_char	type;
85025265Sfsmp
85129850Scharnier    if ( read( pfd, &type, sizeof( u_char ) ) != sizeof( u_char ) )
85229850Scharnier        err( 1, "type read; pfd: %d", pfd );
85325265Sfsmp
85429850Scharnier    if ( lseek( pfd, -1, SEEK_CUR ) < 0 )
85529850Scharnier        err( 1, "type seek" );
85625265Sfsmp
85725265Sfsmp    return (int)type;
85825265Sfsmp}
85925265Sfsmp
86025265Sfsmp
86125265Sfsmp/*
86225265Sfsmp *
86325265Sfsmp */
86425265Sfsmpstatic void
865120590SpeterseekEntry( u_int32_t addr )
86625265Sfsmp{
86729850Scharnier    if ( lseek( pfd, (off_t)addr, SEEK_SET ) < 0 )
86869793Sobrien        err( 1, "%s seek", _PATH_MEM );
86925265Sfsmp}
87025265Sfsmp
87125265Sfsmp
87225265Sfsmp/*
87325265Sfsmp *
87425265Sfsmp */
87525265Sfsmpstatic void
87625265SfsmpreadEntry( void* entry, int size )
87725265Sfsmp{
87829850Scharnier    if ( read( pfd, entry, size ) != size )
87929850Scharnier        err( 1, "readEntry" );
88025265Sfsmp}
88125265Sfsmp
88225265Sfsmp
88325265Sfsmpstatic void
88425265SfsmpprocessorEntry( void )
88525265Sfsmp{
88625265Sfsmp    ProcEntry	entry;
88725265Sfsmp
88825265Sfsmp    /* read it into local memory */
88925265Sfsmp    readEntry( &entry, sizeof( entry ) );
89025265Sfsmp
89125265Sfsmp    /* count it */
89225265Sfsmp    ++ncpu;
89325265Sfsmp
89425265Sfsmp    printf( "\t\t%2d", entry.apicID );
89525265Sfsmp    printf( "\t 0x%2x", entry.apicVersion );
89625265Sfsmp
89725265Sfsmp    printf( "\t %s, %s",
89825265Sfsmp            (entry.cpuFlags & PROCENTRY_FLAG_BP) ? "BSP" : "AP",
89925265Sfsmp            (entry.cpuFlags & PROCENTRY_FLAG_EN) ? "usable" : "unusable" );
90025265Sfsmp
90125265Sfsmp    printf( "\t %d\t %d\t %d",
90225265Sfsmp            (entry.cpuSignature >> 8) & 0x0f,
90325265Sfsmp            (entry.cpuSignature >> 4) & 0x0f,
90425265Sfsmp            entry.cpuSignature & 0x0f );
90525265Sfsmp
90625265Sfsmp    printf( "\t 0x%04x\n", entry.featureFlags );
90725265Sfsmp}
90825265Sfsmp
90925265Sfsmp
91025265Sfsmp/*
91125265Sfsmp *
91225265Sfsmp */
91325265Sfsmpstatic int
91425265SfsmplookupBusType( char* name )
91525265Sfsmp{
91625265Sfsmp    int x;
91725265Sfsmp
91825265Sfsmp    for ( x = 0; x < MAX_BUSTYPE; ++x )
91925265Sfsmp	if ( strcmp( busTypeTable[ x ].name, name ) == 0 )
92025265Sfsmp	    return busTypeTable[ x ].type;
92125265Sfsmp
92225265Sfsmp    return UNKNOWN_BUSTYPE;
92325265Sfsmp}
92425265Sfsmp
92525265Sfsmp
92625265Sfsmpstatic void
92725265SfsmpbusEntry( void )
92825265Sfsmp{
92925265Sfsmp    int		x;
93025265Sfsmp    char	name[ 8 ];
93125265Sfsmp    char	c;
93225265Sfsmp    BusEntry	entry;
93325265Sfsmp
93425265Sfsmp    /* read it into local memory */
93525265Sfsmp    readEntry( &entry, sizeof( entry ) );
93625265Sfsmp
93725265Sfsmp    /* count it */
93825265Sfsmp    ++nbus;
93925265Sfsmp
94025265Sfsmp    printf( "\t\t%2d", entry.busID );
94125265Sfsmp    printf( "\t " ); pnstr( entry.busType, 6 ); printf( "\n" );
94225265Sfsmp
94325265Sfsmp    for ( x = 0; x < 6; ++x ) {
94425265Sfsmp	if ( (c = entry.busType[ x ]) == ' ' )
94525265Sfsmp	    break;
94625265Sfsmp	name[ x ] = c;
94725265Sfsmp    }
94825265Sfsmp    name[ x ] = '\0';
94925265Sfsmp    busses[ entry.busID ] = lookupBusType( name );
95025265Sfsmp}
95125265Sfsmp
95225265Sfsmp
95325265Sfsmpstatic void
95425265SfsmpioApicEntry( void )
95525265Sfsmp{
95625265Sfsmp    IOApicEntry	entry;
95725265Sfsmp
95825265Sfsmp    /* read it into local memory */
95925265Sfsmp    readEntry( &entry, sizeof( entry ) );
96025265Sfsmp
96125265Sfsmp    /* count it */
96225265Sfsmp    ++napic;
96325265Sfsmp
96425265Sfsmp    printf( "\t\t%2d", entry.apicID );
96525265Sfsmp    printf( "\t 0x%02x", entry.apicVersion );
96625265Sfsmp    printf( "\t %s",
96725265Sfsmp            (entry.apicFlags & IOAPICENTRY_FLAG_EN) ? "usable" : "unusable" );
96825265Sfsmp    printf( "\t\t 0x%x\n", entry.apicAddress );
96925265Sfsmp
97025265Sfsmp    apics[ entry.apicID ] = entry.apicID;
97125265Sfsmp}
97225265Sfsmp
97325265Sfsmp
974227224Sedstatic const char *intTypes[] = {
97525265Sfsmp    "INT", "NMI", "SMI", "ExtINT"
97625265Sfsmp};
97725265Sfsmp
978227224Sedstatic const char *polarityMode[] = {
97925265Sfsmp    "conforms", "active-hi", "reserved", "active-lo"
98025265Sfsmp};
981227224Sedstatic const char *triggerMode[] = {
98225265Sfsmp    "conforms", "edge", "reserved", "level"
98325265Sfsmp};
98425265Sfsmp
98525265Sfsmpstatic void
98625265SfsmpintEntry( void )
98725265Sfsmp{
98825265Sfsmp    IntEntry	entry;
98925265Sfsmp
99025265Sfsmp    /* read it into local memory */
99125265Sfsmp    readEntry( &entry, sizeof( entry ) );
99225265Sfsmp
99325265Sfsmp    /* count it */
99425265Sfsmp    if ( (int)entry.type == 3 )
99525265Sfsmp	++nintr;
99625265Sfsmp
99725265Sfsmp    printf( "\t\t%s", intTypes[ (int)entry.intType ] );
99825265Sfsmp
99925265Sfsmp    printf( "\t%9s", polarityMode[ (int)entry.intFlags & 0x03 ] );
100025265Sfsmp    printf( "%12s", triggerMode[ ((int)entry.intFlags >> 2) & 0x03 ] );
100125265Sfsmp
100225265Sfsmp    printf( "\t %5d", (int)entry.srcBusID );
100325265Sfsmp    if ( busses[ (int)entry.srcBusID ] == PCI )
100425265Sfsmp	printf( "\t%2d:%c",
100525265Sfsmp	        ((int)entry.srcBusIRQ >> 2) & 0x1f,
100625265Sfsmp	        ((int)entry.srcBusIRQ & 0x03) + 'A' );
100725265Sfsmp    else
100825265Sfsmp	printf( "\t %3d", (int)entry.srcBusIRQ );
100925265Sfsmp    printf( "\t %6d", (int)entry.dstApicID );
101025265Sfsmp    printf( "\t %3d\n", (int)entry.dstApicINT );
101125265Sfsmp}
101225265Sfsmp
101325265Sfsmp
101425265Sfsmpstatic void
101525265SfsmpsasEntry( void )
101625265Sfsmp{
101725265Sfsmp    SasEntry	entry;
101825265Sfsmp
101925265Sfsmp    /* read it into local memory */
102025265Sfsmp    readEntry( &entry, sizeof( entry ) );
102125265Sfsmp
102264291Stegge    printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
102325265Sfsmp    printf( " bus ID: %d", entry.busID );
102425265Sfsmp    printf( " address type: " );
102525265Sfsmp    switch ( entry.addressType ) {
102625265Sfsmp    case 0:
102725265Sfsmp	printf( "I/O address\n" );
102825265Sfsmp	break;
102925265Sfsmp    case 1:
103025265Sfsmp	printf( "memory address\n" );
103125265Sfsmp	break;
103225265Sfsmp    case 2:
103325265Sfsmp	printf( "prefetch address\n" );
103425265Sfsmp	break;
103525265Sfsmp    default:
103625265Sfsmp	printf( "UNKNOWN type\n" );
103725265Sfsmp	break;
103825265Sfsmp    }
103925265Sfsmp
1040120590Speter    printf( " address base: 0x%llx\n", (long long)entry.addressBase );
1041120590Speter    printf( " address range: 0x%llx\n", (long long)entry.addressLength );
104225265Sfsmp}
104325265Sfsmp
104425265Sfsmp
104525265Sfsmpstatic void
104625265SfsmpbhdEntry( void )
104725265Sfsmp{
104825265Sfsmp    BhdEntry	entry;
104925265Sfsmp
105025265Sfsmp    /* read it into local memory */
105125265Sfsmp    readEntry( &entry, sizeof( entry ) );
105225265Sfsmp
105364291Stegge    printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
105425265Sfsmp    printf( " bus ID: %d", entry.busID );
105525265Sfsmp    printf( " bus info: 0x%02x", entry.busInfo );
105664291Stegge    printf( " parent bus ID: %d\n", entry.busParent );
105725265Sfsmp}
105825265Sfsmp
105925265Sfsmp
106025265Sfsmpstatic void
106125265SfsmpcbasmEntry( void )
106225265Sfsmp{
106325265Sfsmp    CbasmEntry	entry;
106425265Sfsmp
106525265Sfsmp    /* read it into local memory */
106625265Sfsmp    readEntry( &entry, sizeof( entry ) );
106725265Sfsmp
106864291Stegge    printf( "--\n%s\n", extendedtableEntryTypes[entry.type - 128].name );
106925265Sfsmp    printf( " bus ID: %d", entry.busID );
107025265Sfsmp    printf( " address modifier: %s\n", (entry.addressMod & 0x01) ?
107125265Sfsmp                                        "subtract" : "add" );
107264291Stegge    printf( " predefined range: 0x%08x\n", entry.predefinedRange );
107325265Sfsmp}
107425265Sfsmp
107525265Sfsmp
107625265Sfsmp/*
107725265Sfsmp * do a dmesg output
107825265Sfsmp */
107925265Sfsmpstatic void
108025265SfsmpdoDmesg( void )
108125265Sfsmp{
108225265Sfsmp    puts( SEP_LINE );
108325265Sfsmp
108425265Sfsmp    printf( "dmesg output:\n\n" );
108525265Sfsmp    fflush( stdout );
108625265Sfsmp    system( "dmesg" );
108725265Sfsmp}
108825265Sfsmp
108925265Sfsmp
109025265Sfsmp/*
109125265Sfsmp *
109225265Sfsmp */
109325265Sfsmpstatic void
109425265Sfsmppnstr( char* s, int c )
109525265Sfsmp{
109625265Sfsmp    char string[ MAXPNSTR + 1 ];
109725265Sfsmp
109825265Sfsmp    if ( c > MAXPNSTR )
109925265Sfsmp        c = MAXPNSTR;
110025265Sfsmp    strncpy( string, s, c );
110125265Sfsmp    string[ c ] = '\0';
110225265Sfsmp    printf( "%s", string );
110325265Sfsmp}
1104