summaryrefslogtreecommitdiff
path: root/TestPrograms/test_x86_via_rng.cpp
blob: 1ecd8f53598c865f83e89a726df512be36cf8f08 (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
31
32
33
34
35
36
37
38
#include <cstdlib>
int main(int argc, char* argv[])
{
    unsigned int msr=0;
    unsigned int divisor=2;
    unsigned int buffer;

    __asm__ __volatile__
    (
#if defined(__x86_64__) || defined(__amd64__)
        "mov  %1, %%rdi          ;\n"
        "movl %2, %%edx          ;\n"
#else
        "mov  %1, %%edi          ;\n"
        "movl %2, %%edx          ;\n"
#endif

        // xstore-rng
        ".byte 0x0f, 0xa7, 0xc0  ;\n"

#if defined(__x86_64__) || defined(__amd64__)
        "andq %%rax, 0x1f        ;\n"
        "movl %%eax, %0          ;\n"
#else
        "andl  %%eax, 0x1f       ;\n"
        "movl  %%eax, %0         ;\n"
#endif

        : "=g" (msr) : "g" (buffer), "g" (divisor)
#if defined(__x86_64__) || defined(__amd64__)
        : "rax", "rdx", "rdi", "cc"
#else
        : "eax", "edx", "edi", "cc"
#endif
    );

    return 0;
}