Add __NO_FIQ to prevent testing of the PSR FIQ bit

Use VALID_R15_PSR(pc, spsr) instead of testing explicitly
This commit is contained in:
matt 2014-08-13 21:41:32 +00:00
parent f106fcdb01
commit c97e21f563
5 changed files with 37 additions and 29 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ast.c,v 1.23 2014/03/28 21:43:49 matt Exp $ */
/* $NetBSD: ast.c,v 1.24 2014/08/13 21:41:32 matt Exp $ */
/*
* Copyright (c) 1994,1995 Mark Brinicombe
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ast.c,v 1.23 2014/03/28 21:43:49 matt Exp $");
__KERNEL_RCSID(0, "$NetBSD: ast.c,v 1.24 2014/08/13 21:41:32 matt Exp $");
#include "opt_ddb.h"
@ -86,7 +86,8 @@ userret(struct lwp *l)
#endif
#if defined(__PROG32) && defined(DIAGNOSTIC)
KASSERT((lwp_trapframe(l)->tf_spsr & IF32_bits) == 0);
KASSERT(VALID_R15_PSR(lwp_trapframe(l)->tf_pc,
lwp_trapframe(l)->tf_spsr));
#endif
}
@ -111,7 +112,7 @@ ast(struct trapframe *tf)
#endif
#ifdef __PROG32
KASSERT((tf->tf_spsr & IF32_bits) == 0);
KASSERT(VALID_R15_PSR(tf->tf_pc, tf->tf_spsr));
#endif
curcpu()->ci_data.cpu_ntrap++;

View File

@ -1,4 +1,4 @@
/* $NetBSD: process_machdep.c,v 1.29 2014/01/04 00:10:02 dsl Exp $ */
/* $NetBSD: process_machdep.c,v 1.30 2014/08/13 21:41:32 matt Exp $ */
/*
* Copyright (c) 1993 The Regents of the University of California.
@ -133,7 +133,7 @@
#include <sys/param.h>
__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.29 2014/01/04 00:10:02 dsl Exp $");
__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.30 2014/08/13 21:41:32 matt Exp $");
#include <sys/proc.h>
#include <sys/ptrace.h>
@ -158,15 +158,12 @@ process_read_regs(struct lwp *l, struct reg *regs)
regs->r_pc = tf->tf_pc;
regs->r_cpsr = tf->tf_spsr;
KASSERT(VALID_R15_PSR(tf->tf_pc, tf->tf_spsr));
#ifdef THUMB_CODE
if (tf->tf_spsr & PSR_T_bit)
regs->r_pc |= 1;
#endif
#ifdef DIAGNOSTIC
if ((tf->tf_spsr & PSR_MODE) == PSR_USR32_MODE
&& (tf->tf_spsr & IF32_bits))
panic("process_read_regs: IRQs/FIQs blocked in user process");
#endif
return(0);
}
@ -204,11 +201,7 @@ process_write_regs(struct lwp *l, const struct reg *regs)
if ((regs->r_pc & 1) || (regs->r_cpsr & PSR_T_bit))
tf->tf_spsr |= PSR_T_bit;
#endif
#ifdef DIAGNOSTIC
if ((tf->tf_spsr & PSR_MODE) == PSR_USR32_MODE
&& (tf->tf_spsr & IF32_bits))
panic("process_read_regs: IRQs/FIQs blocked in user process");
#endif
KASSERT(VALID_R15_PSR(tf->tf_pc, tf->tf_spsr));
#else /* __PROG26 */
if ((regs->r_pc & (R15_MODE | R15_IRQ_DISABLE | R15_FIQ_DISABLE)) != 0)
return EPERM;

View File

@ -1,4 +1,4 @@
/* $NetBSD: syscall.c,v 1.59 2014/01/29 18:45:21 matt Exp $ */
/* $NetBSD: syscall.c,v 1.60 2014/08/13 21:41:32 matt Exp $ */
/*-
* Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.
@ -71,7 +71,7 @@
#include <sys/param.h>
__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.59 2014/01/29 18:45:21 matt Exp $");
__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.60 2014/08/13 21:41:32 matt Exp $");
#include <sys/cpu.h>
#include <sys/device.h>
@ -109,7 +109,7 @@ swi_handler(trapframe_t *tf)
if ((tf->tf_r15 & R15_IRQ_DISABLE) == 0)
int_on();
#else
KASSERT((tf->tf_spsr & IF32_bits) == 0);
KASSERT(VALID_R15_PSR(tf->tf_pc, tf->tf_spsr));
restore_interrupts(tf->tf_spsr & IF32_bits);
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: fault.c,v 1.100 2014/04/12 09:11:47 skrll Exp $ */
/* $NetBSD: fault.c,v 1.101 2014/08/13 21:41:32 matt Exp $ */
/*
* Copyright 2003 Wasabi Systems, Inc.
@ -81,7 +81,7 @@
#include "opt_kgdb.h"
#include <sys/types.h>
__KERNEL_RCSID(0, "$NetBSD: fault.c,v 1.100 2014/04/12 09:11:47 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: fault.c,v 1.101 2014/08/13 21:41:32 matt Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -253,9 +253,14 @@ data_abort_handler(trapframe_t *tf)
ci->ci_data.cpu_ntrap++;
/* Re-enable interrupts if they were enabled previously */
KASSERT(!TRAP_USERMODE(tf) || (tf->tf_spsr & IF32_bits) == 0);
KASSERT(!TRAP_USERMODE(tf) || VALID_R15_PSR(tf->tf_pc, tf->tf_spsr));
#ifdef __NO_FIQ
if (__predict_true((tf->tf_spsr & I32_bit) != I32_bit))
restore_interrupts(tf->tf_spsr & IF32_bits);
#else
if (__predict_true((tf->tf_spsr & IF32_bits) != IF32_bits))
restore_interrupts(tf->tf_spsr & IF32_bits);
#endif
/* Get the current lwp structure */
@ -800,14 +805,19 @@ prefetch_abort_handler(trapframe_t *tf)
* from user mode so we know interrupts were not disabled.
* But we check anyway.
*/
KASSERT(!TRAP_USERMODE(tf) || (tf->tf_spsr & IF32_bits) == 0);
if (__predict_true((tf->tf_spsr & I32_bit) != IF32_bits))
KASSERT(!TRAP_USERMODE(tf) || VALID_R15_PSR(tf->tf_pc, tf->tf_spsr));
#ifdef __NO_FIQ
if (__predict_true((tf->tf_spsr & I32_bit) != I32_bit))
restore_interrupts(tf->tf_spsr & IF32_bits);
#else
if (__predict_true((tf->tf_spsr & IF32_bits) != IF32_bits))
restore_interrupts(tf->tf_spsr & IF32_bits);
#endif
/* See if the CPU state needs to be fixed up */
switch (prefetch_abort_fixup(tf)) {
case ABORT_FIXUP_RETURN:
KASSERT(!TRAP_USERMODE(tf) || (tf->tf_spsr & IF32_bits) == 0);
KASSERT(!TRAP_USERMODE(tf) || VALID_R15_PSR(tf->tf_pc, tf->tf_spsr));
return;
case ABORT_FIXUP_FAILED:
/* Deliver a SIGILL to the process */
@ -890,7 +900,7 @@ do_trapsignal:
call_trapsignal(l, tf, &ksi);
out:
KASSERT(!TRAP_USERMODE(tf) || (tf->tf_spsr & IF32_bits) == 0);
KASSERT(!TRAP_USERMODE(tf) || VALID_R15_PSR(tf->tf_pc, tf->tf_spsr));
userret(l);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: locore.h,v 1.16 2014/03/28 21:39:09 matt Exp $ */
/* $NetBSD: locore.h,v 1.17 2014/08/13 21:41:32 matt Exp $ */
/*
* Copyright (c) 1994-1996 Mark Brinicombe.
@ -112,9 +112,13 @@
*/
#ifdef __PROG32
#ifdef __NO_FIQ
#define VALID_R15_PSR(r15,psr) \
(((psr) & PSR_MODE) == PSR_USR32_MODE && \
((psr) & (I32_bit | F32_bit)) == 0)
(((psr) & PSR_MODE) == PSR_USR32_MODE && ((psr) & I32_bit) == 0)
#else
#define VALID_R15_PSR(r15,psr) \
(((psr) & PSR_MODE) == PSR_USR32_MODE && ((psr) & IF32_bits) == 0)
#endif
#else
#define VALID_R15_PSR(r15,psr) \
(((r15) & R15_MODE) == R15_MODE_USR && \