rdmsr/wrmsr become tryrdmsr/trywrmsr, we can should check for trap

This commit is contained in:
cinap_lenrek 2012-08-31 16:48:33 +02:00
parent a7ed529d97
commit e91301a401
5 changed files with 21 additions and 34 deletions

View file

@ -29,7 +29,7 @@ cputemprd0(Chan*, void *a, long n, vlong offset)
cpuid(6, regs);
if((regs[0] & 1) == 0)
return readstr(offset, a, n, "-1±-1 unsupported\n");
goto unsup;
if(tj == 0){
/*
* magic undocumented msr. tj(max) is 100 or 85.
@ -38,13 +38,15 @@ cputemprd0(Chan*, void *a, long n, vlong offset)
d = X86MODEL(m->cpuidax);
d |= (m->cpuidax>>12) & 0xf0;
if((d == 0xf && (m->cpuidax & 0xf)>1) || d == 0xe){
rdmsr(0xee, &emsr);
msr = emsr;
if(msr & 1<<30)
tj = 85;
if(rdmsr(0xee, &emsr) == 0){
msr = emsr;
if(msr & 1<<30)
tj = 85;
}
}
}
rdmsr(0x19c, &emsr);
if(rdmsr(0x19c, &emsr) < 0)
goto unsup;
msr = emsr;
t = -1;
if(msr & 1<<31){
@ -57,6 +59,8 @@ cputemprd0(Chan*, void *a, long n, vlong offset)
s = " alarm";
snprint(buf, sizeof buf, "%ld±%uld%s\n", t, res, s);
return readstr(offset, a, n, buf);
unsup:
return readstr(offset, a, n, "-1±-1 unsupported\n");
}
static long

View file

@ -397,7 +397,7 @@ archread(Chan *c, void *a, long n, vlong offset)
error(Ebadarg);
vp = a;
for(port = offset; port < offset+n; port += 8)
if(tryrdmsr(port, vp++) < 0)
if(rdmsr(port, vp++) < 0)
error(Ebadarg);
return n;
@ -476,7 +476,7 @@ archwrite(Chan *c, void *a, long n, vlong offset)
error(Ebadarg);
vp = a;
for(port = offset; port < offset+n; port += 8)
if(trywrmsr(port, *vp++) < 0)
if(wrmsr(port, *vp++) < 0)
error(Ebadarg);
return n;

View file

@ -154,7 +154,7 @@ void putcr0(ulong);
void putcr3(ulong);
void putcr4(ulong);
void* rampage(void);
void rdmsr(int, vlong*);
int rdmsr(int, vlong*);
void realmode(Ureg*);
void screeninit(void);
void (*screenputs)(char*, int);
@ -169,8 +169,6 @@ void trapenable(int, void (*)(Ureg*, void*), void*, char*);
void trapinit(void);
void trapinit0(void);
int tas(void*);
int tryrdmsr(int, vlong*);
int trywrmsr(int, vlong);
uvlong tscticks(uvlong*);
ulong umbmalloc(ulong, int, int);
void umbfree(ulong, int);
@ -184,7 +182,7 @@ void* vmap(ulong, int);
int vmapsync(ulong);
void vunmap(void*, int);
void wbinvd(void);
void wrmsr(int, vlong);
int wrmsr(int, vlong);
int xchgw(ushort*, int);
#define userureg(ur) (((ur)->cs & 3) == 3)

View file

@ -538,39 +538,24 @@ TEXT lcycles(SB),1,$0
RET
TEXT rdmsr(SB), $0 /* model-specific register */
MOVL index+0(FP), CX
RDMSR
MOVL vlong+4(FP), CX /* &vlong */
MOVL AX, 0(CX) /* lo */
MOVL DX, 4(CX) /* hi */
RET
TEXT tryrdmsr(SB), $0 /* model-specific register */
MOVL $0, BP
MOVL index+0(FP), CX
TEXT _tryrdmsrinst(SB), $0
TEXT _rdmsrinst(SB), $0
RDMSR
MOVL vlong+4(FP), CX /* &vlong */
MOVL AX, 0(CX) /* lo */
MOVL DX, 4(CX) /* hi */
MOVL BP, AX
MOVL BP, AX /* BP set to -1 if traped */
RET
TEXT wrmsr(SB), $0
MOVL index+0(FP), CX
MOVL lo+4(FP), AX
MOVL hi+8(FP), DX
WRMSR
RET
TEXT trywrmsr(SB), $0
MOVL $0, BP
MOVL index+0(FP), CX
MOVL lo+4(FP), AX
MOVL hi+8(FP), DX
TEXT _trywrmsrinst(SB), $0
TEXT _wrmsrinst(SB), $0
WRMSR
MOVL BP, AX
MOVL BP, AX /* BP set to -1 if traped */
RET
/*

View file

@ -436,8 +436,8 @@ trap(Ureg* ureg)
extern void _forkretpopes(void);
extern void _forkretpopds(void);
extern void _forkretiret(void);
extern void _tryrdmsrinst(void);
extern void _trywrmsrinst(void);
extern void _rdmsrinst(void);
extern void _wrmsrinst(void);
extern void load_fs(ulong);
extern void load_gs(ulong);
@ -460,7 +460,7 @@ trap(Ureg* ureg)
sp[4] = UDSEL; /* SS */
return;
}
} else if(pc == _tryrdmsrinst || pc == _trywrmsrinst){
} else if(pc == _rdmsrinst || pc == _wrmsrinst){
if(vno == VectorGPF){
ureg->bp = -1;
ureg->pc += 2;