如何放置一个变量在一个给定的绝对地址存储器(与海湾合作委员会) [英] How to place a variable at a given absolute address in memory (with GCC)

查看:254
本文介绍了如何放置一个变量在一个给定的绝对地址存储器(与海湾合作委员会)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ARM的RealView C编译器支持使用变量属性<放置一个变量在一个给定的内存地址code>在(地址):

The RealView ARM C Compiler supports placing a variable at a given memory address using the variable attribute at(address):

int var __attribute__((at(0x40001000)));
var = 4;   // changes the memory located at 0x40001000

GCC是否有类似的变量属性?

Does GCC have a similar variable attribute?

推荐答案

我不知道,但你可以很容易地创建这样一个解决方法:

I don't know, but you can easily create a workaround like this:

int *var = (int*)0x40001000;
*var = 4;

这不是的究竟的同样的事情,但在大多数情况下,一个完美的替代品。

It's not exactly the same thing, but in most situations a perfect substitute.

如果你使用GCC的,我想你也可以使用 GNU LD (尽管它不是当然)和LD是板上钉钉的事情了用于放置变量支持无论你想他们

If you use GCC, i assume you also use GNU ld (although it is not a certainty, of course) and ld has support for placing variables wherever you want them.

我想象让链接器做的工作是pretty常见。

I imagine letting the linker do that job is pretty common.

由@rib回答启发,我会补充说,如果绝对地址是一些控制寄存器,我想补充挥发性指针定义。如果它仅仅是RAM,它并不重要。

Inspired by answer by @rib, I'll add that if the absolute address is for some control register, I'd add volatile to the pointer definition. If it is just RAM, it doesn't matter.

这篇关于如何放置一个变量在一个给定的绝对地址存储器(与海湾合作委员会)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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