xiaoxiang781216 commented on a change in pull request #5782: URL: https://github.com/apache/incubator-nuttx/pull/5782#discussion_r841065392
########## File path: arch/risc-v/src/common/supervisor/riscv_syscall_dispatch.S ########## @@ -0,0 +1,148 @@ +/**************************************************************************** + * arch/risc-v/src/common/supervisor/riscv_syscall_dispatch.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_syscall_dispatch.S" + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <arch/mode.h> + +#include "riscv_exception_macros.S" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Symbols + ****************************************************************************/ + + .globl riscv_syscall_dispatch + +/**************************************************************************** + * Name: riscv_syscall_dispatch + * + * Description: + * Dispatch syscall from kernel + * + * C Function Prototype: + * void riscv_syscall_dispatch(void); + * + * Input Parameters: + * Assumes the context to return is already set up + * + * Returned Value: + * Return value of system call is returned into contex + * + * Assumptions: + * Task is running in privileged mode + * + ****************************************************************************/ + +.type riscv_syscall_dispatch, function + +riscv_syscall_dispatch: + + addi sp, sp, -XCPTCONTEXT_SIZE /* make room */ + save_ctx sp /* save current context */ + + /* Mask interrupts and store the status register to context */ + + li s1, STATUS_IE /* move IE -> PIE */ + csrrc s0, CSR_STATUS, s1 + and s1, s0, s1 /* if (STATUS & IE) */ + beqz s1, 1f + li s1, ~STATUS_IE /* clear IE */ + and s0, s0, s1 + li s1, STATUS_PIE /* set PIE */ + or s0, s0, s1 + + 1: + /* Set previous privilege, we are in privileged mode now */ + + li s1, STATUS_PPP /* set previous privilege */ + or s0, s0, s1 + REGSTORE s0, REG_INT_CTX(sp) /* store status to context */ + + REGSTORE x1, REG_EPC(sp) /* save ra to epc */ + + addi s0, sp, XCPTCONTEXT_SIZE + REGSTORE s0, REG_SP(sp) /* original SP */ + +#ifdef CONFIG_ARCH_FPU + mv a0, sp + jal x1, riscv_savefpu /* FP registers */ +#endif + + mv a0, sp /* a0 = context */ + + /* Switch to interrupt stack */ + +#if CONFIG_ARCH_INTERRUPTSTACK > 15 +#if IRQ_NSTACKS > 1 + jal x1, riscv_mhartid /* get hartid */ + li t0, (CONFIG_ARCH_INTERRUPTSTACK & ~15) + mul t0, a0, t0 + la a0, g_intstacktop + sub sp, a0, t0 +#else + la sp, g_intstacktop +#endif +#endif + + /* Run the handler */ + + jal x1, riscv_perform_syscall Review comment: Ok. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
