xref: /netbsd/common/lib/libc/arch/arm/gen/__aeabi_idiv0.c (revision 9f2c3621)
183d2be0dSmatt /*-
283d2be0dSmatt  * Copyright (c) 2012 The NetBSD Foundation, Inc.
383d2be0dSmatt  * All rights reserved.
483d2be0dSmatt  *
583d2be0dSmatt  * This code is derived from software contributed to The NetBSD Foundation
683d2be0dSmatt  * by Matt Thomas of 3am Software Foundry.
783d2be0dSmatt  *
883d2be0dSmatt  * Redistribution and use in source and binary forms, with or without
983d2be0dSmatt  * modification, are permitted provided that the following conditions
1083d2be0dSmatt  * are met:
1183d2be0dSmatt  * 1. Redistributions of source code must retain the above copyright
1283d2be0dSmatt  *    notice, this list of conditions and the following disclaimer.
1383d2be0dSmatt  * 2. Redistributions in binary form must reproduce the above copyright
1483d2be0dSmatt  *    notice, this list of conditions and the following disclaimer in the
1583d2be0dSmatt  *    documentation and/or other materials provided with the distribution.
1683d2be0dSmatt  *
1783d2be0dSmatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1883d2be0dSmatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1983d2be0dSmatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2083d2be0dSmatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2183d2be0dSmatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2283d2be0dSmatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2383d2be0dSmatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2483d2be0dSmatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2583d2be0dSmatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2683d2be0dSmatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2783d2be0dSmatt  * POSSIBILITY OF SUCH DAMAGE.
2883d2be0dSmatt  */
2983d2be0dSmatt 
3083d2be0dSmatt #include <sys/cdefs.h>
3183d2be0dSmatt 
32*9f2c3621Sjoerg __RCSID("$NetBSD: __aeabi_idiv0.c,v 1.3 2014/01/29 22:29:43 joerg Exp $");
3383d2be0dSmatt 
34*9f2c3621Sjoerg #if defined(_KERNEL) || defined(_STANDALONE)
35*9f2c3621Sjoerg #include <sys/systm.h>
36*9f2c3621Sjoerg #else
3783d2be0dSmatt #include <string.h>
3883d2be0dSmatt #include <unistd.h>
3983d2be0dSmatt #include <sys/types.h>
4083d2be0dSmatt #include <sys/signal.h>
4183d2be0dSmatt #include <sys/siginfo.h>
4283d2be0dSmatt #endif
4383d2be0dSmatt 
4483d2be0dSmatt #include <arm/aeabi.h>
4583d2be0dSmatt 
4683d2be0dSmatt int
__aeabi_idiv0(int result)4783d2be0dSmatt __aeabi_idiv0(int result)
4883d2be0dSmatt {
49*9f2c3621Sjoerg #if defined(_KERNEL) || defined(_STANDALONE)
50*9f2c3621Sjoerg 	panic("divide by 0");
51*9f2c3621Sjoerg #else
5283d2be0dSmatt 	siginfo_t info;
5383d2be0dSmatt 
5483d2be0dSmatt 	memset(&info, 0, sizeof info);
5583d2be0dSmatt 	info.si_signo = SIGFPE;
5683d2be0dSmatt 	info.si_pid = getpid();
5783d2be0dSmatt 	info.si_uid = geteuid();
5883d2be0dSmatt 	info.si_code = FPE_INTDIV;
5983d2be0dSmatt 	sigqueueinfo(getpid(), &info);
6083d2be0dSmatt #endif
6183d2be0dSmatt 	return result;
6283d2be0dSmatt }
63