[英]How do i set up instruction & data memory address when using "riscv32-unknown-elf-gcc"?
I designed RISCV32IM processor, and I used "riscv32-unknown-elf-gcc" to generate code for testing.我设计了RISCV32IM处理器,我使用了“riscv32-unknown-elf-gcc”来生成测试代码。
However, the PC(instruction memory address) value and data memory address of the generated code had arbitrary values.但是,生成的代码的 PC(指令存储器地址)值和数据存储器地址具有任意值。 I used this command:
我使用了这个命令:
riscv32-unknown-elf-gcc -march=rv32im -mabi=ilp32 -nostartfiles test.c
Can I know if I can set the instruction and data memory address I want?我可以知道我是否可以设置我想要的指令和数据存储器地址吗?
Thanks.谢谢。
Thank you for answer.谢谢你的答案。
I designed only HW, and this is my first time using the SW tool chain.我只设计了硬件,这是我第一次使用软件工具链。 Even if my question is rudimentary, please understand.
即使我的问题很初级,也请理解。
The figure is the result of the "-v" option.该图是“-v”选项的结果。 enter image description here
在此处输入图片说明
I can't modify the script file because I use riscv tool chain in DOCKER environment.我无法修改脚本文件,因为我在 DOCKER 环境中使用了 riscv 工具链。 So, I tried to copy the script file (elf32lriscv.x), modify it.
所以,我尝试复制脚本文件(elf32lriscv.x),修改它。 I modified it to 0x10000 ==> 0x00000.
我将其修改为 0x10000 ==> 0x00000。 The file name of the copied script is "test5.x".
复制脚本的文件名为“test5.x”。
And it was executed as follows.它是按如下方式执行的。 What am I doing wrong?
我究竟做错了什么?
The riscv compiler is using the default linker script to place text and date section... . riscv 编译器使用默认链接器脚本来放置文本和日期部分...。
If you add -v
option to your command line riscv32-unknown-elf-gcc -v -march=rv32im -mabi=ilp32 -nostartfiles test.c
, you will see the linker script used by collect 2 ( normally it will be -melf32lriscv . you can find the linker script in ${path_to_toolchain}/riscv32-unknown-elf/lib/ldscripts/
(the default one is .x).如果将
-v
选项添加到命令行riscv32-unknown-elf-gcc -v -march=rv32im -mabi=ilp32 -nostartfiles test.c
,您将看到 collect 2 使用的链接器脚本(通常是 -melf32lriscv . 你可以在${path_to_toolchain}/riscv32-unknown-elf/lib/ldscripts/
找到链接器脚本(默认是 .x)。
You can also use riscv32-unknown-elf-ld --verbose
like explained by @Frant.您还可以使用
riscv32-unknown-elf-ld --verbose
就像@Frant 所解释的那样。 However , you need to be careful if the toolchain was compiled with enable multilib and you compile for rv64 but the default is rv32 or vice versa.但是,如果工具链是使用 enable multilib 编译的并且您编译为 rv64 但默认为 rv32,则您需要小心,反之亦然。 It is not the case probably, but to be sure you can specify the arch with
-A elf32riscv
for an rv32.可能情况并非如此,但要确保您可以使用
-A elf32riscv
为 rv32 指定拱门。
To Set the addresses you can create your own linker script or copy and modify the default one.要设置地址,您可以创建自己的链接描述文件或复制和修改默认的链接描述文件。 You can only modify the executable start like explained by @Frant or make more modification and place whatever you want where you want.
您只能像@Frant 解释的那样修改可执行文件开始,或者进行更多修改并将任何您想要的位置放置在您想要的位置。
Once your own linker script ready you can pass it to the linker with -Wl,-T,${own_linker_script }.准备好自己的链接器脚本后,您可以使用 -Wl,-T,${own_linker_script } 将其传递给链接器。 you command will be
riscv32-unknown-elf-gcc -march=rv32im -mabi=ilp32 -nostartfiles test.c -Wl,-T,${own_linker_script }
你的命令将是
riscv32-unknown-elf-gcc -march=rv32im -mabi=ilp32 -nostartfiles test.c -Wl,-T,${own_linker_script }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.