From 4e62566c48df105bc8d4446444c93c461e6e6f2f Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 25 Sep 2022 17:28:38 +0200 Subject: [PATCH] Add with_value_of and with_value to MSR --- kernel/include/misc/MSR.h | 3 +++ kernel/src/misc/MSR.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+) 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