Kyösti Mälkki (kyosti.malkki@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/1465
-gerrit
commit 0acf1bbe3acb803f2718a5335e53c6df22b6b180 Author: Kyösti Mälkki kyosti.malkki@gmail.com Date: Sun Aug 19 13:27:18 2012 +0300
SerialICE: Separate RDMSR and WRMSR
Use of the flags parameter looked ugly and obscure to me.
Change-Id: I1da5757187a8a2b808288d5f09466457d10aa8e9 Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- qemu-0.15.x/serialice-lua.c | 65 ++++++++++++++++++++++++++++++++------------- qemu-0.15.x/serialice.c | 8 +++--- qemu-0.15.x/serialice.h | 9 +++---- 3 files changed, 55 insertions(+), 27 deletions(-)
diff --git a/qemu-0.15.x/serialice-lua.c b/qemu-0.15.x/serialice-lua.c index 417510b..eecb866 100644 --- a/qemu-0.15.x/serialice-lua.c +++ b/qemu-0.15.x/serialice-lua.c @@ -350,26 +350,44 @@ int serialice_memory_write_filter(uint32_t addr, int size, return ret; }
- -int serialice_msr_filter(int flags, uint32_t addr, uint32_t * hi, - uint32_t * lo) +int serialice_wrmsr_filter(uint32_t addr, uint32_t * hi, uint32_t * lo) { int ret, result;
- if (flags & FILTER_WRITE) { - lua_getglobal(L, "SerialICE_msr_write_filter"); - } else { - lua_getglobal(L, "SerialICE_msr_read_filter"); + lua_getglobal(L, "SerialICE_msr_write_filter"); + lua_pushinteger(L, addr); // port + lua_pushinteger(L, *hi); // high + lua_pushinteger(L, *lo); // low + result = lua_pcall(L, 3, 3, 0); + if (result) { + fprintf(stderr, + "Failed to run function SerialICE_msr_write_filter: %s\n", + lua_tostring(L, -1)); + exit(1); } + ret = lua_toboolean(L, -3); + if (ret) { + *hi = lua_tointeger(L, -1); + *lo = lua_tointeger(L, -2); + } + lua_pop(L, 3); + + return ret; +} + +int serialice_rdmsr_filter(uint32_t addr, uint32_t * hi, uint32_t * lo) +{ + int ret, result;
+ lua_getglobal(L, "SerialICE_msr_read_filter"); lua_pushinteger(L, addr); // port lua_pushinteger(L, *hi); // high lua_pushinteger(L, *lo); // low result = lua_pcall(L, 3, 3, 0); if (result) { fprintf(stderr, - "Failed to run function SerialICE_msr_%s_filter: %s\n", - (flags & FILTER_WRITE) ? "write" : "read", lua_tostring(L, -1)); + "Failed to run function SerialICE_msr_read_filter: %s\n", + lua_tostring(L, -1)); exit(1); } ret = lua_toboolean(L, -3); @@ -446,25 +464,38 @@ void serialice_log(int flags, uint32_t data, uint32_t addr, int size) } }
-void serialice_msr_log(int flags, uint32_t addr, uint32_t hi, +void serialice_wrmsr_log(uint32_t addr, uint32_t hi, uint32_t lo, int filtered) { int result;
- if (flags & LOG_WRITE) { - lua_getglobal(L, "SerialICE_msr_write_log"); - } else { // if (!(flags & LOG_WRITE)) - lua_getglobal(L, "SerialICE_msr_read_log"); + lua_getglobal(L, "SerialICE_msr_write_log"); + lua_pushinteger(L, addr); // addr/port + lua_pushinteger(L, hi); // datasize + lua_pushinteger(L, lo); // data + lua_pushboolean(L, filtered); // data + result = lua_pcall(L, 4, 0, 0); + if (result) { + fprintf(stderr, "Failed to run function SerialICE_msr_write_log: %s\n", + lua_tostring(L, -1)); + exit(1); } +} + +void serialice_rdmsr_log(uint32_t addr, uint32_t hi, + uint32_t lo, int filtered) +{ + int result;
+ lua_getglobal(L, "SerialICE_msr_read_log"); lua_pushinteger(L, addr); // addr/port lua_pushinteger(L, hi); // datasize lua_pushinteger(L, lo); // data lua_pushboolean(L, filtered); // data result = lua_pcall(L, 4, 0, 0); if (result) { - fprintf(stderr, "Failed to run function SerialICE_msr_%s_log: %s\n", - (flags & LOG_WRITE) ? "write" : "read", lua_tostring(L, -1)); + fprintf(stderr, "Failed to run function SerialICE_msr_read_log: %s\n", + lua_tostring(L, -1)); exit(1); } } @@ -490,5 +521,3 @@ void serialice_cpuid_log(uint32_t eax, uint32_t ecx, cpuid_regs_t res, exit(1); } } - - diff --git a/qemu-0.15.x/serialice.c b/qemu-0.15.x/serialice.c index aaf69b0..32dc0ca 100644 --- a/qemu-0.15.x/serialice.c +++ b/qemu-0.15.x/serialice.c @@ -111,7 +111,7 @@ uint64_t serialice_rdmsr(uint32_t addr, uint32_t key) uint64_t ret; int filtered;
- filtered = serialice_msr_filter(FILTER_READ, addr, &hi, &lo); + filtered = serialice_rdmsr_filter(addr, &hi, &lo); if (!filtered) { serialice_rdmsr_wrapper(addr, key, &hi, &lo); } @@ -120,7 +120,7 @@ uint64_t serialice_rdmsr(uint32_t addr, uint32_t key) ret <<= 32; ret |= lo;
- serialice_msr_log(LOG_READ, addr, hi, lo, filtered); + serialice_rdmsr_log(addr, hi, lo, filtered);
return ret; } @@ -133,13 +133,13 @@ void serialice_wrmsr(uint64_t data, uint32_t addr, uint32_t key) hi = (data >> 32); lo = (data & 0xffffffff);
- filtered = serialice_msr_filter(FILTER_WRITE, addr, &hi, &lo); + filtered = serialice_wrmsr_filter(addr, &hi, &lo);
if (!filtered) { serialice_wrmsr_wrapper(addr, key, hi, lo); }
- serialice_msr_log(LOG_WRITE, addr, hi, lo, filtered); + serialice_wrmsr_log(addr, hi, lo, filtered); }
cpuid_regs_t serialice_cpuid(uint32_t eax, uint32_t ecx) diff --git a/qemu-0.15.x/serialice.h b/qemu-0.15.x/serialice.h index e9558f8..4a64284 100644 --- a/qemu-0.15.x/serialice.h +++ b/qemu-0.15.x/serialice.h @@ -38,9 +38,6 @@ #define WRITE_TO_QEMU (1 << 0) #define WRITE_TO_SERIALICE (1 << 1)
-#define FILTER_READ 0 -#define FILTER_WRITE 1 - #define LOG_IO 0 #define LOG_MEMORY 1 #define LOG_READ 0 @@ -95,11 +92,13 @@ int serialice_io_read_filter(uint32_t * data, uint16_t port, int size); int serialice_io_write_filter(uint32_t * data, uint16_t port, int size); int serialice_memory_read_filter(uint32_t addr, uint32_t * data, int size); int serialice_memory_write_filter(uint32_t addr, int size, uint32_t * data); -int serialice_msr_filter(int flags, uint32_t addr, uint32_t * hi, uint32_t * lo); int serialice_cpuid_filter(uint32_t eax, uint32_t ecx, cpuid_regs_t * regs); +int serialice_rdmsr_filter(uint32_t addr, uint32_t * hi, uint32_t * lo); +int serialice_wrmsr_filter(uint32_t addr, uint32_t * hi, uint32_t * lo);
void serialice_log(int flags, uint32_t data, uint32_t addr, int size); -void serialice_msr_log(int flags, uint32_t addr, uint32_t hi, uint32_t lo, int filtered); +void serialice_rdmsr_log(uint32_t addr, uint32_t hi, uint32_t lo, int filtered); +void serialice_wrmsr_log(uint32_t addr, uint32_t hi, uint32_t lo, int filtered); void serialice_cpuid_log(uint32_t eax, uint32_t ecx, cpuid_regs_t res, int filtered);
#endif