/*-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 p[4];3738do_cpuid(1, p);39cpu_feature = p[3];40cpu_feature2 = p[2];41do_cpuid(0, p);42if (p[0] >= 7) {43cpuid_count(7, 0, p);44cpu_stdext_feature = p[1];45cpu_stdext_feature2 = p[2];46} else {47cpu_stdext_feature = 0;48cpu_stdext_feature2 = 0;49}50}5152static void53crt1_handle_rela(const Elf_Rela *r)54{55Elf_Addr *ptr, *where, target;5657switch (ELF_R_TYPE(r->r_info)) {58case R_X86_64_IRELATIVE:59ptr = (Elf_Addr *)r->r_addend;60where = (Elf_Addr *)r->r_offset;61target = ((Elf_Addr (*)(uint32_t, uint32_t, uint32_t,62uint32_t))ptr)(cpu_feature, cpu_feature2,63cpu_stdext_feature, cpu_stdext_feature2);64*where = target;65break;66}67}686970