diff --git a/kernel/include/misc/MSR.h b/kernel/include/misc/MSR.h index aec5e03f..1c7ae4db 100644 --- a/kernel/include/misc/MSR.h +++ b/kernel/include/misc/MSR.h @@ -13,6 +13,9 @@ struct MSR static void write_to(uint32_t msr_num, uint64_t value); static uint64_t read_from(uint32_t msr_num); + static void with_value_of(uint32_t msr_num, void (*callback)(uint64_t&)); + void with_value(void (*callback)(uint64_t&)); + private: uint32_t m_msr_num; }; \ No newline at end of file diff --git a/kernel/src/misc/MSR.cpp b/kernel/src/misc/MSR.cpp index a5813bf7..a4e412da 100644 --- a/kernel/src/misc/MSR.cpp +++ b/kernel/src/misc/MSR.cpp @@ -27,4 +27,19 @@ uint64_t MSR::read() MSR::MSR(uint32_t msr_num) : m_msr_num(msr_num) { +} + +void MSR::with_value_of(uint32_t msr_num, void (*callback)(uint64_t&)) +{ + MSR msr(msr_num); + uint64_t value = msr.read(); + callback(value); + msr.write(value); +} + +void MSR::with_value(void (*callback)(uint64_t&)) +{ + uint64_t value = read(); + callback(value); + write(value); } \ No newline at end of file