[SerialICE] New patch to review for serialice: 070a7f6 SerialICE: Change lua call API for memory

Kyösti Mälkki (kyosti.malkki@gmail.com) gerrit at coreboot.org
Sun May 6 19:16:52 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/1014

-gerrit

commit 070a7f62f174de2f366e8bfa8b6a7c921bca68cc
Author: Kyösti Mälkki <kyosti.malkki at gmail.com>
Date:   Sun May 6 17:29:20 2012 +0300

    SerialICE: Change lua call API for memory
    
    The details of the memory operation are stored in the lua script,
    thus it is not necessary to pass those back-and-forth for logging
    purposes.
    
    NOTE: At the moment it is not possible to change the value returned
    to Qemu on a load operation.
    
    Change-Id: I32405ae501fc6891739a282654e1ca3a451cd0ff
    Signed-off-by: Kyösti Mälkki <kyosti.malkki at gmail.com>
---
 qemu-0.15.x/serialice.c |  118 ++++++++++-------------------------------------
 1 files changed, 24 insertions(+), 94 deletions(-)

diff --git a/qemu-0.15.x/serialice.c b/qemu-0.15.x/serialice.c
index 10623e5..d90aba8 100644
--- a/qemu-0.15.x/serialice.c
+++ b/qemu-0.15.x/serialice.c
@@ -372,15 +372,15 @@ static int serialice_io_write_filter(uint32_t * data, uint16_t port, int size)
     return ret;
 }
 
-static int serialice_memory_read_filter(uint32_t addr, uint32_t * data,
-                                        int size)
+static int serialice_memory_read_filter(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",
@@ -388,13 +388,9 @@ static 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;
 }
 
@@ -402,12 +398,12 @@ static int serialice_memory_write_filter(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,
@@ -415,14 +411,11 @@ static 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;
 }
 
@@ -546,33 +539,6 @@ static void serialice_write_log(int flags)
 }
 
 
-static void serialice_log(int flags, uint32_t data, uint32_t addr, int size)
-{
-    int result;
-
-    if ((flags & LOG_WRITE) && (flags & LOG_MEMORY)) {
-        lua_getglobal(L, "SerialICE_memory_write_log");
-    } else if (!(flags & LOG_WRITE) && (flags & LOG_MEMORY)) {
-        lua_getglobal(L, "SerialICE_memory_read_log");
-    } else if ((flags & LOG_WRITE) && !(flags & LOG_MEMORY)) {
-        lua_getglobal(L, "SerialICE_io_write_log");
-    } else {                    // if (!(flags & LOG_WRITE) && !(flags & LOG_MEMORY))
-        lua_getglobal(L, "SerialICE_io_read_log");
-    }
-
-    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);
-    if (result) {
-        fprintf(stderr, "Failed to run function SerialICE_%s_%s_log: %s\n",
-                (flags & LOG_MEMORY) ? "memory" : "io",
-                (flags & LOG_WRITE) ? "write" : "read", lua_tostring(L, -1));
-        exit(1);
-    }
-}
 
 static void serialice_msr_log(int flags, uint32_t addr, uint32_t hi,
                               uint32_t lo, int filtered)
@@ -864,7 +830,6 @@ cpuid_regs_t serialice_cpuid(uint32_t eax, uint32_t ecx)
 // **************************************************************************
 // memory load handling
 
-
 /**
  * This function is called by the softmmu engine to update the status
  * of a load cycle
@@ -872,12 +837,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)
 {
-    if (caught) {
-        serialice_log(LOG_READ | LOG_MEMORY | LOG_TARGET, result, addr,
-                      data_size);
-    } else {
-        serialice_log(LOG_READ | LOG_MEMORY, result, addr, data_size);
-    }
+    serialice_read_log(LOG_MEMORY, &result);
 }
 
 /* This function can grab Qemu load ops and forward them to the SerialICE
@@ -885,67 +845,37 @@ 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 source = serialice_memory_read_filter(addr, size);
 
-    if (source & READ_FROM_SERIALICE) {
-        *result = serialice_load_wrapper(addr, data_size);
-        return 1;
-    }
-
-    if (source & READ_FROM_QEMU) {
-        return 0;
-    }
+    if (source & READ_FROM_SERIALICE)
+        *data = serialice_load_wrapper(addr, size);
 
-    /* No source for load, so the source is the script */
-    return 1;
+    return !(source & READ_FROM_QEMU);
 }
 
 // **************************************************************************
 // memory store handling
 
-
-static void serialice_log_store(int caught, uint32_t addr, uint32_t val,
-                                unsigned int data_size)
-{
-    if (caught) {
-        serialice_log(LOG_WRITE | LOG_MEMORY | LOG_TARGET, val, addr,
-                      data_size);
-    } else {
-        serialice_log(LOG_WRITE | LOG_MEMORY, 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);
-
-    write_to_target = ((ret & WRITE_TO_SERIALICE) != 0);
-    write_to_qemu = ((ret & WRITE_TO_QEMU) != 0);
+    int target = serialice_memory_write_filter(addr, size, &data);
 
-    serialice_log_store(write_to_target, addr, filtered_data, data_size);
+    if (target & WRITE_TO_SERIALICE)
+        serialice_store_wrapper(addr, size, data);
 
-    if (write_to_target) {
-        serialice_store_wrapper(addr, data_size, filtered_data);
-    }
+    serialice_write_log(LOG_MEMORY);
 
-    return (write_to_qemu == 0);
+    return !(target & WRITE_TO_QEMU);
 }
 
-
 uint32_t serialice_io_read(uint16_t port, unsigned int size)
 {
     uint32_t data = 0;



More information about the SerialICE mailing list