RISC-V incorrect exception generated

Bug #1859291 reported by Teodori Serge
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
QEMU
Expired
Undecided
Unassigned

Bug Description

When using 'ecall' from supervisor mode, user exception is raised instead of supervisor exception. The problem is located under 'target/riscv/insn_trans/trans_priviledged.inc.c' in function 'static bool trans_ecall(DisasContext *ctx, arg_ecall *a)'. Best regards, Serge Teodori

Tags: risc-v
Revision history for this message
Alistair Francis (alistair2323) wrote :

Do you have steps to reproduce this?

Revision history for this message
Teodori Serge (teodori-serge) wrote :
Download full text (4.0 KiB)

code from machine mode:
<pre>
 /* TEST jump to supervisor mode */
 if(mhartid == 3){
  asm volatile ("csrw sepc, %[reg]; sret" : : [reg] "r" (&main_supervisor));
  log("main: jump to supervisor mode failed!\r\n");
 }
</pre>

here is supervisor mode function:
<pre>
void main_supervisor(){
 log("main: we are in supervisor mode, now calling to machine mode\r\n");
 asm volatile ("ecall");
 log("main: we returned to supervisor mode\r\n");
 for(;;){} // TODO supervisor mode not implemented, spin forever
}
</pre>

here is the machine mode interrupt handler:
<pre>
void main_mtrap(){
 uint64_t mhartid, mcause, mip;

 asm volatile ("csrr %[reg], mhartid" : [reg] "=r" (mhartid));
 asm volatile ("csrr %[reg], mcause" : [reg] "=r" (mcause));

 /* if most significant bit is set,
  * then an interrupt is pending
  * else an exception occurred */
 switch(mcause){
 case 0x0:
  log("main: exception (Instruction address misaligned) on hart %x\r\n", mhartid);
  break;
 case 0x1:
  log("main: exception (Instruction access fault) on hart %x\r\n", mhartid);
  break;
 case 0x2:
  log("main: exception (Illegal instruction) on hart %x\r\n", mhartid);
  break;
 case 0x3:
  log("main: exception (Breakpoint) on hart %x\r\n", mhartid);
  break;
 case 0x4:
  log("main: exception (Load address misaligned) on hart %x\r\n", mhartid);
  break;
 case 0x5:
  log("main: exception (Load access fault) on hart %x\r\n", mhartid);
  break;
 case 0x6:
  log("main: exception (Store/AMO address misaligned) on hart %x\r\n", mhartid);
  break;
 case 0x7:
  log("main: exception (Store/AMO access fault) on hart %x\r\n", mhartid);
  break;
 case 0x8:
  log("main: exception (Environment call from U-mode) on hart %x\r\n", mhartid);
  break;
 case 0x9:
  log("main: exception (Environment call from S-mode) on hart %x\r\n", mhartid);
  break;
 case 0xa:
  log("main: exception (Reserved) on hart %x\r\n", mhartid);
  break;
 case 0xb:
  log("main: exception (Environment call from M-mode) on hart %x\r\n", mhartid);
  break;
 case 0xc:
  log("main: exception (Instruction page fault) on hart %x\r\n", mhartid);
  break;
 case 0xd:
  log("main: exception (Load page fault) on hart %x\r\n", mhartid);
  break;
 case 0xe:
  log("main: exception (Reserved) on hart %x\r\n", mhartid);
  break;
 case 0xf:
  log("main: exception (Store/AMO page fault) on hart %x\r\n", mhartid);
  break;
 case 0x8000000000000000:
  log("main: interrupt (User software interrupt) on hart %x\r\n", mhartid);
  break;
 case 0x8000000000000001:
  log("main: interrupt (Supervisor software interrupt) on hart %x\r\n", mhartid);
  break;
 case 0x8000000000000002:
  log("main: interrupt (Reserved) on hart %x\r\n", mhartid);
  break;
 case 0x8000000000000003:
  log("main: interrupt (Machine software interrupt) on hart %x\r\n", mhartid);
  clint_lower(&clint, mhartid);
  break;
 case 0x8000000000000004:
  log("main: interrupt (User timer interrupt) on hart %x\r\n", mhartid);
  break;
 case 0x8000000000000005:
  log("main: interrupt (Supervisor timer interrupt) on hart %x\r\n", mhartid);
  break;
 case 0x8000000000000006:
  log("main: interrupt (Reserved) on hart %x\r\n", mhartid);
  break;
 case 0x8000000000000007:
  log("main: interrupt (Mac...

Read more...

Revision history for this message
Teodori Serge (teodori-serge) wrote :
Revision history for this message
Alistair Francis (alistair2323) wrote :

I don't see the problem still.

When an ecall is generated the riscv_cpu_do_interrupt() function will translate it to the correct call. We run Linux user space inside QEMU, so this is generally working. Can you please attach source code and binaries (or link to it) to reproduce the issue. You also need to include the command line arguments you are using.

The main question is what is different to what you are running and Linux user space?

Revision history for this message
Thomas Huth (th-huth) wrote :

The QEMU project is currently considering to move its bug tracking to
another system. For this we need to know which bugs are still valid
and which could be closed already. Thus we are setting older bugs to
"Incomplete" now.

If you still think this bug report here is valid, then please switch
the state back to "New" within the next 60 days, otherwise this report
will be marked as "Expired". Or please mark it as "Fix Released" if
the problem has been solved with a newer version of QEMU already.

Thank you and sorry for the inconvenience.

Changed in qemu:
status: New → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for QEMU because there has been no activity for 60 days.]

Changed in qemu:
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.