{"by":"Flex247A","descendants":4,"id":47996055,"kids":[48006129,48031749,48002123,48001741,48001072],"score":50,"text":"Demo: <a href=\"https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=f5uygzEmdLw\" rel=\"nofollow\">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=f5uygzEmdLw</a><p>Hi HN,<p>I built a RISC-V emulator that implements the RV32IM instruction set and a minimal syscall interface to run DOOM. A few weeks ago, I got my first output with a simple hello world assembly program.<p>Since then I have been working tirelessly to get DOOM to run.<p>I needed to figure out how to run C programs first, and came across newlib, which allows the underlying environment to implement the syscall stubs one by one until the programs run.<p>I have also added ELF loading, but currently only a single `PT_LOAD` segment is supported.<p>To port DOOM, I used doomgeneric, which was quite convenient to get working once the required stubs were in place.<p>DOOM renders to a fixed area in memory (0x705FDD = VRAM_START):<p><pre><code>  0x7FFFFF  +-------------------------------------+\n            |                                     |\n            |        QUEUE_SIZE (32 bytes)        |\n            |                                     |\n  0x7FFFDF  +-------------------------------------+ &lt;-- QUEUE_START\n  0x7FFFDE  |          QUEUE_READ_IDX             |\n  0x7FFFDD  |          QUEUE_WRITE_IDX            |\n            +-------------------------------------+\n            |                                     |\n            |                                     |\n            |       VRAM (1,024,000 bytes)        |\n            |                                     |\n            |                                     |\n  0x705FDD  +-------------------------------------+ &lt;-- STACK_START\n            |                Stack                |\n            |                  |                  |\n            |                  v                  |\n            |                                     |\n            |                  ^                  |\n            |                  |                  |\n            |         Program data + Heap         |\n            |                                     |\n  0x000000  +-------------------------------------+\n</code></pre>\nI made a small linker script so that the entry point of a C program is at _start and virtual address is always 0. That kept the ELF loader code simple.<p>Inputs are written to the queue by rvcore which are then intercepted by DOOM running inside it.","time":1777809432,"title":"Show HN: I built a RISC-V emulator that runs DOOM","type":"story","url":"https://github.com/lalitshankarch/rvcore"}