How can I compile C code to get a bare-metal skeleton of a minimal RISC-V assembly program?

前端 未结 3 454
野趣味
野趣味 2020-12-24 09:09

I have the following simple C code:

   void main(){
    int A = 333;
    int B=244;
    int sum;
    sum = A + B;  
}

When I compile this w

3条回答
  •  孤独总比滥情好
    2020-12-24 09:41

    The "extra" code is put there by gcc and is the sort of stuff required for any program. The proxy kernel is designed to be the bare minimum amount of support required to run such things. Once your processor is working, I would recommend running things on top of pk rather than bare-metal.

    In the meantime, if you want to look at simple assembly, I would recommend skipping the linking phase with '-c':

    riscv64-unknown-elf-gcc code.c -c -o code.o
    riscv64-unknown-elf-objdump -d code.o
    

    For examples of running code without pk or linux, I would look at riscv-tests.

提交回复
热议问题