From 79603c7c2c45d16796ecc5a2973362af907878a5 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Wed, 11 May 2016 13:56:33 +0100 Subject: [PATCH] Use IS_DEFINED() in preference to #ifdef By exposing more code and having the compiler optimise it out, there is less chance of bitrot. Signed-off-by: Andrew Cooper --- arch/x86/setup.c | 48 ++++++++++++++++++++++------------------------ tests/cpuid/main.c | 9 +++++---- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/arch/x86/setup.c b/arch/x86/setup.c index 6eaacc4..3036fc8 100644 --- a/arch/x86/setup.c +++ b/arch/x86/setup.c @@ -31,32 +31,33 @@ start_info_t *start_info = NULL; */ static void init_hypercalls(void) { -#ifdef CONFIG_HVM - uint32_t eax, ebx, ecx, edx, base; - bool found = false; - - for ( base = XEN_CPUID_FIRST_LEAF; - base < XEN_CPUID_FIRST_LEAF + 0x10000; base += 0x100 ) + if ( IS_DEFINED(CONFIG_HVM) ) { - cpuid(base, &eax, &ebx, &ecx, &edx); + uint32_t eax, ebx, ecx, edx, base; + bool found = false; - if ( (ebx == XEN_CPUID_SIGNATURE_EBX) && - (ecx == XEN_CPUID_SIGNATURE_ECX) && - (edx == XEN_CPUID_SIGNATURE_EDX) && - ((eax - base) >= 2) ) + for ( base = XEN_CPUID_FIRST_LEAF; + base < XEN_CPUID_FIRST_LEAF + 0x10000; base += 0x100 ) { - found = true; - break; + cpuid(base, &eax, &ebx, &ecx, &edx); + + if ( (ebx == XEN_CPUID_SIGNATURE_EBX) && + (ecx == XEN_CPUID_SIGNATURE_ECX) && + (edx == XEN_CPUID_SIGNATURE_EDX) && + ((eax - base) >= 2) ) + { + found = true; + break; + } } - } - if ( !found ) - panic("Unable to locate Xen CPUID leaves\n"); + if ( !found ) + panic("Unable to locate Xen CPUID leaves\n"); - cpuid(base + 2, &eax, &ebx, &ecx, &edx); - wrmsr(ebx, (unsigned long)&hypercall_page); - barrier(); -#endif /* CONFIG_HVM */ + cpuid(base + 2, &eax, &ebx, &ecx, &edx); + wrmsr(ebx, (unsigned long)&hypercall_page); + barrier(); + } /* * Confirm that the `ret` poision has been overwritten with a real @@ -91,14 +92,12 @@ static void setup_pv_console(void) init_pv_console(cons_ring, cons_evtchn); } -#if defined(CONFIG_HVM) static void qemu_console_write(const char *buf, size_t len) { asm volatile("rep; outsb" : "+S" (buf), "+c" (len) : "d" (0x12)); } -#endif static void xen_console_write(const char *buf, size_t len) { @@ -107,9 +106,8 @@ static void xen_console_write(const char *buf, size_t len) void arch_setup(void) { -#if defined(CONFIG_HVM) - register_console_callback(qemu_console_write); -#endif + if ( IS_DEFINED(CONFIG_HVM) ) + register_console_callback(qemu_console_write); register_console_callback(xen_console_write); diff --git a/tests/cpuid/main.c b/tests/cpuid/main.c index bdb9a23..f07cf1c 100644 --- a/tests/cpuid/main.c +++ b/tests/cpuid/main.c @@ -99,10 +99,11 @@ void test_main(void) printk("Native cpuid:\n"); dump_leaves(cpuid_count); -#ifdef CONFIG_PV - printk("Emulated cpuid:\n"); - dump_leaves(pv_cpuid_count); -#endif + if ( IS_DEFINED(CONFIG_PV) ) + { + printk("Emulated cpuid:\n"); + dump_leaves(pv_cpuid_count); + } xtf_success(NULL); } -- 2.39.5