diff --git a/arch/risc-v/src/common/riscv_cpuindex.c b/arch/risc-v/src/common/riscv_cpuindex.c index 5f06c2ceca..c3ce34118b 100644 --- a/arch/risc-v/src/common/riscv_cpuindex.c +++ b/arch/risc-v/src/common/riscv_cpuindex.c @@ -30,37 +30,11 @@ #include #include "riscv_internal.h" -#include "riscv_percpu.h" /**************************************************************************** * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: riscv_mhartid - * - * Description: - * Context aware way to query hart id - * - * Returned Value: - * Hart id - * - ****************************************************************************/ - -uintptr_t riscv_mhartid(void) -{ -#ifdef CONFIG_ARCH_USE_S_MODE - /* Kernel is in S-mode */ - - return riscv_percpu_get_hartid(); - -#else - /* Kernel is in M-mode */ - - return READ_CSR(mhartid); -#endif -} - /**************************************************************************** * Name: up_cpu_index * diff --git a/arch/risc-v/src/common/riscv_macros.S b/arch/risc-v/src/common/riscv_macros.S index 7a675ab262..76d43eab79 100644 --- a/arch/risc-v/src/common/riscv_macros.S +++ b/arch/risc-v/src/common/riscv_macros.S @@ -152,3 +152,23 @@ .endm #endif /* !defined(CONFIG_SMP) && !defined(CONFIG_ARCH_USE_S_MODE) */ #endif /* CONFIG_ARCH_INTERRUPTSTACK > 15 */ + +/**************************************************************************** + * Name: riscv_mhartid + * + * Description: + * Context aware way to query hart id + * + * Returned Value: + * Hart id + * + ****************************************************************************/ + +.macro riscv_mhartid out +#ifdef CONFIG_ARCH_USE_S_MODE + csrr \out, CSR_SCRATCH + REGLOAD \out, RISCV_PERCPU_HARTID(\out) +#else + csrr \out, mhartid +#endif +.endm diff --git a/arch/risc-v/src/common/riscv_mhartid.S b/arch/risc-v/src/common/riscv_mhartid.S new file mode 100644 index 0000000000..0cfcfc256c --- /dev/null +++ b/arch/risc-v/src/common/riscv_mhartid.S @@ -0,0 +1,53 @@ +/**************************************************************************** + * arch/risc-v/src/common/riscv_mhartid.S + * + * 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. + * + ****************************************************************************/ + +.file "riscv_mhartid.S" + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "riscv_macros.S" + +/**************************************************************************** + * Public Symbols + ****************************************************************************/ + + .globl riscv_mhartid + +/**************************************************************************** + * Name: riscv_mhartid + * + * Description: + * Context aware way to query hart id + * + * Returned Value: + * Hart id + * + ****************************************************************************/ + +.type riscv_mhartid, function + +riscv_mhartid: + + riscv_mhartid a0 + ret diff --git a/arch/risc-v/src/k210/Make.defs b/arch/risc-v/src/k210/Make.defs index 89bec1c201..39413b80db 100644 --- a/arch/risc-v/src/k210/Make.defs +++ b/arch/risc-v/src/k210/Make.defs @@ -39,6 +39,7 @@ CMN_CSRCS += riscv_misaligned.c ifeq ($(CONFIG_SMP), y) CMN_CSRCS += riscv_cpuindex.c riscv_cpupause.c riscv_cpustart.c +CMN_ASRCS += riscv_mhartid.S endif ifeq ($(CONFIG_SCHED_BACKTRACE),y) diff --git a/arch/risc-v/src/mpfs/Make.defs b/arch/risc-v/src/mpfs/Make.defs index 6b27e0eba8..66654a03e4 100755 --- a/arch/risc-v/src/mpfs/Make.defs +++ b/arch/risc-v/src/mpfs/Make.defs @@ -32,7 +32,10 @@ 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 CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_getnewintctx.c -CMN_CSRCS += riscv_cpuindex.c riscv_doirq.c riscv_mtimer.c +CMN_CSRCS += riscv_doirq.c riscv_mtimer.c + +# Specify ASM code within the common directory to be included +CMN_ASRCS += riscv_mhartid.S ifeq ($(CONFIG_SCHED_BACKTRACE),y) CMN_CSRCS += riscv_backtrace.c diff --git a/arch/risc-v/src/qemu-rv/Make.defs b/arch/risc-v/src/qemu-rv/Make.defs index bc11bf5815..11a8cf93f4 100644 --- a/arch/risc-v/src/qemu-rv/Make.defs +++ b/arch/risc-v/src/qemu-rv/Make.defs @@ -38,6 +38,7 @@ CMN_CSRCS += riscv_exception.c riscv_getnewintctx.c riscv_doirq.c ifeq ($(CONFIG_SMP), y) CMN_CSRCS += riscv_cpuindex.c riscv_cpupause.c riscv_cpustart.c +CMN_ASRCS += riscv_mhartid.S endif ifeq ($(CONFIG_SCHED_BACKTRACE),y)