-
Notifications
You must be signed in to change notification settings - Fork 154
qemu-system-riscv32 store doesn't modify the memory during a sw ra, 12(sp)
#137
Comments
It seems there is two separate issues in fact:
You'll fine attached my current project (set to compile the sifive_e version) |
The issue seems related to I only had the issue on 32 bit RISCV. |
sw ra, 12(sd)
sw ra, 12(sd)
sw ra, 12(sp)
Thanks for the report, test case and GDB testing. There are different code paths in |
Now that I understand a bit better riscv, I'll try to reproduce the issue without gdb to confirm your idea. I'll let you know |
I wrote a minimal code that basically just dump info from Machine CSR registers. I works in 32 bit mode (sifive_u) but not in 32 bit mode (sifive_e) with the following compilation / qemu options:
Here are the two main files:
|
BTW this might help:
It would be possible to add the sifive uart to
Note
Something like this should work for the SiFive UART (borrowed from bbl):
I might abstract |
I'll have a look thanks ! It looks like a lot like the small code I wrote to understand all the machine registers :) |
Yes. I used it for basic compatibility testing for reading and comparing machine CSRs between spike and QEMU in 32-bit mode and 64-bit mode. You'll get different results if you run it on |
There is also https://github.com/riscv/riscv-tests which can be run in QEMU. The 'v' tests run in the |
Okay, I updated riscv-probe (https://github.com/michaeljclark/riscv-probe) with support for both HTIF and UART, added invocation examples to the README and moved the linker script into a conf directory (defaults to |
Were you able to resolve this @vsiles? Was it your code at fault, or is there an issue with
Which shouldn't be happening. I'd like to know if this is something I need to fix my end, or in qemu. Thanks! |
I didn't try to resolve it, since we were only working with 64 bit archs. In such case, gdb display is funky (it might skip steps) but the behavior was correct. I did not look into the 32 bit case more in depth, sorry. |
Thanks for the reply. Something funky is going on. The code enters this function:
At 0x20400378,
So
I'll build from the latest source, but I can't see anything that's changed that would fix this. Is this something I could help with or patch if there's a problem with rv32 Edit: It's still overwriting |
I am wondering if it might be decompression related thus in BTW The disassembler is distinct from the decoder in I have not encountered any issues like this on riscv32 yet so I'm curious what is going on... I'm surprised that riscv32 linux boots oif we can't I can try your reproducer. Do you have the linker script? |
Sorry, I no longer have access to these files (former job)... But I didn't have anything clever in it anyway |
Perhaps there is a buffer overflow that is clobbering values on the stack. Since the problem only happens for 32-bit code, maybe the buffer overflow doesn't happen for 64-bit code. This could be a compiler or library bug where the size of something is computed wrong when you have a 32-bit target. |
OK. It's my fault. I could have sworn there was 128KB of DRAM in the E300 series. It's 16KB. That'll be why (PS: thanks for the port, it's appreciated!) |
Might have been that indeed ! |
Hi !
I'm trying to test a simple bare metal C code with qemu-system-riscv32 [1], and I think the jump instructions are off by 4 bytes. You can simply test it by running the "ROM" code of the sifive_e machine in gdb:
This as a nasty side effect with call: when we get back from a function call, the instruction restoring
ra
is skipped, so if you have several chained function calls, the firstret
will return and the secondret
will trigger an illegal access to address0
(most of the time).For the record, my actual test code is a bare metal application printing "hello world" on the uart:
CFLAGS := -ffreestanding -nostdlib -nostartfiles -march=rv32imafdc -mabi=ilp32 -mcmodel=medany -g -O1
[1] actual revision:
The text was updated successfully, but these errors were encountered: