rsd-devel / rsd

RSD: RISC-V Out-of-Order Superscalar Processor
Apache License 2.0
934 stars 95 forks source link

Report 'Memory address 0x1e38 is invalid' when running helloworld.elf in spike #73

Closed zhangkanqi closed 5 months ago

zhangkanqi commented 6 months ago

Hi,

I find that when running helloworld.elf(exactly~/rsd/Processor/Src/Verification/TestCode/C/HelloWorld/code.elf) in the latest spike, it reports the following message:

image

Do you know how to address this problem? I have no idea at the moment.

Looking forward to your reply:)

shioyadan commented 6 months ago

Hello, Apologies for the delayed response.

I believe the error you're encountering stems from a difference between the memory address map used by RSD and one assumed by Spike.

The binaries for RSD are compiled based on the address map defined in the linker script found here: https://github.com/rsd-devel/rsd/blob/master/Processor/Src/Verification/TestCode/rsd-ld.script. However, it seems Spike utilizes a different address map.

If you're looking to run RSD binaries on Spike, it would be advisable to check and align with the address map that Spike assumes.

In case your goal is simply to execute RSD binaries on an emulator, I suggest using an older version of QEMU (around 2017). Recent versions of QEMU appear to have adopted a different address map. However, the memory address map RSD assumes aligns with that of the older QEMU versions. For instance, we previously ran binaries on QEMU as demonstrated in this Makefile: https://github.com/rsd-devel/rsd/blob/master/Processor/Tools/QEMU_SimDriver/Makefile.

zhangkanqi commented 5 months ago

Can I put the instructions to be executed in the RAM area(pc>=0x8000 0000)? I tried and failed. I think that might due to the width of pc. Because in rsd, the pc is 19-bit, but RAM starts with 0x8000 0000.

shioyadan commented 5 months ago

I suspect that the issue is due to the placement in code.hex. Check the contents of your generated code.hex. The first 64KB of code.hex is loaded into the ROM area and the rest into the RAM area (0x8000000000>=). You need to be aware of this when creating binaries.

In the case of Verilator, code.hex is loaded at the following location. (Sorry, the comment is written in Japanese...) https://github.com/rsd-devel/rsd/blob/3d13af1bc14d2b34a546754973d832d0309d118e/Processor/Src/SysDeps/Verilator/TestMain.cpp#L219

code.hex is generated by the following makefile. https://github.com/rsd-devel/rsd/blob/3d13af1bc14d2b34a546754973d832d0309d118e/Processor/Src/Verification/TestCode/Makefile.inc

Note that, RSD has 19-bit compressed logical addresses by default, but RSD can use 0x8000000000 >= space with a hack that treats the most significant bit specially.

Also, you can disable this compression feature by disabling the macro on the following line: https://github.com/rsd-devel/rsd/blob/3d13af1bc14d2b34a546754973d832d0309d118e/Processor/Src/Memory/MemoryMapTypes.sv#L27

zhangkanqi commented 5 months ago

Thanks a lot. I have modified spike, now it can run instructions in ROM.