You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/12/30 10:15:53 UTC

[GitHub] [incubator-nuttx] no1wudi removed a comment on pull request #5115: arch/risc-v: Refine syscall interface

no1wudi removed a comment on pull request #5115:
URL: https://github.com/apache/incubator-nuttx/pull/5115#issuecomment-1002954211


   @masayuki2009 @xiaoxiang781216 
   Hi, I find that this crash is caused by RISC-V's C extension , in riscv_syscall.S:
   ```
   sys_call0:	/* a0 holds the syscall number */		
    sys_call1:	/* a0 holds the syscall number, argument in a1 */		
    sys_call2:	/* a0 holds the syscall number, arguments in a1 and a2 */		
    sys_call3:	/* a0 holds the syscall number, arguments in a1, a2, and a3 */		
    sys_call4:	/* a0 holds the syscall number, arguments in a1, a2, a3 and a4 */		
    sys_call5:	/* a0 holds the syscall number, arguments in a1, a2, a3, a4 and a5 */		
   
     	/* Issue the ECALL opcode to perform a SW interrupt to the OS */		
   
     	ecall		
   
     	/* The actual interrupt may not a occur for a few more cycles.  Let's		
    	 * put a few nop's here in hope that the SW interrupt occurs during		
    	 * the sequence of nops.		
    	 */		
   
     	nop		
    	nop		
   
     	/* Then return with the result of the software interrupt in v0 */		
   
     	ret		
    	nop		
   ```
   All instruction use the normal 32bit instruction, but on some platform with C (Compressed instruction) support it would be 16bit, for FE310, you can adjust the mepc with 2 instead of 4:
   ```
   void *fe310_dispatch_irq(uint32_t vector, uint32_t *regs)
   {
     uint32_t  irq = (vector >> 27) | (vector & 0xf);
     uint32_t *mepc = regs;
   
     /* Firstly, check if the irq is machine external interrupt */
   
     if (FE310_IRQ_MEXT == irq)
       {
         uint32_t val = getreg32(FE310_PLIC_CLAIM);
   
         /* Add the value to nuttx irq which is offset to the mext */
   
         irq += val;
       }
   
     /* NOTE: In case of ecall, we need to adjust mepc in the context */
   
     if (FE310_IRQ_ECALLM == irq)
       {
         /* It should be 2 instead of 4 on target with C extension */
         *mepc += 4;
       }
    ...
   }
   ```
   @masayuki2009 Could you please have test ?
   


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org