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/1016
-gerrit
commit 738b5e2ddb51b1b93ff1b3f12b3a52450995a491 Author: Kyösti Mälkki kyosti.malkki@gmail.com Date: Sun May 6 18:16:24 2012 +0300
SerialICE: Change lua call API for CPUID
With the change it is possible to divert an CPUID to Qemu or drop it entirely.
Change-Id: Id6a1b401517555da067902d2cec853def6aba729 Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- qemu-0.15.x/serialice.c | 85 +++++++++++------------------------ qemu-0.15.x/target-i386/cpu.h | 1 + qemu-0.15.x/target-i386/op_helper.c | 32 +++++++------ 3 files changed, 45 insertions(+), 73 deletions(-)
diff --git a/qemu-0.15.x/serialice.c b/qemu-0.15.x/serialice.c index 655c72f..aaf3091 100644 --- a/qemu-0.15.x/serialice.c +++ b/qemu-0.15.x/serialice.c @@ -65,6 +65,7 @@
#define SERIALICE_DEBUG 3 #define BUFFER_SIZE 1024 + typedef struct { #ifdef WIN32 HANDLE fd; @@ -100,11 +101,6 @@ static lua_State *L; #define LOG_MEMORY (1<<1) #define LOG_MSR (1<<2)
-/* FIXME */ -#define LOG_TARGET (1<<3) -#define LOG_READ (1<<4) -#define LOG_WRITE (1<<5) - // ************************************************************************** // LUA scripting interface and callbacks
@@ -463,21 +459,15 @@ static int serialice_rdmsr_filter(uint32_t addr) return ret; }
-static int serialice_cpuid_filter(uint32_t eax, uint32_t ecx, - cpuid_regs_t * regs) +static int serialice_cpuid_filter(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", @@ -485,15 +475,9 @@ static 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; }
@@ -548,26 +532,28 @@ static void serialice_write_log(int flags) } }
-static void serialice_cpuid_log(uint32_t eax, uint32_t ecx, cpuid_regs_t res, - int filtered) +static void serialice_cpuid_log(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 void serialice_rdmsr_log(uint32_t *hi, uint32_t *lo) @@ -793,35 +779,18 @@ void serialice_wrmsr(uint64_t data, uint32_t addr, uint32_t key) serialice_write_log(LOG_MSR); }
- cpuid_regs_t serialice_cpuid(uint32_t eax, uint32_t ecx) { cpuid_regs_t ret; - int filtered; - - ret.eax = eax; - ret.ebx = 0; // either set by filter or by target - ret.ecx = ecx; - ret.edx = 0; // either set by filter or by target - - sprintf(s->command, "*ci%08x.%08x", eax, ecx); + ret.eax = ret.ebx = ret.ecx = ret.edx = 0; + int source = serialice_cpuid_filter(eax, ecx);
- // command read back: "\n000006f2.00000000.00001234.12340324" - // (36 characters) - serialice_command(s->command, 36); - - s->buffer[9] = 0; // . -> \0 - s->buffer[18] = 0; // . -> \0 - s->buffer[27] = 0; // . -> \0 - ret.eax = (uint32_t) strtoul(s->buffer + 1, (char **)NULL, 16); - ret.ebx = (uint32_t) strtoul(s->buffer + 10, (char **)NULL, 16); - ret.ecx = (uint32_t) strtoul(s->buffer + 19, (char **)NULL, 16); - ret.edx = (uint32_t) strtoul(s->buffer + 28, (char **)NULL, 16); - - filtered = serialice_cpuid_filter(eax, ecx, &ret); - - serialice_cpuid_log(eax, ecx, ret, filtered); + if (source & READ_FROM_SERIALICE) + serialice_cpuid_wrapper(eax, ecx, &ret); + if (source & READ_FROM_QEMU) + ret = cpu_cpuid(eax, ecx);
+ serialice_cpuid_log(&ret); return ret; }
diff --git a/qemu-0.15.x/target-i386/cpu.h b/qemu-0.15.x/target-i386/cpu.h index e919129..44f9353 100644 --- a/qemu-0.15.x/target-i386/cpu.h +++ b/qemu-0.15.x/target-i386/cpu.h @@ -1057,6 +1057,7 @@ void svm_check_intercept(CPUState *env1, uint32_t type);
void cpu_wrmsr(uint64_t val, uint32_t addr); uint64_t cpu_rdmsr(uint32_t addr); +cpuid_regs_t cpu_cpuid(uint32_t in_eax, uint32_t in_ecx);
uint32_t cpu_cc_compute_all(CPUState *env1, int op);
diff --git a/qemu-0.15.x/target-i386/op_helper.c b/qemu-0.15.x/target-i386/op_helper.c index 695a307..1823c74 100644 --- a/qemu-0.15.x/target-i386/op_helper.c +++ b/qemu-0.15.x/target-i386/op_helper.c @@ -2010,29 +2010,31 @@ void helper_single_step(void) raise_exception(EXCP01_DB); }
-void helper_cpuid(void) +cpuid_regs_t cpu_cpuid(uint32_t in_eax, uint32_t in_ecx) { - uint32_t eax, ebx, ecx, edx; + cpuid_regs_t ret; + cpu_x86_cpuid(env, in_eax, in_ecx, &ret.eax, &ret.ebx, &ret.ecx, &ret.edx); + return ret; +}
+void helper_cpuid(void) +{ + cpuid_regs_t ret; helper_svm_check_intercept_param(SVM_EXIT_CPUID, 0);
#ifdef CONFIG_SERIALICE - if (serialice_active) { - cpuid_regs_t ret; + if (serialice_active) ret = serialice_cpuid((uint32_t) EAX, (uint32_t) ECX); - EAX = ret.eax; - EBX = ret.ebx; - ECX = ret.ecx; - EDX = ret.edx; - return; - } + else + ret = cpu_cpuid((uint32_t) EAX, (uint32_t) ECX); +#else + cpu_x86_cpuid(env, (uint32_t) EAX, (uint32_t) ECX, &ret.eax, &ret.ebx, &ret.ecx, &ret.edx); #endif
- cpu_x86_cpuid(env, (uint32_t)EAX, (uint32_t)ECX, &eax, &ebx, &ecx, &edx); - EAX = eax; - EBX = ebx; - ECX = ecx; - EDX = edx; + EAX = ret.eax; + EBX = ret.ebx; + ECX = ret.ecx; + EDX = ret.edx; }
void helper_enter_level(int level, int data32, target_ulong t1)