arch/risc-v: Merge riscv_getnewintctx into common

And also mask the bits which should be preserved (from ISA spec)

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
Huang Qi
2022-03-18 12:20:15 +08:00
committed by Xiang Xiao
parent c01cd62666
commit 00efcd3308
20 changed files with 88 additions and 209 deletions
+8
View File
@@ -307,6 +307,14 @@
#define MSTATUS_FS_CLEAN (0x2 << 13)
#define MSTATUS_FS_DIRTY (0x3 << 13)
/* Mask of preserved bits for mstatus */
#ifdef CONFIG_ARCH_RV32
#define MSTATUS_WPRI (0xff << 23 | 0x15)
#else
#define MSTATUS_WPRI (UINT64_C(0x1ffffff) << 38 | UINT64_C(0x1ff) << 23 | 0x15)
#endif
/* In mie (machine interrupt enable) register */
#define MIE_MSIE (0x1 << 3) /* Machine Software Interrupt Enable */
+1 -1
View File
@@ -33,7 +33,7 @@ CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c riscv_mde
CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.c
CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c
CMN_CSRCS += riscv_sigdeliver.c riscv_udelay.c riscv_unblocktask.c riscv_usestack.c
CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c
CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_getnewintctx.c
ifeq ($(CONFIG_SCHED_BACKTRACE),y)
CMN_CSRCS += riscv_backtrace.c
-23
View File
@@ -163,29 +163,6 @@ void up_enable_irq(int irq)
}
}
/****************************************************************************
* Name: riscv_get_newintctx
*
* Description:
* Return initial mstatus when a task is created.
*
****************************************************************************/
uintptr_t riscv_get_newintctx(void)
{
/* Set machine previous privilege mode to machine mode.
* Also set machine previous interrupt enable
*/
uintptr_t mstatus = READ_CSR(mstatus);
#ifdef CONFIG_ARCH_FPU
return (mstatus | MSTATUS_FS_INIT | MSTATUS_MPPM | MSTATUS_MPIE);
#else
return (mstatus | MSTATUS_MPPM | MSTATUS_MPIE);
#endif
}
/****************************************************************************
* Name: riscv_ack_irq
*
+1 -1
View File
@@ -34,7 +34,7 @@ CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c
CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c
CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c
CMN_CSRCS += riscv_mdelay.c riscv_copyfullstate.c riscv_idle.c
CMN_CSRCS += riscv_tcbinfo.c
CMN_CSRCS += riscv_tcbinfo.c riscv_getnewintctx.c
ifeq ($(CONFIG_SCHED_BACKTRACE),y)
CMN_CSRCS += riscv_backtrace.c
-27
View File
@@ -194,33 +194,6 @@ void up_enable_irq(int irq)
}
}
/****************************************************************************
* Name: riscv_get_newintctx
*
* Description:
* Return initial mstatus when a task is created.
*
****************************************************************************/
uintptr_t riscv_get_newintctx(void)
{
/* Set machine previous privilege mode to machine mode. Reegardless of
* how NuttX is configured and of what kind of thread is being started.
* That is because all threads, even user-mode threads will start in
* kernel trampoline at nxtask_start() or pthread_start().
* The thread's privileges will be dropped before transitioning to
* user code. Also set machine previous interrupt enable.
*/
uintptr_t mstatus = READ_CSR(mstatus);
#ifdef CONFIG_ARCH_FPU
return (mstatus | MSTATUS_FS_INIT | MSTATUS_MPPM | MSTATUS_MPIE);
#else
return (mstatus | MSTATUS_MPPM | MSTATUS_MPIE);
#endif
}
/****************************************************************************
* Name: riscv_ack_irq
*
@@ -0,0 +1,71 @@
/****************************************************************************
* arch/risc-v/src/common/riscv_getnewintctx.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/arch.h>
#include <arch/irq.h>
#include <arch/csr.h>
#include "riscv_internal.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: riscv_get_newintctx
*
* Description:
* Return initial mstatus when a task is created.
*
****************************************************************************/
uintptr_t riscv_get_newintctx(void)
{
/* Set machine previous privilege mode to machine mode. Reegardless of
* how NuttX is configured and of what kind of thread is being started.
* That is because all threads, even user-mode threads will start in
* kernel trampoline at nxtask_start() or pthread_start().
* The thread's privileges will be dropped before transitioning to
* user code. Also set machine previous interrupt enable.
*
* Mask the bits which should be preserved (from ISA spec)
*/
uintptr_t mstatus = READ_CSR(mstatus);
mstatus &= MSTATUS_WPRI;
return (mstatus | MSTATUS_MPPM | MSTATUS_MPIE
#ifdef CONFIG_ARCH_FPU
| MSTATUS_FS_INIT
#endif
);
}
+1 -1
View File
@@ -36,7 +36,7 @@ CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c riscv_mde
CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.c
CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c
CMN_CSRCS += riscv_sigdeliver.c riscv_udelay.c riscv_unblocktask.c riscv_usestack.c
CMN_CSRCS += riscv_tcbinfo.c
CMN_CSRCS += riscv_tcbinfo.c riscv_getnewintctx.c
ifeq ($(CONFIG_SCHED_BACKTRACE),y)
CMN_CSRCS += riscv_backtrace.c
-19
View File
@@ -134,25 +134,6 @@ void up_irqinitialize(void)
#endif
}
/****************************************************************************
* Name: riscv_get_newintctx
*
* Description:
* Return initial mstatus when a task is created.
*
****************************************************************************/
uintptr_t riscv_get_newintctx(void)
{
/* Set machine previous privilege mode to machine mode.
* Also set machine previous interrupt enable
*/
uintptr_t mstatus = READ_CSR(mstatus);
return (mstatus | MSTATUS_MPPM | MSTATUS_MPIE);
}
/****************************************************************************
* Name: up_enable_irq
*
+1 -1
View File
@@ -33,7 +33,7 @@ CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c riscv_mde
CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.c
CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c
CMN_CSRCS += riscv_sigdeliver.c riscv_udelay.c riscv_unblocktask.c riscv_usestack.c
CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c
CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_getnewintctx.c
ifeq ($(CONFIG_SCHED_BACKTRACE),y)
CMN_CSRCS += riscv_backtrace.c
-19
View File
@@ -165,25 +165,6 @@ void up_enable_irq(int irq)
}
}
/****************************************************************************
* Name: riscv_get_newintctx
*
* Description:
* Return initial mstatus when a task is created.
*
****************************************************************************/
uintptr_t riscv_get_newintctx(void)
{
/* Set machine previous privilege mode to machine mode.
* Also set machine previous interrupt enable
*/
uintptr_t mstatus = READ_CSR(mstatus);
return (mstatus | MSTATUS_MPPM | MSTATUS_MPIE);
}
/****************************************************************************
* Name: riscv_ack_irq
*
+1 -1
View File
@@ -34,7 +34,7 @@ CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c
CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c
CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c
CMN_CSRCS += riscv_mdelay.c riscv_copyfullstate.c riscv_idle.c
CMN_CSRCS += riscv_tcbinfo.c riscv_cpuidlestack.c
CMN_CSRCS += riscv_tcbinfo.c riscv_cpuidlestack.c riscv_getnewintctx.c
ifeq ($(CONFIG_SMP), y)
CMN_CSRCS += riscv_cpuindex.c riscv_cpupause.c riscv_cpustart.c
-23
View File
@@ -210,29 +210,6 @@ void up_enable_irq(int irq)
}
}
/****************************************************************************
* Name: riscv_get_newintctx
*
* Description:
* Return initial mstatus when a task is created.
*
****************************************************************************/
uintptr_t riscv_get_newintctx(void)
{
/* Set machine previous privilege mode to machine mode. Reegardless of
* how NuttX is configured and of what kind of thread is being started.
* That is because all threads, even user-mode threads will start in
* kernel trampoline at nxtask_start() or pthread_start().
* The thread's privileges will be dropped before transitioning to
* user code. Also set machine previous interrupt enable.
*/
uintptr_t mstatus = READ_CSR(mstatus);
return (mstatus | MSTATUS_MPPM | MSTATUS_MPIE);
}
/****************************************************************************
* Name: riscv_ack_irq
*
+1 -1
View File
@@ -33,7 +33,7 @@ CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c riscv_mde
CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.c
CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c
CMN_CSRCS += riscv_sigdeliver.c riscv_udelay.c riscv_unblocktask.c riscv_usestack.c
CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c
CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_getnewintctx.c
ifeq ($(CONFIG_SCHED_BACKTRACE),y)
CMN_CSRCS += riscv_backtrace.c
-19
View File
@@ -171,25 +171,6 @@ void up_enable_irq(int irq)
}
}
/****************************************************************************
* Name: riscv_get_newintctx
*
* Description:
* Return initial mstatus when a task is created.
*
****************************************************************************/
uintptr_t riscv_get_newintctx(void)
{
/* Set machine previous privilege mode to machine mode.
* Also set machine previous interrupt enable
*/
uintptr_t mstatus = READ_CSR(mstatus);
return (mstatus | MSTATUS_MPPM | MSTATUS_MPIE);
}
/****************************************************************************
* Name: riscv_ack_irq
*
+1 -1
View File
@@ -31,7 +31,7 @@ CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c
CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c
CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c
CMN_CSRCS += riscv_mdelay.c riscv_udelay.c riscv_copyfullstate.c
CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c
CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_getnewintctx.c
CMN_CSRCS += riscv_cpuindex.c
ifeq ($(CONFIG_SCHED_BACKTRACE),y)
-27
View File
@@ -205,33 +205,6 @@ void up_enable_irq(int irq)
}
}
/****************************************************************************
* Name: riscv_get_newintctx
*
* Description:
* Return initial mstatus when a task is created.
*
****************************************************************************/
uintptr_t riscv_get_newintctx(void)
{
/* Set machine previous privilege mode to machine mode. Reegardless of
* how NuttX is configured and of what kind of thread is being started.
* That is because all threads, even user-mode threads will start in
* kernel trampoline at nxtask_start() or pthread_start().
* The thread's privileges will be dropped before transitioning to
* user code. Also set machine previous interrupt enable.
*/
uintptr_t mstatus = READ_CSR(mstatus);
#ifdef CONFIG_ARCH_FPU
return (mstatus | MSTATUS_FS_INIT | MSTATUS_MPPM | MSTATUS_MPIE);
#else
return (mstatus | MSTATUS_MPPM | MSTATUS_MPIE);
#endif
}
/****************************************************************************
* Name: riscv_ack_irq
*
+1 -1
View File
@@ -34,7 +34,7 @@ CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.
CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c
CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c
CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_cpuidlestack.c
CMN_CSRCS += riscv_fault.c
CMN_CSRCS += riscv_fault.c riscv_getnewintctx.c
ifeq ($(CONFIG_SMP), y)
CMN_CSRCS += riscv_cpuindex.c riscv_cpupause.c riscv_cpustart.c
-24
View File
@@ -205,27 +205,3 @@ irqstate_t up_irq_enable(void)
oldstat = READ_AND_SET_CSR(mstatus, MSTATUS_MIE);
return oldstat;
}
/****************************************************************************
* Name: riscv_get_newintctx
*
* Description:
* Return initial mstatus when a task is created.
*
****************************************************************************/
uintptr_t riscv_get_newintctx(void)
{
/* Set machine previous privilege mode to machine mode.
* Also set machine previous interrupt enable
* Note: In qemu, FPU is always exist even if don't use F|D ISA extension
*/
uintptr_t mstatus = READ_CSR(mstatus);
#ifdef CONFIG_ARCH_FPU
return (mstatus | MSTATUS_MPPM | MSTATUS_MPIE | MSTATUS_FS_INIT);
#else
return (mstatus | MSTATUS_MPPM | MSTATUS_MPIE);
#endif
}
+1 -1
View File
@@ -33,7 +33,7 @@ CMN_CSRCS += riscv_interruptcontext.c riscv_modifyreg32.c riscv_puts.c
CMN_CSRCS += riscv_releasepending.c riscv_reprioritizertr.c riscv_copyfullstate.c
CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c
CMN_CSRCS += riscv_sigdeliver.c riscv_unblocktask.c riscv_usestack.c
CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c
CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_getnewintctx.c
ifeq ($(CONFIG_SCHED_BACKTRACE),y)
CMN_CSRCS += riscv_backtrace.c
-19
View File
@@ -213,25 +213,6 @@ void up_enable_irq(int irq)
}
}
/****************************************************************************
* Name: riscv_get_newintctx
*
* Description:
* Return initial mstatus when a task is created.
*
****************************************************************************/
uintptr_t riscv_get_newintctx(void)
{
/* Set machine previous privilege mode to machine mode.
* Also set machine previous interrupt enable
*/
uintptr_t mstatus = READ_CSR(mstatus);
return (mstatus | MSTATUS_MPPM | MSTATUS_MPIE);
}
/****************************************************************************
* Name: riscv_ack_irq
*