Home | History | Annotate | Line # | Download | only in arm
      1 /*	$NetBSD: ast.c,v 1.34 2026/04/28 05:51:14 skrll Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994,1995 Mark Brinicombe
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the RiscBSD team.
     18  * 4. The name of the company nor the name of the author may be used to
     19  *    endorse or promote products derived from this software without specific
     20  *    prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     23  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
     26  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  * RiscBSD kernel project
     35  *
     36  * ast.c
     37  *
     38  * Code to handle ast's and returns to user mode
     39  *
     40  * Created      : 11/10/94
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: ast.c,v 1.34 2026/04/28 05:51:14 skrll Exp $");
     45 
     46 #include "opt_ddb.h"
     47 
     48 #include <sys/param.h>
     49 #include <sys/cpu.h>
     50 #include <sys/proc.h>
     51 #include <sys/acct.h>
     52 #include <sys/systm.h>
     53 #include <sys/atomic.h>
     54 #include <sys/kernel.h>
     55 #include <sys/signal.h>
     56 #include <sys/userret.h>
     57 #include <sys/vmmeter.h>
     58 
     59 #include <arm/locore.h>
     60 
     61 #include <uvm/uvm_extern.h>
     62 
     63 /*
     64  * Prototypes
     65  */
     66 void ast(struct trapframe *);
     67 
     68 void
     69 userret(struct lwp *l)
     70 {
     71 #if defined(ARM_MMU_EXTENDED)
     72 	KASSERTMSG(curcpu()->ci_pmap_cur == l->l_proc->p_vmspace->vm_map.pmap,
     73 	    "%p vs %p", curcpu()->ci_pmap_cur,
     74 	    l->l_proc->p_vmspace->vm_map.pmap);
     75 
     76 	KASSERT(
     77 	    (armreg_pfr1_read() & ARM_PFR1_SEC_MASK) == 0 ||
     78 	    (armreg_ttbcr_read() & TTBCR_S_PD0) == 0
     79 	);
     80 #endif
     81 
     82 	/* Invoke MI userret code */
     83 	mi_userret(l);
     84 
     85 	KASSERT(VALID_PSR(lwp_trapframe(l)->tf_spsr));
     86 }
     87 
     88 
     89 /*
     90  * Handle asynchronous system traps.
     91  * This is called from the irq handler to deliver signals
     92  * and switch processes if required.
     93  */
     94 
     95 void
     96 ast(struct trapframe *tf)
     97 {
     98 	struct lwp * const l = curlwp;
     99 
    100 	/* Interrupts were restored by exception_exit. */
    101 
    102 	KASSERT(VALID_PSR(tf->tf_spsr));
    103 
    104 #ifdef __HAVE_PREEMPTION
    105 	kpreempt_disable();
    106 #endif
    107 	struct cpu_info * const ci = curcpu();
    108 
    109 	ci->ci_data.cpu_ntrap++;
    110 
    111 	KDASSERT(ci->ci_cpl == IPL_NONE);
    112 #ifdef __HAVE_PREEMPTION
    113 	kpreempt_enable();
    114 #endif
    115 
    116 	if (l->l_pflag & LP_OWEUPC) {
    117 		l->l_pflag &= ~LP_OWEUPC;
    118 		ADDUPROF(l);
    119 	}
    120 
    121 	userret(l);
    122 }
    123