inline assembly: write MSR
Posted: Tue Jan 19, 2016 10:32 am
Hi, I use this code as a helper function to write MSR:
The key is "A" notation, which stands for "edx:eax" according to GCC manual. However, "write_msr" works well under QEMU, but always fail under Bochs.
So I changed the function to this:
And both QEMU and Bochs runs well. But I can't understand the reason.
PS. My OS is 64 bit, does it matters?
Code: Select all
static inline void write_msr(uint32_t msr_id, uint64_t msr_val) {
__asm__ __volatile__("wrmsr" :: "c"(msr_id), "A"(msr_val));
}
So I changed the function to this:
Code: Select all
static inline void write_msr(uint32_t msr_id, uint64_t msr_val) {
uint32_t edx = msr_val >> 32;
uint32_t eax = msr_val & 0xffffffff;
__asm__ __volatile__("wrmsr" :: "c"(msr_id), "d"(edx), "a"(eax));
}
PS. My OS is 64 bit, does it matters?