pc kernel: get rid of ugly and partially broken cpuid macros

This commit is contained in:
aiju 2018-07-11 14:50:22 +01:00
parent 911df94e5d
commit 3a77c01f43
7 changed files with 27 additions and 18 deletions

View file

@ -35,7 +35,7 @@ cputemprd0(Chan*, void *a, long n, vlong offset)
* magic undocumented msr. tj(max) is 100 or 85. * magic undocumented msr. tj(max) is 100 or 85.
*/ */
tj = 100; tj = 100;
d = X86MODEL(m->cpuidax); d = m->cpuidmodel;
d |= (m->cpuidax>>12) & 0xf0; d |= (m->cpuidax>>12) & 0xf0;
if((d == 0xf && (m->cpuidax & 0xf)>1) || d == 0xe){ if((d == 0xf && (m->cpuidax & 0xf)>1) || d == 0xe){
if(rdmsr(0xee, &emsr) == 0){ if(rdmsr(0xee, &emsr) == 0){
@ -109,7 +109,7 @@ amd0ftemprd(Chan*, void *a, long n, vlong offset)
for(j = 0; j < max; j++){ for(j = 0; j < max; j++){
pcicfgw32(p, 0xe4, pcicfgr32(p, 0xe4) & ~4 | j<<2); pcicfgw32(p, 0xe4, pcicfgr32(p, 0xe4) & ~4 | j<<2);
i = pcicfgr32(p, 0xe4); i = pcicfgr32(p, 0xe4);
if(X86STEPPING(m->cpuidax) == 2) if(m->cpuidstepping == 2)
t = i>>16 & 0xff; t = i>>16 & 0xff;
else{ else{
t = i>>14 & 0x3ff; t = i>>14 & 0x3ff;
@ -165,8 +165,8 @@ cputemplink(void)
{ {
if(intelcputempok()) if(intelcputempok())
addarchfile("cputemp", 0444, intelcputemprd, nil); addarchfile("cputemp", 0444, intelcputemprd, nil);
if(X86FAMILY(m->cpuidax) == 0x0f && !strcmp(m->cpuidid, "AuthenticAMD")) if(m->cpuidfamily == 0x0f && !strcmp(m->cpuidid, "AuthenticAMD"))
addarchfile("cputemp", 0444, amd0ftemprd, nil); addarchfile("cputemp", 0444, amd0ftemprd, nil);
if(X86FAMILY(m->cpuidax) == 0x10 && !strcmp(m->cpuidid, "AuthenticAMD")) if(m->cpuidfamily == 0x10 && !strcmp(m->cpuidid, "AuthenticAMD"))
addarchfile("cputemp", 0444, amd10temprd, nil); addarchfile("cputemp", 0444, amd10temprd, nil);
} }

View file

@ -238,6 +238,9 @@ struct Mach
int cpuiddx; int cpuiddx;
char cpuidid[16]; char cpuidid[16];
char* cpuidtype; char* cpuidtype;
uchar cpuidfamily;
uchar cpuidmodel;
uchar cpuidstepping;
int havetsc; int havetsc;
int havepge; int havepge;
int havewatchpt8; int havewatchpt8;

View file

@ -753,6 +753,17 @@ cpuidentify(void)
m->cpuidax = regs[0]; m->cpuidax = regs[0];
m->cpuidcx = regs[2]; m->cpuidcx = regs[2];
m->cpuiddx = regs[3]; m->cpuiddx = regs[3];
m->cpuidfamily = m->cpuidax >> 8 & 0xf;
m->cpuidmodel = m->cpuidax >> 4 & 0xf;
m->cpuidstepping = m->cpuidax & 0xf;
switch(m->cpuidfamily){
case 6:
m->cpuidmodel += m->cpuidax >> 16 & 0xf;
/* wet floor */
case 15:
m->cpuidfamily += m->cpuidax >> 20 & 0xff;
}
if(strncmp(m->cpuidid, "AuthenticAMD", 12) == 0 || if(strncmp(m->cpuidid, "AuthenticAMD", 12) == 0 ||
strncmp(m->cpuidid, "Geode by NSC", 12) == 0) strncmp(m->cpuidid, "Geode by NSC", 12) == 0)
@ -764,8 +775,8 @@ cpuidentify(void)
else else
tab = x86intel; tab = x86intel;
family = X86FAMILY(m->cpuidax); family = m->cpuidfamily;
model = X86MODEL(m->cpuidax); model = m->cpuidmodel;
for(t=tab; t->name; t++) for(t=tab; t->name; t++)
if((t->family == family && t->model == model) if((t->family == family && t->model == model)
|| (t->family == family && t->model == -1) || (t->family == family && t->model == -1)
@ -994,7 +1005,7 @@ archctlwrite(Chan*, void *a, long n, vlong)
if(strcmp(cb->f[1], "mb386") == 0) if(strcmp(cb->f[1], "mb386") == 0)
coherence = mb386; coherence = mb386;
else if(strcmp(cb->f[1], "mb586") == 0){ else if(strcmp(cb->f[1], "mb586") == 0){
if(X86FAMILY(m->cpuidax) < 5) if(m->cpuidfamily < 5)
error("invalid coherence ctl on this cpu family"); error("invalid coherence ctl on this cpu family");
coherence = mb586; coherence = mb586;
}else if(strcmp(cb->f[1], "mfence") == 0){ }else if(strcmp(cb->f[1], "mfence") == 0){
@ -1093,13 +1104,13 @@ archinit(void)
* We get another chance to set it in mpinit() for a * We get another chance to set it in mpinit() for a
* multiprocessor. * multiprocessor.
*/ */
if(X86FAMILY(m->cpuidax) == 3) if(m->cpuidfamily == 3)
conf.copymode = 1; conf.copymode = 1;
if(X86FAMILY(m->cpuidax) >= 4) if(m->cpuidfamily >= 4)
cmpswap = cmpswap486; cmpswap = cmpswap486;
if(X86FAMILY(m->cpuidax) >= 5) if(m->cpuidfamily >= 5)
coherence = mb586; coherence = mb586;
if(m->cpuiddx & Sse2) if(m->cpuiddx & Sse2)

View file

@ -1,8 +1,3 @@
#define X86STEPPING(x) ((x) & 0x0F)
/* incorporates extended-model and -family bits */
#define X86MODEL(x) ((((x)>>4) & 0x0F) | (((x)>>16) & 0x0F)<<4)
#define X86FAMILY(x) ((((x)>>8) & 0x0F) | (((x)>>20) & 0xFF)<<4)
enum { enum {
VectorDE = 1, /* debug exception */ VectorDE = 1, /* debug exception */
VectorNMI = 2, /* non-maskable interrupt */ VectorNMI = 2, /* non-maskable interrupt */

View file

@ -569,7 +569,7 @@ void
mathinit(void) mathinit(void)
{ {
trapenable(VectorCERR, matherror, 0, "matherror"); trapenable(VectorCERR, matherror, 0, "matherror");
if(X86FAMILY(m->cpuidax) == 3) if(m->cpuidfamily == 3)
intrenable(IrqIRQ13, matherror, 0, BUSUNKNOWN, "matherror"); intrenable(IrqIRQ13, matherror, 0, BUSUNKNOWN, "matherror");
trapenable(VectorCNA, mathemu, 0, "mathemu"); trapenable(VectorCNA, mathemu, 0, "mathemu");
trapenable(VectorCSO, mathover, 0, "mathover"); trapenable(VectorCSO, mathover, 0, "mathover");

View file

@ -198,7 +198,7 @@ flushmmu(void)
void void
flushpg(ulong va) flushpg(ulong va)
{ {
if(X86FAMILY(m->cpuidax) >= 4) if(m->cpuidfamily >= 4)
invlpg(va); invlpg(va);
else else
putcr3(getcr3()); putcr3(getcr3());

View file

@ -216,7 +216,7 @@ mpinit(void)
* set conf.copymode here if nmach > 1. * set conf.copymode here if nmach > 1.
* Should look for an ExtINT line and enable it. * Should look for an ExtINT line and enable it.
*/ */
if(X86FAMILY(m->cpuidax) == 3 || conf.nmach > 1) if(m->cpuidfamily == 3 || conf.nmach > 1)
conf.copymode = 1; conf.copymode = 1;
} }