svn commit: r360916 - stable/12/sys/riscv/riscv

John Baldwin jhb at FreeBSD.org
Mon May 11 19:57:45 UTC 2020


Author: jhb
Date: Mon May 11 19:57:45 2020
New Revision: 360916
URL: https://svnweb.freebsd.org/changeset/base/360916

Log:
  MFC 357594: Use csr_read() to read sstatus instead of inline assembly.
  
  While here, remove a local variable to avoid the CSR read in non-debug
  kernels.

Modified:
  stable/12/sys/riscv/riscv/trap.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/riscv/riscv/trap.c
==============================================================================
--- stable/12/sys/riscv/riscv/trap.c	Mon May 11 19:36:38 2020	(r360915)
+++ stable/12/sys/riscv/riscv/trap.c	Mon May 11 19:57:45 2020	(r360916)
@@ -246,12 +246,10 @@ void
 do_trap_supervisor(struct trapframe *frame)
 {
 	uint64_t exception;
-	uint64_t sstatus;
 
 	/* Ensure we came from supervisor mode, interrupts disabled */
-	__asm __volatile("csrr %0, sstatus" : "=&r" (sstatus));
-	KASSERT((sstatus & (SSTATUS_SPP | SSTATUS_SIE)) == SSTATUS_SPP,
-			("We must came from S mode with interrupts disabled"));
+	KASSERT((csr_read(sstatus) & (SSTATUS_SPP | SSTATUS_SIE)) ==
+	    SSTATUS_SPP, ("Came from S mode with interrupts enabled"));
 
 	exception = (frame->tf_scause & EXCP_MASK);
 	if (frame->tf_scause & EXCP_INTR) {
@@ -306,7 +304,6 @@ do_trap_user(struct trapframe *frame)
 {
 	uint64_t exception;
 	struct thread *td;
-	uint64_t sstatus;
 	struct pcb *pcb;
 
 	td = curthread;
@@ -314,9 +311,8 @@ do_trap_user(struct trapframe *frame)
 	pcb = td->td_pcb;
 
 	/* Ensure we came from usermode, interrupts disabled */
-	__asm __volatile("csrr %0, sstatus" : "=&r" (sstatus));
-	KASSERT((sstatus & (SSTATUS_SPP | SSTATUS_SIE)) == 0,
-			("We must came from U mode with interrupts disabled"));
+	KASSERT((csr_read(sstatus) & (SSTATUS_SPP | SSTATUS_SIE)) == 0,
+	    ("Came from U mode with interrupts enabled"));
 
 	exception = (frame->tf_scause & EXCP_MASK);
 	if (frame->tf_scause & EXCP_INTR) {


More information about the svn-src-stable mailing list