From 852722fdfd87c8446079714509a1988d75287f2c Mon Sep 17 00:00:00 2001 From: kib Date: Thu, 10 May 2018 15:01:43 +0000 Subject: [PATCH] Make fpusave() and fpurestore() on amd64 ifuncs. From now on, linking amd64 kernel requires either lld or newer ld.bfd. Reviewed by: jhb (as part of the large patch) Discussed with: emaste Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D13838 --- sys/amd64/amd64/fpu.c | 62 ++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index c3b254ef5ab9..5abd82f665df 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include /* * Floating point support. @@ -151,24 +152,58 @@ struct xsave_area_elm_descr { u_int size; } *xsave_area_desc; -void -fpusave(void *addr) +static void +fpusave_xsave(void *addr) { - if (use_xsave) - xsave((char *)addr, xsave_mask); - else - fxsave((char *)addr); + xsave((char *)addr, xsave_mask); } -void -fpurestore(void *addr) +static void +fpurestore_xrstor(void *addr) +{ + + xrstor((char *)addr, xsave_mask); +} + +static void +fpusave_fxsave(void *addr) +{ + + fxsave((char *)addr); +} + +static void +fpurestore_fxrstor(void *addr) +{ + + fxrstor((char *)addr); +} + +static void +init_xsave(void) { if (use_xsave) - xrstor((char *)addr, xsave_mask); - else - fxrstor((char *)addr); + return; + if ((cpu_feature2 & CPUID2_XSAVE) == 0) + return; + use_xsave = 1; + TUNABLE_INT_FETCH("hw.use_xsave", &use_xsave); +} + +DEFINE_IFUNC(, void, fpusave, (void *), static) +{ + + init_xsave(); + return (use_xsave ? fpusave_xsave : fpusave_fxsave); +} + +DEFINE_IFUNC(, void, fpurestore, (void *), static) +{ + + init_xsave(); + return (use_xsave ? fpurestore_xrstor : fpurestore_fxrstor); } void @@ -207,13 +242,8 @@ fpuinit_bsp1(void) uint64_t xsave_mask_user; bool old_wp; - if ((cpu_feature2 & CPUID2_XSAVE) != 0) { - use_xsave = 1; - TUNABLE_INT_FETCH("hw.use_xsave", &use_xsave); - } if (!use_xsave) return; - cpuid_count(0xd, 0x0, cp); xsave_mask = XFEATURE_ENABLED_X87 | XFEATURE_ENABLED_SSE; if ((cp[0] & xsave_mask) != xsave_mask)