Xen Test Framework
msr.c
Go to the documentation of this file.
1
6#include <xtf/report.h>
7#include <xtf/test.h>
8
9#include <arch/msr.h>
10
12{
13 uint32_t lo, hi;
14
15 asm volatile (_ASM_XEN_FEP "rdmsr"
16 : "=a" (lo), "=d" (hi)
17 : "c" (idx));
18
19 return (((uint64_t)hi) << 32) | lo;
20}
21
22static void force_wrmsr(uint32_t idx, uint64_t val)
23{
24 asm volatile (_ASM_XEN_FEP "wrmsr":
25 : "c" (idx), "a" ((uint32_t)val),
26 "d" ((uint32_t)(val >> 32)));
27}
28
30{
31 size_t i;
32 uint64_t val;
33
34 for ( i = 0; i < t->nr_vals; ++i )
35 {
36 if ( !t->vals[i].pred )
37 continue;
38
39 wrmsr(t->msr, t->vals[i].val);
40 val = rdmsr(t->msr);
41
42 if ( val != t->vals[i].val )
43 xtf_failure("Fail: MSR %08x, real write, real read\n"
44 " Got %016"PRIx64", Expected %016"PRIx64"\n",
45 t->msr, val, t->vals[i].val);
46
47 if ( !xtf_has_fep )
48 continue;
49
50 val = force_rdmsr(t->msr);
51
52 if ( val != t->vals[i].val )
53 xtf_failure("Fail: MSR %08x, real write, emul read\n"
54 " Got %016"PRIx64", Expected %016"PRIx64"\n",
55 t->msr, val, t->vals[i].val);
56 }
57
58 if ( !xtf_has_fep )
59 return;
60
61 for ( i = 0; i < t->nr_vals; ++i )
62 {
63 if ( !t->vals[i].pred )
64 continue;
65
66 force_wrmsr(t->msr, t->vals[i].val);
67 val = rdmsr(t->msr);
68
69 if ( val != t->vals[i].val )
70 xtf_failure("Fail: MSR %08x, emul write, real read\n"
71 " Got %016"PRIx64", Expected %016"PRIx64"\n",
72 t->msr, val, t->vals[i].val);
73
74 val = force_rdmsr(t->msr);
75
76 if ( val != t->vals[i].val )
77 xtf_failure("Fail: MSR %08x, emul write, emul read\n"
78 " Got %016"PRIx64", Expected %016"PRIx64"\n",
79 t->msr, val, t->vals[i].val);
80 }
81}
82
83/*
84 * Local variables:
85 * mode: C
86 * c-file-style: "BSD"
87 * c-basic-offset: 4
88 * tab-width: 4
89 * indent-tabs-mode: nil
90 * End:
91 */
#define _ASM_XEN_FEP
Xen Forced Emulation Prefix.
Definition: xen.h:150
void xtf_msr_consistency_test(const struct xtf_msr_consistency_test_data *t)
Run consistency tests as described by t.
Definition: msr.c:29
static void force_wrmsr(uint32_t idx, uint64_t val)
Definition: msr.c:22
static uint64_t force_rdmsr(uint32_t idx)
Definition: msr.c:11
bool xtf_has_fep
Boolean indicating whether generic Force Emulation Prefix support is available for the test to use.
Definition: setup.c:276
API for tests.
#define PRIx64
Definition: inttypes.h:23
Model Specific Register mnemonics and bit definitions.
static uint64_t rdmsr(uint32_t idx)
Thin wrapper around an rdmsr instruction.
Definition: msr.h:19
static void wrmsr(uint32_t idx, uint64_t val)
Thin wrapper around an wrmsr instruction.
Definition: msr.h:55
void xtf_failure(const char *fmt,...)
Report a test failure.
Definition: report.c:94
API for reporting test status.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:16
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17
const struct xtf_msr_consistency_test_data::xtf_msr_consistency_test_vals * vals