diff options
| author | Ada Christine <adachristine18@gmail.com> | 2022-01-17 12:22:30 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2022-01-17 12:22:30 +0000 |
| commit | 2f2e5b43d2985abd504ecd5672ce783bef904f2f (patch) | |
| tree | 3c24efcea6b0ce6dda0ee720b3afe250247f2dfb /kc/core/cpu/msr.c | |
| parent | dc7152c1cc6412871e1120ed53fb94ed386613cc (diff) | |
preparing for multitasking
Diffstat (limited to 'kc/core/cpu/msr.c')
| -rw-r--r-- | kc/core/cpu/msr.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/kc/core/cpu/msr.c b/kc/core/cpu/msr.c new file mode 100644 index 0000000..2efdd7d --- /dev/null +++ b/kc/core/cpu/msr.c @@ -0,0 +1,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) + ); +} + |
