summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-07-16 15:42:20 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-07-16 15:42:20 -0700
commitb852724c9d4b2fe91c327447666c51409fc263f8 (patch)
tree97fb9d4760d1f1b0f4cdccb3f749b23ec8bcbd3f
parentd0647cde615a7eac404d44da26c6ec93789faed8 (diff)
downloadsyslinux-b852724c9d4b2fe91c327447666c51409fc263f8.tar.gz
ifcpu64.c32: clean up the sourcessyslinux-3.71-pre14
Clean up the sources to make them easier to read. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--com32/modules/ifcpu64.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/com32/modules/ifcpu64.c b/com32/modules/ifcpu64.c
index def43b35..7d4581dd 100644
--- a/com32/modules/ifcpu64.c
+++ b/com32/modules/ifcpu64.c
@@ -36,43 +36,38 @@
#include <cpuid.h>
#include <syslinux/boot.h>
-static bool cpu_has_cpuid(void)
+static bool __constfunc cpu_has_cpuid(void)
{
return cpu_has_eflag(X86_EFLAGS_ID);
}
-static bool cpu_has_level(uint32_t level)
+static bool __constfunc cpu_has_level(uint32_t level)
{
- uint32_t group = level & 0xffff0000;
- uint32_t limit = cpuid_eax(group);
- if ((limit & 0xffff0000) != group)
- return false;
- if (level > limit)
+ uint32_t group;
+ uint32_t limit;
+
+ if (!cpu_has_cpuid())
return false;
- return true;
-}
+ group = level & 0xffff0000;
+ limit = cpuid_eax(group);
-static bool cpu_has_pae(void)
-{
- if (!cpu_has_cpuid())
+ if ((limit & 0xffff0000) != group)
return false;
- if (!cpu_has_level(0x00000001))
+ if (level > limit)
return false;
- return !!(cpuid_edx(0x00000001) & (X86_FEATURE_PAE & 31));
+ return true;
}
-static bool cpu_has_lm(void)
+/* This only supports feature groups 0 and 1, corresponding to the
+ Intel and AMD EDX bit vectors. We can add more later if need be. */
+static bool __constfunc cpu_has_feature(int x)
{
- if (!cpu_has_cpuid())
- return false;
-
- if (!cpu_has_level(0x80000001))
- return false;
+ uint32_t level = ((x & 1) << 31) | 1;
- return !!(cpuid_edx(0x80000001) & (X86_FEATURE_LM & 31));
+ return cpu_has_level(level) && ((cpuid_edx(level) >> (x & 31) & 1));
}
/* XXX: this really should be librarized */
@@ -119,8 +114,8 @@ int main(int argc, char *argv[])
break;
}
- boot_args(cpu_has_lm() ? args[0] :
- cpu_has_pae() ? args[1] :
+ boot_args(cpu_has_feature(X86_FEATURE_LM) ? args[0] :
+ cpu_has_feature(X86_FEATURE_PAE) ? args[1] :
args[2]);
return -1;
}