From 0b60a062da0c28ed4779ab707c64dde6d3af8ef1 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 15 Jun 2009 23:03:05 -0400 Subject: [PATCH] Unify mode16/32 compiler checks. Add ASSERT16/ASSERT32 macros to farptr.h. Use those macros in place of open-coded checks. Add "noreturn" attribute to functions to reduce compiler warnings. Add ASSERT32 to smp_probe() to eliminate 16bit assembler warnings. --- src/biosvar.h | 8 ++------ src/farptr.h | 8 ++++++++ src/smpdetect.c | 1 + src/types.h | 1 + src/util.c | 10 ++-------- src/util.h | 5 +---- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/biosvar.h b/src/biosvar.h index c0b46cc..821aa35 100644 --- a/src/biosvar.h +++ b/src/biosvar.h @@ -248,9 +248,7 @@ static inline u16 get_ebda_seg() { static inline struct extended_bios_data_area_s * get_ebda_ptr() { - extern void *__force_link_error__get_ebda_ptr_only_in_32bit(); - if (MODE16) - return __force_link_error__get_ebda_ptr_only_in_32bit(); + ASSERT32(); return MAKE_FLATPTR(get_ebda_seg(), 0); } #define GET_EBDA2(eseg, var) \ @@ -279,9 +277,7 @@ static inline u16 get_global_seg() { #define GET_GLOBAL(var) \ GET_VAR(GLOBAL_SEGREG, (var)) #define SET_GLOBAL(var, val) do { \ - extern void __force_link_error__set_global_only_in_32bit(); \ - if (MODE16) \ - __force_link_error__set_global_only_in_32bit(); \ + ASSERT32(); \ (var) = (val); \ } while (0) diff --git a/src/farptr.h b/src/farptr.h index a26cf08..4fc727b 100644 --- a/src/farptr.h +++ b/src/farptr.h @@ -157,6 +157,10 @@ static inline void outsl_fl(u16 port, void *ptr_fl, u16 count) { outsl(port, (u32*)FLATPTR_TO_OFFSET(ptr_fl), count); } +extern void __force_link_error__only_in_32bit() __attribute__ ((noreturn)); +#define ASSERT16() do { } while (0) +#define ASSERT32() __force_link_error__only_in_32bit() + #else // In 32-bit mode there is no need to mess with the segments. @@ -178,6 +182,10 @@ static inline void outsl_fl(u16 port, void *ptr_fl, u16 count) { #define outsw_fl(port, ptr_fl, count) outsw(port, ptr_fl, count) #define outsl_fl(port, ptr_fl, count) outsl(port, ptr_fl, count) +extern void __force_link_error__only_in_16bit() __attribute__ ((noreturn)); +#define ASSERT16() __force_link_error__only_in_16bit() +#define ASSERT32() do { } while (0) + #endif #endif // farptr.h diff --git a/src/smpdetect.c b/src/smpdetect.c index c54ec57..8d17e0e 100644 --- a/src/smpdetect.c +++ b/src/smpdetect.c @@ -64,6 +64,7 @@ ASM16( int smp_probe(void) { + ASSERT32(); if (smp_cpus) return smp_cpus; diff --git a/src/types.h b/src/types.h index aa9e12d..9f93e0b 100644 --- a/src/types.h +++ b/src/types.h @@ -50,6 +50,7 @@ union u64_u32_u { # define VAR16FIXED(addr) __aligned(1) __VISIBLE __section(".fixedaddr." __stringify(addr)) // Designate top-level assembler as 16bit only. # define ASM16(code) __ASM(code) +// Designate top-level assembler as 32bit only. # define ASM32(code) #else # define VISIBLE16 diff --git a/src/util.c b/src/util.c index a44b35d..1faca26 100644 --- a/src/util.c +++ b/src/util.c @@ -30,10 +30,7 @@ call16(struct bregs *callregs) inline void call16big(struct bregs *callregs) { - extern void __force_link_error__call16big_only_in_32bit_mode(); - if (MODE16) - __force_link_error__call16big_only_in_32bit_mode(); - + ASSERT32(); asm volatile( "calll __call16big_from32" : "+a" (callregs), "+m" (*callregs) @@ -56,10 +53,7 @@ __call16_int(struct bregs *callregs, u16 offset) inline u32 stack_hop(u32 eax, u32 edx, u32 ecx, void *func) { - extern void __force_link_error__stack_hop_only_in_16bit_mode(); - if (!MODE16) - __force_link_error__stack_hop_only_in_16bit_mode(); - + ASSERT16(); u16 ebda_seg = get_ebda_seg(), bkup_ss; u32 bkup_esp; asm volatile( diff --git a/src/util.h b/src/util.h index 23750cd..9790798 100644 --- a/src/util.h +++ b/src/util.h @@ -66,10 +66,7 @@ static inline u64 rdtscll(void) } #define call16_simpint(nr, peax, pflags) do { \ - extern void __force_link_error__call16_simpint_only_in_16bit_mode(); \ - if (!MODE16) \ - __force_link_error__call16_simpint_only_in_16bit_mode(); \ - \ + ASSERT16(); \ asm volatile( \ "stc\n" \ "int %2\n" \ -- 2.25.1