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/1468
-gerrit
commit 9d5fcdd21c92f8918730448692eacb04439f22ca Author: Kyösti Mälkki kyosti.malkki@gmail.com Date: Mon Aug 20 16:21:33 2012 +0300
SerialICE: Create capsule for serial protocol
Change makes it easier to make a more generic "multiplex" that chooses if operations are handled by Qemu or external target. Also it allows for the use of another communication channel in place of serial stream.
Change-Id: I46e0abf8b1f4e1fa4dd30332778f5e73528a8dd4 Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- qemu-0.15.x/serialice-com.c | 52 +++++++++++++++++++++++++++++++-------------- qemu-0.15.x/serialice.c | 20 ++++++++++------- qemu-0.15.x/serialice.h | 29 ++++++++++++------------- 3 files changed, 62 insertions(+), 39 deletions(-)
diff --git a/qemu-0.15.x/serialice-com.c b/qemu-0.15.x/serialice-com.c index ef5fd84..ee539f4 100644 --- a/qemu-0.15.x/serialice-com.c +++ b/qemu-0.15.x/serialice-com.c @@ -52,12 +52,15 @@ typedef struct { } SerialICEState;
static SerialICEState *s; +static const SerialICE_target serialice_protocol; const char *serialice_mainboard = NULL;
#ifndef WIN32 static struct termios options; #endif
+// ************************************************************************** +// low level communication with the SerialICE shell (serial communication) static int handshake_mode = 0;
static void *mallocz(unsigned int size) @@ -157,7 +160,7 @@ static int serialice_wait_prompt(void) return 0; }
-void serialice_serial_init(void) +const SerialICE_target *serialice_serial_init(void) { s = mallocz(sizeof(SerialICEState));
@@ -252,13 +255,17 @@ void serialice_serial_init(void) serialice_write(s, "@", 1);
handshake_mode = 0; // from now on, warn about readback errors. + return &serialice_protocol; +}
- serialice_get_version(); - - serialice_get_mainboard(); +void serialice_serial_exit(void) +{ + free(s->command); + free(s->buffer); + free(s); }
-void serialice_command(const char *command, int reply_len) +static void serialice_command(const char *command, int reply_len) { #if SERIALICE_DEBUG > 5 int i; @@ -296,7 +303,10 @@ void serialice_command(const char *command, int reply_len) #endif }
-void serialice_get_version(void) +// ************************************************************************** +// high level communication with the SerialICE shell + +static void msg_version(void) { int len = 0; printf("SerialICE: Version.....: "); @@ -313,7 +323,7 @@ void serialice_get_version(void) printf("%s\n", s->buffer); }
-void serialice_get_mainboard(void) +static void msg_mainboard(void) { int len = 31;
@@ -326,7 +336,7 @@ void serialice_get_mainboard(void) printf("%s\n", serialice_mainboard); }
-uint32_t serialice_io_read_wrapper(uint16_t port, unsigned int size) +static uint32_t msg_io_read(uint16_t port, unsigned int size) { switch (size) { case 1: @@ -350,7 +360,7 @@ uint32_t serialice_io_read_wrapper(uint16_t port, unsigned int size) } }
-void serialice_io_write_wrapper(uint16_t port, unsigned int size, uint32_t data) +static void msg_io_write(uint16_t port, unsigned int size, uint32_t data) { switch (size) { case 1: @@ -371,7 +381,7 @@ void serialice_io_write_wrapper(uint16_t port, unsigned int size, uint32_t data) return; }
-uint32_t serialice_load_wrapper(uint32_t addr, unsigned int size) +static uint32_t msg_load(uint32_t addr, unsigned int size) { switch (size) { case 1: @@ -395,7 +405,7 @@ uint32_t serialice_load_wrapper(uint32_t addr, unsigned int size) return 0; }
-void serialice_store_wrapper(uint32_t addr, unsigned int size, uint32_t data) +static void msg_store(uint32_t addr, unsigned int size, uint32_t data) { switch (size) { case 1: @@ -415,8 +425,7 @@ void serialice_store_wrapper(uint32_t addr, unsigned int size, uint32_t data) } }
-void serialice_rdmsr_wrapper(uint32_t addr, uint32_t key, - uint32_t * hi, uint32_t * lo) +static void msg_rdmsr(uint32_t addr, uint32_t key, uint32_t * hi, uint32_t * lo) { sprintf(s->command, "*rc%08x.%08x", addr, key); // command read back: "\n00000000.00000000" (18 characters) @@ -426,14 +435,13 @@ void serialice_rdmsr_wrapper(uint32_t addr, uint32_t key, *lo = (uint32_t) strtoul(s->buffer + 10, (char **)NULL, 16); }
-void serialice_wrmsr_wrapper(uint32_t addr, uint32_t key, - uint32_t hi, uint32_t lo) +static void msg_wrmsr(uint32_t addr, uint32_t key, uint32_t hi, uint32_t lo) { sprintf(s->command, "*wc%08x.%08x=%08x.%08x", addr, key, hi, lo); serialice_command(s->command, 0); }
-void serialice_cpuid_wrapper(uint32_t eax, uint32_t ecx, cpuid_regs_t * ret) +static void msg_cpuid(uint32_t eax, uint32_t ecx, cpuid_regs_t * ret) { sprintf(s->command, "*ci%08x.%08x", eax, ecx); // command read back: "\n000006f2.00000000.00001234.12340324" @@ -447,3 +455,15 @@ void serialice_cpuid_wrapper(uint32_t eax, uint32_t ecx, cpuid_regs_t * ret) ret->ecx = (uint32_t) strtoul(s->buffer + 19, (char **)NULL, 16); ret->edx = (uint32_t) strtoul(s->buffer + 28, (char **)NULL, 16); } + +static const SerialICE_target serialice_protocol = { + .version = msg_version, + .mainboard = msg_mainboard, + .io_read = msg_io_read, + .io_write = msg_io_write, + .load = msg_load, + .store = msg_store, + .rdmsr = msg_rdmsr, + .wrmsr = msg_wrmsr, + .cpuid = msg_cpuid, +}; diff --git a/qemu-0.15.x/serialice.c b/qemu-0.15.x/serialice.c index 74aa9ff..5fe5cfb 100644 --- a/qemu-0.15.x/serialice.c +++ b/qemu-0.15.x/serialice.c @@ -50,6 +50,8 @@ #define DEFAULT_RAM_SIZE 128 #define BIOS_FILENAME "bios.bin"
+const SerialICE_target *target; + int serialice_active = 0;
static DisplayState *ds; @@ -113,7 +115,7 @@ uint64_t serialice_rdmsr(uint32_t addr, uint32_t key)
filtered = serialice_rdmsr_filter(addr, &hi, &lo); if (!filtered) { - serialice_rdmsr_wrapper(addr, key, &hi, &lo); + target->rdmsr(addr, key, &hi, &lo); }
ret = hi; @@ -136,7 +138,7 @@ void serialice_wrmsr(uint64_t data, uint32_t addr, uint32_t key) filtered = serialice_wrmsr_filter(addr, &hi, &lo);
if (!filtered) { - serialice_wrmsr_wrapper(addr, key, hi, lo); + target->wrmsr(addr, key, hi, lo); }
serialice_wrmsr_log(addr, hi, lo, filtered); @@ -147,7 +149,7 @@ cpuid_regs_t serialice_cpuid(uint32_t eax, uint32_t ecx) cpuid_regs_t ret; int filtered;
- serialice_cpuid_wrapper(eax, ecx, &ret); + target->cpuid(eax, ecx, &ret);
filtered = serialice_cpuid_filter(eax, ecx, &ret);
@@ -182,7 +184,7 @@ int serialice_handle_load(uint32_t addr, uint32_t * result, source = serialice_memory_read_filter(addr, result, data_size);
if (source & READ_FROM_SERIALICE) { - *result = serialice_load_wrapper(addr, data_size); + *result = target->load(addr, data_size); return 1; }
@@ -222,7 +224,7 @@ int serialice_handle_store(uint32_t addr, uint32_t val, unsigned int data_size) serialice_log_store(write_to_target, addr, filtered_data, data_size);
if (write_to_target) { - serialice_store_wrapper(addr, data_size, filtered_data); + target->store(addr, data_size, filtered_data); }
return (write_to_qemu == 0); @@ -237,7 +239,7 @@ uint32_t serialice_io_read(uint16_t port, unsigned int size)
filtered = serialice_io_read_filter(&data, port, size); if (!filtered) { - return serialice_io_read_wrapper(port, size); + return target->io_read(port, size); }
data = mask_data(data, size); @@ -256,7 +258,7 @@ void serialice_io_write(uint16_t port, unsigned int size, uint32 data) data = mask_data(filtered_data, size); } else { data = mask_data(filtered_data, size); - serialice_io_write_wrapper(port, size, data); + target->io_write(port, size, data); }
serialice_io_write_log(0, data, port, size); @@ -270,7 +272,9 @@ static void serialice_init(void) serialice_screen();
printf("SerialICE: Open connection to target hardware...\n"); - serialice_serial_init(); + target = serialice_serial_init(); + target->version(); + target->mainboard();
printf("SerialICE: LUA init...\n"); serialice_lua_init(); diff --git a/qemu-0.15.x/serialice.h b/qemu-0.15.x/serialice.h index 4624deb..3a12b53 100644 --- a/qemu-0.15.x/serialice.h +++ b/qemu-0.15.x/serialice.h @@ -44,12 +44,6 @@ extern int serialice_active; int serialice_lua_init(void); const char *serialice_lua_execute(const char *cmd);
-void serialice_serial_init(void); -void serialice_command(const char *command, int reply_len); - -void serialice_get_version(void); -void serialice_get_mainboard(void); - uint32_t serialice_io_read(uint16_t port, unsigned int size); void serialice_io_write(uint16_t port, unsigned int size, uint32_t data);
@@ -69,15 +63,20 @@ void serialice_log_load(int caught, uint32_t addr, uint32_t result, int serialice_handle_store(uint32_t addr, uint32_t val, unsigned int data_size);
/* serialice protocol */ -uint32_t serialice_io_read_wrapper(uint16_t port, unsigned int size); -void serialice_io_write_wrapper(uint16_t port, unsigned int size, uint32_t data); - -uint32_t serialice_load_wrapper(uint32_t addr, unsigned int size); -void serialice_store_wrapper(uint32_t addr, unsigned int size, uint32_t data); - -void serialice_rdmsr_wrapper(uint32_t addr, uint32_t key, uint32_t *hi, uint32_t *lo); -void serialice_wrmsr_wrapper(uint32_t addr, uint32_t key, uint32_t hi, uint32_t lo); -void serialice_cpuid_wrapper(uint32_t eax, uint32_t ecx, cpuid_regs_t * ret); +typedef struct { + void (*version) (void); + void (*mainboard) (void); + uint32_t (*io_read) (uint16_t port, unsigned int size); + void (*io_write) (uint16_t port, unsigned int size, uint32_t data); + uint32_t (*load) (uint32_t addr, unsigned int size); + void (*store) (uint32_t addr, unsigned int size, uint32_t data); + void (*rdmsr) (uint32_t addr, uint32_t key, uint32_t * hi, uint32_t * lo); + void (*wrmsr) (uint32_t addr, uint32_t key, uint32_t hi, uint32_t lo); + void (*cpuid) (uint32_t eax, uint32_t ecx, cpuid_regs_t * ret); +} SerialICE_target; + +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);