Fix insufficient memory on some platforms
[Problem] The MEM_SIZE is hard-corded, but on some platforms, memory is insufficient. Perhaps we should allow user to config accordingly
[Solution] Expose an environment variable, CONFIG_MEM_SIZE, to allow user config the memory size with it
[Test]
-
before $> make $> ./build/rv32emu ./build/hello.elf rv32emu: src/riscv.c:199: rv_create: Assertion `attr->mem' failed. Aborted (core dumped)
-
after $> CONFIG_MEM_SIZE=0x40000000 make $> ./build/rv32emu ./build/hello.elf Hello World! Hello World! Hello World! Hello World! Hello World! inferior exit code 0
[Reference] #488
I don't think the proposed change resolves the insufficient memory issue because it just relies on compile-time configurations instead of an adaptive approach to acquire the necessary system resources based on the requirements of RISC-V programs during instruction simulation.
@qwe661234, can you comment this?
This issue arises when the memory size is insufficient, especially when running rv32emu on a VM. However, arbitrarily setting a MEM_SIZE to pass specific tests can cause segmentation faults in other tests. A better solution is to revert to the original virtual memory implementation when memory size is insufficient, allocating memory only as needed for read or write operations.
After investigation, you can set MEM_SIZE to 0x80000 to run the benchmarks in directory tests. However, if you want to run some video games like doom or quake, the 4G memory is required.
Reworked in commit feca1dea732e110a8b08926f3266d2db732147b0