From: Teodori Serge <teodori.serge@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Bug 1859291] Re: RISC-V incorrect exception generated
Date: Mon, 03 Feb 2020 13:32:06 -0000 [thread overview]
Message-ID: <158073672622.18906.14219281705734898954.malone@gac.canonical.com> (raw)
In-Reply-To: 157875755996.2711.225801499083245592.malonedeb@soybean.canonical.com
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 (Machine timer interrupt) on hart %x\r\n", mhartid);
clint_timer(&clint, mhartid, 0x1000000);
break;
case 0x8000000000000008:
log("main: interrupt (User external interrupt) on hart %x\r\n", mhartid);
break;
case 0x8000000000000009:
log("main: interrupt (Supervisor external interrupt) on hart %x\r\n", mhartid);
break;
case 0x800000000000000a:
log("main: interrupt (Reserved) on hart %x\r\n", mhartid);
break;
case 0x800000000000000b:
log("main: interrupt (Machine external interrupt) on hart %x\r\n", mhartid);
main_plic_wake_up(mhartid);
break;
default:
if(mcause < 0x8000000000000000) log("main: unknown exception (%x) on hart %x\r\n", mcause, mhartid);
else log("main: unknown interrupt (%x) on hart %x\r\n", mcause & 0x7fffffffffffffff, mhartid);
break;
}
while(mcause < 0x8000000000000000){} // TODO exception or interrupt not implemented, spin forever
}
</pre>
--
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1859291
Title:
RISC-V incorrect exception generated
Status in QEMU:
New
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
To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1859291/+subscriptions
next prev parent reply other threads:[~2020-02-03 13:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-11 15:45 [Bug 1859291] [NEW] RISC-V incorrect exception generated Teodori Serge
2020-02-01 1:24 ` Alistair Francis
2020-02-01 1:31 ` [Bug 1859291] " Alistair Francis
2020-02-03 13:32 ` Teodori Serge [this message]
2020-02-03 13:34 ` Teodori Serge
2020-03-17 20:25 ` Alistair Francis
2021-05-02 18:22 ` Thomas Huth
2021-07-02 4:17 ` Launchpad Bug Tracker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=158073672622.18906.14219281705734898954.malone@gac.canonical.com \
--to=teodori.serge@gmail.com \
--cc=1859291@bugs.launchpad.net \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).