doldooly
doldooly

Reputation: 55

How do i set up data memory address when using "riscv32/64-unknown-elf-gcc"?

I designed RISCV32IM processor, and i used "riscv32/64-unknown-elf-gcc" to generate code for test. Instruction memory setting has been solved with the options below(-Ttext option), but data memory setting has not been solved yet.

riscv64-unknown-elf-gcc -v -march=rv32im -mabi=ilp32 -nostartfiles -x c  -Ttext 40000000 -o main.o main.c

Can I know if I can set the data memory address I want?

Upvotes: 1

Views: 961

Answers (1)

Alexy Khilaev
Alexy Khilaev

Reputation: 444

looks like you need to link linker script, something like:

OUTPUT_ARCH( "riscv" )
ENTRY(_start)

SECTIONS
{
  . = 0x40000000;
  .text.init : { *(.text.init) }
  . = ALIGN(0x1000);
  .text : { *(.text) }
  . = ALIGN(0x1000);
  .data : { *(.data) }
  .bss : { *(.bss) }
  _end = .;
}
  • _start is a start symbol and 0x40000000 is a memory start address, followed by the section names aligned by 0x1000.
  • text this is the program itself
  • data is a statically initialized variables
  • bss is a statically allocated variables

Upvotes: 2

Related Questions