如何获取我的code的结束地址 [英] How to fetch the end address of my code

查看:133
本文介绍了如何获取我的code的结束地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个从无到有的实时操作系统的课程项目。我想知道我的code的结束地址我把它下载到芯片后,因为我计划使用免费的内存堆栈空间,我需要确保我不会覆盖现有code

I'm writing a real-time operation system from scratch for a course project. I want to know the end address of my code after I download it to the chip, because I am planning to use the free memory for stack space and I need make sure that I won't overwrite the existing code.

我听说海湾合作委员会提供__end变量是code的结束,但我不知道是什么__end以及如何使用它在我的code的含义想法。谁能解释这一点,或者提供链接到一些材料,因为我不能谷歌__end?

I heard about __end variable provided by GCC is the end of the code, but I have no idea about what is the meaning of __end and how to use it in my code. Could anyone explain it a little bit or provide links to some materials, cos I couldn't google __end?

非常感谢。

推荐答案

正如亚当罗森菲尔德所指出的,你需要使用的链接器控制文件来定义您位于precisely正确的位置一个或多个符号。

As Adam Rosenfeld points out, you need to use the linker control file to define one or more symbols for you that is located at the precisely correct place.

有关gcc和binutils的,您将使用LD的链接脚本语法。请参阅LD手册对所有我要离开这里出来的细节。这是一点点不透明的,但你应该花一些时间,如果你要花费的心血任何显著量在嵌入式世界。它会为你付出过。

For gcc and binutils, you will be using ld's linker script syntax. Refer to ld's manual for all the details I'm leaving out here. It is a tad opaque, but you should spend some time with it if you are going to spend any significant amount of effort in the embedded world. It will pay off for you.

在链接脚本,你希望你的.text段之前定义一个符号,和一个后。

In the linker script, you want to define a symbol before your .text segment, and one after.

亚当提到了提供()语法,这将正常工作。但是你可能并不需要包装在提供的定义,如果你能保证你的名字是唯一的。请注意,这是你必须能够作出的保证,或者你以后冒险了很多困惑。

Adam mentions the PROVIDE() syntax, which will work. But you may not need to wrap the definition in PROVIDE if you can guarantee that your name is unique. Note that this is a guarantee that you must be able to make, or you risk a lot of confusion later.

在我的剧本,我只是用这样的:

In my script, I just use something like:

__SDRAM_CS1 = 0x10000000;

定义与引用(在这种情况下),以我们决定,SDRAM控制器将映射SDRAM存储器,以及在C位置的常量地址符号我声明它像

to define the symbol with a constant address that refers (in this case) to the location we decided that the SDRAM controller will map the SDRAM memory, and in C I declare it like:

extern unsigned char __SDRAM_CS1[];

,以便它可以在code,需要知道在哪里的SDRAM实际上是可以使用。

so that it can be used in code that needs to know where the SDRAM actually is.

有关的象征定位的.text段的结尾,你会像在链接脚本以下<​​/ P>

For a symbol locating the end of the .text segment, you would have something like the following in the linker script

SECTIONS
{
    ...
    .text {
        _start_text = .;
        *(.text);
        ...
        _end_text = .;
    }
    ...
}

和申报的开始和结束符号

and declare the start and end symbols as

extern unsigned char _start_text[];
extern unsigned char _end_text[];

在C.然后,起始地址根本 _start_text ,并在文本段的字节长度为 _end_text - _start_text

in C. Then, the start address is simply _start_text, and the length in bytes of the text segment is _end_text - _start_text.

请注意,我已经离开了很多细节。你可能有一个名为.text段比其他东西,好像他们是在文本段,必须处理的部分。一个典型的例子是只读的,往往可以位于文本段安全,因为它是已知的数据常量和嵌入式系统,你不想复制有价值的内存,如果你不就得了。另外,对于数据段,和全局对象的构造的所有内部产生的列表初始化获得位于文本段附近。

Note that I've left out a lot of detail. You probably have sections named things other than .text that must be treated as if they were in the text segment. A prime example is read-only data which often can be located in the text segment safely because it is known to be const and in an embedded system you'd rather not copy it to valuable RAM if you don't have to. Also, initializers for the data segment, and the internally generated lists of constructors of global objects all get located near the text segment.

无论您在您的图像大小这样的事情是,你需要了解他们是用什么后,做出设计决策。

Whether you include such things in your image size is a design decision that you need to make after understanding what they are used for.

这篇关于如何获取我的code的结束地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆