2

Does gcc have any keyword exactly equivalent to _at_ in Keil?

struct Location
{
  uint_32 x;
  uint_32 y;
  uint_32 z;
  char protocol[10];
};

struct link idata list _at_ 0x40;     /* list at idata 0x40 */

Note: I do not want to define a pointer at all. I want an exactly the same variable.

Note: the idata here can be ignored.

hadoop
  • 85
  • 1
  • 1
  • 9
  • Which target platform do you use? – the busybee Jan 09 '20 at 07:17
  • Related: https://stackoverflow.com/questions/4067811/how-to-place-a-variable-at-a-given-absolute-address-in-memory-with-gcc – dragosht Jan 09 '20 at 07:20
  • What is `link`? What has `Location` anything to do with the rest? – Acorn Jan 09 '20 at 22:06
  • @Acorn, It is a hypothetical example. In reality, the structure holds information to be sent to a server host including an encryption buffer. This data is supposed to be read by the embedded OS and then dispatched. That's why the application has such an obligation. – hadoop Jan 10 '20 at 02:25

1 Answers1

2

No, it doesn't. This Keil support page on the topic also suggests there is no direct equivalent of CARM's __at__ and armcc's __attribute__(at) in gcc:

GNU GCC Compiler
Use only pointer definitions to access absolute memory locations. For example:

/* General Purpose Input/Output (GPIO) */
#define IOPIN0         (*((volatile unsigned long *) 0xE0028000))
.
.
.
IOPIN0 = 0x4;

As an alternative to that, you can also define your own sections using an ld script.

dragosht
  • 3,237
  • 2
  • 23
  • 32
  • Then how do you guarantee that your variable does not collide with another variable? Forget windows and Linux. If you have an embedded system OS which reads certain address locations in the application to communicate, then your application cannot have a clean design but it should follow the OS rules. Yet, I need to have my struct defined in the designated address. – hadoop Jan 09 '20 at 22:01
  • Please forget my original `struct` example. It was a copy/paste without much evaluation. I have updated it to a better one. – hadoop Jan 09 '20 at 22:04
  • I guess such a collision may only be possible if the memory section your variable resides in is used by the compiler (e.g. somewhere in .data). But you could guarantee that the compiler won't interfere by scripting it in the linker, maybe use a dedicated section for that. – dragosht Jan 10 '20 at 06:52
  • Thank you very much. Would you please explain it in more details how to do that? – hadoop Jan 12 '20 at 22:35
  • You probably need something like this adapted for your board: https://electronics.stackexchange.com/questions/438488/gcc-attribute-section-not-working – dragosht Jan 13 '20 at 10:55