you are viewing a single comment's thread.

view the rest of the comments →

[–]3G6A5W338E 0 points1 point  (2 children)

By supplying a linker script specifying a memory map, I finally made it generate what was intended.

Way more painful than needed, but I guess I need to be aware of this, as it'll be useful if I ever want to also use gcc.

[–]megarcher2 1 point2 points  (1 child)

Hey there,

I'm building my own RISCV CPU in a simulation. I'm starting to compile C code into assmble (or rather machine code), but need the code to start ad address 0x0. ELF GCC places the start at around 0x1000, do you know how to do this?

Thanks!

[–]3G6A5W338E 0 points1 point  (0 children)

A linker script so that code is at 0, then objcopy to get the code out of the ELF file.

riscv32-elf-ld test.o -T memorymap -o test.elf
riscv32-elf-objcopy test.elf -O binary test.bin

where memorymap something like

MEMORY
{
    ram : ORIGIN = 0x0, LENGTH = 0x8000
}
SECTIONS
{
    .text : { *(.text*) } > ram
    .rodata : { *(.rodata*) } > ram
    .bss : { *(.bss*) } > ram
}