[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 1/2] i386: rewrite way CPUID index is validated
From: |
Daniel P. Berrange |
Subject: |
[Qemu-devel] [PATCH v2 1/2] i386: rewrite way CPUID index is validated |
Date: |
Fri, 5 May 2017 15:27:42 +0100 |
Change the nested if statements into a flat switch, to make
it clearer what validation / capping is being performed on
different CPUID index values.
Signed-off-by: Daniel P. Berrange <address@hidden>
---
target/i386/cpu.c | 43 +++++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 18 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 13c0985..3d5903c 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -2628,26 +2628,33 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
uint32_t count,
uint32_t pkg_offset;
/* test if maximum index reached */
- if (index & 0x80000000) {
+ switch (index & 0xF0000000) {
+ case 0:
+ /* Intel documentation states that invalid EAX input will
+ * return the same information as EAX=cpuid_level
+ * (Intel SDM Vol. 2A - Instruction Set Reference - CPUID)
+ */
+ if (index > env->cpuid_level) {
+ index = env->cpuid_level;
+ }
+ break;
+ case 0x80000000:
if (index > env->cpuid_xlevel) {
- if (env->cpuid_xlevel2 > 0) {
- /* Handle the Centaur's CPUID instruction. */
- if (index > env->cpuid_xlevel2) {
- index = env->cpuid_xlevel2;
- } else if (index < 0xC0000000) {
- index = env->cpuid_xlevel;
- }
- } else {
- /* Intel documentation states that invalid EAX input will
- * return the same information as EAX=cpuid_level
- * (Intel SDM Vol. 2A - Instruction Set Reference - CPUID)
- */
- index = env->cpuid_level;
- }
+ index = env->cpuid_xlevel;
}
- } else {
- if (index > env->cpuid_level)
- index = env->cpuid_level;
+ break;
+ case 0xC0000000:
+ if (index > env->cpuid_xlevel2) {
+ index = env->cpuid_xlevel2;
+ }
+ break;
+ default:
+ /* Intel documentation states that invalid EAX input will
+ * return the same information as EAX=cpuid_level
+ * (Intel SDM Vol. 2A - Instruction Set Reference - CPUID)
+ */
+ index = env->cpuid_level;
+ break;
}
switch(index) {
--
2.9.3