diff options
49 files changed, 3275 insertions, 0 deletions
diff --git a/lib/csu/sh/Makefile b/lib/csu/sh/Makefile new file mode 100644 index 00000000000..f3043e142f8 --- /dev/null +++ b/lib/csu/sh/Makefile @@ -0,0 +1,63 @@ +# $OpenBSD: Makefile,v 1.1 2006/10/10 22:07:10 miod Exp $ +# from: @(#)Makefile 8.1 (Berkeley) 6/1/93 + +CFLAGS+= -DLIBC_SCCS +OBJS= crt0.o gcrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o +SRCS= crt0.c crtbegin.c crtbeginS.c crtend.c crtendS.c + +ELFDIR= ${.CURDIR}/../common_elf +.PATH: ${ELFDIR} +CFLAGS+= -I${ELFDIR} -I${.CURDIR} + +#PICFLAG?=-fpic +PICFLAG= + +all: ${OBJS} + +crt0.o: crt0.c + @echo ${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET} + @${COMPILE.c} -DCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o + @${LD} -x -r -o ${.TARGET} ${.TARGET}.o + @rm -f ${.TARGET}.o + +gcrt0.o: crt0.c + @echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET} + @${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o + @${LD} -x -r -o ${.TARGET} ${.TARGET}.o + @rm -f ${.TARGET}.o + +crtbegin.o: crtbegin.c + @echo ${COMPILE.c} ${ELFDIR}/crtbegin.c -o ${.TARGET} + @${COMPILE.c} ${ELFDIR}/crtbegin.c -o ${.TARGET}.o + @${LD} -x -r -o ${.TARGET} ${.TARGET}.o + @rm -f ${.TARGET}.o + +crtbeginS.o: crtbeginS.c + @echo ${COMPILE.c} ${PICFLAG} -DPIC ${ELFDIR}/crtbeginS.c -o ${.TARGET} + @${COMPILE.c} ${PICFLAG} -DPIC ${ELFDIR}/crtbeginS.c -o ${.TARGET}.o + @${LD} -x -r -o ${.TARGET} ${.TARGET}.o + @rm -f ${.TARGET}.o + +crtend.o: crtend.c + @echo ${COMPILE.c} ${ELFDIR}/crtend.c -o ${.TARGET} + @${COMPILE.c} ${ELFDIR}/crtend.c -o ${.TARGET}.o + @${LD} -x -r -o ${.TARGET} ${.TARGET}.o + @rm -f ${.TARGET}.o + +crtendS.o: crtendS.c + @echo ${COMPILE.c} ${PICFLAG} -DPIC ${ELFDIR}/crtendS.c -o ${.TARGET} + @${COMPILE.c} ${PICFLAG} -DPIC ${ELFDIR}/crtendS.c -o ${.TARGET}.o + @${LD} -x -r -o ${.TARGET} ${.TARGET}.o + @rm -f ${.TARGET}.o + +realinstall: + ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \ + ${DESTDIR}/usr/lib + +afterdepend:: .depend + @(TMP=/tmp/_depend$$$$; \ + sed -e 's/^\([^\.]*\).o[ ]*:/\1.o g\1.o:/' \ + < .depend > $$TMP; \ + mv $$TMP .depend) + +.include <bsd.prog.mk> diff --git a/lib/csu/sh/crt0.c b/lib/csu/sh/crt0.c new file mode 100644 index 00000000000..af87c4d7bf0 --- /dev/null +++ b/lib/csu/sh/crt0.c @@ -0,0 +1,122 @@ +/* $OpenBSD: crt0.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: crt0.c,v 1.10 2004/08/26 21:16:41 thorpej Exp $ */ + +/* + * Copyright (c) 1998 Christos Zoulas + * Copyright (c) 1995 Christopher G. Demetriou + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the + * NetBSD Project. See http://www.NetBSD.org/ for + * information about NetBSD. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. + * + * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> + */ + +#include <sys/cdefs.h> +#include <sys/param.h> + +#include <machine/asm.h> +#include <stdlib.h> + +static char *_strrchr(const char *, char); + +char **environ; + +char * __progname = ""; + +char __progname_storage[NAME_MAX+1]; + +#ifdef MCRT0 +extern void monstartup(u_long, u_long); +extern void _mcleanup(void); +extern unsigned char _etext, _eprol; +#endif /* MCRT0 */ + +extern void _start(void); +void ___start(int, char *[], char *[], void *, + const void *, void (*)(void)); + +__asm( " .text \n" + " .align 2 \n" + " .globl _start \n" + " .globl __start \n" + "_start: \n" + "__start: \n" + " mov.l r9,@-r15 \n" + " bra ___start \n" + " mov.l r8,@-r15"); + +void +___start(int argc, char **argv, char **envp, void *ps_strings, + const void *obj, void (*cleanup)(void)) +{ + char *s; + + environ = envp; + + if ((__progname = argv[0]) != NULL) { /* NULL ptr if argc = 0 */ + if ((__progname = _strrchr(__progname, '/')) == NULL) + __progname = argv[0]; + else + __progname++; + for (s = __progname_storage; *__progname && + s < &__progname_storage[sizeof __progname_storage - 1]; ) + *s++ = *__progname++; + *s = '\0'; + __progname = __progname_storage; + } + +#if 0 + atexit(cleanup); +#endif +#ifdef MCRT0 + atexit(_mcleanup); + monstartup((u_long)&_eprol, (u_long)&_etext); +#endif /* MCRT0 */ + +#ifndef SCRT0 + __init(); +#endif + +__asm("__callmain:"); /* Defined for the benefit of debuggers */ + exit(main(argc, argv, envp)); +} + +static char * +_strrchr(const char *p, char ch) +{ + char *save; + + for (save = NULL;; ++p) { + if (*p == ch) + save = (char *)p; + if (!*p) + return(save); + } + /* NOTREACHED */ +} +asm (" .section \".text\" \n_eprol:"); diff --git a/lib/csu/sh/md_init.h b/lib/csu/sh/md_init.h new file mode 100644 index 00000000000..96da9375c13 --- /dev/null +++ b/lib/csu/sh/md_init.h @@ -0,0 +1,68 @@ +/* $OpenBSD: md_init.h,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: dot_init.h,v 1.3 2005/12/24 22:02:10 perry Exp $ */ + +/*- + * Copyright (c) 2001 Ross Harvey + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#define MD_SECTION_PROLOGUE(sect, entry_pt) \ + __asm ( \ + ".section "#sect",\"ax\",@progbits \n" \ + " .globl " #entry_pt " \n" \ + " .type " #entry_pt ",@function \n" \ + #entry_pt": \n" \ + " sts.l pr, @-r15 \n" \ + " .align 2 \n" \ + " /* fall thru */ \n" \ + ".previous") + +#define MD_SECTION_EPILOGUE(sect) \ + __asm ( \ + ".section "#sect",\"ax\",@progbits \n" \ + " lds.l @r15+, pr \n" \ + " rts \n" \ + " nop \n" \ + ".previous") + +/* + * We need to put the function pointer in our own constant + * pool (otherwise it might be too far away to reference). + */ +#define MD_SECT_CALL_FUNC(section, func) \ +__asm(".section " #section "\n" \ +" mov.l 1f, r1 \n" \ +" mova 2f, r0 \n" \ +" braf r1 \n" \ +" lds r0, pr \n" \ +"0: .p2align 2 \n" \ +"1: .long " #func " - 0b \n" \ +"2: .previous"); diff --git a/lib/libc/arch/sh/Makefile.inc b/lib/libc/arch/sh/Makefile.inc new file mode 100644 index 00000000000..48a20dc9573 --- /dev/null +++ b/lib/libc/arch/sh/Makefile.inc @@ -0,0 +1 @@ +# $OpenBSD: Makefile.inc,v 1.1 2006/10/10 22:07:10 miod Exp $ diff --git a/lib/libc/arch/sh/SYS.h b/lib/libc/arch/sh/SYS.h new file mode 100644 index 00000000000..823f6c2769b --- /dev/null +++ b/lib/libc/arch/sh/SYS.h @@ -0,0 +1,132 @@ +/* $OpenBSD: SYS.h,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 + * $NetBSD: SYS.h,v 1.9 2006/01/06 06:19:20 uwe Exp $ + */ + +#include <machine/asm.h> +#include <sys/syscall.h> + +#ifdef __STDC__ +#define SYSENTRY(x) \ + .weak _C_LABEL(x); \ + _C_LABEL(x) = _C_LABEL(_thread_sys_ ## x); \ + ENTRY(_thread_sys_ ## x) +#else +#define SYSENTRY(x) \ + .weak _C_LABEL(x); \ + _C_LABEL(x) = _C_LABEL(_thread_sys_/**/x); \ + ENTRY(_thread_sys_/**/x) +#endif + +#ifdef __STDC__ +#define SYSTRAP(x) \ + mov.l 903f, r0; \ + .word 0xc380; /* trapa #0x80; */ \ + bra 904f; \ + nop; \ + .align 2; \ + 903: .long (SYS_ ## x); \ + 904: +#else +#define SYSTRAP(x) \ + mov.l 903f, r0; \ + trapa #0x80; \ + bra 904f; \ + nop; \ + .align 2; \ + 903: .long (SYS_/**/x); \ + 904: +#endif + +#define CERROR _C_LABEL(__cerror) + +#define _SYSCALL_NOERROR(x,y) \ + SYSENTRY(x); \ + SYSTRAP(y) + +#ifdef PIC + +#define JUMP_CERROR \ + mov r0, r4; \ + mov.l 912f, r1; \ + mova 912f, r0; \ + mov.l 913f, r2; \ + add r1, r0; \ + mov.l @(r0, r2), r3; \ + jmp @r3; \ + nop; \ + .align 2; \ + 912: .long _GLOBAL_OFFSET_TABLE_; \ + 913: .long PIC_GOT(CERROR) + +#else /* !PIC */ + +#define JUMP_CERROR \ + mov.l 912f, r3; \ + jmp @r3; \ + mov r0, r4; \ + .align 2; \ + 912: .long CERROR + +#endif /* !PIC */ + +#define _SYSCALL(x,y) \ + .text; \ + 911: JUMP_CERROR; \ + _SYSCALL_NOERROR(x,y); \ + bf 911b + +#define SYSCALL_NOERROR(x) \ + _SYSCALL_NOERROR(x,x) + +#define SYSCALL(x) \ + _SYSCALL(x,x) + +#define PSEUDO_NOERROR(x,y) \ + _SYSCALL_NOERROR(x,y); \ + rts; \ + nop + +#define PSEUDO(x,y) \ + _SYSCALL(x,y); \ + rts; \ + nop + +#define RSYSCALL_NOERROR(x) \ + PSEUDO_NOERROR(x,x) + +#define RSYSCALL(x) \ + PSEUDO(x,x) + + .globl CERROR diff --git a/lib/libc/arch/sh/gen/Makefile.inc b/lib/libc/arch/sh/gen/Makefile.inc new file mode 100644 index 00000000000..cdb96b73edf --- /dev/null +++ b/lib/libc/arch/sh/gen/Makefile.inc @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile.inc,v 1.1 2006/10/10 22:07:10 miod Exp $ + +SRCS+= fabs.c flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c \ + fpsetmask.c fpsetround.c fpsetsticky.c isinf.c isnan.c infinity.c \ + setjmp.S _setjmp.S sigsetjmp.S diff --git a/lib/libc/arch/sh/gen/_setjmp.S b/lib/libc/arch/sh/gen/_setjmp.S new file mode 100644 index 00000000000..09e4f3785d9 --- /dev/null +++ b/lib/libc/arch/sh/gen/_setjmp.S @@ -0,0 +1,86 @@ +/* $OpenBSD: _setjmp.S,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: _setjmp.S,v 1.7 2006/01/05 02:04:41 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)_setjmp.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> +#include <machine/setjmp.h> + +/* + * C library -- _setjmp, _longjmp + * + * _longjmp(a,v) + * will generate a "return(v)" from the last call to + * _setjmp(a) + * by restoring registers from the stack. + * The previous signal state is NOT restored. + */ + +ENTRY(_setjmp) + add #((_JB_HAS_MASK + 1) * 4), r4 + mov #0, r0 + mov.l r0, @-r4 /* no saved signal mask */ + mov.l r15, @-r4 + mov.l r14, @-r4 + mov.l r13, @-r4 + mov.l r12, @-r4 + mov.l r11, @-r4 + mov.l r10, @-r4 + mov.l r9, @-r4 + mov.l r8, @-r4 + sts.l pr, @-r4 + rts + xor r0, r0 + SET_ENTRY_SIZE(_setjmp) + +ENTRY(_longjmp) + lds.l @r4+, pr + mov.l @r4+, r8 + mov.l @r4+, r9 + mov.l @r4+, r10 + mov.l @r4+, r11 + mov.l @r4+, r12 + mov.l @r4+, r13 + mov.l @r4+, r14 + mov.l @r4+, r15 + + mov r5, r0 + tst r0, r0 + bf .L0 + add #1, r0 +.L0: + rts + nop + SET_ENTRY_SIZE(_longjmp) diff --git a/lib/libc/arch/sh/gen/fabs.c b/lib/libc/arch/sh/gen/fabs.c new file mode 100644 index 00000000000..d31572b61fe --- /dev/null +++ b/lib/libc/arch/sh/gen/fabs.c @@ -0,0 +1,26 @@ +/* $OpenBSD: fabs.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* + * Copyright (c) 2006 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <math.h> + +double +fabs(double x) +{ + __asm__ __volatile__("fabs %0" : "=f"(x)); + return (x); +} diff --git a/lib/libc/arch/sh/gen/flt_rounds.c b/lib/libc/arch/sh/gen/flt_rounds.c new file mode 100644 index 00000000000..dcee4aeb078 --- /dev/null +++ b/lib/libc/arch/sh/gen/flt_rounds.c @@ -0,0 +1,37 @@ +/* $OpenBSD: flt_rounds.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* + * Copyright (c) 2006 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <machine/float.h> +#include <machine/ieeefp.h> + +static const int rndmap[] = { + 1, /* round to nearest */ + 0, /* round to zero */ + 2, /* round to positive infinity */ + 3 /* round to negative infinity */ +}; + +int +__flt_rounds() +{ + register_t fpscr; + + __asm__ __volatile__ ("sts fpscr, %0" : "=r" (fpscr)); + return rndmap[fpscr & 0x03]; +} diff --git a/lib/libc/arch/sh/gen/fpgetmask.c b/lib/libc/arch/sh/gen/fpgetmask.c new file mode 100644 index 00000000000..b062a3aab1f --- /dev/null +++ b/lib/libc/arch/sh/gen/fpgetmask.c @@ -0,0 +1,29 @@ +/* $OpenBSD: fpgetmask.c,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* + * Copyright (c) 2006 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <ieeefp.h> + +fp_except +fpgetmask() +{ + register_t fpscr; + + __asm__ __volatile__ ("sts fpscr, %0" : "=r" (fpscr)); + return ((fpscr >> 7) & 0x1f); +} diff --git a/lib/libc/arch/sh/gen/fpgetround.c b/lib/libc/arch/sh/gen/fpgetround.c new file mode 100644 index 00000000000..d3bf8d55da5 --- /dev/null +++ b/lib/libc/arch/sh/gen/fpgetround.c @@ -0,0 +1,29 @@ +/* $OpenBSD: fpgetround.c,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* + * Copyright (c) 2006 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <ieeefp.h> + +fp_rnd +fpgetround() +{ + register_t fpscr; + + __asm__ __volatile__ ("sts fpscr, %0" : "=r" (fpscr)); + return (fpscr & 0x3); +} diff --git a/lib/libc/arch/sh/gen/fpgetsticky.c b/lib/libc/arch/sh/gen/fpgetsticky.c new file mode 100644 index 00000000000..a8e65136d2e --- /dev/null +++ b/lib/libc/arch/sh/gen/fpgetsticky.c @@ -0,0 +1,29 @@ +/* $OpenBSD: fpgetsticky.c,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* + * Copyright (c) 2006 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <ieeefp.h> + +fp_except +fpgetsticky() +{ + register_t fpscr; + + __asm__ __volatile__ ("sts fpscr, %0" : "=r" (fpscr)); + return ((fpscr >> 2) & 0x1f); +} diff --git a/lib/libc/arch/sh/gen/fpsetmask.c b/lib/libc/arch/sh/gen/fpsetmask.c new file mode 100644 index 00000000000..7e93cae3ef7 --- /dev/null +++ b/lib/libc/arch/sh/gen/fpsetmask.c @@ -0,0 +1,31 @@ +/* $OpenBSD: fpsetmask.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* + * Copyright (c) 2006 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <ieeefp.h> + +fp_except +fpsetmask(fp_except mask) +{ + register_t fpscr, nfpscr; + + __asm__ __volatile__ ("sts fpscr, %0" : "=r" (fpscr)); + nfpscr = (fpscr & ~(0x1f << 7)) | (mask << 7); + __asm__ __volatile__ ("lds %0, fpscr" : : "r" (nfpscr)); + return ((fpscr >> 7) & 0x1f); +} diff --git a/lib/libc/arch/sh/gen/fpsetround.c b/lib/libc/arch/sh/gen/fpsetround.c new file mode 100644 index 00000000000..dafac3f72be --- /dev/null +++ b/lib/libc/arch/sh/gen/fpsetround.c @@ -0,0 +1,35 @@ +/* $OpenBSD: fpsetround.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* + * Copyright (c) 2006 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <ieeefp.h> + +fp_rnd +fpsetround(fp_rnd rnd_dir) +{ + register_t fpscr, nfpscr; + + __asm__ __volatile__ ("sts fpscr, %0" : "=r" (fpscr)); + if (rnd_dir == FP_RN || rnd_dir == FP_RZ) { + nfpscr = (fpscr & ~0x03) | rnd_dir; + __asm__ __volatile__ ("lds %0, fpscr" : : "r" (nfpscr)); + } + /* else how report an error? */ + + return (fpscr & 0x03); +} diff --git a/lib/libc/arch/sh/gen/fpsetsticky.c b/lib/libc/arch/sh/gen/fpsetsticky.c new file mode 100644 index 00000000000..07c1f3be480 --- /dev/null +++ b/lib/libc/arch/sh/gen/fpsetsticky.c @@ -0,0 +1,31 @@ +/* $OpenBSD: fpsetsticky.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* + * Copyright (c) 2006 Miodrag Vallat. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice, this permission notice, and the disclaimer below + * appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <ieeefp.h> + +fp_except +fpsetsticky(fp_except mask) +{ + register_t fpscr, nfpscr; + + __asm__ __volatile__ ("sts fpscr, %0" : "=r" (fpscr)); + nfpscr = (fpscr & ~(0x1f << 2)) | (mask << 2); + __asm__ __volatile__ ("lds %0, fpscr" : : "r" (nfpscr)); + return ((fpscr >> 2) & 0x1f); +} diff --git a/lib/libc/arch/sh/gen/infinity.c b/lib/libc/arch/sh/gen/infinity.c new file mode 100644 index 00000000000..a8006550db2 --- /dev/null +++ b/lib/libc/arch/sh/gen/infinity.c @@ -0,0 +1,9 @@ +/* $OpenBSD: infinity.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ + +/* infinity.c */ + +#include <math.h> + +/* bytes for +Infinity on a SH4 FPU (double precision) */ +char __infinity[] __attribute__((__aligned__(sizeof(double)))) = + { 0x7f, (char)0xf0, 0, 0, 0, 0, 0, 0 }; diff --git a/lib/libc/arch/sh/gen/isinf.c b/lib/libc/arch/sh/gen/isinf.c new file mode 100644 index 00000000000..5d4ace22288 --- /dev/null +++ b/lib/libc/arch/sh/gen/isinf.c @@ -0,0 +1,47 @@ +/* $OpenBSD: isinf.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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/types.h> +#include <machine/ieee.h> + +int +isinf(d) + double d; +{ + struct ieee_double *p = (struct ieee_double *)&d; + + return (p->dbl_exp == DBL_EXP_INFNAN && + p->dbl_frach == 0 && p->dbl_fracl == 0); +} diff --git a/lib/libc/arch/sh/gen/isnan.c b/lib/libc/arch/sh/gen/isnan.c new file mode 100644 index 00000000000..9c1a98d1018 --- /dev/null +++ b/lib/libc/arch/sh/gen/isnan.c @@ -0,0 +1,47 @@ +/* $OpenBSD: isnan.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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/types.h> +#include <machine/ieee.h> + +int +isnan(d) + double d; +{ + struct ieee_double *p = (struct ieee_double *)&d; + + return (p->dbl_exp == DBL_EXP_INFNAN && + (p->dbl_frach != 0 || p->dbl_fracl != 0)); +} diff --git a/lib/libc/arch/sh/gen/ldexp.c b/lib/libc/arch/sh/gen/ldexp.c new file mode 100644 index 00000000000..6c3723ded7c --- /dev/null +++ b/lib/libc/arch/sh/gen/ldexp.c @@ -0,0 +1,140 @@ +/* $OpenBSD: ldexp.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: Header: ldexp.c,v 1.1 91/07/07 04:28:19 torek Exp + */ + +#include <sys/types.h> +#include <machine/ieee.h> +#include <errno.h> + +/* + * double ldexp(double val, int exp) + * returns: val * (2**exp) + */ +double +ldexp(val, exp) + double val; + int exp; +{ + register int oldexp, newexp, mulexp; + union doub { + double v; + struct ieee_double s; + } u, mul; + + /* + * If input is zero, or no change, just return input. + * Likewise, if input is Inf or NaN, just return it. + */ + u.v = val; + oldexp = u.s.dbl_exp; + if (val == 0 || exp == 0 || oldexp == DBL_EXP_INFNAN) + return (val); + + /* + * Compute new exponent and check for over/under flow. + * Underflow, unfortunately, could mean switching to denormal. + * If result out of range, set ERANGE and return 0 if too small + * or Inf if too big, with the same sign as the input value. + */ + newexp = oldexp + exp; + if (newexp >= DBL_EXP_INFNAN) { + /* u.s.dbl_sign = val < 0; -- already set */ + u.s.dbl_exp = DBL_EXP_INFNAN; + u.s.dbl_frach = u.s.dbl_fracl = 0; + errno = ERANGE; + return (u.v); /* Inf */ + } + if (newexp <= 0) { + /* + * The output number is either a denormal or underflows + * (see comments in machine/ieee.h). + */ + if (newexp <= -DBL_FRACBITS) { + /* u.s.dbl_sign = val < 0; -- already set */ + u.s.dbl_exp = 0; + u.s.dbl_frach = u.s.dbl_fracl = 0; + errno = ERANGE; + return (u.v); /* zero */ + } + /* + * We are going to produce a denorm. Our `exp' argument + * might be as small as -2097, and we cannot compute + * 2^-2097, so we may have to do this as many as three + * steps (not just two, as for positive `exp's below). + */ + mul.v = 0; + while (exp <= -DBL_EXP_BIAS) { + mul.s.dbl_exp = 1; + val *= mul.v; + exp += DBL_EXP_BIAS - 1; + } + mul.s.dbl_exp = exp + DBL_EXP_BIAS; + val *= mul.v; + return (val); + } + + /* + * Newexp is positive. + * + * If oldexp is zero, we are starting with a denorm, and simply + * adjusting the exponent will produce bogus answers. We need + * to fix that first. + */ + if (oldexp == 0) { + /* + * Multiply by 2^mulexp to make the number normalizable. + * We cannot multiply by more than 2^1023, but `exp' + * argument might be as large as 2046. A single + * adjustment, however, will normalize the number even + * for huge `exp's, and then we can use exponent + * arithmetic just as for normal `double's. + */ + mulexp = exp <= DBL_EXP_BIAS ? exp : DBL_EXP_BIAS; + mul.v = 0; + mul.s.dbl_exp = mulexp + DBL_EXP_BIAS; + val *= mul.v; + if (mulexp == exp) + return (val); + u.v = val; + newexp -= mulexp; + } + + /* + * Both oldexp and newexp are positive; just replace the + * old exponent with the new one. + */ + u.s.dbl_exp = newexp; + return (u.v); +} diff --git a/lib/libc/arch/sh/gen/modf.c b/lib/libc/arch/sh/gen/modf.c new file mode 100644 index 00000000000..da646541432 --- /dev/null +++ b/lib/libc/arch/sh/gen/modf.c @@ -0,0 +1,305 @@ +/* $OpenBSD: modf.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* @(#)s_modf.c 5.1 93/09/24 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * modf(double x, double *iptr) + * return fraction part of x, and return x's integral part in *iptr. + * Method: + * Bit twiddling. + * + * Exception: + * No exception. + */ + +#include "math.h" + +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * from: @(#)fdlibm.h 5.1 93/09/24 + */ + +#ifndef _MATH_PRIVATE_H_ +#define _MATH_PRIVATE_H_ + +#include <sys/types.h> +#include <machine/endian.h> + +/* The original fdlibm code used statements like: + n0 = ((*(int*)&one)>>29)^1; * index of high word * + ix0 = *(n0+(int*)&x); * high word of x * + ix1 = *((1-n0)+(int*)&x); * low word of x * + to dig two 32 bit words out of the 64 bit IEEE floating point + value. That is non-ANSI, and, moreover, the gcc instruction + scheduler gets it wrong. We instead use the following macros. + Unlike the original code, we determine the endianness at compile + time, not at run time; I don't see much benefit to selecting + endianness at run time. */ + +/* A union which permits us to convert between a double and two 32 bit + ints. */ + +/* + * The arm32 port is little endian except for the FP word order which is + * big endian. + */ + +#if (BYTE_ORDER == BIG_ENDIAN) || defined(arm32) + +typedef union +{ + double value; + struct + { + u_int32_t msw; + u_int32_t lsw; + } parts; +} ieee_double_shape_type; + +#endif + +#if (BYTE_ORDER == LITTLE_ENDIAN) && !defined(arm32) + +typedef union +{ + double value; + struct + { + u_int32_t lsw; + u_int32_t msw; + } parts; +} ieee_double_shape_type; + +#endif + +/* Get two 32 bit ints from a double. */ + +#define EXTRACT_WORDS(ix0,ix1,d) \ +do { \ + ieee_double_shape_type ew_u; \ + ew_u.value = (d); \ + (ix0) = ew_u.parts.msw; \ + (ix1) = ew_u.parts.lsw; \ +} while (0) + +/* Get the more significant 32 bit int from a double. */ + +#define GET_HIGH_WORD(i,d) \ +do { \ + ieee_double_shape_type gh_u; \ + gh_u.value = (d); \ + (i) = gh_u.parts.msw; \ +} while (0) + +/* Get the less significant 32 bit int from a double. */ + +#define GET_LOW_WORD(i,d) \ +do { \ + ieee_double_shape_type gl_u; \ + gl_u.value = (d); \ + (i) = gl_u.parts.lsw; \ +} while (0) + +/* Set a double from two 32 bit ints. */ + +#define INSERT_WORDS(d,ix0,ix1) \ +do { \ + ieee_double_shape_type iw_u; \ + iw_u.parts.msw = (ix0); \ + iw_u.parts.lsw = (ix1); \ + (d) = iw_u.value; \ +} while (0) + +/* Set the more significant 32 bits of a double from an int. */ + +#define SET_HIGH_WORD(d,v) \ +do { \ + ieee_double_shape_type sh_u; \ + sh_u.value = (d); \ + sh_u.parts.msw = (v); \ + (d) = sh_u.value; \ +} while (0) + +/* Set the less significant 32 bits of a double from an int. */ + +#define SET_LOW_WORD(d,v) \ +do { \ + ieee_double_shape_type sl_u; \ + sl_u.value = (d); \ + sl_u.parts.lsw = (v); \ + (d) = sl_u.value; \ +} while (0) + +/* A union which permits us to convert between a float and a 32 bit + int. */ + +typedef union +{ + float value; + u_int32_t word; +} ieee_float_shape_type; + +/* Get a 32 bit int from a float. */ + +#define GET_FLOAT_WORD(i,d) \ +do { \ + ieee_float_shape_type gf_u; \ + gf_u.value = (d); \ + (i) = gf_u.word; \ +} while (0) + +/* Set a float from a 32 bit int. */ + +#define SET_FLOAT_WORD(d,i) \ +do { \ + ieee_float_shape_type sf_u; \ + sf_u.word = (i); \ + (d) = sf_u.value; \ +} while (0) + +/* ieee style elementary functions */ +extern double __ieee754_sqrt(double); +extern double __ieee754_acos(double); +extern double __ieee754_acosh(double); +extern double __ieee754_log(double); +extern double __ieee754_atanh(double); +extern double __ieee754_asin(double); +extern double __ieee754_atan2(double,double); +extern double __ieee754_exp(double); +extern double __ieee754_cosh(double); +extern double __ieee754_fmod(double,double); +extern double __ieee754_pow(double,double); +extern double __ieee754_lgamma_r(double,int *); +extern double __ieee754_gamma_r(double,int *); +extern double __ieee754_lgamma(double); +extern double __ieee754_gamma(double); +extern double __ieee754_log10(double); +extern double __ieee754_sinh(double); +extern double __ieee754_hypot(double,double); +extern double __ieee754_j0(double); +extern double __ieee754_j1(double); +extern double __ieee754_y0(double); +extern double __ieee754_y1(double); +extern double __ieee754_jn(int,double); +extern double __ieee754_yn(int,double); +extern double __ieee754_remainder(double,double); +extern int __ieee754_rem_pio2(double,double*); +extern double __ieee754_scalb(double,double); + +/* fdlibm kernel function */ +extern double __kernel_standard(double,double,int); +extern double __kernel_sin(double,double,int); +extern double __kernel_cos(double,double); +extern double __kernel_tan(double,double,int); +extern int __kernel_rem_pio2(double*,double*,int,int,int,const int*); + + +/* ieee style elementary float functions */ +extern float __ieee754_sqrtf(float); +extern float __ieee754_acosf(float); +extern float __ieee754_acoshf(float); +extern float __ieee754_logf(float); +extern float __ieee754_atanhf(float); +extern float __ieee754_asinf(float); +extern float __ieee754_atan2f(float,float); +extern float __ieee754_expf(float); +extern float __ieee754_coshf(float); +extern float __ieee754_fmodf(float,float); +extern float __ieee754_powf(float,float); +extern float __ieee754_lgammaf_r(float,int *); +extern float __ieee754_gammaf_r(float,int *); +extern float __ieee754_lgammaf(float); +extern float __ieee754_gammaf(float); +extern float __ieee754_log10f(float); +extern float __ieee754_sinhf(float); +extern float __ieee754_hypotf(float,float); +extern float __ieee754_j0f(float); +extern float __ieee754_j1f(float); +extern float __ieee754_y0f(float); +extern float __ieee754_y1f(float); +extern float __ieee754_jnf(int,float); +extern float __ieee754_ynf(int,float); +extern float __ieee754_remainderf(float,float); +extern int __ieee754_rem_pio2f(float,float*); +extern float __ieee754_scalbf(float,float); + +/* float versions of fdlibm kernel functions */ +extern float __kernel_sinf(float,float,int); +extern float __kernel_cosf(float,float); +extern float __kernel_tanf(float,float,int); +extern int __kernel_rem_pio2f(float*,float*,int,int,int,const int*); + +#endif /* _MATH_PRIVATE_H_ */ +#ifdef __STDC__ +static const double one = 1.0; +#else +static double one = 1.0; +#endif + +#ifdef __STDC__ + double modf(double x, double *iptr) +#else + double modf(x, iptr) + double x,*iptr; +#endif +{ + int32_t i0,i1,j0; + u_int32_t i; + EXTRACT_WORDS(i0,i1,x); + j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */ + if(j0<20) { /* integer part in high x */ + if(j0<0) { /* |x|<1 */ + INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */ + return x; + } else { + i = (0x000fffff)>>j0; + if(((i0&i)|i1)==0) { /* x is integral */ + u_int32_t high; + *iptr = x; + GET_HIGH_WORD(high,x); + INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ + return x; + } else { + INSERT_WORDS(*iptr,i0&(~i),0); + return x - *iptr; + } + } + } else if (j0>51) { /* no fraction part */ + u_int32_t high; + *iptr = x*one; + GET_HIGH_WORD(high,x); + INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ + return x; + } else { /* fraction part in low x */ + i = ((u_int32_t)(0xffffffff))>>(j0-20); + if((i1&i)==0) { /* x is integral */ + u_int32_t high; + *iptr = x; + GET_HIGH_WORD(high,x); + INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ + return x; + } else { + INSERT_WORDS(*iptr,i0,i1&(~i)); + return x - *iptr; + } + } +} diff --git a/lib/libc/arch/sh/gen/setjmp.S b/lib/libc/arch/sh/gen/setjmp.S new file mode 100644 index 00000000000..e2d1eff9d16 --- /dev/null +++ b/lib/libc/arch/sh/gen/setjmp.S @@ -0,0 +1,127 @@ +/* $OpenBSD: setjmp.S,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: setjmp.S,v 1.10 2006/01/05 19:21:37 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)setjmp.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> +#include <machine/setjmp.h> + +/* + * C library -- setjmp, longjmp + * + * longjmp(a,v) + * will generate a "return(v)" from the last call to + * setjmp(a) + * by restoring registers from the stack. + * The previous signal state is restored. + */ + +ENTRY(setjmp) + PIC_PROLOGUE(.L_got_1) + sts.l pr, @-sp + mov.l r4, @-sp + + mov.l .L_sigprocmask_1, r0 + mov r4, r6 + mov #1, r4 /* how = SIG_BLOCK */ + mov #0, r5 /* new = NULL */ +1: CALL r0 + add #(_JB_SIGMASK * 4), r6 /* old = &sigmask */ + + mov.l @sp+, r4 + lds.l @sp+, pr + PIC_EPILOGUE + + /* identical to _setjmp except that _JB_HAS_MASK is non-zero */ + add #((_JB_HAS_MASK + 1) * 4), r4 + mov #1, r0 + mov.l r0, @-r4 /* has signal mask */ + mov.l r15, @-r4 + mov.l r14, @-r4 + mov.l r13, @-r4 + mov.l r12, @-r4 + mov.l r11, @-r4 + mov.l r10, @-r4 + mov.l r9, @-r4 + mov.l r8, @-r4 + sts.l pr, @-r4 + rts + xor r0, r0 + + .align 2 +.L_got_1: PIC_GOT_DATUM +.L_sigprocmask_1: CALL_DATUM(_C_LABEL(sigprocmask), 1b) + SET_ENTRY_SIZE(setjmp) + + +ENTRY(longjmp) + /* we won't return here, so we don't need to save pr and r12 */ + PIC_PROLOGUE_NOSAVE(.L_got_2) + mov.l r5, @-sp + mov.l r4, @-sp + + mov.l .L_sigprocmask_2, r0 + mov r4, r5 + mov #3, r4 /* how = SIG_SETMASK */ + add #(_JB_SIGMASK * 4), r5 /* new = &sigmask */ +1: CALL r0 + mov #0, r6 /* old = NULL */ + + mov.l @sp+, r4 + mov.l @sp+, r5 + + /* identical to _longjmp */ + lds.l @r4+, pr + mov.l @r4+, r8 + mov.l @r4+, r9 + mov.l @r4+, r10 + mov.l @r4+, r11 + mov.l @r4+, r12 + mov.l @r4+, r13 + mov.l @r4+, r14 + mov.l @r4+, r15 + + mov r5, r0 + tst r0, r0 /* make sure return value is non-zero */ + bf .L0 + add #1, r0 +.L0: + rts + nop + + .align 2 +.L_got_2: PIC_GOT_DATUM +.L_sigprocmask_2: CALL_DATUM(_C_LABEL(sigprocmask), 1b) + SET_ENTRY_SIZE(longjmp) diff --git a/lib/libc/arch/sh/gen/sigsetjmp.S b/lib/libc/arch/sh/gen/sigsetjmp.S new file mode 100644 index 00000000000..2467a3f707b --- /dev/null +++ b/lib/libc/arch/sh/gen/sigsetjmp.S @@ -0,0 +1,127 @@ +/* $OpenBSD: sigsetjmp.S,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: sigsetjmp.S,v 1.9 2006/01/05 19:21:37 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)setjmp.s 5.1 (Berkeley) 4/23/90 + */ + +#include <machine/asm.h> +#include <machine/setjmp.h> + +ENTRY(sigsetjmp) + tst r5, r5 + bt 2f /* if (savemask == 0) */ + + /* identical to longjmp except that _JB_HAS_MASK is in the argument */ + PIC_PROLOGUE(.L_got_1) + sts.l pr, @-sp + mov.l r4, @-sp + mov.l r5, @-sp + + mov.l .L_sigprocmask_1, r0 + mov r4, r6 + mov #1, r4 /* how = SIG_BLOCK */ + mov #0, r5 /* new = NULL */ +1: CALL r0 + add #(_JB_SIGMASK * 4), r6 /* old = &sigmask */ + + mov.l @sp+, r5 + mov.l @sp+, r4 + lds.l @sp+, pr + PIC_EPILOGUE + +2: /* identical to _setjmp except that _JB_HAS_MASK is in the argument */ + add #((_JB_HAS_MASK + 1) * 4), r4 + mov.l r5, @-r4 /* has signal mask? */ + mov.l r15, @-r4 + mov.l r14, @-r4 + mov.l r13, @-r4 + mov.l r12, @-r4 + mov.l r11, @-r4 + mov.l r10, @-r4 + mov.l r9, @-r4 + mov.l r8, @-r4 + sts.l pr, @-r4 + rts + xor r0, r0 + + .align 2 +.L_got_1: PIC_GOT_DATUM +.L_sigprocmask_1: CALL_DATUM(_C_LABEL(sigprocmask), 1b) + SET_ENTRY_SIZE(sigsetjmp) + + +ENTRY(siglongjmp) + mov.l @(_JB_HAS_MASK * 4, r4), r0 + tst r0, r0 + bt 2f /* if no mask */ + + /* identical to longjmp */ + /* we won't return here, so we don't need to save pr and r12 */ + PIC_PROLOGUE_NOSAVE(.L_got_2) + mov.l r5, @-sp + mov.l r4, @-sp + + mov.l .L_sigprocmask_2, r0 + mov r4, r5 + mov #3, r4 /* how = SIG_SETMASK */ + add #(_JB_SIGMASK * 4), r5 /* new = &sigmask */ +1: CALL r0 + mov #0, r6 /* old = NULL */ + + mov.l @sp+, r4 + mov.l @sp+, r5 + +2: /* identical to _longjmp */ + lds.l @r4+, pr + mov.l @r4+, r8 + mov.l @r4+, r9 + mov.l @r4+, r10 + mov.l @r4+, r11 + mov.l @r4+, r12 + mov.l @r4+, r13 + mov.l @r4+, r14 + mov.l @r4+, r15 + + mov r5, r0 + tst r0, r0 /* make sure return value is non-zero */ + bf .L0 + add #1, r0 +.L0: + rts + nop + + .align 2 +.L_got_2: PIC_GOT_DATUM +.L_sigprocmask_2: CALL_DATUM(_C_LABEL(sigprocmask), 1b) + SET_ENTRY_SIZE(siglongjmp) diff --git a/lib/libc/arch/sh/net/Makefile.inc b/lib/libc/arch/sh/net/Makefile.inc new file mode 100644 index 00000000000..13bfad7c42f --- /dev/null +++ b/lib/libc/arch/sh/net/Makefile.inc @@ -0,0 +1,4 @@ +# $OpenBSD: Makefile.inc,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ +# $NetBSD: Makefile.inc,v 1.1 2000/01/05 14:07:36 msaitoh Exp $ + +SRCS+= htonl.c htons.c ntohl.c ntohs.c diff --git a/lib/libc/arch/sh/net/htonl.c b/lib/libc/arch/sh/net/htonl.c new file mode 100644 index 00000000000..04776d7288e --- /dev/null +++ b/lib/libc/arch/sh/net/htonl.c @@ -0,0 +1,58 @@ +/* $OpenBSD: htonl.c,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: htonl.c,v 1.3 2005/12/24 23:10:08 perry Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)htonl.s 5.2 (Berkeley) 12/17/90 + */ + +#include <sys/types.h> +#include <machine/endian.h> + +#undef htonl + +/* hostorder = htonl(netorder) */ +u_int32_t +htonl(x) + u_int32_t x; +{ +#if BYTE_ORDER == LITTLE_ENDIAN + u_int32_t y = 0; + + __asm("swap.b %1, %0" : "=r" (y) : "r" (x)); + __asm("swap.w %1, %0" : "=r" (y) : "r" (y)); + __asm("swap.b %1, %0" : "=r" (y) : "r" (y)); + return y; +#else + return x; +#endif +} diff --git a/lib/libc/arch/sh/net/htons.c b/lib/libc/arch/sh/net/htons.c new file mode 100644 index 00000000000..5c1f28c8c1e --- /dev/null +++ b/lib/libc/arch/sh/net/htons.c @@ -0,0 +1,52 @@ +/* $OpenBSD: htons.c,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: htons.c,v 1.3 2005/12/24 23:10:08 perry Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)htonl.s 5.2 (Berkeley) 12/17/90 + */ + +#include <sys/types.h> +#include <machine/endian.h> + +#undef htons + +/* netorder = htons(hostorder) */ +u_int16_t +htons(x) + u_int16_t x; +{ +#if BYTE_ORDER == LITTLE_ENDIAN + __asm("swap.b %1, %0" : "=r" (x) : "r" (x)); +#endif + return x; +} diff --git a/lib/libc/arch/sh/net/ntohl.c b/lib/libc/arch/sh/net/ntohl.c new file mode 100644 index 00000000000..427fd3ae95f --- /dev/null +++ b/lib/libc/arch/sh/net/ntohl.c @@ -0,0 +1,58 @@ +/* $OpenBSD: ntohl.c,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: ntohl.c,v 1.3 2005/12/24 23:10:08 perry Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)ntohl.s 5.2 (Berkeley) 12/17/90 + */ + +#include <sys/types.h> +#include <machine/endian.h> + +#undef ntohl + +/* netorder = ntohl(hostorder) */ +u_int32_t +ntohl(x) + u_int32_t x; +{ +#if BYTE_ORDER == LITTLE_ENDIAN + u_int32_t y = 0; + + __asm("swap.b %1, %0" : "=r" (y) : "r" (x)); + __asm("swap.w %1, %0" : "=r" (y) : "r" (y)); + __asm("swap.b %1, %0" : "=r" (y) : "r" (y)); + return y; +#else + return x; +#endif +} diff --git a/lib/libc/arch/sh/net/ntohs.c b/lib/libc/arch/sh/net/ntohs.c new file mode 100644 index 00000000000..925dd9e603b --- /dev/null +++ b/lib/libc/arch/sh/net/ntohs.c @@ -0,0 +1,52 @@ +/* $OpenBSD: ntohs.c,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: ntohs.c,v 1.3 2005/12/24 23:10:08 perry Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)ntohl.s 5.2 (Berkeley) 12/17/90 + */ + +#include <sys/types.h> +#include <machine/endian.h> + +#undef ntohs + +/* hostorder = ntohs(netorder) */ +u_int16_t +ntohs(x) + u_int16_t x; +{ +#if BYTE_ORDER == LITTLE_ENDIAN + __asm("swap.b %1, %0" : "=r" (x) : "r" (x)); +#endif + return x; +} diff --git a/lib/libc/arch/sh/string/Makefile.inc b/lib/libc/arch/sh/string/Makefile.inc new file mode 100644 index 00000000000..3f8ac34e8b0 --- /dev/null +++ b/lib/libc/arch/sh/string/Makefile.inc @@ -0,0 +1,8 @@ +# $OpenBSD: Makefile.inc,v 1.1 2006/10/10 22:07:10 miod Exp $ +# $NetBSD: Makefile.inc,v 1.3 2002/11/20 14:23:54 itohy Exp $ + +SRCS+= bcmp.c bcopy.S bzero.S ffs.S index.c memchr.c memcmp.c memset.S \ + rindex.c strcat.c strcmp.c strcpy.c strcspn.c strlen.c \ + strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \ + strspn.c strstr.c swab.c strlcpy.c strlcat.c +SRCS+= memcpy.S memmove.S diff --git a/lib/libc/arch/sh/string/bcopy.S b/lib/libc/arch/sh/string/bcopy.S new file mode 100644 index 00000000000..48efa2a5972 --- /dev/null +++ b/lib/libc/arch/sh/string/bcopy.S @@ -0,0 +1,5 @@ +/* $OpenBSD: bcopy.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: bcopy.S,v 1.3 2006/04/23 00:08:18 uwe Exp $ */ + +#define BCOPY +#include "memcpy.S" diff --git a/lib/libc/arch/sh/string/bzero.S b/lib/libc/arch/sh/string/bzero.S new file mode 100644 index 00000000000..db410a81051 --- /dev/null +++ b/lib/libc/arch/sh/string/bzero.S @@ -0,0 +1,6 @@ +/* $OpenBSD: bzero.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: bzero.S,v 1.1 2002/11/20 14:23:54 itohy Exp $ */ + +#define BZERO +#include "memset.S" + diff --git a/lib/libc/arch/sh/string/ffs.S b/lib/libc/arch/sh/string/ffs.S new file mode 100644 index 00000000000..df1a495f469 --- /dev/null +++ b/lib/libc/arch/sh/string/ffs.S @@ -0,0 +1,100 @@ +/* $OpenBSD: ffs.S,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: ffs.S,v 1.1 2005/12/20 19:28:50 christos Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by ITOH Yasufumi. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <machine/asm.h> + +/* + * ffs - find first bit set + * + * This code makes use of ``test 8bit'' and ``shift 8bit'' instructions. + * The remaining 8bit is tested in every 2bit. + */ + +ENTRY(ffs) + mov r4,r0 ! using r0 specific instructions + tst #0xff,r0 + bf/s L8bit + mov #0+1,r1 ! ret = 1..8 + + tst r0,r0 ! ffs(0) is 0 + bt Lzero ! testing here to accelerate ret=1..8 cases + + shlr8 r0 + tst #0xff,r0 + bf/s L8bit + mov #8+1,r1 ! ret = 9..16 + + shlr8 r0 + tst #0xff,r0 + bf/s L8bit + mov #16+1,r1 ! ret = 17..24 + + shlr8 r0 + mov #24+1,r1 ! ret = 25..32 + +L8bit: + tst #0x0f,r0 + bt 4f + + tst #0x03,r0 + bt 2f + tst #0x01,r0 ! not bit 0 -> T + mov #0,r0 + rts + addc r1,r0 ! 0 + r1 + T -> r0 + +2: tst #0x04,r0 + mov #2,r0 + rts + addc r1,r0 + +4: tst #0x30,r0 + bt 6f + tst #0x10,r0 + mov #4,r0 + rts + addc r1,r0 + +6: tst #0x40,r0 + mov #6,r0 + rts + addc r1,r0 + +Lzero: rts + nop diff --git a/lib/libc/arch/sh/string/memcpy.S b/lib/libc/arch/sh/string/memcpy.S new file mode 100644 index 00000000000..9d1b89716eb --- /dev/null +++ b/lib/libc/arch/sh/string/memcpy.S @@ -0,0 +1,268 @@ +/* $OpenBSD: memcpy.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: memcpy.S,v 1.2 2006/04/22 23:53:47 uwe Exp $ */ + +/* + * Copyright (c) 2000 SHIMIZU Ryo <ryo@misakimix.org> + * 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 <machine/asm.h> + +#if !defined(MEMCOPY) && !defined(MEMMOVE) && !defined(BCOPY) +#define MEMCOPY +#endif + +#if defined(MEMCOPY) || defined(MEMMOVE) +#define REG_DST0 r3 +#define REG_SRC r5 +#define REG_DST r4 +#else +#define REG_SRC r4 +#define REG_DST r5 +#endif + +#define REG_LEN r6 + +#if defined(MEMCOPY) +ENTRY(memcpy) +#elif defined(MEMMOVE) +ENTRY(memmove) +#elif defined(BCOPY) +ENTRY(bcopy) +#endif +#ifdef REG_DST0 + mov REG_DST,REG_DST0 +#endif + cmp/eq REG_DST,REG_SRC /* if ( src == dst ) return; */ + bt/s bcopy_return + cmp/hi REG_DST,REG_SRC + bf/s bcopy_overlap + + mov REG_SRC,r0 + xor REG_DST,r0 + and #3,r0 + mov r0,r1 + tst r0,r0 /* (src ^ dst) & 3 */ + bf/s word_align + +longword_align: + tst REG_LEN,REG_LEN /* if ( len==0 ) return; */ + bt/s bcopy_return + + + mov REG_SRC,r0 + tst #1,r0 /* if ( src & 1 ) */ + bt 1f + mov.b @REG_SRC+,r0 /* *dst++ = *src++; */ + add #-1,REG_LEN + mov.b r0,@REG_DST + add #1,REG_DST +1: + + + mov #1,r0 + cmp/hi r0,REG_LEN /* if ( (len > 1) && */ + bf/s 1f + mov REG_SRC,r0 + tst #2,r0 /* (src & 2) { */ + bt 1f + mov.w @REG_SRC+,r0 /* *((unsigned short*)dst)++ = *((unsigned short*)src)++; */ + add #-2,REG_LEN /* len -= 2; */ + mov.w r0,@REG_DST + add #2,REG_DST /* } */ +1: + + + mov #3,r1 + cmp/hi r1,REG_LEN /* while ( len > 3 ) { */ + bf/s no_align_delay + tst REG_LEN,REG_LEN +2: + mov.l @REG_SRC+,r0 /* *((unsigned long*)dst)++ = *((unsigned long*)src)++; */ + add #-4,REG_LEN /* len -= 4; */ + mov.l r0,@REG_DST + cmp/hi r1,REG_LEN + bt/s 2b + add #4,REG_DST /* } */ + + bra no_align_delay + tst REG_LEN,REG_LEN + + +word_align: + mov r1,r0 + tst #1,r0 + bf/s no_align_delay + tst REG_LEN,REG_LEN /* if ( len == 0 ) return; */ + bt bcopy_return + + + mov REG_SRC,r0 /* if ( src & 1 ) */ + tst #1,r0 + bt 1f + mov.b @REG_SRC+,r0 /* *dst++ = *src++; */ + add #-1,REG_LEN + mov.b r0,@REG_DST + add #1,REG_DST +1: + + + mov #1,r1 + cmp/hi r1,REG_LEN /* while ( len > 1 ) { */ + bf/s no_align_delay + tst REG_LEN,REG_LEN +2: + mov.w @REG_SRC+,r0 /* *((unsigned short*)dst)++ = *((unsigned short*)src)++; */ + add #-2,REG_LEN /* len -= 2; */ + mov.w r0,@REG_DST + cmp/hi r1,REG_LEN + bt/s 2b + add #2,REG_DST /* } */ + + +no_align: + tst REG_LEN,REG_LEN /* while ( len!= ) { */ +no_align_delay: + bt bcopy_return +1: + mov.b @REG_SRC+,r0 /* *dst++ = *src++; */ + add #-1,REG_LEN /* len--; */ + mov.b r0,@REG_DST + tst REG_LEN,REG_LEN + bf/s 1b + add #1,REG_DST /* } */ +bcopy_return: + rts +#ifdef REG_DST0 + mov REG_DST0,r0 +#else + nop +#endif + + +bcopy_overlap: + add REG_LEN,REG_SRC + add REG_LEN,REG_DST + + mov REG_SRC,r0 + xor REG_DST,r0 + and #3,r0 + mov r0,r1 + tst r0,r0 /* (src ^ dst) & 3 */ + bf/s ov_word_align + +ov_longword_align: + tst REG_LEN,REG_LEN /* if ( len==0 ) return; */ + bt/s bcopy_return + + + mov REG_SRC,r0 + tst #1,r0 /* if ( src & 1 ) */ + bt 1f + add #-1,REG_SRC /* *--dst = *--src; */ + mov.b @REG_SRC,r0 + mov.b r0,@-REG_DST + add #-1,REG_LEN +1: + + + mov #1,r0 + cmp/hi r0,REG_LEN /* if ( (len > 1) && */ + bf/s 1f + mov REG_SRC,r0 + tst #2,r0 /* (src & 2) { */ + bt 1f + add #-2,REG_SRC /* *--((unsigned short*)dst) = *--((unsigned short*)src); */ + mov.w @REG_SRC,r0 + add #-2,REG_LEN /* len -= 2; */ + mov.w r0,@-REG_DST /* } */ +1: + + + mov #3,r1 + cmp/hi r1,REG_LEN /* while ( len > 3 ) { */ + bf/s ov_no_align_delay + tst REG_LEN,REG_LEN +2: + add #-4,REG_SRC + mov.l @REG_SRC,r0 /* *((unsigned long*)dst)++ = *((unsigned long*)src)++; */ + add #-4,REG_LEN /* len -= 4; */ + cmp/hi r1,REG_LEN + bt/s 2b + mov.l r0,@-REG_DST /* } */ + + bra ov_no_align_delay + tst REG_LEN,REG_LEN + + +ov_word_align: + mov r1,r0 + tst #1,r0 + bf/s ov_no_align_delay + tst REG_LEN,REG_LEN /* if ( len == 0 ) return; */ + bt bcopy_return + + + mov REG_SRC,r0 /* if ( src & 1 ) */ + tst #1,r0 + bt 1f + add #-1,REG_SRC + mov.b @REG_SRC,r0 /* *--dst = *--src; */ + add #-1,REG_LEN + mov.b r0,@-REG_DST +1: + + + mov #1,r1 + cmp/hi r1,REG_LEN /* while ( len > 1 ) { */ + bf/s ov_no_align_delay + tst REG_LEN,REG_LEN +2: + add #-2,REG_SRC + mov.w @REG_SRC,r0 /* *--((unsigned short*)dst) = *--((unsigned short*)src); */ + add #-2,REG_LEN /* len -= 2; */ + cmp/hi r1,REG_LEN + bt/s 2b + mov.w r0,@-REG_DST /* } */ + + +ov_no_align: + tst REG_LEN,REG_LEN /* while ( len!= ) { */ +ov_no_align_delay: + bt 9f +1: + add #-1,REG_SRC + mov.b @REG_SRC,r0 /* *--dst = *--src; */ + add #-1,REG_LEN /* len--; */ + tst REG_LEN,REG_LEN + bf/s 1b + mov.b r0,@-REG_DST /* } */ +9: + rts +#ifdef REG_DST0 + mov REG_DST0,r0 +#else + nop +#endif diff --git a/lib/libc/arch/sh/string/memmove.S b/lib/libc/arch/sh/string/memmove.S new file mode 100644 index 00000000000..023fc10559d --- /dev/null +++ b/lib/libc/arch/sh/string/memmove.S @@ -0,0 +1,5 @@ +/* $OpenBSD: memmove.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: memmove.S,v 1.2 2006/04/22 23:53:47 uwe Exp $ */ + +#define MEMMOVE +#include "memcpy.S" diff --git a/lib/libc/arch/sh/string/memset.S b/lib/libc/arch/sh/string/memset.S new file mode 100644 index 00000000000..73b0d066908 --- /dev/null +++ b/lib/libc/arch/sh/string/memset.S @@ -0,0 +1,295 @@ +/* $OpenBSD: memset.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: memset.S,v 1.1 2005/12/20 19:28:50 christos Exp $ */ + +/*- + * Copyright (c) 2002 SHIMIZU Ryo. 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 <machine/asm.h> + +#define REG_PTR r0 +#define REG_TMP1 r1 + +#ifdef BZERO +# define REG_C r2 +# define REG_DST r4 +# define REG_LEN r5 +#else +# define REG_DST0 r3 +# define REG_DST r4 +# define REG_C r5 +# define REG_LEN r6 +#endif + +#ifdef BZERO +ENTRY(bzero) +#else +ENTRY(memset) + mov REG_DST,REG_DST0 /* for return value */ +#endif + /* small amount to fill ? */ + mov #28,REG_TMP1 + cmp/hs REG_TMP1,REG_LEN /* if (len >= 28) goto large; */ + bt/s large + mov #12,REG_TMP1 /* if (len >= 12) goto small; */ + cmp/hs REG_TMP1,REG_LEN + bt/s small +#ifdef BZERO + mov #0,REG_C +#endif + /* very little fill (0 ~ 11 bytes) */ + tst REG_LEN,REG_LEN + add REG_DST,REG_LEN + bt/s done + add #1,REG_DST + + /* unroll 4 loops */ + cmp/eq REG_DST,REG_LEN +1: mov.b REG_C,@-REG_LEN + bt/s done + cmp/eq REG_DST,REG_LEN + mov.b REG_C,@-REG_LEN + bt/s done + cmp/eq REG_DST,REG_LEN + mov.b REG_C,@-REG_LEN + bt/s done + cmp/eq REG_DST,REG_LEN + mov.b REG_C,@-REG_LEN + bf/s 1b + cmp/eq REG_DST,REG_LEN +done: +#ifdef BZERO + rts + nop +#else + rts + mov REG_DST0,r0 +#endif + + +small: + mov REG_DST,r0 + tst #1,r0 + bt/s small_aligned + mov REG_DST,REG_TMP1 + shll REG_LEN + mova 1f,r0 /* 1f must be 4bytes aligned! */ + add #16,REG_TMP1 /* REG_TMP1 = dst+16; */ + sub REG_LEN,r0 + jmp @r0 + mov REG_C,r0 + + .align 2 + mov.b r0,@(15,REG_TMP1) + mov.b r0,@(14,REG_TMP1) + mov.b r0,@(13,REG_TMP1) + mov.b r0,@(12,REG_TMP1) + mov.b r0,@(11,REG_TMP1) + mov.b r0,@(10,REG_TMP1) + mov.b r0,@(9,REG_TMP1) + mov.b r0,@(8,REG_TMP1) + mov.b r0,@(7,REG_TMP1) + mov.b r0,@(6,REG_TMP1) + mov.b r0,@(5,REG_TMP1) + mov.b r0,@(4,REG_TMP1) + mov.b r0,@(3,REG_TMP1) + mov.b r0,@(2,REG_TMP1) + mov.b r0,@(1,REG_TMP1) + mov.b r0,@REG_TMP1 + mov.b r0,@(15,REG_DST) + mov.b r0,@(14,REG_DST) + mov.b r0,@(13,REG_DST) + mov.b r0,@(12,REG_DST) + mov.b r0,@(11,REG_DST) + mov.b r0,@(10,REG_DST) + mov.b r0,@(9,REG_DST) + mov.b r0,@(8,REG_DST) + mov.b r0,@(7,REG_DST) + mov.b r0,@(6,REG_DST) + mov.b r0,@(5,REG_DST) + mov.b r0,@(4,REG_DST) + mov.b r0,@(3,REG_DST) + mov.b r0,@(2,REG_DST) + mov.b r0,@(1,REG_DST) +#ifdef BZERO + rts +1: mov.b r0,@REG_DST +#else + mov.b r0,@REG_DST +1: rts + mov REG_DST0,r0 +#endif + + +/* 2 bytes aligned small fill */ +small_aligned: +#ifndef BZERO + extu.b REG_C,REG_TMP1 /* REG_C = ??????xx, REG_TMP1 = ????00xx */ + shll8 REG_C /* REG_C = ????xx00, REG_TMP1 = ????00xx */ + or REG_TMP1,REG_C /* REG_C = ????xxxx */ +#endif + + mov REG_LEN,r0 + tst #1,r0 /* len is aligned? */ + bt/s 1f + add #-1,r0 + mov.b REG_C,@(r0,REG_DST) /* fill last a byte */ + mov r0,REG_LEN +1: + + mova 1f,r0 /* 1f must be 4bytes aligned! */ + sub REG_LEN,r0 + jmp @r0 + mov REG_C,r0 + + .align 2 + mov.w r0,@(30,REG_DST) + mov.w r0,@(28,REG_DST) + mov.w r0,@(26,REG_DST) + mov.w r0,@(24,REG_DST) + mov.w r0,@(22,REG_DST) + mov.w r0,@(20,REG_DST) + mov.w r0,@(18,REG_DST) + mov.w r0,@(16,REG_DST) + mov.w r0,@(14,REG_DST) + mov.w r0,@(12,REG_DST) + mov.w r0,@(10,REG_DST) + mov.w r0,@(8,REG_DST) + mov.w r0,@(6,REG_DST) + mov.w r0,@(4,REG_DST) + mov.w r0,@(2,REG_DST) +#ifdef BZERO + rts +1: mov.w r0,@REG_DST +#else + mov.w r0,@REG_DST +1: rts + mov REG_DST0,r0 +#endif + + + + .align 2 +large: +#ifdef BZERO + mov #0,REG_C +#else + extu.b REG_C,REG_TMP1 /* REG_C = ??????xx, REG_TMP1 = ????00xx */ + shll8 REG_C /* REG_C = ????xx00, REG_TMP1 = ????00xx */ + or REG_C,REG_TMP1 /* REG_C = ????xx00, REG_TMP1 = ????xxxx */ + swap.w REG_TMP1,REG_C /* REG_C = xxxx????, REG_TMP1 = ????xxxx */ + xtrct REG_TMP1,REG_C /* REG_C = xxxxxxxx */ +#endif + + mov #3,REG_TMP1 + tst REG_TMP1,REG_DST + mov REG_DST,REG_PTR + bf/s unaligned_dst + add REG_LEN,REG_PTR /* REG_PTR = dst + len; */ + tst REG_TMP1,REG_LEN + bf/s unaligned_len + +aligned: + /* fill 32*n bytes */ + mov #32,REG_TMP1 + cmp/hi REG_LEN,REG_TMP1 + bt 9f + .align 2 +1: sub REG_TMP1,REG_PTR + mov.l REG_C,@REG_PTR + sub REG_TMP1,REG_LEN + mov.l REG_C,@(4,REG_PTR) + cmp/hi REG_LEN,REG_TMP1 + mov.l REG_C,@(8,REG_PTR) + mov.l REG_C,@(12,REG_PTR) + mov.l REG_C,@(16,REG_PTR) + mov.l REG_C,@(20,REG_PTR) + mov.l REG_C,@(24,REG_PTR) + bf/s 1b + mov.l REG_C,@(28,REG_PTR) +9: + + /* fill left 4*n bytes */ + cmp/eq REG_DST,REG_PTR + bt 9f + add #4,REG_DST + cmp/eq REG_DST,REG_PTR +1: mov.l REG_C,@-REG_PTR + bt/s 9f + cmp/eq REG_DST,REG_PTR + mov.l REG_C,@-REG_PTR + bt/s 9f + cmp/eq REG_DST,REG_PTR + mov.l REG_C,@-REG_PTR + bt/s 9f + cmp/eq REG_DST,REG_PTR + mov.l REG_C,@-REG_PTR + bf/s 1b + cmp/eq REG_DST,REG_PTR +9: +#ifdef BZERO + rts + nop +#else + rts + mov REG_DST0,r0 +#endif + + +unaligned_dst: + mov #1,REG_TMP1 + tst REG_TMP1,REG_DST /* if (dst & 1) { */ + add #1,REG_TMP1 + bt/s 2f + tst REG_TMP1,REG_DST + mov.b REG_C,@REG_DST /* *dst++ = c; */ + add #1,REG_DST + tst REG_TMP1,REG_DST +2: /* } */ + /* if (dst & 2) { */ + bt 4f + mov.w REG_C,@REG_DST /* *(u_int16_t*)dst++ = c; */ + add #2,REG_DST +4: /* } */ + + + tst #3,REG_PTR /* if (ptr & 3) { */ + bt/s 4f /* */ +unaligned_len: + tst #1,REG_PTR /* if (ptr & 1) { */ + bt/s 2f + tst #2,REG_PTR + mov.b REG_C,@-REG_PTR /* --ptr = c; */ +2: /* } */ + /* if (ptr & 2) { */ + bt 4f + mov.w REG_C,@-REG_PTR /* *--(u_int16_t*)ptr = c; */ +4: /* } */ + /* } */ + + mov REG_PTR,REG_LEN + bra aligned + sub REG_DST,REG_LEN + diff --git a/lib/libc/arch/sh/sys/Ovfork.S b/lib/libc/arch/sh/sys/Ovfork.S new file mode 100644 index 00000000000..d6ea110c1d1 --- /dev/null +++ b/lib/libc/arch/sh/sys/Ovfork.S @@ -0,0 +1,63 @@ +/* $OpenBSD: Ovfork.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: Ovfork.S,v 1.5 2003/08/07 16:42:20 agc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)Ovfork.s 5.1 (Berkeley) 4/23/90 + */ + +#include "SYS.h" + +/* + * pid = vfork(); + * + * r1 == 0 in parent process, r1 == 1 in child process. + * r0 == pid of child in parent, r0 == pid of parent in child. + * + */ +SYSENTRY(vfork) + mov.l .L_SYS_vfork, r0 + trapa #0x80 + bf err + + add #0xff, r1 /* from 1 to 0 in child, 0 to -1 in parent */ + rts + and r1, r0 /* 0 in child, child pid in parent */ + +err: + JUMP_CERROR + + .align 2 +.L_SYS_vfork: + .long SYS_vfork + + SET_ENTRY_SIZE(vfork) diff --git a/lib/libc/arch/sh/sys/brk.S b/lib/libc/arch/sh/sys/brk.S new file mode 100644 index 00000000000..282ffc578c2 --- /dev/null +++ b/lib/libc/arch/sh/sys/brk.S @@ -0,0 +1,94 @@ +/* $OpenBSD: brk.S,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: brk.S,v 1.10 2006/01/06 03:58:31 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)brk.s 5.2 (Berkeley) 12/17/90 + */ + +#include "SYS.h" + +#ifdef WEAK_ALIAS +WEAK_ALIAS(brk,_brk) +#endif + + .data + .globl _C_LABEL(__minbrk) + .align 2 +_C_LABEL(__minbrk): + .long _C_LABEL(end) + + .text + +SYSENTRY(_brk) +#ifdef PIC + mova L_GOT, r0 + mov.l L_GOT, r2 + add r0, r2 + mov.l Lminbrk, r0 + mov.l @(r0, r2), r0 + mov.l @r0, r0 +#else + mov.l Lminbrk, r0 + mov.l @r0, r0 +#endif + cmp/hs r4, r0 + bf 1f + mov r0, r4 +1: + mov.l LSYS_break, r0 + trapa #0x80 + bf err +#ifdef PIC + mov.l Lcurbrk, r0 + mov.l @(r0, r2), r1 + xor r0, r0 +#else + xor r0, r0 + mov.l Lcurbrk, r1 +#endif + rts + mov.l r4, @r1 +err: + JUMP_CERROR + + .align 2 +LSYS_break: .long SYS_break +#ifdef PIC +L_GOT: .long _GLOBAL_OFFSET_TABLE_ +Lminbrk: .long _C_LABEL(__minbrk)@GOT +Lcurbrk: .long _C_LABEL(__curbrk)@GOT +#else +Lminbrk: .long _C_LABEL(__minbrk) +Lcurbrk: .long _C_LABEL(__curbrk) +#endif + SET_ENTRY_SIZE(_brk) diff --git a/lib/libc/arch/sh/sys/cerror.S b/lib/libc/arch/sh/sys/cerror.S new file mode 100644 index 00000000000..8c645497b34 --- /dev/null +++ b/lib/libc/arch/sh/sys/cerror.S @@ -0,0 +1,83 @@ +/* $OpenBSD: cerror.S,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: cerror.S,v 1.10 2006/01/06 05:14:39 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)cerror.s 5.1 (Berkeley) 4/23/90 + */ + +#include "SYS.h" + +ASENTRY(CERROR) +#ifdef _REENTRANT + mov.l .L___errno, r1 + PIC_PROLOGUE(.L_got) + sts.l pr, @-sp +1: CALL r1 + mov.l r4, @-sp ! save error code + mov.l @sp+, r4 + lds.l @sp+, pr + PIC_EPILOGUE + mov.l r4, @r0 + mov #-1, r1 + rts + mov #-1, r0 + + .align 2 +.L_got: PIC_GOT_DATUM +.L___errno: CALL_DATUM(_C_LABEL(__errno), 1b) + SET_ASENTRY_SIZE(cerror) + +#else /* !_REENTRANT */ +#ifdef PIC + mova L_GOT, r0 + mov.l L_GOT, r1 + add r0, r1 + mov.l L_errno, r0 + mov.l @(r0, r1), r1 + mov.l r4, @r1 +#else + mov.l L_errno, r1 + mov.l r4, @r1 +#endif + mov #-1, r0 + rts + mov #-1, r1 + + .align 2 +#ifdef PIC +L_GOT: .long _GLOBAL_OFFSET_TABLE_ +L_errno: .long _C_LABEL(errno)@GOT +#else +L_errno: .long _C_LABEL(errno) +#endif +#endif /* !_REENTRANT */ diff --git a/lib/libc/arch/sh/sys/exect.S b/lib/libc/arch/sh/sys/exect.S new file mode 100644 index 00000000000..929c5ebce03 --- /dev/null +++ b/lib/libc/arch/sh/sys/exect.S @@ -0,0 +1,40 @@ +/* $OpenBSD: exect.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: exect.S,v 1.5 2006/01/06 01:53:30 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)exect.s 5.1 (Berkeley) 4/23/90 + */ + +#include "SYS.h" + +PSEUDO(exect,execve) diff --git a/lib/libc/arch/sh/sys/fork.S b/lib/libc/arch/sh/sys/fork.S new file mode 100644 index 00000000000..761116c0697 --- /dev/null +++ b/lib/libc/arch/sh/sys/fork.S @@ -0,0 +1,59 @@ +/* $OpenBSD: fork.S,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: fork.S,v 1.10 2006/01/06 05:11:29 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)fork.s 5.1 (Berkeley) 4/23/90 + */ + +#include "SYS.h" + +/* + * pid = fork(); + * + * r1 == 0 in parent process, r1 == 1 in child process. + * r0 == pid of child in parent, r0 == pid of parent in child. + * + */ +_SYSCALL(fork,fork) + mov #SYS_fork, r0 + trapa #0x80 + bf err + + add #0xff, r1 /* from 1 to 0 in child, 0 to -1 in parent */ + rts + and r1, r0 /* 0 in child, child pid in parent */ + +err: + JUMP_CERROR + + SET_ENTRY_SIZE(fork) diff --git a/lib/libc/arch/sh/sys/rfork.S b/lib/libc/arch/sh/sys/rfork.S new file mode 100644 index 00000000000..746e4c7841e --- /dev/null +++ b/lib/libc/arch/sh/sys/rfork.S @@ -0,0 +1,32 @@ +/* $OpenBSD: rfork.S,v 1.1 2006/10/10 22:07:10 miod Exp $ */ + +/* + * Copyright (c) 2004 Dale Rahn + * + * 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 ``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 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. + */ + +/* pid = rfork() */ + +#include "SYS.h" + +RSYSCALL(rfork) diff --git a/lib/libc/arch/sh/sys/sbrk.S b/lib/libc/arch/sh/sys/sbrk.S new file mode 100644 index 00000000000..1dfcb028fca --- /dev/null +++ b/lib/libc/arch/sh/sys/sbrk.S @@ -0,0 +1,89 @@ +/* $OpenBSD: sbrk.S,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: sbrk.S,v 1.9 2006/01/06 03:58:31 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)sbrk.s 5.1 (Berkeley) 4/23/90 + */ + +#include "SYS.h" + + .globl _C_LABEL(end) + .globl _C_LABEL(__curbrk) + +#ifdef WEAK_ALIAS +WEAK_ALIAS(sbrk,_sbrk) +#endif + + .data +_C_LABEL(__curbrk): + .long _C_LABEL(end) + .text + +SYSENTRY(_sbrk) + mov r4, r2 +#ifdef PIC + mova L_GOT, r0 + mov.l L_GOT, r3 + add r0, r3 + mov.l Lcurbrk, r0 + mov.l @(r0, r3), r0 +#else + mov.l Lcurbrk, r0 +#endif + mov.l @r0, r0 + add r0, r4 + mov.l LSYS_break, r0 + trapa #0x80 + bf err +#ifdef PIC + mov.l Lcurbrk, r0 + mov.l @(r0, r3), r1 +#else + mov.l Lcurbrk, r1 +#endif + mov.l @r1, r0 + add r0, r2 + rts + mov.l r2, @r1 +err: + JUMP_CERROR + + .align 2 +LSYS_break: .long SYS_break +#ifdef PIC +L_GOT: .long _GLOBAL_OFFSET_TABLE_ +Lcurbrk: .long _C_LABEL(__curbrk)@GOT +#else +Lcurbrk: .long _C_LABEL(__curbrk) +#endif + SET_ENTRY_SIZE(_sbrk) diff --git a/lib/libc/arch/sh/sys/sigpending.S b/lib/libc/arch/sh/sys/sigpending.S new file mode 100644 index 00000000000..37965ac35c9 --- /dev/null +++ b/lib/libc/arch/sh/sys/sigpending.S @@ -0,0 +1,37 @@ +/* $OpenBSD: sigpending.S,v 1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: sigpending.S,v 1.5 2003/08/07 16:42:05 agc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)sigpending.s 5.1 (Berkeley) 7/1/90 + */ + +#include "SYS.h" + +RSYSCALL(sigpending) diff --git a/lib/libc/arch/sh/sys/sigprocmask.S b/lib/libc/arch/sh/sys/sigprocmask.S new file mode 100644 index 00000000000..88efac381f0 --- /dev/null +++ b/lib/libc/arch/sh/sys/sigprocmask.S @@ -0,0 +1,65 @@ +/* $OpenBSD: sigprocmask.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: sigprocmask.S,v 1.6 2003/08/07 16:42:21 agc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)sigprocmask.s 5.2 (Berkeley) 12/17/90 + */ + +#include "SYS.h" + +SYSENTRY(sigprocmask) + mov r5, r2 /* fetch new sigset pointer */ + tst r2, r2 /* check new sigset pointer */ + bf 1f /* if not null, indirect */ + mov #1, r4 /* SIG_BLOCK */ + bra 2f + nop +1: mov.l @r2, r2 /* fetch indirect ... */ + mov r2, r5 /* to new mask arg */ +2: mov.l LSYS_sigprocmask, r0 + trapa #0x80 + bf err + mov r6, r2 /* fetch old mask requested */ + tst r2, r2 /* test if old mask requested */ + bt out + mov.l r0, @r2 /* store old mask */ +out: + xor r0, r0 + rts + nop +err: + JUMP_CERROR + + .align 2 +LSYS_sigprocmask: + .long SYS_sigprocmask diff --git a/lib/libc/arch/sh/sys/sigreturn.S b/lib/libc/arch/sh/sys/sigreturn.S new file mode 100644 index 00000000000..6e9da57b9bc --- /dev/null +++ b/lib/libc/arch/sh/sys/sigreturn.S @@ -0,0 +1,41 @@ +/* $OpenBSD: sigreturn.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: sigreturn.S,v 1.2 2003/08/07 16:42:05 agc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)sigreturn.s 5.2 (Berkeley) 12/17/90" + */ + +#include "SYS.h" + +/* + * We must preserve the state of the registers as the user has set them up. + */ + +RSYSCALL(sigreturn) diff --git a/lib/libc/arch/sh/sys/sigsuspend.S b/lib/libc/arch/sh/sys/sigsuspend.S new file mode 100644 index 00000000000..24a4e1ebbe7 --- /dev/null +++ b/lib/libc/arch/sh/sys/sigsuspend.S @@ -0,0 +1,55 @@ +/* $OpenBSD: sigsuspend.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: sigsuspend.S,v 1.5 2003/08/07 16:42:21 agc Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)sigsuspend.s 5.2 (Berkeley) 12/17/90 + */ + +#include "SYS.h" + +SYSENTRY(sigsuspend) + mov r4, r0 /* fetch mask arg */ + mov.l @r0, r0 /* indirect to mask arg */ + mov r0, r4 + mov.l LSYS_sigsuspend, r0 + trapa #0x80 + bf err + xor r0, r0 /* shouldn t happen */ + rts + nop +err: + JUMP_CERROR + + .align 2 +LSYS_sigsuspend: + .long SYS_sigsuspend diff --git a/lib/libc/arch/sh/sys/syscall.S b/lib/libc/arch/sh/sys/syscall.S new file mode 100644 index 00000000000..f9c6a47ea2a --- /dev/null +++ b/lib/libc/arch/sh/sys/syscall.S @@ -0,0 +1,40 @@ +/* $OpenBSD: syscall.S,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */ +/* $NetBSD: syscall.S,v 1.6 2006/01/06 01:27:23 uwe Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * from: @(#)syscall.s 5.1 (Berkeley) 4/23/90 + */ + +#include "SYS.h" + +RSYSCALL(syscall) diff --git a/lib/libkvm/kvm_sh.c b/lib/libkvm/kvm_sh.c new file mode 100644 index 00000000000..4940acbb7d3 --- /dev/null +++ b/lib/libkvm/kvm_sh.c @@ -0,0 +1,76 @@ +/* $OpenBSD: kvm_sh.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ + +/* + * Copyright (c) 2002, Miodrag Vallat. + * 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 ``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 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/param.h> + +#include <unistd.h> +#include <stdlib.h> +#include <kvm.h> + +#include <db.h> + +#include "kvm_private.h" + +void +_kvm_freevtop(kvm_t *kd) +{ + if (kd->vmst != NULL) { + free(kd->vmst); + kd->vmst = NULL; + } +} + +int +_kvm_initvtop(kvm_t *kd) +{ + return (0); +} + +int +_kvm_kvatop(kvm_t *kd, u_long va, paddr_t *pa) +{ + int offset; + + if (ISALIVE(kd)) { + _kvm_err(kd, 0, "vatop called in live kernel!"); + return (0); + } + + /* TODO */ + return (0); +} + +/* + * Translate a physical address to a file offset in the crash dump. + */ +off_t +_kvm_pa2off(kvm_t *kd, paddr_t pa) +{ + /* TODO */ + return (0); +} + diff --git a/lib/libpthread/arch/sh/_atomic_lock.c b/lib/libpthread/arch/sh/_atomic_lock.c new file mode 100644 index 00000000000..aab3da2c9d1 --- /dev/null +++ b/lib/libpthread/arch/sh/_atomic_lock.c @@ -0,0 +1,60 @@ +/* $OpenBSD: _atomic_lock.c,v 1.1 2006/10/10 22:07:10 miod Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Gregory McGarry. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 "spinlock.h" + +int +_atomic_lock(volatile _spinlock_lock_t *lock) +{ + _spinlock_lock_t old; + + __asm volatile( + " tas.b %0 \n" + " mov #0, %1 \n" + " rotcl %1 \n" + : "=m" (*lock), "=r" (old)); + + return (old != _SPINLOCK_UNLOCKED); +} + +int +_atomic_is_locked(volatile _spinlock_lock_t *lock) +{ + + return (*lock != _SPINLOCK_UNLOCKED); +} diff --git a/lib/libpthread/arch/sh/uthread_machdep.h b/lib/libpthread/arch/sh/uthread_machdep.h new file mode 100644 index 00000000000..10ddc93492c --- /dev/null +++ b/lib/libpthread/arch/sh/uthread_machdep.h @@ -0,0 +1,4 @@ +/* $OpenBSD: uthread_machdep.h,v 1.1 2006/10/10 22:07:10 miod Exp $ */ + +struct _machdep_state { +}; |