/*-1* Copyright (c) 2018 The FreeBSD Foundation2*3* This software was developed by Konstantin Belousov <[email protected]>4* under sponsorship from the FreeBSD Foundation.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND13* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE14* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE15* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE16* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL17* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS18* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)19* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT20* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY21* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF22* SUCH DAMAGE.23*/2425#include <sys/cdefs.h>2627#include <machine/specialreg.h>28#include <machine/cpufunc.h>2930static uint32_t cpu_feature, cpu_feature2;31static uint32_t cpu_stdext_feature, cpu_stdext_feature2;3233static void34ifunc_init(const Elf_Auxinfo *aux __unused)35{36u_int cpuid_supported, p[4];3738__asm __volatile(39" pushfl\n"40" popl %%eax\n"41" movl %%eax,%%ecx\n"42" xorl $0x200000,%%eax\n"43" pushl %%eax\n"44" popfl\n"45" pushfl\n"46" popl %%eax\n"47" xorl %%eax,%%ecx\n"48" je 1f\n"49" movl $1,%0\n"50" jmp 2f\n"51"1: movl $0,%0\n"52"2:\n"53: "=r" (cpuid_supported) : : "eax", "ecx", "cc");54if (cpuid_supported) {55do_cpuid(1, p);56cpu_feature = p[3];57cpu_feature2 = p[2];58do_cpuid(0, p);59if (p[0] >= 7) {60cpuid_count(7, 0, p);61cpu_stdext_feature = p[1];62cpu_stdext_feature2 = p[2];63} else {64cpu_stdext_feature = 0;65cpu_stdext_feature2 = 0;66}67} else {68cpu_feature = 0;69cpu_feature2 = 0;70cpu_stdext_feature = 0;71cpu_stdext_feature2 = 0;72}73}7475static void76crt1_handle_rel(const Elf_Rel *r)77{78Elf_Addr *where, target;7980switch (ELF_R_TYPE(r->r_info)) {81case R_386_IRELATIVE:82where = (Elf_Addr *)r->r_offset;83target = ((Elf_Addr (*)(uint32_t, uint32_t, uint32_t,84uint32_t))*where)(cpu_feature, cpu_feature2,85cpu_stdext_feature, cpu_stdext_feature2);86*where = target;87break;88}89}909192