diff options
author | jake <jake@FreeBSD.org> | 2002-01-01 21:58:32 +0000 |
---|---|---|
committer | jake <jake@FreeBSD.org> | 2002-01-01 21:58:32 +0000 |
commit | bf1d0034f89ebcd1a59f23f89e05129d1433363c (patch) | |
tree | 29e5e5e7d08437ad1c106d7e2870d6377e7e4aff /lib/libc/sparc64 | |
parent | 92bcc2bcb13b0bb05a3dbf0d19358b2d4be32c35 (diff) | |
download | FreeBSD-src-bf1d0034f89ebcd1a59f23f89e05129d1433363c.zip FreeBSD-src-bf1d0034f89ebcd1a59f23f89e05129d1433363c.tar.gz |
Add libc side of user trap handling.
Add support for handling floating point disabled traps mostly in userland
for the simple single threaded case. Not yet enabled by default.
Implement __sparc_utrap_install as specified by the sparc abi.
Diffstat (limited to 'lib/libc/sparc64')
-rw-r--r-- | lib/libc/sparc64/sys/__sparc_utrap.c | 96 | ||||
-rw-r--r-- | lib/libc/sparc64/sys/__sparc_utrap_fp_disabled.S | 39 | ||||
-rw-r--r-- | lib/libc/sparc64/sys/__sparc_utrap_gen.S | 95 | ||||
-rw-r--r-- | lib/libc/sparc64/sys/__sparc_utrap_install.c | 49 | ||||
-rw-r--r-- | lib/libc/sparc64/sys/__sparc_utrap_private.h | 53 | ||||
-rw-r--r-- | lib/libc/sparc64/sys/__sparc_utrap_setup.c | 59 | ||||
-rw-r--r-- | lib/libc/sparc64/sys/assym.s | 32 |
7 files changed, 423 insertions, 0 deletions
diff --git a/lib/libc/sparc64/sys/__sparc_utrap.c b/lib/libc/sparc64/sys/__sparc_utrap.c new file mode 100644 index 0000000..d59436f --- /dev/null +++ b/lib/libc/sparc64/sys/__sparc_utrap.c @@ -0,0 +1,96 @@ +/*- + * Copyright (c) 2001 Jake Burkholder. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> + +#include <machine/utrap.h> +#include <machine/sysarch.h> + +#include <stdio.h> +#include <stdlib.h> + +#include "__sparc_utrap_private.h" + +static const char *utrap_msg[] = { + "reserved", + "instruction access exception", + "instruction access error", + "instruction access protection", + "illtrap instruction", + "illegal instruction", + "privileged opcode", + "floating point disabled", + "floating point exception ieee 754", + "floating point exception other", + "tag overflow", + "division by zero", + "data access exception", + "data access error", + "data access protection", + "memory address not aligned", + "privileged action", + "async data error", + "trap instruction 16", + "trap instruction 17", + "trap instruction 18", + "trap instruction 19", + "trap instruction 20", + "trap instruction 21", + "trap instruction 22", + "trap instruction 23", + "trap instruction 24", + "trap instruction 25", + "trap instruction 26", + "trap instruction 27", + "trap instruction 28", + "trap instruction 29", + "trap instruction 30", + "trap instruction 31", +}; + +void +__sparc_utrap(struct utrapframe *uf) +{ + + switch (uf->uf_type) { + case UT_FP_EXCEPTION_IEEE_754: + case UT_FP_EXCEPTION_OTHER: + case UT_ILLEGAL_INSTRUCTION: + case UT_MEM_ADDRESS_NOT_ALIGNED: + break; + case UT_TRAP_INSTRUCTION_16: + UF_DONE(uf); + return; + default: + break; + } + printf("__sparc_utrap: type=%s pc=%#lx npc=%#lx\n", + utrap_msg[uf->uf_type], uf->uf_pc, uf->uf_npc); + abort(); +} diff --git a/lib/libc/sparc64/sys/__sparc_utrap_fp_disabled.S b/lib/libc/sparc64/sys/__sparc_utrap_fp_disabled.S new file mode 100644 index 0000000..e6055b1 --- /dev/null +++ b/lib/libc/sparc64/sys/__sparc_utrap_fp_disabled.S @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2001 Jake Burkholder. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(SYSLIBC_RCS) && !defined(lint) + .text + .asciz "$FreeBSD$" +#endif /* SYSLIBC_RCS and not lint */ + +#include <machine/asm.h> +#include <machine/utrap.h> + +ENTRY(__sparc_utrap_fp_disabled) + ta %xcc, ST_FP_RESTORE + jmpl %l6, %g0 + return %l7 +END(__sparc_utrap_fp_disabled) diff --git a/lib/libc/sparc64/sys/__sparc_utrap_gen.S b/lib/libc/sparc64/sys/__sparc_utrap_gen.S new file mode 100644 index 0000000..592db56 --- /dev/null +++ b/lib/libc/sparc64/sys/__sparc_utrap_gen.S @@ -0,0 +1,95 @@ +/*- + * Copyright (c) 2001 Jake Burkholder. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(SYSLIBC_RCS) && !defined(lint) + .text + .asciz "$FreeBSD$" +#endif /* SYSLIBC_RCS and not lint */ + + .register %g2, #ignore + .register %g3, #ignore + .register %g6, #ignore + .register %g7, #ignore + +#include <machine/asm.h> +#include <machine/utrap.h> + +#include "assym.s" + +ENTRY(__sparc_utrap_gen) + sub %fp, CCFSZ + UF_SIZEOF, %sp + + stx %o0, [%sp + SPOFF + CCFSZ + UF_TYPE] + stx %o3, [%sp + SPOFF + CCFSZ + UF_TAR] + stx %o4, [%sp + SPOFF + CCFSZ + UF_SFAR] + stx %o5, [%sp + SPOFF + CCFSZ + UF_SFSR] + + stx %l6, [%sp + SPOFF + CCFSZ + UF_PC] + stx %l7, [%sp + SPOFF + CCFSZ + UF_NPC] + + stx %g1, [%sp + SPOFF + CCFSZ + UF_G1] + stx %g2, [%sp + SPOFF + CCFSZ + UF_G2] + stx %g3, [%sp + SPOFF + CCFSZ + UF_G3] + stx %g4, [%sp + SPOFF + CCFSZ + UF_G4] + stx %g5, [%sp + SPOFF + CCFSZ + UF_G5] + stx %g6, [%sp + SPOFF + CCFSZ + UF_G6] + stx %g7, [%sp + SPOFF + CCFSZ + UF_G7] + + stx %i0, [%sp + SPOFF + CCFSZ + UF_O0] + stx %i1, [%sp + SPOFF + CCFSZ + UF_O1] + stx %i2, [%sp + SPOFF + CCFSZ + UF_O2] + stx %i3, [%sp + SPOFF + CCFSZ + UF_O3] + stx %i4, [%sp + SPOFF + CCFSZ + UF_O4] + stx %i5, [%sp + SPOFF + CCFSZ + UF_O5] + stx %i6, [%sp + SPOFF + CCFSZ + UF_O6] + stx %i7, [%sp + SPOFF + CCFSZ + UF_O7] + + call __sparc_utrap + add %sp, SPOFF + CCFSZ, %o0 + + ldx [%sp + SPOFF + CCFSZ + UF_G1], %g1 + ldx [%sp + SPOFF + CCFSZ + UF_G2], %g2 + ldx [%sp + SPOFF + CCFSZ + UF_G3], %g3 + ldx [%sp + SPOFF + CCFSZ + UF_G4], %g4 + ldx [%sp + SPOFF + CCFSZ + UF_G5], %g5 + ldx [%sp + SPOFF + CCFSZ + UF_G6], %g6 + ldx [%sp + SPOFF + CCFSZ + UF_G7], %g7 + + ldx [%sp + SPOFF + CCFSZ + UF_O0], %i0 + ldx [%sp + SPOFF + CCFSZ + UF_O1], %i1 + ldx [%sp + SPOFF + CCFSZ + UF_O2], %i2 + ldx [%sp + SPOFF + CCFSZ + UF_O3], %i3 + ldx [%sp + SPOFF + CCFSZ + UF_O4], %i4 + ldx [%sp + SPOFF + CCFSZ + UF_O5], %i5 + ldx [%sp + SPOFF + CCFSZ + UF_O6], %i6 + ldx [%sp + SPOFF + CCFSZ + UF_O7], %i7 + + ldx [%sp + SPOFF + CCFSZ + UF_PC], %l6 + ldx [%sp + SPOFF + CCFSZ + UF_NPC], %l7 + + jmpl %l6, %g0 + return %l7 +END(__sparc_utrap_gen) diff --git a/lib/libc/sparc64/sys/__sparc_utrap_install.c b/lib/libc/sparc64/sys/__sparc_utrap_install.c new file mode 100644 index 0000000..9ed61c7 --- /dev/null +++ b/lib/libc/sparc64/sys/__sparc_utrap_install.c @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 2001 Jake Burkholder. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <machine/utrap.h> +#include <machine/sysarch.h> + +int +__sparc_utrap_install(utrap_entry_t type, utrap_handler_t new_precise, + utrap_handler_t new_deferred, utrap_handler_t *old_precise, + utrap_handler_t *old_deferred) +{ + struct sparc_utrap_install_args uia; + struct sparc_utrap_args ua[1]; + + ua[0].type = type; + ua[0].new_precise = new_precise; + ua[0].new_deferred = new_deferred; + ua[0].old_precise = old_precise; + ua[0].old_deferred = old_deferred; + uia.num = 1; + uia.handlers = ua; + return (sysarch(SPARC_UTRAP_INSTALL, (char *)&uia)); +} diff --git a/lib/libc/sparc64/sys/__sparc_utrap_private.h b/lib/libc/sparc64/sys/__sparc_utrap_private.h new file mode 100644 index 0000000..5946134 --- /dev/null +++ b/lib/libc/sparc64/sys/__sparc_utrap_private.h @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2001 Jake Burkholder. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef ___SPARC_UTRAP_PRIVATE_H_ +#define ___SPARC_UTRAP_PRIVATE_H_ + +#define UF_DONE(uf) do { \ + uf->uf_pc = uf->uf_npc; \ + uf->uf_npc = uf->uf_pc + 4; \ +} while (0) + +struct utrapframe { + u_long uf_global[8]; + u_long uf_out[8]; + u_long uf_pc; + u_long uf_npc; + u_long uf_sfar; + u_long uf_sfsr; + u_long uf_tar; + u_long uf_type; +}; + +extern char __sparc_utrap_fp_disabled[]; +extern char __sparc_utrap_gen[]; + +void __sparc_utrap(struct utrapframe *); + +#endif diff --git a/lib/libc/sparc64/sys/__sparc_utrap_setup.c b/lib/libc/sparc64/sys/__sparc_utrap_setup.c new file mode 100644 index 0000000..5993468 --- /dev/null +++ b/lib/libc/sparc64/sys/__sparc_utrap_setup.c @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2001 Jake Burkholder. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> + +#include <machine/utrap.h> +#include <machine/sysarch.h> + +#include <stdlib.h> + +#include "__sparc_utrap_private.h" + +static const struct sparc_utrap_args ua[] = { + { UT_FP_DISABLED, __sparc_utrap_fp_disabled, NULL, NULL, NULL }, +#if 0 + { UT_FP_EXCEPTION_IEEE_754, __sparc_utrap_gen, NULL, NULL, NULL }, + { UT_FP_EXCEPTION_OTHER, __sparc_utrap_gen, NULL, NULL, NULL }, + { UT_ILLEGAL_INSTRUCTION, __sparc_utrap_gen, NULL, NULL, NULL }, + { UT_MEM_ADDRESS_NOT_ALIGNED, __sparc_utrap_gen, NULL, NULL, NULL }, +#endif + { UT_TRAP_INSTRUCTION_16, __sparc_utrap_gen, NULL, NULL, NULL }, +}; + +static const struct sparc_utrap_install_args uia[] = { + sizeof (ua) / sizeof (*ua), ua +}; + +void +__sparc_utrap_setup(void) +{ + + sysarch(SPARC_UTRAP_INSTALL, &uia); +} diff --git a/lib/libc/sparc64/sys/assym.s b/lib/libc/sparc64/sys/assym.s new file mode 100644 index 0000000..58d1f65 --- /dev/null +++ b/lib/libc/sparc64/sys/assym.s @@ -0,0 +1,32 @@ +/* + * Offsets into structures used from asm. Must be kept in sync with + * appropriate headers. + * + * $FreeBSD$ + */ + +#define FPRS_FEF 0x4 + +#define UF_G0 0x0 +#define UF_G1 0x8 +#define UF_G2 0x10 +#define UF_G3 0x18 +#define UF_G4 0x20 +#define UF_G5 0x28 +#define UF_G6 0x30 +#define UF_G7 0x38 +#define UF_O0 0x40 +#define UF_O1 0x48 +#define UF_O2 0x50 +#define UF_O3 0x58 +#define UF_O4 0x60 +#define UF_O5 0x68 +#define UF_O6 0x70 +#define UF_O7 0x78 +#define UF_PC 0x90 +#define UF_NPC 0x98 +#define UF_SFAR 0xa0 +#define UF_SFSR 0xa8 +#define UF_TAR 0xb0 +#define UF_TYPE 0xb8 +#define UF_SIZEOF 0xc0 |