搜索
bottom↓
回复: 10

如何将写好的C函数 映射到内存上一个固定地址上

[复制链接]

出0入0汤圆

发表于 2011-3-28 19:38:42 | 显示全部楼层 |阅读模式
例如:void test(void)
      {
          a=10;
      }

我想把test 映射到地址0x000010上,当我执行0x00000010时能够执行test这个函数。

请问怎么做?

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

发表于 2011-3-28 22:01:16 | 显示全部楼层
可以这样?等高人

出0入0汤圆

发表于 2011-3-28 22:06:36 | 显示全部楼层
函数指针

出0入0汤圆

发表于 2011-3-28 23:28:26 | 显示全部楼层
如果用gcc编译,在链接时用链接脚本就可以了!

出0入0汤圆

发表于 2011-3-28 23:52:19 | 显示全部楼层
#define TEST (*(pFN*)0x000010)

typedf void(*pFN)(void);

void test(void)
      {
          a=10;
      }

TEST= test;

出0入0汤圆

 楼主| 发表于 2011-3-29 08:20:53 | 显示全部楼层
多谢楼上高人,研究下

出0入0汤圆

发表于 2011-3-29 08:49:14 | 显示全部楼层
这个应该同编译器的编译链接脚本有关吧。
大概看了看KEIL下

Using __attribute__((section("name")))
Placing a code or data object in its own source file and then placing the object file sections uses standard coding techniques. However, you can also use __attribute__((section("name"))) and a scatter-loading description file to place named sections. Create a module, for example, adder.c and name a section explicitly as shown in Example 5.4.

Example 5.4. Naming a section

int variable __attribute__((section("foo"))) = 10;


Use a scatter-loading description file to specify where the named section is placed, see Example 5.5. If both code and data sections have the same name, the code section is placed first.

Example 5.5. Placing a section

FLASH 0x24000000 0x4000000
{
    ...                                ; rest of code

    ADDER 0x08000000
    {
        adder.o (foo)                  ; select section foo from adder.o
    }
}


Using __at sections to place sections at a specific address
A section can be given a special name that encodes the address at which it must be placed. The name can be specified as follows:

.ARM.__at_address
Where:

address
is the required address of the section. This can be specified in hexadecimal or decimal. Sections in the form of .ARM.__at_address are referred to by the abbreviation __at.

In the compiler, variables can be assigned to __at sections by either explicitly naming the section using the __attribute__((section(”name”))) or by using the attribute __at which sets up the name of the section for you. See Example 5.6.

Note

出0入0汤圆

发表于 2011-3-29 09:02:26 | 显示全部楼层
也在研究这方面。收藏

出0入0汤圆

发表于 2011-3-29 09:06:43 | 显示全部楼层
还可以这样啊!

出0入0汤圆

 楼主| 发表于 2011-3-29 19:52:32 | 显示全部楼层
还是不懂,怎么用呀?

出0入0汤圆

 楼主| 发表于 2011-3-29 19:54:36 | 显示全部楼层
忘了说,我用的是ADS编译
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-24 01:30

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表