summaryrefslogtreecommitdiff
path: root/kc/core/cpu/msr.c
blob: 2efdd7df02a044f1f9ccd059107a59a8cbbcf4cc (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
#include "msr.h"

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;
}

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)
        );
}