NEMU icon indicating copy to clipboard operation
NEMU copied to clipboard

[Bug Report] `mie` register not implemented correctly

Open ha0lyu opened this issue 1 year ago • 3 comments

According to the privileged specification in chapter 3.1.9. Machine Interrupt Registers, some bits in MIE are set to zero.

image

However, if we write 0xffffffff to mie, the NEMU will set it to 0xffffffff.

d6b3a49b95a1de3da74c349878549f4

The bug was found when I tested Xiangshan. This is the test program mie_bug.zip.

Here are some env information:

NEMU commit: 3033a69f, xs-env commit: master, Xiangshan commit: 8fae59bba.

ha0lyu avatar Sep 11 '24 08:09 ha0lyu

Thank you for your bug reporting. I'm handling this.

huxuan0307 avatar Sep 12 '24 05:09 huxuan0307

Hi @huxuan0307, I have tested this bug in the newest version NEMU, commit id is 821ea961. I changed some code in order to run ./build/riscv64-nemu-interpreter -d ./ready-to-run/riscv64-spike-so -b mie.bin. image

Actually, I doubt the reference spike is not correct because I ran the code in spike, the 1.1.1-dev version, the right value is mie = 0x0000000000000aaa after we write it. image

Is there a way to run NEMU like spike step by step? I have not found it. I want to help to improve NEMU.

ha0lyu avatar Oct 10 '24 09:10 ha0lyu

In src/isa/riscv64/system/priv.c, you can look at the source code for writing the mie register. We now support the RV_H and RV_SSCOFPMF extensions, so the corresponding bits of mie are readable and writable.

We made a modification based on Spike, you can get it in https://github.com/OpenXiangShan/riscv-isa-sim. If you want to modify and generate spike-so that diff with NEMU, you can read README in riscv-isa-sim/difftest/

Besides, You can remove the -b option and run ./build/riscv64-nemu-interpreter -d ./ready-to-run/riscv64-spike-so mie.bin. Execute help to view options.

sinceforYy avatar Oct 11 '24 02:10 sinceforYy

Thanks for your reply @sinceforYy.

I have RTFM in chapter 17 & 18.4, NEMU 821ea961 version is right, but 3033a69 was wrong, as we can see the picture in my first comment: 366359785-fefe5ae2-db34-4af9-9612-4fa46407496d Yes, xiangshan supports the RV_H and RV_SSCOFPMF extensions, so NEMU 821ea961 version is right when we write 0xffffffff to mie:

C17: Note that the new count overflow interrupt will be treated as a standard local interrupt that is assigned to bit 13 in the mip/mie/sip/sie registers. image

This bug had been fixed.

ha0lyu avatar Oct 31 '24 04:10 ha0lyu