qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* QEMU RISC-V
@ 2023-06-24 22:16 Peter Samir
  2023-07-03  4:15 ` Alistair Francis
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Samir @ 2023-06-24 22:16 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 914 bytes --]

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 ?

[-- Attachment #2: Type: text/html, Size: 1772 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: QEMU RISC-V
  2023-06-24 22:16 QEMU RISC-V Peter Samir
@ 2023-07-03  4:15 ` Alistair Francis
  0 siblings, 0 replies; 2+ messages in thread
From: Alistair Francis @ 2023-07-03  4:15 UTC (permalink / raw)
  To: Peter Samir; +Cc: qemu-devel

On Sun, Jun 25, 2023 at 8:27 AM Peter Samir
<petersamir06423852@gmail.com> 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-03  4:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-24 22:16 QEMU RISC-V Peter Samir
2023-07-03  4:15 ` Alistair Francis

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).