From 0976258299a30132f679ebac6a800e186fc3052b Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Thu, 3 Oct 2024 12:28:44 +0300 Subject: [PATCH] riscv/kstack: Remove riscv_current_ksp as obsolete Unwinding the kernel stack did not work previously due to the way the task startup logic works via nxtask_start and the up_task_start() system call. After modifying the logic behind those, the kernel stack is in fact fully unwound when return_from_exception is executed, so calling the original hack "riscv_current_ksp" is not necessary anymore. --- arch/risc-v/src/common/CMakeLists.txt | 2 +- arch/risc-v/src/common/Make.defs | 2 +- .../src/common/riscv_exception_common.S | 4 +- arch/risc-v/src/common/riscv_ksp.c | 38 ------------------- 4 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 arch/risc-v/src/common/riscv_ksp.c diff --git a/arch/risc-v/src/common/CMakeLists.txt b/arch/risc-v/src/common/CMakeLists.txt index df5ca6b2df122..9fc26e6baa76e 100644 --- a/arch/risc-v/src/common/CMakeLists.txt +++ b/arch/risc-v/src/common/CMakeLists.txt @@ -108,7 +108,7 @@ if(CONFIG_ARCH_USE_MMU) endif() if(CONFIG_ARCH_KERNEL_STACK) - list(APPEND SRCS riscv_addrenv_kstack.c riscv_ksp.c) + list(APPEND SRCS riscv_addrenv_kstack.c) endif() if(CONFIG_ARCH_ADDRENV) diff --git a/arch/risc-v/src/common/Make.defs b/arch/risc-v/src/common/Make.defs index 693c8ca58f786..742942c849fd2 100644 --- a/arch/risc-v/src/common/Make.defs +++ b/arch/risc-v/src/common/Make.defs @@ -109,7 +109,7 @@ CMN_CSRCS += riscv_mmu.c endif ifeq ($(CONFIG_ARCH_KERNEL_STACK),y) -CMN_CSRCS += riscv_addrenv_kstack.c riscv_ksp.c +CMN_CSRCS += riscv_addrenv_kstack.c endif ifeq ($(CONFIG_ARCH_ADDRENV),y) diff --git a/arch/risc-v/src/common/riscv_exception_common.S b/arch/risc-v/src/common/riscv_exception_common.S index ec585f653af69..24223067f8b7e 100644 --- a/arch/risc-v/src/common/riscv_exception_common.S +++ b/arch/risc-v/src/common/riscv_exception_common.S @@ -250,9 +250,9 @@ return_from_exception: and s0, s0, s1 bnez s0, 1f - /* Set the next task's kernel stack to the scratch area */ + /* Set the unwound kernel stack to the scratch area */ - jal x1, riscv_current_ksp + addi a0, sp, XCPTCONTEXT_SIZE csrr s0, CSR_SCRATCH REGSTORE a0, RISCV_PERCPU_KSP(s0) diff --git a/arch/risc-v/src/common/riscv_ksp.c b/arch/risc-v/src/common/riscv_ksp.c deleted file mode 100644 index 41146717c83a9..0000000000000 --- a/arch/risc-v/src/common/riscv_ksp.c +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** - * arch/risc-v/src/common/riscv_ksp.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 - -#include - -#include "sched/sched.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -uintptr_t riscv_current_ksp(void) -{ - return (uintptr_t)this_task()->xcp.kstkptr; -}