[SerialICE] Patch set updated for serialice: 4f0c698 SerialICE: LUA interface change for Qemu [NOTFORMERGE]

Kyösti Mälkki (kyosti.malkki@gmail.com) gerrit at coreboot.org
Tue Aug 21 08:06:40 CEST 2012


Kyösti Mälkki (kyosti.malkki at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/1017

-gerrit

commit 4f0c69800165ddf6715e2101563c3de02f7640fb
Author: Kyösti Mälkki <kyosti.malkki at gmail.com>
Date:   Mon May 7 20:31:52 2012 +0300

    SerialICE: LUA interface change for Qemu [NOTFORMERGE]
    
    This is the final results of lua interface change to support modular
    scripting system. Compatibility to the single-file serialice.lua is
    dropped, you have to fetch the modular version of the scripts from git.
    
    At the time of writing, I am still working towards not to make this
    break compatibility with single-file script.
    
    Change-Id: Iefe6c44a4a0b8241dd02ea03fed94d2a8f79a917
    Signed-off-by: Kyösti Mälkki <kyosti.malkki at gmail.com>
---
 qemu-0.15.x/serialice-lua.c | 271 ++++++++++++++++++++------------------------
 qemu-0.15.x/serialice.c     | 138 ++++++++++------------
 qemu-0.15.x/serialice.h     |  41 ++++---
 3 files changed, 206 insertions(+), 244 deletions(-)

diff --git a/qemu-0.15.x/serialice-lua.c b/qemu-0.15.x/serialice-lua.c
index 638f1d3..0216eb2 100644
--- a/qemu-0.15.x/serialice-lua.c
+++ b/qemu-0.15.x/serialice-lua.c
@@ -43,12 +43,11 @@
 
 #define LOG_IO		1
 #define LOG_MEMORY	2
-#define LOG_TARGET	4
+#define LOG_MSR		4
 
 static lua_State *L;
-
-extern const char *serialice_mainboard;
-static const char *serialice_lua_script = "serialice.lua";
+extern char *serialice_mainboard;
+static const SerialICE_filter lua_ops;
 
 // **************************************************************************
 // LUA scripting interface and callbacks
@@ -193,10 +192,12 @@ static int serialice_lua_registers(void)
     return 0;
 }
 
-int serialice_lua_init(void)
+const SerialICE_filter * serialice_lua_init(const char *serialice_lua_script)
 {
     int status;
 
+    printf("SerialICE: LUA init...\n");
+
     /* Create a LUA context and load LUA libraries */
     L = luaL_newstate();
     luaL_openlibs(L);
@@ -228,18 +229,13 @@ int serialice_lua_init(void)
     }
     lua_pop(L, 1);
 
-    return 0;
+    return &lua_ops;
 }
 
-#if 0
-/* not used yet */
-int serialice_lua_exit(void)
+void serialice_lua_exit(void)
 {
     lua_close(L);
-    return 0;
 }
-#endif
-
 
 const char *serialice_lua_execute(const char *cmd)
 {
@@ -255,59 +251,60 @@ const char *serialice_lua_execute(const char *cmd)
     return errstring;
 }
 
-int serialice_io_read_filter(uint32_t * data, uint16_t port, int size)
+static int io_read_pre(uint16_t port, int size)
 {
-    int ret, result;
+    int ret = 0, result;
 
     lua_getglobal(L, "SerialICE_io_read_filter");
     lua_pushinteger(L, port);   // port
     lua_pushinteger(L, size);   // datasize
+
     result = lua_pcall(L, 2, 2, 0);
     if (result) {
         fprintf(stderr, "Failed to run function SerialICE_io_read_filter: %s\n",
                 lua_tostring(L, -1));
         exit(1);
     }
-    *data = lua_tointeger(L, -1);
-    ret = lua_toboolean(L, -2);
-    lua_pop(L, 2);
 
+    ret |= lua_toboolean(L, -1) ? READ_FROM_QEMU : 0;
+    ret |= lua_toboolean(L, -2) ? READ_FROM_SERIALICE : 0;
+    lua_pop(L, 2);
     return ret;
 }
 
-int serialice_io_write_filter(uint32_t * data, uint16_t port, int size)
+static int io_write_pre(uint32_t * data, uint16_t port, int size)
 {
-    int ret, result;
+    int ret = 0, result;
 
     lua_getglobal(L, "SerialICE_io_write_filter");
     lua_pushinteger(L, port);   // port
     lua_pushinteger(L, size);   // datasize
     lua_pushinteger(L, *data);  // data
 
-    result = lua_pcall(L, 3, 2, 0);
+    result = lua_pcall(L, 3, 3, 0);
     if (result) {
         fprintf(stderr,
                 "Failed to run function SerialICE_io_write_filter: %s\n",
                 lua_tostring(L, -1));
         exit(1);
     }
-    *data = lua_tointeger(L, -1);
-    ret = lua_toboolean(L, -2);
-    lua_pop(L, 2);
 
+    *data = lua_tointeger(L, -1);
+    ret |= lua_toboolean(L, -2) ? WRITE_TO_QEMU : 0;
+    ret |= lua_toboolean(L, -3) ? WRITE_TO_SERIALICE : 0;
+    lua_pop(L, 3);
     return ret;
 }
 
-
-int serialice_memory_read_filter(uint32_t addr, uint32_t * data,
-                                        int size)
+static int memory_read_pre(uint32_t addr, int size)
 {
     int ret = 0, result;
 
     lua_getglobal(L, "SerialICE_memory_read_filter");
-    lua_pushinteger(L, addr);   // addr
-    lua_pushinteger(L, size);   // datasize
-    result = lua_pcall(L, 2, 3, 0);
+    lua_pushinteger(L, addr);
+    lua_pushinteger(L, size);
+
+    result = lua_pcall(L, 2, 2, 0);
     if (result) {
         fprintf(stderr,
                 "Failed to run function SerialICE_memory_read_filter: %s\n",
@@ -315,27 +312,22 @@ int serialice_memory_read_filter(uint32_t addr, uint32_t * data,
         exit(1);
     }
 
-    *data = lua_tointeger(L, -1);       // result
-
-    ret |= lua_toboolean(L, -2) ? READ_FROM_QEMU : 0;   // to_qemu
-    ret |= lua_toboolean(L, -3) ? READ_FROM_SERIALICE : 0;      // to_hw
-
-    lua_pop(L, 3);
-
+    ret |= lua_toboolean(L, -1) ? READ_FROM_QEMU : 0;
+    ret |= lua_toboolean(L, -2) ? READ_FROM_SERIALICE : 0;
+    lua_pop(L, 2);
     return ret;
 }
 
-
-int serialice_memory_write_filter(uint32_t addr, int size,
+static int memory_write_pre(uint32_t addr, int size,
                                          uint32_t * data)
 {
     int ret = 0, result;
-    int write_to_qemu, write_to_serialice;
 
     lua_getglobal(L, "SerialICE_memory_write_filter");
     lua_pushinteger(L, addr);   // address
     lua_pushinteger(L, size);   // datasize
     lua_pushinteger(L, *data);  // data
+
     result = lua_pcall(L, 3, 3, 0);
     if (result) {
         fprintf(stderr,
@@ -343,82 +335,67 @@ int serialice_memory_write_filter(uint32_t addr, int size,
                 lua_tostring(L, -1));
         exit(1);
     }
+
     *data = lua_tointeger(L, -1);
-    write_to_qemu = lua_toboolean(L, -2);
-    write_to_serialice = lua_toboolean(L, -3);
+    ret |= lua_toboolean(L, -2) ? WRITE_TO_QEMU : 0;
+    ret |= lua_toboolean(L, -3) ? WRITE_TO_SERIALICE : 0;
     lua_pop(L, 3);
-
-    ret |= write_to_qemu ? WRITE_TO_QEMU : 0;
-    ret |= write_to_serialice ? WRITE_TO_SERIALICE : 0;
-
     return ret;
 }
 
-int serialice_wrmsr_filter(uint32_t addr, uint32_t * hi, uint32_t * lo)
+static int wrmsr_pre(uint32_t addr, uint32_t * hi, uint32_t * lo)
 {
-    int ret, result;
+    int ret = 0, result;
 
     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);
+
+    result = lua_pcall(L, 3, 4, 0);
     if (result) {
         fprintf(stderr,
-                "Failed to run function SerialICE_msr_write_filter: %s\n",
-                lua_tostring(L, -1));
+                "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);
 
+    *lo = lua_tointeger(L, -1);
+    *hi = lua_tointeger(L, -2);
+    ret |= lua_toboolean(L, -3) ? WRITE_TO_QEMU : 0;
+    ret |= lua_toboolean(L, -4) ? WRITE_TO_SERIALICE : 0;
+    lua_pop(L, 4);
     return ret;
 }
 
-int serialice_rdmsr_filter(uint32_t addr, uint32_t * hi, uint32_t * lo)
+static int rdmsr_pre(uint32_t addr)
 {
-    int ret, result;
+    int ret = 0, 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);
+    lua_pushinteger(L, addr);
+
+    result = lua_pcall(L, 1, 2, 0);
     if (result) {
         fprintf(stderr,
-                "Failed to run function SerialICE_msr_read_filter: %s\n",
-                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);
-    if (ret) {
-        *hi = lua_tointeger(L, -1);
-        *lo = lua_tointeger(L, -2);
-    }
-    lua_pop(L, 3);
 
+    ret |= lua_toboolean(L, -1) ? WRITE_TO_QEMU : 0;
+    ret |= lua_toboolean(L, -2) ? WRITE_TO_SERIALICE : 0;
+    lua_pop(L, 2);
     return ret;
 }
 
-int serialice_cpuid_filter(uint32_t eax, uint32_t ecx,
-                                  cpuid_regs_t * regs)
+static int cpuid_pre(uint32_t eax, uint32_t ecx)
 {
-    int ret, result;
+    int ret = 0, result;
 
     lua_getglobal(L, "SerialICE_cpuid_filter");
-
     lua_pushinteger(L, eax);    // eax before calling
     lua_pushinteger(L, ecx);    // ecx before calling
-    // and the registers after calling cpuid
-    lua_pushinteger(L, regs->eax);      // eax
-    lua_pushinteger(L, regs->ebx);      // ebx
-    lua_pushinteger(L, regs->ecx);      // ecx
-    lua_pushinteger(L, regs->edx);      // edx
-    result = lua_pcall(L, 6, 5, 0);
+
+    result = lua_pcall(L, 2, 2, 0);
     if (result) {
         fprintf(stderr,
                 "Failed to run function SerialICE_cpuid_filter: %s\n",
@@ -426,59 +403,54 @@ int serialice_cpuid_filter(uint32_t eax, uint32_t ecx,
         exit(1);
     }
 
-    ret = lua_toboolean(L, -5);
-    if (ret) {
-        regs->eax = lua_tointeger(L, -4);
-        regs->ebx = lua_tointeger(L, -3);
-        regs->ecx = lua_tointeger(L, -2);
-        regs->edx = lua_tointeger(L, -1);
-    }
-    lua_pop(L, 5);
-
+    ret |= lua_toboolean(L, -1) ? WRITE_TO_QEMU : 0;
+    ret |= lua_toboolean(L, -2) ? WRITE_TO_SERIALICE : 0;
+    lua_pop(L, 2);
     return ret;
 }
 
 /* SerialICE output loggers */
 
-static void __read_log(int flags, uint32_t data, uint32_t addr, int size)
+static void __read_post(int flags, uint32_t *data)
 {
     int result;
 
     if (flags & LOG_MEMORY) {
         lua_getglobal(L, "SerialICE_memory_read_log");
-    } else {
+    } else if (flags & LOG_IO) {
         lua_getglobal(L, "SerialICE_io_read_log");
+    } else {
+        fprintf(stderr, "serialice_read_log: bad type\n");
+        exit(1);
     }
 
-    lua_pushinteger(L, addr);   // addr/port
-    lua_pushinteger(L, size);   // datasize
-    lua_pushinteger(L, data);   // data
-    lua_pushboolean(L, ((flags & LOG_TARGET) != 0));
-
-    result = lua_pcall(L, 4, 0, 0);
+    lua_pushinteger(L, *data);
+    result = lua_pcall(L, 1, 1, 0);
     if (result) {
         fprintf(stderr, "Failed to run function SerialICE_%s_read_log: %s\n",
                 (flags & LOG_MEMORY) ? "memory" : "io", lua_tostring(L, -1));
         exit(1);
     }
+    *data = lua_tointeger(L, -1);
+    lua_pop(L, 1);
 }
 
-static void __write_log(int flags, uint32_t data, uint32_t addr, int size)
+static void __write_post(int flags)
 {
     int result;
 
     if (flags & LOG_MEMORY) {
         lua_getglobal(L, "SerialICE_memory_write_log");
-    } else  {
+    } else if (flags & LOG_IO) {
         lua_getglobal(L, "SerialICE_io_write_log");
+    } else if (flags & LOG_MSR) {
+        lua_getglobal(L, "SerialICE_msr_write_log");
+    } else {
+        fprintf(stderr, "serialice_write_log: bad type\n");
+        exit(1);
     }
 
-    lua_pushinteger(L, addr);   // addr/port
-    lua_pushinteger(L, size);   // datasize
-    lua_pushinteger(L, data);   // data
-    lua_pushboolean(L, ((flags & LOG_TARGET) != 0));
-
-    result = lua_pcall(L, 4, 0, 0);
+    result = lua_pcall(L, 0, 0, 0);
     if (result) {
         fprintf(stderr, "Failed to run function SerialICE_%s_write_log: %s\n",
                 (flags & LOG_MEMORY) ? "memory" : "io", lua_tostring(L, -1));
@@ -486,81 +458,86 @@ static void __write_log(int flags, uint32_t data, uint32_t addr, int size)
     }
 }
 
-void serialice_memory_read_log(int caught, uint32_t data, uint32_t addr, int size)
+static void memory_read_post(uint32_t * data)
 {
-    __read_log(LOG_MEMORY | (caught ? LOG_TARGET : 0), data, addr, size);
+    __read_post(LOG_MEMORY, data);
 }
 
-void serialice_memory_write_log(int caught, uint32_t data, uint32_t addr, int size)
+static void memory_write_post(void)
 {
-    __write_log(LOG_MEMORY | (caught ? LOG_TARGET : 0), data, addr, size);
+    __write_post(LOG_MEMORY);
 }
 
-
-void serialice_io_read_log(int caught, uint32_t data, uint32_t addr, int size)
+static void io_read_post(uint32_t * data)
 {
-    __read_log(LOG_IO | (caught ? LOG_TARGET : 0), data, addr, size);
+    __read_post(LOG_IO, data);
 }
 
-void serialice_io_write_log(int caught, uint32_t data, uint32_t addr, int size)
+static void io_write_post(void)
 {
-    __write_log(LOG_IO | (caught ? LOG_TARGET : 0), data, addr, size);
+    __write_post(LOG_IO);
 }
 
-void serialice_wrmsr_log(uint32_t addr, uint32_t hi,
-                              uint32_t lo, int filtered)
+static void wrmsr_post(void)
 {
-    int result;
-
-    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);
-    }
+    __write_post(LOG_MSR);
 }
 
-void serialice_rdmsr_log(uint32_t addr, uint32_t hi,
-                              uint32_t lo, int filtered)
+static void rdmsr_post(uint32_t *hi, uint32_t *lo)
 {
     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);
+    lua_pushinteger(L, *hi);
+    lua_pushinteger(L, *lo);
+
+    result = lua_pcall(L, 2, 2, 0);
     if (result) {
         fprintf(stderr, "Failed to run function SerialICE_msr_read_log: %s\n",
-                lua_tostring(L, -1));
+			lua_tostring(L, -1));
         exit(1);
     }
+    *hi = lua_tointeger(L, -2);
+    *lo = lua_tointeger(L, -1);
+    lua_pop(L, 2);
 }
 
-void serialice_cpuid_log(uint32_t eax, uint32_t ecx, cpuid_regs_t res,
-                                int filtered)
+static void cpuid_post(cpuid_regs_t * res)
 {
     int result;
 
     lua_getglobal(L, "SerialICE_cpuid_log");
+    lua_pushinteger(L, res->eax);        // output: eax
+    lua_pushinteger(L, res->ebx);        // output: ebx
+    lua_pushinteger(L, res->ecx);        // output: ecx
+    lua_pushinteger(L, res->edx);        // output: edx
 
-    lua_pushinteger(L, eax);    // input: eax
-    lua_pushinteger(L, ecx);    // input: ecx
-    lua_pushinteger(L, res.eax);        // output: eax
-    lua_pushinteger(L, res.ebx);        // output: ebx
-    lua_pushinteger(L, res.ecx);        // output: ecx
-    lua_pushinteger(L, res.edx);        // output: edx
-    lua_pushboolean(L, filtered);       // data
-    result = lua_pcall(L, 7, 0, 0);
+    result = lua_pcall(L, 4, 4, 0);
     if (result) {
         fprintf(stderr, "Failed to run function SerialICE_cpuid_log: %s\n",
                 lua_tostring(L, -1));
         exit(1);
     }
+    res->edx = lua_tointeger(L, -1);
+    res->ecx = lua_tointeger(L, -2);
+    res->ebx = lua_tointeger(L, -3);
+    res->eax = lua_tointeger(L, -4);
+    lua_pop(L, 4);
 }
+
+static const SerialICE_filter lua_ops = {
+    .io_read_pre = io_read_pre,
+    .io_read_post = io_read_post,
+    .io_write_pre = io_write_pre,
+    .io_write_post = io_write_post,
+    .load_pre = memory_read_pre,
+    .load_post = memory_read_post,
+    .store_pre = memory_write_pre,
+    .store_post = memory_write_post,
+    .rdmsr_pre = rdmsr_pre,
+    .rdmsr_post = rdmsr_post,
+    .wrmsr_pre = wrmsr_pre,
+    .wrmsr_post = wrmsr_post,
+    .cpuid_pre = cpuid_pre,
+    .cpuid_post = cpuid_post,
+};
diff --git a/qemu-0.15.x/serialice.c b/qemu-0.15.x/serialice.c
index 69568f0..398f378 100644
--- a/qemu-0.15.x/serialice.c
+++ b/qemu-0.15.x/serialice.c
@@ -42,10 +42,13 @@
 #include "serialice.h"
 #include "sysemu.h"
 
+#define SERIALICE_LUA_SCRIPT "serialice.lua"
+
 #define DEFAULT_RAM_SIZE 128
 #define BIOS_FILENAME "bios.bin"
 
 const SerialICE_target *target;
+const SerialICE_filter *filter;
 
 int serialice_active = 0;
 
@@ -54,52 +57,56 @@ int serialice_active = 0;
 
 uint64_t serialice_rdmsr(uint32_t addr, uint32_t key)
 {
-    uint32_t hi, lo;
-    uint64_t ret;
-    int filtered;
+    uint32_t hi = 0, lo = 0;
+    uint64_t data;
 
-    filtered = serialice_rdmsr_filter(addr, &hi, &lo);
-    if (!filtered) {
-        target->rdmsr(addr, key, &hi, &lo);
-    }
+    int mux = filter->rdmsr_pre(addr);
 
-    ret = hi;
-    ret <<= 32;
-    ret |= lo;
+    if (mux & READ_FROM_SERIALICE)
+        target->rdmsr(addr, key, &hi, &lo);
 
-    serialice_rdmsr_log(addr, hi, lo, filtered);
+    if (mux & READ_FROM_QEMU) {
+        data = cpu_rdmsr(addr);
+        hi = (data >> 32);
+        lo = (data & 0xffffffff);
+    }
 
-    return ret;
+    filter->rdmsr_post(&hi, &lo);
+    data = hi;
+    data <<= 32;
+    data |= lo;
+    return data;
 }
 
 void serialice_wrmsr(uint64_t data, uint32_t addr, uint32_t key)
 {
-    uint32_t hi, lo;
-    int filtered;
+    uint32_t hi = (data >> 32);
+    uint32_t lo = (data & 0xffffffff);
 
-    hi = (data >> 32);
-    lo = (data & 0xffffffff);
+    int mux = filter->wrmsr_pre(addr, &hi, &lo);
 
-    filtered = serialice_wrmsr_filter(addr, &hi, &lo);
-
-    if (!filtered) {
+    if (mux & WRITE_TO_SERIALICE)
         target->wrmsr(addr, key, hi, lo);
+    if (mux & WRITE_TO_QEMU) {
+        data = lo | ((uint64_t)hi)<<32;
+        cpu_wrmsr(addr, data);
     }
-
-    serialice_wrmsr_log(addr, hi, lo, filtered);
+    filter->wrmsr_post();
 }
 
 cpuid_regs_t serialice_cpuid(uint32_t eax, uint32_t ecx)
 {
     cpuid_regs_t ret;
-    int filtered;
+    ret.eax = ret.ebx = ret.ecx = ret.edx = 0;
 
-    target->cpuid(eax, ecx, &ret);
+    int mux = filter->cpuid_pre(eax, ecx);
 
-    filtered = serialice_cpuid_filter(eax, ecx, &ret);
-
-    serialice_cpuid_log(eax, ecx, ret, filtered);
+    if (mux & READ_FROM_SERIALICE)
+        target->cpuid(eax, ecx, &ret);
+    if (mux & READ_FROM_QEMU)
+        ret = cpu_cpuid(eax, ecx);
 
+    filter->cpuid_post(&ret);
     return ret;
 }
 
@@ -113,7 +120,7 @@ cpuid_regs_t serialice_cpuid(uint32_t eax, uint32_t ecx)
 void serialice_log_load(int caught, uint32_t addr, uint32_t result,
                         unsigned int data_size)
 {
-    serialice_memory_read_log(caught, result, addr, data_size);
+    filter->load_post(&result);
 }
 
 /* This function can grab Qemu load ops and forward them to the SerialICE
@@ -121,58 +128,34 @@ void serialice_log_load(int caught, uint32_t addr, uint32_t result,
  *
  * @return 0: pass on to Qemu; 1: handled locally.
  */
-int serialice_handle_load(uint32_t addr, uint32_t * result,
-                          unsigned int data_size)
+int serialice_handle_load(uint32_t addr, uint32_t * data, unsigned int size)
 {
-    int source;
-
-    source = serialice_memory_read_filter(addr, result, data_size);
+    int mux = filter->load_pre(addr, size);
 
-    if (source & READ_FROM_SERIALICE) {
-        *result = target->load(addr, data_size);
-        return 1;
-    }
-
-    if (source & READ_FROM_QEMU) {
-        return 0;
-    }
+    if (mux & READ_FROM_SERIALICE)
+        *data = target->load(addr, size);
 
-    /* No source for load, so the source is the script */
-    return 1;
+    return !(mux & READ_FROM_QEMU);
 }
 
 // **************************************************************************
 // memory store handling
 
-static void serialice_log_store(int caught, uint32_t addr, uint32_t val,
-                                unsigned int data_size)
-{
-    serialice_memory_write_log(caught, val, addr, data_size);
-}
-
 /* This function can grab Qemu store ops and forward them to the SerialICE
  * target
  *
  * @return 0: Qemu exclusive or shared; 1: SerialICE exclusive.
  */
 
-int serialice_handle_store(uint32_t addr, uint32_t val, unsigned int data_size)
+int serialice_handle_store(uint32_t addr, uint32_t data, unsigned int size)
 {
-    int write_to_target, write_to_qemu, ret;
-    uint32_t filtered_data = val;
-
-    ret = serialice_memory_write_filter(addr, data_size, &filtered_data);
+    int mux = filter->store_pre(addr, size, &data);
 
-    write_to_target = ((ret & WRITE_TO_SERIALICE) != 0);
-    write_to_qemu = ((ret & WRITE_TO_QEMU) != 0);
-
-    serialice_log_store(write_to_target, addr, filtered_data, data_size);
-
-    if (write_to_target) {
-        target->store(addr, data_size, filtered_data);
-    }
+    if (mux & WRITE_TO_SERIALICE)
+        target->store(addr, size, data);
 
-    return (write_to_qemu == 0);
+    filter->store_post();
+    return !(mux & WRITE_TO_QEMU);
 }
 
 #define mask_data(val,bytes) (val & (((uint64_t)1<<(bytes*8))-1))
@@ -180,33 +163,30 @@ int serialice_handle_store(uint32_t addr, uint32_t val, unsigned int data_size)
 uint32_t serialice_io_read(uint16_t port, unsigned int size)
 {
     uint32_t data = 0;
-    int filtered;
+    int mux = filter->io_read_pre(port, size);
 
-    filtered = serialice_io_read_filter(&data, port, size);
-    if (!filtered) {
-        return target->io_read(port, size);
-    }
+    if (mux & READ_FROM_QEMU)
+        data = cpu_io_read_wrapper(port, size);
+    if (mux & READ_FROM_SERIALICE)
+        data = target->io_read(port, size);
 
     data = mask_data(data, size);
-    serialice_io_read_log(0, data, port, size);
+    filter->io_read_post(&data);
     return data;
 }
 
 void serialice_io_write(uint16_t port, unsigned int size, uint32 data)
 {
-    uint32_t filtered_data = mask_data(data, size);
-    int filtered;
-
-    filtered = serialice_io_write_filter(&filtered_data, port, size);
+    data = mask_data(data, size);
+    int mux = filter->io_write_pre(&data, port, size);
+    data = mask_data(data, size);
 
-    if (filtered) {
-        data = mask_data(filtered_data, size);
-    } else {
-        data = mask_data(filtered_data, size);
+    if (mux & WRITE_TO_QEMU)
+        cpu_io_write_wrapper(port, size, data);
+    if (mux & WRITE_TO_SERIALICE)
         target->io_write(port, size, data);
-    }
 
-    serialice_io_write_log(0, data, port, size);
+    filter->io_write_post();
 }
 
 // **************************************************************************
@@ -222,7 +202,7 @@ static void serialice_init(void)
     target->mainboard();
 
     printf("SerialICE: LUA init...\n");
-    serialice_lua_init();
+    filter = serialice_lua_init(SERIALICE_LUA_SCRIPT);
 
     /* Let the rest of Qemu know we're alive */
     serialice_active = 1;
diff --git a/qemu-0.15.x/serialice.h b/qemu-0.15.x/serialice.h
index 3a12b53..23e3af6 100644
--- a/qemu-0.15.x/serialice.h
+++ b/qemu-0.15.x/serialice.h
@@ -41,9 +41,6 @@
 extern const char *serialice_device;
 extern int serialice_active;
 
-int serialice_lua_init(void);
-const char *serialice_lua_execute(const char *cmd);
-
 uint32_t serialice_io_read(uint16_t port, unsigned int size);
 void serialice_io_write(uint16_t port, unsigned int size, uint32_t data);
 
@@ -79,20 +76,28 @@ const SerialICE_target *serialice_serial_init(void);
 void serialice_serial_exit(void);
 
 /* serialice LUA */
-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_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_io_read_log(int caught, uint32_t data, uint32_t addr, int size);
-void serialice_io_write_log(int caught, uint32_t data, uint32_t addr, int size);
-void serialice_memory_read_log(int caught, uint32_t data, uint32_t addr, int size);
-void serialice_memory_write_log(int caught, uint32_t data, uint32_t addr, int size);
-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);
+typedef struct {
+    int (*io_read_pre) (uint16_t port, int size);
+    void (*io_read_post) (uint32_t * data);
+    int (*io_write_pre) (uint32_t * data, uint16_t port, int size);
+    void (*io_write_post) (void);
+
+    int (*load_pre) (uint32_t addr, int size);
+    void (*load_post) (uint32_t * data);
+    int (*store_pre) (uint32_t addr, int size, uint32_t * data);
+    void (*store_post) (void);
+
+    int (*rdmsr_pre) (uint32_t addr);
+    void (*rdmsr_post) (uint32_t * hi, uint32_t * lo);
+    int (*wrmsr_pre) (uint32_t addr, uint32_t * hi, uint32_t * lo);
+    void (*wrmsr_post) (void);
+
+    int (*cpuid_pre) (uint32_t eax, uint32_t ecx);
+    void (*cpuid_post) (cpuid_regs_t * res);
+} SerialICE_filter;
+
+const SerialICE_filter *serialice_lua_init(const char *serialice_lua_script);
+void serialice_lua_exit(void);
+const char *serialice_lua_execute(const char *cmd);
 
 #endif



More information about the SerialICE mailing list