On Sun, Jun 25, 2023 at 8:27 AM Peter Samir <[email protected]> wrote: > > hello, > I built RISC-V toolchain and QEMU as follows: > # Install prerequisites: > https://github.com/riscv-collab/riscv-gnu-toolchain#prerequisites > # Install additional prerequisites: > https://github.com/riscv-collab/riscv-gnu-toolchain/issues/1251 > git clone https://github.com/riscv-collab/riscv-gnu-toolchain > cd riscv-gnu-toolchain > ./configure --prefix=/home/RISCV-installed-Tools --with-arch=rv32i_zicsr > --with-abi=ilp32 > make > make build-qemu > > > QEMU Version: > qemu-riscv32 version 7.1.0 (v7.1.0) > Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers > > > i debug as follows: > riscv32-unknown-elf-gcc -g test.S -o test > qemu-riscv32 -g 3333 test > // in another terminal > riscv32-unknown-elf-gdb test -ex "target remote :3333" > > but Qemu reports this error when I use CSR instructions: > Program received signal SIGILL, Illegal instruction. main () at main.S:2 2 > main: csrw mepc, t0 > > how to resolve this error ?
Hello, >From what you have provided it does seem like QEMU is doing the correct thing. You are trying to run a Linux user application (test.S) which is trying to access the mepc CSR. That is going to result in an illegal instruction exception as only Machine mode (M-mode) firmware can access the MEPC CSR. If you didn't intend to run a Linux user application you should use QEMU softMMU, which is the `qemu-system-riscv32` binary. That will allow a full system emulation. Obviously then you need to make sure your executable matches the machine hardware you are using (memory addresses for example). If using the virt machine you will also want to disable OpenSBI (-bios none) to run your own M-mode code. Alistair
