Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/pc/archgeneric.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname pc/archgeneric.c 1992/0923
## diff -e /dev/null /n/bootesdump/1992/0923/sys/src/9/pc/archgeneric.c
0a
#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"

static void
genericreset(void)
{
	print("Reset the machine!\n");
	for(;;);
}

PCArch generic =
{
	"generic",
	genericreset,
	0,
	0,
	0,
	0,
	0,
	0,
};
.
## diffname pc/archgeneric.c 1992/1013
## diff -e /n/bootesdump/1992/0923/sys/src/9/pc/archgeneric.c /n/bootesdump/1992/1013/sys/src/9/pc/archgeneric.c
18c
	i8042reset,
.
## diffname pc/archgeneric.c 1997/0327
## diff -e /n/bootesdump/1992/1013/sys/src/9/pc/archgeneric.c /n/emeliedump/1997/0327/sys/src/brazil/pc/archgeneric.c
25a

void
cpuidprint(void)
{
	int i;
	char buf[128];

	i = sprint(buf, "cpu%d: %dMHz ", m->machno, m->cpumhz);
	if(m->cpuidid[0])
		i += sprint(buf+i, "%s ", m->cpuidid);
	sprint(buf+i, "%s (cpuid: AX 0x%4.4luX DX 0x%4.4luX)\n",
		m->cpuidtype, m->cpuidax, m->cpuiddx);
	print(buf);
}

int
cpuidentify(void)
{
	int family, model;
	X86type *t;
	ulong cr4, mct[2];

	cpuid(m->cpuidid, &m->cpuidax, &m->cpuiddx);
	family = X86FAMILY(m->cpuidax);
	model = X86MODEL(m->cpuidax);
	for(t = x86type; t->name; t++){
		if((t->family == family && t->model == model)
		|| (t->family == family && t->model == -1)
		|| (t->family == -1))
			break;
	}
	m->cpuidtype = t->name;
	i8253init(t->aalcycles);

	/*
	 * If machine check exception or page size extensions are supported
	 * enable them in CR4 and clear any other set extensions.
	 * If machine check was enabled clear out any lingering status.
	 */
	if(m->cpuiddx & 0x88){
		cr4 = 0;
		if(m->cpuiddx & 0x08)
			cr4 |= 0x10;		/* page size extensions */
		if(m->cpuiddx & 0x80)
			cr4 |= 0x40;		/* machine check enable */
		putcr4(cr4);
		if(m->cpuiddx & 0x80)
			rdmsr(0x01, &mct[1], &mct[0]);
	}

	return t->family;
}

void
archinit(void)
{
	PCArch **p;

	arch = 0;
	for(p = knownarch; *p; p++){
		if((*p)->ident && (*p)->ident() == 0){
			arch = *p;
			break;
		}
	}
	if(arch == 0)
		arch = &archgeneric;
	else{
		if(arch->id == 0)
			arch->id = archgeneric.id;
		if(arch->reset == 0)
			arch->reset = archgeneric.reset;
		if(arch->serialpower == 0)
			arch->serialpower = archgeneric.serialpower;
		if(arch->modempower == 0)
			arch->modempower = archgeneric.modempower;
	
		if(arch->intrinit == 0)
			arch->intrinit = archgeneric.intrinit;
		if(arch->intrenable == 0)
			arch->intrenable = archgeneric.intrenable;
	}

	/*
	 * Decide whether to use copy-on-reference (386 and mp).
	 */
	if(X86FAMILY(m->cpuidax) == 3 || conf.nmach > 1)
		conf.copymode = 1;

	if(X86FAMILY(m->cpuidax) == 6 /*&& conf.nmach > 1*/)
		coherence = wbflush;
}
.
17,24c
	{ 4,	0,	22,	"486DX", },	/* known chips */
	{ 4,	1,	22,	"486DX50", },
	{ 4,	2,	22,	"486SX", },
	{ 4,	3,	22,	"486DX2", },
	{ 4,	4,	22,	"486SL", },
	{ 4,	5,	22,	"486SX2", },
	{ 4,	7,	22,	"DX2WB", },	/* P24D */
	{ 4,	8,	22,	"DX4", },
	{ 4,	9,	22,	"DX4WB", },
	{ 5,	0,	23,	"P5", },
	{ 5,	1,	23,	"P5", },
	{ 5,	2,	23,	"P54C", },
	{ 5,	3,	23,	"P24T", },	/* PODP5V83 */
	{ 5,	4,	23,	"PODP54", },
	{ 5,	5,	23,	"PODDX4", },
	{ 5,	6,	23,	"PODP5", },
	{ 6,	4,	23,	"P55CT", },
	{ 6,	1,	16,	"PentiumPro", },/* determined by trial and error */

	{ 3,	-1,	32,	"386", },	/* family defaults */
	{ 4,	-1,	22,	"486", },
	{ 5,	-1,	23,	"Pentium", },
	{ 6,	-1,	16,	"PentiumPro", },

	{ -1,	-1,	23,	"unknown", },	/* total default */
.
15c
void (*coherence)(void) = nop;

PCArch* arch;
extern PCArch* knownarch[];

PCArch archgeneric = {
	"generic",				/* id */
	0,					/* ident */
	i8042reset,				/* reset */
	unimplemented,				/* serialpower */
	unimplemented,				/* modempower */

	i8259init,				/* intrinit */
	i8259enable,				/* intrenable */

	i8253enable,				/* clockenable */
};

typedef struct {
	int	family;
	int	model;
	int	aalcycles;
	char*	name;
} X86type;

static X86type x86type[] =
.
11,12d
9c
nop(void)
.
7a
static int
unimplemented(int)
{
	return 0;
}

.
## diffname pc/archgeneric.c 1997/0404
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1997/0404/sys/src/brazil/pc/archgeneric.c
61a
	{ 5,	7,	23,	"P54C VRT", },
.
59c
	{ 5,	4,	23,	"P54C MMX", },
.
## diffname pc/archgeneric.c 1997/0407
## diff -e /n/emeliedump/1997/0404/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1997/0407/sys/src/brazil/pc/archgeneric.c
63d
58,59c
	{ 5,	3,	23,	"P24T", },
	{ 5,	4,	23,	"P55C MMX", },
.
53,54c
	{ 4,	8,	22,	"DX4", },	/* P24C */
	{ 4,	9,	22,	"DX4WB", },	/* P24CT */
.
## diffname pc/archgeneric.c 1997/0408
## diff -e /n/emeliedump/1997/0407/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1997/0408/sys/src/brazil/pc/archgeneric.c
60,61d
## diffname pc/archgeneric.c 1998/0115
## diff -e /n/emeliedump/1997/0408/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/0115/sys/src/brazil/pc/archgeneric.c
61a
	{ 6,	3,	16,	"PentiumII", },	/* determined by trial and error */
.
## diffname pc/archgeneric.c 1998/0401
## diff -e /n/emeliedump/1998/0115/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/0401/sys/src/brazil/pc/archgeneric.c
118c
			rdmsr(0x01, &mct);
.
91c
	ulong cr4;
	vlong mct;
.
## diffname pc/archgeneric.c 1998/0404
## diff -e /n/emeliedump/1998/0401/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/0404/sys/src/brazil/pc/archgeneric.c
62a
	{ 6,	5,	16,	"PentiumII", },	/* determined by trial and error */
.
## diffname pc/archgeneric.c 1998/0522
## diff -e /n/emeliedump/1998/0404/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/0522/sys/src/brazil/pc/archgeneric.c
102a
		t++;
.
98c
	while(t->name){
.
95a
	if(strncmp(m->cpuidid, "AuthenticAMD", 12) == 0)
		t = x86amd;
	else
		t = x86intel;
.
72a
/*
 * The AMD processors all implement the CPUID instruction.
 * The later ones also return the processor name via functions
 * 0x80000002, 0x80000003 and 0x80000004 in registers AX, BX, CX
 * and DX:
 *	K5	"AMD-K5(tm) Processor"
 *	K6	"AMD-K6tm w/ multimedia extensions"
 *	K6 3D	"AMD-K6(tm) 3D processor"
 *	K6 3D+	?
 */
static X86type x86amd[] =
{
	{ 5,	0,	23,	"AMD-K5", },	/* guesswork */
	{ 5,	1,	23,	"AMD-K5", },	/* guesswork */
	{ 5,	2,	23,	"AMD-K5", },	/* guesswork */
	{ 5,	3,	23,	"AMD-K5", },	/* guesswork */
	{ 5,	6,	23,	"AMD-K6", },	/* guesswork */
	{ 5,	7,	23,	"AMD-K6", },	/* guesswork */
	{ 5,	8,	23,	"AMD-K6 3D", },	/* guesswork */
	{ 5,	9,	23,	"AMD-K6 3D+", },/* guesswork */

	{ 4,	-1,	22,	"Am486", },	/* guesswork */
	{ 5,	-1,	23,	"AMD-K5/K6", },	/* guesswork */

	{ -1,	-1,	23,	"unknown", },	/* total default */
};

.
44c
static X86type x86intel[] =
.
## diffname pc/archgeneric.c 1998/0702
## diff -e /n/emeliedump/1998/0522/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/0702/sys/src/brazil/pc/archgeneric.c
89,90c
	{ 5,	6,	11,	"AMD-K6", },	/* determined by trial and error */
	{ 5,	7,	11,	"AMD-K6", },	/* determined by trial and error */
.
## diffname pc/archgeneric.c 1998/0710
## diff -e /n/emeliedump/1998/0702/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/0710/sys/src/brazil/pc/archgeneric.c
195a
}

static uvlong fasthz;

void
cycletimerinit(void)
{
	fasthz = 1000000LL*m->cpumhz;
}

/*
 *  return the most precice clock we have
 */
uvlong
cycletimer(uvlong *hz)
{
	uvlong tsc;

	rdmsr(0x10, (vlong*)&tsc);
	if(hz != nil)
		*hz = fasthz;
	return tsc;
}

uvlong
fastticks(uvlong *hz)
{
	return (*arch->fastclock)(hz);
.
187a
	/* pick the better timer */
	if(X86FAMILY(m->cpuidax) >= 5){
		cycletimerinit();
		arch->fastclock = cycletimer;
	}

.
34a

	i8253read,				/* read the standard timer */
.
19a
void cycletimerinit(void);
uvlong cycletimer(uvlong*);
.
## diffname pc/archgeneric.c 1998/0716
## diff -e /n/emeliedump/1998/0710/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/0716/sys/src/brazil/pc/archgeneric.c
212a
	wrmsr(0x10, 0);
.
## diffname pc/archgeneric.c 1998/0717
## diff -e /n/emeliedump/1998/0716/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/0717/sys/src/brazil/pc/archgeneric.c
225a
	m->fastclock = tsc;
.
## diffname pc/archgeneric.c 1998/0825
## diff -e /n/emeliedump/1998/0717/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/0825/sys/src/brazil/pc/archgeneric.c
113c
	sprint(buf+i, "%s (cpuid: AX 0x%4.4uX DX 0x%4.4uX)\n",
.
## diffname pc/archgeneric.c 1998/0906
## diff -e /n/emeliedump/1998/0825/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/0906/sys/src/brazil/pc/archgeneric.c
71,72c
	{ 5,	-1,	23,	"P5", },
	{ 6,	-1,	16,	"P6", },
.
66,67c
	{ 6,	3,	16,	"PentiumII", },
	{ 6,	5,	16,	"PentiumII/Xeon", },
.
## diffname pc/archgeneric.c 1998/1106
## diff -e /n/emeliedump/1998/0906/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/1106/sys/src/brazil/pc/archgeneric.c
218c
 *  return the most precise clock we have
.
## diffname pc/archgeneric.c 1998/1222
## diff -e /n/emeliedump/1998/1106/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1998/1222/sys/src/brazil/pc/archgeneric.c
95,96c
	{ 5,	8,	11,	"AMD-K6 3D", },	/* guesswork */
	{ 5,	9,	11,	"AMD-K6 3D+", },/* guesswork */
.
## diffname pc/archgeneric.c 1999/0112
## diff -e /n/emeliedump/1998/1222/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1999/0112/sys/src/brazil/pc/archgeneric.c
204c
	if(X86FAMILY(m->cpuidax) >= 5)
.
## diffname pc/archgeneric.c 1999/0129
## diff -e /n/emeliedump/1999/0112/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1999/0129/sys/src/brazil/pc/archgeneric.c
230,235d
208c
extern uvlong fasthz;
.
## diffname pc/archgeneric.c 1999/0130
## diff -e /n/emeliedump/1999/0129/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1999/0130/sys/src/brazil/pc/archgeneric.c
229a
}

vlong
fastticks(uvlong *hz)
{
	return (*arch->fastclock)(hz);
.
208c
static uvlong fasthz;
.
## diffname pc/archgeneric.c 1999/0131
## diff -e /n/emeliedump/1999/0130/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1999/0131/sys/src/brazil/pc/archgeneric.c
141c
	i8253init(t->aalcycles, t->family >= 5);
.
## diffname pc/archgeneric.c 1999/0218
## diff -e /n/emeliedump/1999/0131/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1999/0218/sys/src/brazil/pc/archgeneric.c
214c
	fasthz = m->cpuhz;
.
## diffname pc/archgeneric.c 1999/0820 # deleted
## diff -e /n/emeliedump/1999/0218/sys/src/brazil/pc/archgeneric.c /n/emeliedump/1999/0820/sys/src/brazil/pc/archgeneric.c
1,236d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].