Author: nwhitehorn
Date: Sun Jan 10 16:42:14 2016
New Revision: 293636
URL: https://svnweb.freebsd.org/changeset/base/293636

Log:
  Use setjmp() instead of the identical-except-for-having-a-wrong-prototype
  setfault() when testing for faults. This should also help the compiler
  do the right thing with this complicated-to-optimize function.

Modified:
  head/sys/powerpc/include/pcb.h
  head/sys/powerpc/include/setjmp.h
  head/sys/powerpc/ofw/rtas.c
  head/sys/powerpc/powermac/grackle.c
  head/sys/powerpc/powerpc/copyinout.c
  head/sys/powerpc/powerpc/mp_machdep.c
  head/sys/powerpc/powerpc/trap.c

Modified: head/sys/powerpc/include/pcb.h
==============================================================================
--- head/sys/powerpc/include/pcb.h      Sun Jan 10 16:31:28 2016        
(r293635)
+++ head/sys/powerpc/include/pcb.h      Sun Jan 10 16:42:14 2016        
(r293636)
@@ -35,7 +35,7 @@
 #ifndef _MACHINE_PCB_H_
 #define        _MACHINE_PCB_H_
 
-typedef register_t faultbuf[25];
+#include <machine/setjmp.h>
 
 struct pcb {
        register_t      pcb_context[20];        /* non-volatile r14-r31 */
@@ -44,7 +44,7 @@ struct pcb {
        register_t      pcb_toc;                /* toc pointer */
        register_t      pcb_lr;                 /* link register */
        struct          pmap *pcb_pm;           /* pmap of our vmspace */
-       faultbuf        *pcb_onfault;           /* For use during
+       jmp_buf         *pcb_onfault;           /* For use during
                                                    copyin/copyout */
        int             pcb_flags;
 #define        PCB_FPU         1       /* Process uses FPU */

Modified: head/sys/powerpc/include/setjmp.h
==============================================================================
--- head/sys/powerpc/include/setjmp.h   Sun Jan 10 16:31:28 2016        
(r293635)
+++ head/sys/powerpc/include/setjmp.h   Sun Jan 10 16:42:14 2016        
(r293636)
@@ -8,7 +8,11 @@
 
 #include <sys/cdefs.h>
 
+#ifdef _KERNEL
+#define        _JBLEN  25      /* Kernel doesn't save FP and Altivec regs */
+#else
 #define        _JBLEN  100
+#endif
 
 /*
  * jmp_buf and sigjmp_buf are encapsulated in different structs to force

Modified: head/sys/powerpc/ofw/rtas.c
==============================================================================
--- head/sys/powerpc/ofw/rtas.c Sun Jan 10 16:31:28 2016        (r293635)
+++ head/sys/powerpc/ofw/rtas.c Sun Jan 10 16:42:14 2016        (r293636)
@@ -62,8 +62,6 @@ int rtascall(vm_offset_t callbuffer, uin
 extern uintptr_t       rtas_entry;
 extern register_t      rtasmsr;
 
-int setfault(faultbuf);             /* defined in locore.S */
-
 /*
  * After the VM is up, allocate RTAS memory and instantiate it
  */
@@ -203,7 +201,7 @@ int
 rtas_call_method(cell_t token, int nargs, int nreturns, ...)
 {
        vm_offset_t argsptr;
-       faultbuf env, *oldfaultbuf;
+       jmp_buf env, *oldfaultbuf;
        va_list ap;
        struct {
                cell_t token;
@@ -233,7 +231,8 @@ rtas_call_method(cell_t token, int nargs
        /* Get rid of any stale machine checks that have been waiting.  */
        __asm __volatile ("sync; isync");
        oldfaultbuf = curthread->td_pcb->pcb_onfault;
-        if (!setfault(env)) {
+       curthread->td_pcb->pcb_onfault = &env;
+       if (!setjmp(env)) {
                __asm __volatile ("sync");
                result = rtascall(argsptr, rtas_private_data);
                __asm __volatile ("sync; isync");

Modified: head/sys/powerpc/powermac/grackle.c
==============================================================================
--- head/sys/powerpc/powermac/grackle.c Sun Jan 10 16:31:28 2016        
(r293635)
+++ head/sys/powerpc/powermac/grackle.c Sun Jan 10 16:42:14 2016        
(r293636)
@@ -82,8 +82,6 @@ static int            grackle_enable_config(struct
 static void            grackle_disable_config(struct grackle_softc *);
 static int             badaddr(void *, size_t);
 
-int                    setfault(faultbuf);     /* defined in locore.S */
-
 /*
  * Driver methods.
  */
@@ -244,7 +242,7 @@ static int
 badaddr(void *addr, size_t size)
 {
        struct thread   *td;
-       faultbuf        env, *oldfaultbuf;
+       jmp_buf         env, *oldfaultbuf;
        int             x;
 
        /* Get rid of any stale machine checks that have been waiting.  */
@@ -253,7 +251,8 @@ badaddr(void *addr, size_t size)
        td = curthread;
 
        oldfaultbuf = td->td_pcb->pcb_onfault;
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = oldfaultbuf;
                __asm __volatile ("sync");
                return 1;

Modified: head/sys/powerpc/powerpc/copyinout.c
==============================================================================
--- head/sys/powerpc/powerpc/copyinout.c        Sun Jan 10 16:31:28 2016        
(r293635)
+++ head/sys/powerpc/powerpc/copyinout.c        Sun Jan 10 16:42:14 2016        
(r293636)
@@ -71,8 +71,6 @@ __FBSDID("$FreeBSD$");
 #include <machine/slb.h>
 #include <machine/vmparam.h>
 
-int    setfault(faultbuf);     /* defined in locore.S */
-
 #ifdef AIM
 /*
  * Makes sure that the right segment of userspace is mapped in.
@@ -176,7 +174,7 @@ copyout(const void *kaddr, void *udaddr,
 {
        struct          thread *td;
        pmap_t          pm;
-       faultbuf        env;
+       jmp_buf         env;
        const char      *kp;
        char            *up, *p;
        size_t          l;
@@ -184,7 +182,8 @@ copyout(const void *kaddr, void *udaddr,
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (EFAULT);
        }
@@ -214,7 +213,7 @@ copyin(const void *udaddr, void *kaddr, 
 {
        struct          thread *td;
        pmap_t          pm;
-       faultbuf        env;
+       jmp_buf         env;
        const char      *up;
        char            *kp, *p;
        size_t          l;
@@ -222,7 +221,8 @@ copyin(const void *udaddr, void *kaddr, 
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (EFAULT);
        }
@@ -285,13 +285,14 @@ subyte(volatile void *addr, int byte)
 {
        struct          thread *td;
        pmap_t          pm;
-       faultbuf        env;
+       jmp_buf         env;
        char            *p;
 
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (-1);
        }
@@ -313,13 +314,14 @@ suword32(volatile void *addr, int word)
 {
        struct          thread *td;
        pmap_t          pm;
-       faultbuf        env;
+       jmp_buf         env;
        int             *p;
 
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (-1);
        }
@@ -341,13 +343,14 @@ suword(volatile void *addr, long word)
 {
        struct          thread *td;
        pmap_t          pm;
-       faultbuf        env;
+       jmp_buf         env;
        long            *p;
 
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (-1);
        }
@@ -382,14 +385,15 @@ fubyte(volatile const void *addr)
 {
        struct          thread *td;
        pmap_t          pm;
-       faultbuf        env;
+       jmp_buf         env;
        u_char          *p;
        int             val;
 
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (-1);
        }
@@ -410,13 +414,14 @@ fuword16(volatile const void *addr)
 {
        struct          thread *td;
        pmap_t          pm;
-       faultbuf        env;
+       jmp_buf         env;
        uint16_t        *p, val;
 
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (-1);
        }
@@ -437,13 +442,14 @@ fueword32(volatile const void *addr, int
 {
        struct          thread *td;
        pmap_t          pm;
-       faultbuf        env;
+       jmp_buf         env;
        int32_t         *p;
 
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (-1);
        }
@@ -465,13 +471,14 @@ fueword64(volatile const void *addr, int
 {
        struct          thread *td;
        pmap_t          pm;
-       faultbuf        env;
+       jmp_buf         env;
        int64_t         *p;
 
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (-1);
        }
@@ -493,13 +500,14 @@ fueword(volatile const void *addr, long 
 {
        struct          thread *td;
        pmap_t          pm;
-       faultbuf        env;
+       jmp_buf         env;
        long            *p;
 
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (-1);
        }
@@ -521,13 +529,14 @@ casueword32(volatile uint32_t *addr, uin
 {
        struct thread *td;
        pmap_t pm;
-       faultbuf env;
+       jmp_buf         env;
        uint32_t *p, val;
 
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (-1);
        }
@@ -572,13 +581,14 @@ casueword(volatile u_long *addr, u_long 
 {
        struct thread *td;
        pmap_t pm;
-       faultbuf env;
+       jmp_buf         env;
        u_long *p, val;
 
        td = curthread;
        pm = &td->td_proc->p_vmspace->vm_pmap;
 
-       if (setfault(env)) {
+       td->td_pcb->pcb_onfault = &env;
+       if (setjmp(env)) {
                td->td_pcb->pcb_onfault = NULL;
                return (-1);
        }

Modified: head/sys/powerpc/powerpc/mp_machdep.c
==============================================================================
--- head/sys/powerpc/powerpc/mp_machdep.c       Sun Jan 10 16:31:28 2016        
(r293635)
+++ head/sys/powerpc/powerpc/mp_machdep.c       Sun Jan 10 16:42:14 2016        
(r293636)
@@ -67,7 +67,6 @@ volatile static u_quad_t ap_timebase;
 static u_int ipi_msg_cnt[32];
 static struct mtx ap_boot_mtx;
 struct pcb stoppcbs[MAXCPU];
-int longfault(faultbuf, int);
 
 void
 machdep_ap_bootstrap(void)

Modified: head/sys/powerpc/powerpc/trap.c
==============================================================================
--- head/sys/powerpc/powerpc/trap.c     Sun Jan 10 16:31:28 2016        
(r293635)
+++ head/sys/powerpc/powerpc/trap.c     Sun Jan 10 16:42:14 2016        
(r293636)
@@ -74,11 +74,12 @@ __FBSDID("$FreeBSD$");
 #include <machine/spr.h>
 #include <machine/sr.h>
 
-#define        FAULTBUF_LR     0
+/* Below matches setjmp.S */
+#define        FAULTBUF_LR     21
 #define        FAULTBUF_R1     1
 #define        FAULTBUF_R2     2
-#define        FAULTBUF_CR     3
-#define        FAULTBUF_R13    4
+#define        FAULTBUF_CR     22
+#define        FAULTBUF_R14    3
 
 static void    trap_fatal(struct trapframe *frame);
 static void    printtrap(u_int vector, struct trapframe *frame, int isfatal,
@@ -462,18 +463,19 @@ static int
 handle_onfault(struct trapframe *frame)
 {
        struct          thread *td;
-       faultbuf        *fb;
+       jmp_buf         *fb;
 
        td = curthread;
        fb = td->td_pcb->pcb_onfault;
        if (fb != NULL) {
-               frame->srr0 = (*fb)[FAULTBUF_LR];
-               frame->fixreg[1] = (*fb)[FAULTBUF_R1];
-               frame->fixreg[2] = (*fb)[FAULTBUF_R2];
+               frame->srr0 = (*fb)->_jb[FAULTBUF_LR];
+               frame->fixreg[1] = (*fb)->_jb[FAULTBUF_R1];
+               frame->fixreg[2] = (*fb)->_jb[FAULTBUF_R2];
                frame->fixreg[3] = 1;
-               frame->cr = (*fb)[FAULTBUF_CR];
-               bcopy(&(*fb)[FAULTBUF_R13], &frame->fixreg[13],
-                   19 * sizeof(register_t));
+               frame->cr = (*fb)->_jb[FAULTBUF_CR];
+               bcopy(&(*fb)->_jb[FAULTBUF_R14], &frame->fixreg[14],
+                   18 * sizeof(register_t));
+               td->td_pcb->pcb_onfault = NULL; /* Returns twice, not thrice */
                return (1);
        }
        return (0);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to