简体   繁体   English

使用“riscv32-unknown-elf-gcc”时如何设置指令和数据内存地址?

[英]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?我究竟做错了什么?

enter image description here在此处输入图片说明

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.

相关问题 使用“riscv32-unknown-elf-gcc”时,如何按字节单位存储或加载到 memory 中? - How do I store or load by byte unit into memory when using “riscv32-unknown-elf-gcc”? 如何在特定地址转储 ELF 文件的内容? - How do I dump the contents of an ELF file at a specific address? 如何链接 ELF 文件中的数据以在运行时显示? STM32 - How to link Data in ELF file to show up during run time? STM32 如何通过指令执行反汇编的ELF指令? - How to execute a disassembled ELF instruction by instruction? 如何使用GCC生成ELF文件? - How can I generate an ELF file with GCC? elf文件如何加载正确的内存地址并成功执行? - How elf file loaded correct memory address and executed successfully? 当我想要一个共享库时,GCC输出一个可执行的ELF文件 - GCC outputs an executable ELF file when I want a shared library 在没有虚拟内存的系统上如何处理 ELF 入口点地址? - How is ELF entry point address handled on systems without virtual memory? entry()进入与我在Elf中设置的入口点不同的地址 - entry() get into the different address from the entry point I set in the Elf 如何让 GCC 生成 ELF 目标文件? - How can I make GCC generate ELF object files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM