summaryrefslogtreecommitdiff
path: root/lib/asm/x86_64/msr.c
blob: 2dfdc44596e2d8f9f63dbeddbc0437e17ba1e7c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <asm/x86_64/msr.h>

void msr_write(uint32_t index, uint64_t value)
{
    uint32_t low = value & 0xffffffff;
    uint32_t high = value >> 32;

    __asm__ volatile
        (
         "wrmsr\n\t"
         :
		 : "a"(low), "d"(high), "c"(index)
        );
}

uint64_t msr_read(uint32_t index)
{
    uint32_t low;
    uint32_t high;

    __asm__ volatile
        (
         "rdmsr\n\t"
         : "=a"(low), "=d"(high)
         : "c"(index)
        );

    return ((uint64_t)high << 32)|low;
}