2 * SPDX-License-Identifier: BSD-2-Clause-NetBSD
4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * Copyright (c) 2013 Andrew Turner
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Matt Thomas of 3am Software Foundry.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
32 * Bases on NetBSD lib/libc/arch/arm/misc/arm_initfini.c
33 * $NetBSD: arm_initfini.c,v 1.2 2013/01/31 06:47:55 matt Exp $
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
40 * To properly implement setjmp/longjmp for the ARM AAPCS ABI, it has to be
41 * aware of whether there is a FPU is present or not. Regardless of whether
42 * the hard-float ABI is being used, setjmp needs to save D8-D15. But it can
43 * only do this if those instructions won't cause an exception.
46 #include <sys/param.h>
47 #include <sys/sysctl.h>
52 extern int __sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
53 void *newp, size_t newlen);
55 int _libc_arm_fpu_present;
56 static bool _libc_aapcs_initialized;
58 void _libc_aapcs_init(void) __attribute__((__constructor__, __used__));
61 _libc_aapcs_init(void)
66 if (_libc_aapcs_initialized)
70 mib[1] = HW_FLOATINGPT;
72 len = sizeof(_libc_arm_fpu_present);
73 if (__sysctl(mib, 2, &_libc_arm_fpu_present, &len, NULL, 0) == -1 ||
74 len != sizeof(_libc_arm_fpu_present)) {
75 /* sysctl failed, assume no vfp */
76 _libc_arm_fpu_present = 0;
79 _libc_aapcs_initialized = true;