-# $OpenBSD: files.m68k,v 1.6 1997/03/21 00:36:34 niklas Exp $
+# $OpenBSD: files.m68k,v 1.7 1997/03/26 08:23:52 downsj Exp $
# $NetBSD: files.m68k,v 1.16 1997/02/12 01:01:07 gwr Exp $
#
file arch/m68k/m68k/db_disasm.c ddb
file arch/m68k/m68k/ns_cksum.c ns
file arch/m68k/m68k/oc_cksum.s inet
file arch/m68k/m68k/process_machdep.c
+file arch/m68k/m68k/sig_machdep.c
file arch/m68k/m68k/random.s
+file arch/m68k/m68k/copy.s
+file arch/m68k/m68k/bcopy.s
+file arch/m68k/m68k/copypage.s
include "../../../compat/m68k4k/files.m68k4k"
--- /dev/null
+/* $OpenBSD: bcopy.s,v 1.1 1997/03/26 08:23:53 downsj Exp $ */
+/* $NetBSD: bcopy.s,v 1.1 1997/03/17 19:44:33 gwr Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * 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 University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+/*
+ * This is based on: src/lib/libc/arch/m68k/string/bcopy.S
+ * identified as: @(#)bcopy.s 5.1 (Berkeley) 5/12/90
+ */
+
+#include <machine/asm.h>
+
+ .file "bcopy.s"
+ .text
+
+/*
+ * {ov}bcopy(from, to, len)
+ * memcpy(to, from, len)
+ *
+ * Works for counts up to 128K.
+ */
+ALTENTRY(memmove, _memcpy)
+ENTRY(memcpy)
+ movl sp@(12),d0 | get count
+ jeq Lbccpyexit | if zero, return
+ movl sp@(8), a0 | src address
+ movl sp@(4), a1 | dest address
+ jra Lbcdocopy | jump into bcopy
+ALTENTRY(ovbcopy, _bcopy)
+ENTRY(bcopy)
+ movl sp@(12),d0 | get count
+ jeq Lbccpyexit | if zero, return
+ movl sp@(4),a0 | src address
+ movl sp@(8),a1 | dest address
+Lbcdocopy:
+ cmpl a1,a0 | src before dest?
+ jlt Lbccpyback | yes, copy backwards (avoids overlap)
+ movl a0,d1
+ btst #0,d1 | src address odd?
+ jeq Lbccfeven | no, go check dest
+ movb a0@+,a1@+ | yes, copy a byte
+ subql #1,d0 | update count
+ jeq Lbccpyexit | exit if done
+Lbccfeven:
+ movl a1,d1
+ btst #0,d1 | dest address odd?
+ jne Lbccfbyte | yes, must copy by bytes
+ movl d0,d1 | no, get count
+ lsrl #2,d1 | convert to longwords
+ jeq Lbccfbyte | no longwords, copy bytes
+ subql #1,d1 | set up for dbf
+Lbccflloop:
+ movl a0@+,a1@+ | copy longwords
+ dbf d1,Lbccflloop | til done
+ andl #3,d0 | get remaining count
+ jeq Lbccpyexit | done if none
+Lbccfbyte:
+ subql #1,d0 | set up for dbf
+Lbccfbloop:
+ movb a0@+,a1@+ | copy bytes
+ dbf d0,Lbccfbloop | til done
+Lbccpyexit:
+ rts
+Lbccpyback:
+ addl d0,a0 | add count to src
+ addl d0,a1 | add count to dest
+ movl a0,d1
+ btst #0,d1 | src address odd?
+ jeq Lbccbeven | no, go check dest
+ movb a0@-,a1@- | yes, copy a byte
+ subql #1,d0 | update count
+ jeq Lbccpyexit | exit if done
+Lbccbeven:
+ movl a1,d1
+ btst #0,d1 | dest address odd?
+ jne Lbccbbyte | yes, must copy by bytes
+ movl d0,d1 | no, get count
+ lsrl #2,d1 | convert to longwords
+ jeq Lbccbbyte | no longwords, copy bytes
+ subql #1,d1 | set up for dbf
+Lbccblloop:
+ movl a0@-,a1@- | copy longwords
+ dbf d1,Lbccblloop | til done
+ andl #3,d0 | get remaining count
+ jeq Lbccpyexit | done if none
+Lbccbbyte:
+ subql #1,d0 | set up for dbf
+Lbccbbloop:
+ movb a0@-,a1@- | copy bytes
+ dbf d0,Lbccbbloop | til done
+ rts
-/* $OpenBSD: copy.s,v 1.5 1997/02/10 11:11:50 downsj Exp $ */
-/* $NetBSD: copy.s,v 1.25 1997/02/02 06:50:06 thorpej Exp $ */
+/* $OpenBSD: copy.s,v 1.6 1997/03/26 08:23:54 downsj Exp $ */
+/* $NetBSD: copy.s,v 1.26 1997/03/17 19:46:36 gwr Exp $ */
/*-
* Copyright (c) 1994, 1995 Charles Hannum.
* SUCH DAMAGE.
*/
+/*
+ * This file contains the functions for user-space access:
+ * copyin/copyout, fuword/suword, etc.
+ */
+
#include <sys/errno.h>
#include <machine/asm.h>
Lsdone:
clrl a1@(PCB_ONFAULT) | clear fault handler
rts
-
-/*
- * {ov}bcopy(from, to, len)
- * memcpy(to, from, len)
- *
- * Works for counts up to 128K.
- */
-ALTENTRY(memmove, _memcpy)
-ENTRY(memcpy)
- movl sp@(12),d0 | get count
- jeq Lbccpyexit | if zero, return
- movl sp@(8), a0 | src address
- movl sp@(4), a1 | dest address
- jra Lbcdocopy | jump into bcopy
-ALTENTRY(ovbcopy, _bcopy)
-ENTRY(bcopy)
- movl sp@(12),d0 | get count
- jeq Lbccpyexit | if zero, return
- movl sp@(4),a0 | src address
- movl sp@(8),a1 | dest address
-Lbcdocopy:
- cmpl a1,a0 | src before dest?
- jlt Lbccpyback | yes, copy backwards (avoids overlap)
- movl a0,d1
- btst #0,d1 | src address odd?
- jeq Lbccfeven | no, go check dest
- movb a0@+,a1@+ | yes, copy a byte
- subql #1,d0 | update count
- jeq Lbccpyexit | exit if done
-Lbccfeven:
- movl a1,d1
- btst #0,d1 | dest address odd?
- jne Lbccfbyte | yes, must copy by bytes
- movl d0,d1 | no, get count
- lsrl #2,d1 | convert to longwords
- jeq Lbccfbyte | no longwords, copy bytes
- subql #1,d1 | set up for dbf
-Lbccflloop:
- movl a0@+,a1@+ | copy longwords
- dbf d1,Lbccflloop | til done
- andl #3,d0 | get remaining count
- jeq Lbccpyexit | done if none
-Lbccfbyte:
- subql #1,d0 | set up for dbf
-Lbccfbloop:
- movb a0@+,a1@+ | copy bytes
- dbf d0,Lbccfbloop | til done
-Lbccpyexit:
- rts
-Lbccpyback:
- addl d0,a0 | add count to src
- addl d0,a1 | add count to dest
- movl a0,d1
- btst #0,d1 | src address odd?
- jeq Lbccbeven | no, go check dest
- movb a0@-,a1@- | yes, copy a byte
- subql #1,d0 | update count
- jeq Lbccpyexit | exit if done
-Lbccbeven:
- movl a1,d1
- btst #0,d1 | dest address odd?
- jne Lbccbbyte | yes, must copy by bytes
- movl d0,d1 | no, get count
- lsrl #2,d1 | convert to longwords
- jeq Lbccbbyte | no longwords, copy bytes
- subql #1,d1 | set up for dbf
-Lbccblloop:
- movl a0@-,a1@- | copy longwords
- dbf d1,Lbccblloop | til done
- andl #3,d0 | get remaining count
- jeq Lbccpyexit | done if none
-Lbccbbyte:
- subql #1,d0 | set up for dbf
-Lbccbbloop:
- movb a0@-,a1@- | copy bytes
- dbf d0,Lbccbbloop | til done
- rts
-
-/*
- * copypage(fromaddr, toaddr)
- *
- * Optimized version of bcopy for a single page-aligned NBPG byte copy.
- */
-ENTRY(copypage)
- movl sp@(4),a0 | source address
- movl sp@(8),a1 | destiniation address
- movl #NBPG/32-1,d0 | number of 32 byte chunks - 1
-#if defined(M68040) || defined(M68060)
-#if defined(M68020) || defined(M68030)
- cmpl #CPU_68030,_cputype | 68030 or less?
- jle Lmlloop | yes, use movl
-#endif /* M68020 || M68030 */
-Lm16loop:
- .long 0xf6209000 | move16 a0@+,a1@+
- .long 0xf6209000 | move16 a0@+,a1@+
- dbf d0,Lm16loop
- rts
-#endif /* M68040 || M68060 */
-#if defined(M68020) || defined(M68030)
-Lmlloop:
- movl a0@+,a1@+
- movl a0@+,a1@+
- movl a0@+,a1@+
- movl a0@+,a1@+
- movl a0@+,a1@+
- movl a0@+,a1@+
- movl a0@+,a1@+
- movl a0@+,a1@+
- dbf d0,Lmlloop
-#endif /* M68020 || M68030 */
- rts
-
-/*
- * zeropage(addr)
- *
- * Optimized version of bzero for a single page-aligned NBPG byte zero.
- */
-ENTRY(zeropage)
- movl sp@(4),a0 | dest address
- movl #NBPG/32-1,d0 | number of 32 byte chunks - 1
- movq #0,d1
-Lzloop:
- movl d1,a0@+
- movl d1,a0@+
- movl d1,a0@+
- movl d1,a0@+
- movl d1,a0@+
- movl d1,a0@+
- movl d1,a0@+
- movl d1,a0@+
- dbf d0,Lzloop
- rts
--- /dev/null
+/* $OpenBSD: copypage.s,v 1.1 1997/03/26 08:23:54 downsj Exp $ */
+/* $NetBSD: copypage.s,v 1.1 1997/03/17 19:44:35 gwr Exp $ */
+
+/*-
+ * Copyright (c) 1997 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by J.T. Conklin
+ *
+ * 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.
+ */
+
+/*
+ * Optimized functions for copying/clearing a whole page.
+ */
+
+#include <machine/asm.h>
+#include "assym.h"
+
+ .file "copypage.s"
+ .text
+
+/*
+ * copypage040(fromaddr, toaddr)
+ *
+ * Optimized version of bcopy for a single page-aligned NBPG byte copy,
+ * using instuctions only available on the mc68040 and later.
+ */
+#if defined(M68040) || defined(M68060)
+ENTRY(copypage040)
+ movl sp@(4),a0 | source address
+ movl sp@(8),a1 | destiniation address
+ movl #NBPG/32-1,d0 | number of 32 byte chunks - 1
+Lm16loop:
+ .long 0xf6209000 | move16 a0@+,a1@+
+ .long 0xf6209000 | move16 a0@+,a1@+
+ dbf d0,Lm16loop
+ rts
+#endif /* M68040 || M68060 */
+
+/*
+ * copypage(fromaddr, toaddr)
+ *
+ * Optimized version of bcopy for a single page-aligned NBPG byte copy.
+ */
+ENTRY(copypage)
+ movl sp@(4),a0 | source address
+ movl sp@(8),a1 | destiniation address
+ movl #NBPG/32-1,d0 | number of 32 byte chunks - 1
+Lmlloop:
+ movl a0@+,a1@+
+ movl a0@+,a1@+
+ movl a0@+,a1@+
+ movl a0@+,a1@+
+ movl a0@+,a1@+
+ movl a0@+,a1@+
+ movl a0@+,a1@+
+ movl a0@+,a1@+
+ dbf d0,Lmlloop
+ rts
+
+/*
+ * zeropage(addr)
+ *
+ * Optimized version of bzero for a single page-aligned NBPG byte zero.
+ */
+ENTRY(zeropage)
+ movl sp@(4),a0 | dest address
+ movl #NBPG/32-1,d0 | number of 32 byte chunks - 1
+ movq #0,d1
+Lzloop:
+ movl d1,a0@+
+ movl d1,a0@+
+ movl d1,a0@+
+ movl d1,a0@+
+ movl d1,a0@+
+ movl d1,a0@+
+ movl d1,a0@+
+ movl d1,a0@+
+ dbf d0,Lzloop
+ rts
--- /dev/null
+/* $OpenBSD: sig_machdep.c,v 1.1 1997/03/26 08:23:55 downsj Exp $ */
+/* $NetBSD: sig_machdep.c,v 1.2 1997/03/17 19:03:11 gwr Exp $ */
+
+/*
+ * Copyright (c) 1997 Theo de Raadt
+ *
+ * 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 under OpenBSD by
+ * Theo de Raadt.
+ * 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.
+ *
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1982, 1986, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * 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 University of
+ * California, Berkeley and its contributors.
+ * 4. 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: Utah Hdr: machdep.c 1.74 92/12/20
+ * from: @(#)machdep.c 8.10 (Berkeley) 4/20/94
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/user.h>
+#include <sys/exec.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <sys/signal.h>
+#include <sys/signalvar.h>
+#include <sys/malloc.h>
+#include <sys/buf.h>
+
+#include <sys/syscallargs.h>
+
+#include <machine/cpu.h>
+#include <machine/reg.h>
+
+extern int fputype;
+extern short exframesize[];
+void m68881_save __P((struct fpframe *));
+void m68881_restore __P((struct fpframe *));
+
+#define SS_RTEFRAME 1
+#define SS_FPSTATE 2
+#define SS_USERREGS 4
+
+struct sigstate {
+ int ss_flags; /* which of the following are valid */
+ struct frame ss_frame; /* original exception frame */
+ struct fpframe ss_fpstate; /* 68881/68882 state info */
+};
+
+/*
+ * WARNING: code in locore.s assumes the layout shown for sf_signum
+ * thru sf_handler so... don't screw with them!
+ */
+struct sigframe {
+ int sf_signum; /* signo for handler */
+ siginfo_t *sf_sip; /* pointer to siginfo_t */
+ struct sigcontext *sf_scp; /* context ptr for handler */
+ sig_t sf_handler; /* handler addr for u_sigc */
+ struct sigstate sf_state; /* state of the hardware */
+ struct sigcontext sf_sc; /* actual context */
+ siginfo_t sf_si;
+};
+
+#ifdef DEBUG
+int sigdebug = 0;
+int sigpid = 0;
+#define SDB_FOLLOW 0x01
+#define SDB_KSTACK 0x02
+#define SDB_FPSTATE 0x04
+#endif
+
+/*
+ * Send an interrupt to process.
+ */
+void
+sendsig(catcher, sig, mask, code, type, val)
+ sig_t catcher;
+ int sig, mask;
+ u_long code;
+ int type;
+ union sigval val;
+{
+ register struct proc *p = curproc;
+ register struct sigframe *fp, *kfp;
+ register struct frame *frame;
+ register struct sigacts *psp = p->p_sigacts;
+ register short ft;
+ int oonstack, fsize;
+ extern char sigcode[], esigcode[];
+
+ frame = (struct frame *)p->p_md.md_regs;
+ ft = frame->f_format;
+ oonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
+
+ /*
+ * Allocate and validate space for the signal handler
+ * context. Note that if the stack is in P0 space, the
+ * call to grow() is a nop, and the useracc() check
+ * will fail if the process has not already allocated
+ * the space with a `brk'.
+ */
+ fsize = sizeof(struct sigframe);
+ if ((psp->ps_flags & SAS_ALTSTACK) && !oonstack &&
+ (psp->ps_sigonstack & sigmask(sig))) {
+ fp = (struct sigframe *)(psp->ps_sigstk.ss_sp +
+ psp->ps_sigstk.ss_size - fsize);
+ psp->ps_sigstk.ss_flags |= SS_ONSTACK;
+ } else
+ fp = (struct sigframe *)(frame->f_regs[SP] - fsize);
+ if ((unsigned)fp <= USRSTACK - ctob(p->p_vmspace->vm_ssize))
+ (void)grow(p, (unsigned)fp);
+#ifdef DEBUG
+ if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
+ printf("sendsig(%d): sig %d ssp %x usp %x scp %x ft %d\n",
+ p->p_pid, sig, &oonstack, fp, &fp->sf_sc, ft);
+#endif
+ if (useracc((caddr_t)fp, fsize, B_WRITE) == 0) {
+#ifdef DEBUG
+ if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
+ printf("sendsig(%d): useracc failed on sig %d\n",
+ p->p_pid, sig);
+#endif
+ /*
+ * Process has trashed its stack; give it an illegal
+ * instruction to halt it in its tracks.
+ */
+ SIGACTION(p, SIGILL) = SIG_DFL;
+ sig = sigmask(SIGILL);
+ p->p_sigignore &= ~sig;
+ p->p_sigcatch &= ~sig;
+ p->p_sigmask &= ~sig;
+ psignal(p, SIGILL);
+ return;
+ }
+ kfp = (struct sigframe *)malloc((u_long)fsize, M_TEMP, M_WAITOK);
+ /*
+ * Build the argument list for the signal handler.
+ */
+ kfp->sf_signum = sig;
+ kfp->sf_sip = NULL;
+ kfp->sf_scp = &fp->sf_sc;
+ kfp->sf_handler = catcher;
+
+ /*
+ * Save necessary hardware state. Currently this includes:
+ * - general registers
+ * - original exception frame (if not a "normal" frame)
+ * - FP coprocessor state
+ */
+ kfp->sf_state.ss_flags = SS_USERREGS;
+ bcopy((caddr_t)frame->f_regs,
+ (caddr_t)kfp->sf_state.ss_frame.f_regs, sizeof frame->f_regs);
+ if (ft >= FMT7) {
+#ifdef DEBUG
+ if (ft > 15 || exframesize[ft] < 0)
+ panic("sendsig: bogus frame type");
+#endif
+ kfp->sf_state.ss_flags |= SS_RTEFRAME;
+ kfp->sf_state.ss_frame.f_format = frame->f_format;
+ kfp->sf_state.ss_frame.f_vector = frame->f_vector;
+ bcopy((caddr_t)&frame->F_u,
+ (caddr_t)&kfp->sf_state.ss_frame.F_u, exframesize[ft]);
+ /*
+ * Leave an indicator that we need to clean up the kernel
+ * stack. We do this by setting the "pad word" above the
+ * hardware stack frame to the amount the stack must be
+ * adjusted by.
+ *
+ * N.B. we increment rather than just set f_stackadj in
+ * case we are called from syscall when processing a
+ * sigreturn. In that case, f_stackadj may be non-zero.
+ */
+ frame->f_stackadj += exframesize[ft];
+ frame->f_format = frame->f_vector = 0;
+#ifdef DEBUG
+ if (sigdebug & SDB_FOLLOW)
+ printf("sendsig(%d): copy out %d of frame %d\n",
+ p->p_pid, exframesize[ft], ft);
+#endif
+ }
+
+ if (fputype) {
+ kfp->sf_state.ss_flags |= SS_FPSTATE;
+ m68881_save(&kfp->sf_state.ss_fpstate);
+ }
+#ifdef DEBUG
+ if ((sigdebug & SDB_FPSTATE) && *(char *)&kfp->sf_state.ss_fpstate)
+ printf("sendsig(%d): copy out FP state (%x) to %x\n",
+ p->p_pid, *(u_int *)&kfp->sf_state.ss_fpstate,
+ &kfp->sf_state.ss_fpstate);
+#endif
+ /*
+ * Build the signal context to be used by sigreturn.
+ */
+ kfp->sf_sc.sc_onstack = oonstack;
+ kfp->sf_sc.sc_mask = mask;
+ kfp->sf_sc.sc_sp = frame->f_regs[SP];
+ kfp->sf_sc.sc_fp = frame->f_regs[A6];
+ kfp->sf_sc.sc_ap = (int)&fp->sf_state;
+ kfp->sf_sc.sc_pc = frame->f_pc;
+ kfp->sf_sc.sc_ps = frame->f_sr;
+
+ if (psp->ps_siginfo & sigmask(sig)) {
+ kfp->sf_sip = &fp->sf_si;
+ initsiginfo(&kfp->sf_si, sig, code, type, val);
+ }
+
+ /* XXX do not copy out siginfo if not needed */
+ (void) copyout((caddr_t)kfp, (caddr_t)fp, fsize);
+ frame->f_regs[SP] = (int)fp;
+#ifdef DEBUG
+ if (sigdebug & SDB_FOLLOW)
+ printf("sendsig(%d): sig %d scp %x fp %x sc_sp %x sc_ap %x\n",
+ p->p_pid, sig, kfp->sf_scp, fp,
+ kfp->sf_sc.sc_sp, kfp->sf_sc.sc_ap);
+#endif
+ /*
+ * Signal trampoline code is at base of user stack.
+ */
+ frame->f_pc = (int)PS_STRINGS - (esigcode - sigcode);
+#ifdef DEBUG
+ if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
+ printf("sendsig(%d): sig %d returns\n",
+ p->p_pid, sig);
+#endif
+ free((caddr_t)kfp, M_TEMP);
+}
+
+/*
+ * System call to cleanup state after a signal
+ * has been taken. Reset signal mask and
+ * stack state from context left by sendsig (above).
+ * Return to previous pc and psl as specified by
+ * context left by sendsig. Check carefully to
+ * make sure that the user has not modified the
+ * psl to gain improper priviledges or to cause
+ * a machine fault.
+ */
+int
+sys_sigreturn(p, v, retval)
+ struct proc *p;
+ void *v;
+ register_t *retval;
+{
+ struct sys_sigreturn_args /* {
+ syscallarg(struct sigcontext *) sigcntxp;
+ } */ *uap = v;
+ register struct sigcontext *scp;
+ register struct frame *frame;
+ register int rf;
+ struct sigcontext tsigc;
+ struct sigstate tstate;
+ int flags;
+
+ scp = SCARG(uap, sigcntxp);
+#ifdef DEBUG
+ if (sigdebug & SDB_FOLLOW)
+ printf("sigreturn: pid %d, scp %x\n", p->p_pid, scp);
+#endif
+ if ((int)scp & 1)
+ return (EINVAL);
+
+ /*
+ * Test and fetch the context structure.
+ * We grab it all at once for speed.
+ */
+ if (useracc((caddr_t)scp, sizeof (*scp), B_WRITE) == 0 ||
+ copyin((caddr_t)scp, (caddr_t)&tsigc, sizeof tsigc))
+ return (EINVAL);
+ scp = &tsigc;
+ if ((scp->sc_ps & (PSL_MBZ|PSL_IPL|PSL_S)) != 0)
+ return (EINVAL);
+ /*
+ * Restore the user supplied information
+ */
+ if (scp->sc_onstack & 1)
+ p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
+ else
+ p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
+ p->p_sigmask = scp->sc_mask &~ sigcantmask;
+ frame = (struct frame *) p->p_md.md_regs;
+ frame->f_regs[SP] = scp->sc_sp;
+ frame->f_regs[A6] = scp->sc_fp;
+ frame->f_pc = scp->sc_pc;
+ frame->f_sr = scp->sc_ps;
+
+ /*
+ * Grab pointer to hardware state information.
+ * If zero, the user is probably doing a longjmp.
+ */
+ if ((rf = scp->sc_ap) == 0)
+ return (EJUSTRETURN);
+ /*
+ * See if there is anything to do before we go to the
+ * expense of copying in close to 1/2K of data
+ */
+ flags = fuword((caddr_t)rf);
+#ifdef DEBUG
+ if (sigdebug & SDB_FOLLOW)
+ printf("sigreturn(%d): sc_ap %x flags %x\n",
+ p->p_pid, rf, flags);
+#endif
+ /*
+ * fuword failed (bogus sc_ap value).
+ */
+ if (flags == -1)
+ return (EINVAL);
+ if (flags == 0 || copyin((caddr_t)rf, (caddr_t)&tstate, sizeof tstate))
+ return (EJUSTRETURN);
+#ifdef DEBUG
+ if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
+ printf("sigreturn(%d): ssp %x usp %x scp %x ft %d\n",
+ p->p_pid, &flags, scp->sc_sp, SCARG(uap, sigcntxp),
+ (flags&SS_RTEFRAME) ? tstate.ss_frame.f_format : -1);
+#endif
+ /*
+ * Restore most of the users registers except for A6 and SP
+ * which were handled above.
+ */
+ if (flags & SS_USERREGS)
+ bcopy((caddr_t)tstate.ss_frame.f_regs,
+ (caddr_t)frame->f_regs, sizeof(frame->f_regs)-2*NBPW);
+ /*
+ * Restore long stack frames. Note that we do not copy
+ * back the saved SR or PC, they were picked up above from
+ * the sigcontext structure.
+ */
+ if (flags & SS_RTEFRAME) {
+ register int sz;
+
+ /* grab frame type and validate */
+ sz = tstate.ss_frame.f_format;
+ if (sz > 15 || (sz = exframesize[sz]) < 0)
+ return (EINVAL);
+ frame->f_stackadj -= sz;
+ frame->f_format = tstate.ss_frame.f_format;
+ frame->f_vector = tstate.ss_frame.f_vector;
+ bcopy((caddr_t)&tstate.ss_frame.F_u, (caddr_t)&frame->F_u, sz);
+#ifdef DEBUG
+ if (sigdebug & SDB_FOLLOW)
+ printf("sigreturn(%d): copy in %d of frame type %d\n",
+ p->p_pid, sz, tstate.ss_frame.f_format);
+#endif
+ }
+ /*
+ * Finally we restore the original FP context
+ */
+ if (fputype && (flags & SS_FPSTATE))
+ m68881_restore(&tstate.ss_fpstate);
+#ifdef DEBUG
+ if ((sigdebug & SDB_FPSTATE) && *(char *)&tstate.ss_fpstate)
+ printf("sigreturn(%d): copied in FP state (%x) at %x\n",
+ p->p_pid, *(u_int *)&tstate.ss_fpstate,
+ &tstate.ss_fpstate);
+ if ((sigdebug & SDB_FOLLOW) ||
+ ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid))
+ printf("sigreturn(%d): returns\n", p->p_pid);
+#endif
+ return (EJUSTRETURN);
+}
--- /dev/null
+/* $OpenBSD: support.s,v 1.1 1997/03/26 08:23:55 downsj Exp $ */
+/* $NetBSD: support.s,v 1.1 1997/03/16 10:47:33 thorpej Exp $ */
+
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1980, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * 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 University of
+ * California, Berkeley and its contributors.
+ * 4. 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: Utah $Hdr: locore.s 1.66 92/12/22$
+ *
+ * @(#)locore.s 8.6 (Berkeley) 5/27/94
+ */
+
+/*
+ * Miscellaneous support routines common to all m68k ports.
+ */
+
+/*
+ * NOTICE: This is not a standalone file. To use it, #include it in
+ * your port's locore.s, like so:
+ *
+ * #include <m68k/m68k/support.s>
+ */
+
+/*
+ * non-local gotos
+ */
+ENTRY(setjmp)
+ movl sp@(4),a0 | savearea pointer
+ moveml #0xFCFC,a0@ | save d2-d7/a2-a7
+ movl sp@,a0@(48) | and return address
+ moveq #0,d0 | return 0
+ rts
+
+ENTRY(longjmp)
+ movl sp@(4),a0
+ moveml a0@+,#0xFCFC
+ movl a0@,sp@
+ moveq #1,d0
+ rts
+
+/*
+ * the queue functions
+ */
+ENTRY(_insque)
+ movw sr,d0
+ movw #PSL_HIGHIPL,sr | atomic
+ movl sp@(8),a0 | where to insert (after)
+ movl sp@(4),a1 | element to insert (e)
+ movl a0@,a1@ | e->next = after->next
+ movl a0,a1@(4) | e->prev = after
+ movl a1,a0@ | after->next = e
+ movl a1@,a0
+ movl a1,a0@(4) | e->next->prev = e
+ movw d0,sr
+ rts
+
+ENTRY(_remque)
+ movw sr,d0
+ movw #PSL_HIGHIPL,sr | atomic
+ movl sp@(4),a0 | element to remove (e)
+ movl a0@,a1
+ movl a0@(4),a0
+ movl a0,a1@(4) | e->next->prev = e->prev
+ movl a1,a0@ | e->prev->next = e->next
+ movw d0,sr
+ rts