xref: /minix3/lib/libc/arch/arm/misc/arm_initfini.c (revision 4f89addcc198bff2fc614da2f8f4a7beb4b6cb7d)
184d9c625SLionel Sambuc /*-
284d9c625SLionel Sambuc  * Copyright (c) 2013 The NetBSD Foundation, Inc.
384d9c625SLionel Sambuc  * All rights reserved.
484d9c625SLionel Sambuc  *
584d9c625SLionel Sambuc  * This code is derived from software contributed to The NetBSD Foundation
684d9c625SLionel Sambuc  * by Matt Thomas of 3am Software Foundry.
784d9c625SLionel Sambuc  *
884d9c625SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
984d9c625SLionel Sambuc  * modification, are permitted provided that the following conditions
1084d9c625SLionel Sambuc  * are met:
1184d9c625SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
1284d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
1384d9c625SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
1484d9c625SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
1584d9c625SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
1684d9c625SLionel Sambuc  *
1784d9c625SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1884d9c625SLionel Sambuc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1984d9c625SLionel Sambuc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2084d9c625SLionel Sambuc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2184d9c625SLionel Sambuc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2284d9c625SLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2384d9c625SLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2484d9c625SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2584d9c625SLionel Sambuc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2684d9c625SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2784d9c625SLionel Sambuc  * POSSIBILITY OF SUCH DAMAGE.
2884d9c625SLionel Sambuc  */
2984d9c625SLionel Sambuc 
3084d9c625SLionel Sambuc #include <sys/cdefs.h>
3184d9c625SLionel Sambuc 
3284d9c625SLionel Sambuc __RCSID("$NetBSD: arm_initfini.c,v 1.7 2013/09/08 13:15:53 matt Exp $");
3384d9c625SLionel Sambuc 
3484d9c625SLionel Sambuc #include "namespace.h"
3584d9c625SLionel Sambuc 
3684d9c625SLionel Sambuc /*
3784d9c625SLionel Sambuc  * To properly implement setjmp/longjmp for the ARM AAPCS ABI, it has to be
3884d9c625SLionel Sambuc  * aware of whether there is a FPU is present or not.  Regardless of whether
3984d9c625SLionel Sambuc  * the hard-float ABI is being used, setjmp needs to save D8-D15.  But it can
4084d9c625SLionel Sambuc  * only do this if those instructions won't cause an exception.
4184d9c625SLionel Sambuc  */
4284d9c625SLionel Sambuc 
4384d9c625SLionel Sambuc #include <sys/param.h>
4484d9c625SLionel Sambuc #include <sys/sysctl.h>
4584d9c625SLionel Sambuc 
4684d9c625SLionel Sambuc #include <stdbool.h>
4784d9c625SLionel Sambuc #include <stddef.h>
4884d9c625SLionel Sambuc 
4984d9c625SLionel Sambuc __dso_hidden int _libc_arm_fpu_present;
5084d9c625SLionel Sambuc #ifndef __ARM_ARCH_EXT_IDIV__
5184d9c625SLionel Sambuc __dso_hidden int _libc_arm_hwdiv_present;
5284d9c625SLionel Sambuc #endif
5384d9c625SLionel Sambuc static bool _libc_aapcs_initialized;
5484d9c625SLionel Sambuc 
5584d9c625SLionel Sambuc void	_libc_aapcs_init(void) __attribute__((__constructor__, __used__));
5684d9c625SLionel Sambuc 
5784d9c625SLionel Sambuc void __section(".text.startup")
_libc_aapcs_init(void)5884d9c625SLionel Sambuc _libc_aapcs_init(void)
5984d9c625SLionel Sambuc {
6084d9c625SLionel Sambuc 	if (!_libc_aapcs_initialized) {
61*4f89addcSEmmanuel Blot #if !defined(__minix)
6284d9c625SLionel Sambuc 		size_t len = sizeof(_libc_arm_fpu_present);
63*4f89addcSEmmanuel Blot #endif
6484d9c625SLionel Sambuc 		_libc_aapcs_initialized = true;
6584d9c625SLionel Sambuc #if !defined(__minix)
6684d9c625SLionel Sambuc 		(void)sysctlbyname("machdep.fpu_present",
6784d9c625SLionel Sambuc 		    &_libc_arm_fpu_present, &len, NULL, 0);
6884d9c625SLionel Sambuc #ifndef __ARM_ARCH_EXT_IDIV__
6984d9c625SLionel Sambuc 		(void)sysctlbyname("machdep.hwdiv_present",
7084d9c625SLionel Sambuc 		    &_libc_arm_hwdiv_present, &len, NULL, 0);
7184d9c625SLionel Sambuc #endif
7284d9c625SLionel Sambuc #endif /* !defined(__minix) */
7384d9c625SLionel Sambuc 	}
7484d9c625SLionel Sambuc }
75