2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2001 Jake Burkholder.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/types.h>
34 #include <machine/utrap.h>
35 #include <machine/sysarch.h>
44 #include "fpu_extern.h"
45 #include "__sparc_utrap_private.h"
47 extern ssize_t __sys_write(int, const void *, size_t);
48 extern int __sys_kill(pid_t, int);
49 extern pid_t __sys_getpid(void);
51 static const char *utrap_msg[] = {
53 "instruction access exception",
54 "instruction access error",
55 "instruction access protection",
56 "illtrap instruction",
57 "illegal instruction",
59 "floating point disabled",
60 "floating point exception ieee 754",
61 "floating point exception other",
64 "data access exception",
66 "data access protection",
67 "memory address not aligned",
70 "trap instruction 16",
71 "trap instruction 17",
72 "trap instruction 18",
73 "trap instruction 19",
74 "trap instruction 20",
75 "trap instruction 21",
76 "trap instruction 22",
77 "trap instruction 23",
78 "trap instruction 24",
79 "trap instruction 25",
80 "trap instruction 26",
81 "trap instruction 27",
82 "trap instruction 28",
83 "trap instruction 29",
84 "trap instruction 30",
85 "trap instruction 31",
89 __sparc_utrap(struct utrapframe *uf)
93 switch (uf->uf_type) {
94 case UT_FP_EXCEPTION_IEEE_754:
95 case UT_FP_EXCEPTION_OTHER:
96 sig = __fpu_exception(uf);
98 case UT_ILLEGAL_INSTRUCTION:
99 sig = __emul_insn(uf);
101 case UT_MEM_ADDRESS_NOT_ALIGNED:
102 sig = __unaligned_fixup(uf);
108 __utrap_write("__sparc_utrap: fatal ");
109 __utrap_write(utrap_msg[uf->uf_type]);
111 __utrap_kill_self(sig);
117 __utrap_write(const char *str)
122 __sys_write(STDERR_FILENO, str, strlen(str));
127 __utrap_kill_self(int sig)
132 __sys_kill(__sys_getpid(), sig);
137 __utrap_panic(const char *msg)
142 __utrap_kill_self(SIGKILL);