From 2726c9bbeb32ad40d154f05e11db556246f38635 Mon Sep 17 00:00:00 2001 From: kleink Date: Tue, 21 Jan 2003 20:50:43 +0000 Subject: [PATCH] Add ns32k ucontext kernel portions. Not entirely updated for the LWP universe (like the rest of the port), but presumed working. --- sys/arch/pc532/include/Makefile | 4 +- sys/arch/pc532/include/mcontext.h | 77 +++++++++++++++++++++++++++++++ sys/arch/pc532/pc532/machdep.c | 70 +++++++++++++++++++++++++++- 3 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 sys/arch/pc532/include/mcontext.h diff --git a/sys/arch/pc532/include/Makefile b/sys/arch/pc532/include/Makefile index 071881169436..73806eb374ce 100644 --- a/sys/arch/pc532/include/Makefile +++ b/sys/arch/pc532/include/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.16 2002/11/26 23:30:21 lukem Exp $ +# $NetBSD: Makefile,v 1.17 2003/01/21 20:50:43 kleink Exp $ INCSDIR= /usr/include/pc532 @@ -14,7 +14,7 @@ INCS= ansi.h aout_machdep.h asm.h autoconf.h \ jmpbuf.h \ kcore.h \ limits.h lock.h \ - math.h mtpr.h \ + math.h mcontext.h mtpr.h \ param.h pcb.h pmap.h pmc.h proc.h profile.h psl.h pte.h ptrace.h \ reg.h \ setjmp.h signal.h stdarg.h \ diff --git a/sys/arch/pc532/include/mcontext.h b/sys/arch/pc532/include/mcontext.h new file mode 100644 index 000000000000..0505fd0e83ba --- /dev/null +++ b/sys/arch/pc532/include/mcontext.h @@ -0,0 +1,77 @@ +/* $NetBSD: mcontext.h,v 1.1 2003/01/21 20:50:43 kleink Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Klaus Klein. + * + * 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. + */ + +#ifndef _NS32K_MCONTEXT_H_ +#define _NS32K_MCONTEXT_H_ + +/* + * Layout of mcontext_t for the ns32k architecture. Lacking an SVR4 + * ABI definition, reuse the `struct reg' layout for simplicity. + */ + +#define _NGREG 13 +typedef int __greg_t; +typedef __greg_t __gregset_t[_NGREG]; + +#define _REG_R7 0 +#define _REG_R6 1 +#define _REG_R5 2 +#define _REG_R4 3 +#define _REG_R3 4 +#define _REG_R2 5 +#define _REG_R1 6 +#define _REG_R0 7 +#define _REG_SP 8 +#define _REG_SB 9 +#define _REG_FP 10 +#define _REG_PC 11 +#define _REG_PS 12 + +typedef struct { + int __fpr_psr; + double __fpr_regs[8]; +} __fpregset_t; + +typedef struct { + __gregset_t __gregs; + __fpregset_t __fpregs; +} mcontext_t; + +#define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP]) + +#endif /* !_NS32K_MCONTEXT_H_ */ diff --git a/sys/arch/pc532/pc532/machdep.c b/sys/arch/pc532/pc532/machdep.c index cb8210c50dd9..9116c13e8658 100644 --- a/sys/arch/pc532/pc532/machdep.c +++ b/sys/arch/pc532/pc532/machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.135 2002/12/06 01:55:55 simonb Exp $ */ +/* $NetBSD: machdep.c,v 1.136 2003/01/21 20:50:43 kleink Exp $ */ /*- * Copyright (c) 1996 Matthias Pfaller. @@ -66,6 +66,7 @@ #include #include #include +#include #include @@ -485,6 +486,73 @@ sys___sigreturn14(p, v, retval) return(EJUSTRETURN); } +void +cpu_getmcontext(l, mcp, flags) + struct lwp *l; + mcontext_t *mcp; + unsigned int *flags; +{ + + (void)memcpy(mcp->__gregs, l->l_md.md_regs, sizeof (mcp->__gregs)); + *flags |= _UC_CPU; + +#ifdef NS381 + { + /* + * XXX Unaware of LWP universe. + */ + extern struct proc *fpu_proc; + + /* If we're the FPU owner, dump its state to the PCB first. */ + if (fpu_proc == p) + save_fpu_context(&l->l_addr->u_pcb); + + mcp->__fpregs.__fpr_psr = l->l_addr->u_pcb.pcb_fsr; + (void)memcpy(mcp->__fpregs.__fpr_regs, + l->l_addr->u_pcb.pcb_freg, + sizeof (mcp->__fpregs.__fpr_regs)); + *flags |= _UC_FPU; + } +#endif +} + +int +cpu_setmcontext(l, mcp, flags) + struct lwp *l; + const mcontext_t *mcp; + unsigned int flags; +{ + struct reg *regs = l->l_md.md_regs; + + /* Restore CPU context, if any. */ + if (flags & _UC_CPU) { + /* Check for security violations. */ + if (((mcp.__gregs[_REG_PS] ^ regs->r_psr) & PSL_USERSTATIC) + != 0) + return (EINVAL); + (void)memcpy(l->l_md.md_regs, mcp->__gregs, + sizeof (l->l_md.md_regs)); + } + +#ifdef NS381 + /* Restore FPU context, if any. */ + /* + * XXX Unaware of LWP universe. + */ + if (flags & _UC_FPU) { + l->l_addr->u_pcb.pcb_fsr = mcp->__fpregs.__fpr_psr; + (void)memcpy(l->l_addr->u_pcb.pcb_freg, + mcp->__fpregs.__fpr_regs, + sizeof (l->l_addr->u_pcb.pcb_freg)); + /* If we're the FPU owner, force a reload. */ + if (fpu_proc == p) + restore_fpu_context(&l->l_addr->u_pcb); + } +#endif + + return (0); +} + int waittime = -1; static struct switchframe dump_sf;