This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Proposal: GAS, nested structures


Hi Erik.

Very good answer (all of it). :)

I'll go into some details about why I think it's needed, and I'll give an example as well.

On Wed, 15 May 2013 20:03:22 +1000, Erik Christiansen wrote:
> True, but my home-baked macro implementation from about 13 years ago
> gave errors with current gas versions, when I tried it last week. So I
> moved to using .struct, despite the absence of documentation. It was
> easier to use what's there, than grump about my petunias having been run
> over.

Your macros are definitely usable for normal structures, no doubt.
It's also a good idea to use .pushsection and .popsection in them as well.
I like your 'sizeof' and 'numof' extras too.
As for myself, I made RSRESET, RSSET, RS.B, RS.H, RS.L macros; these do not require sections, as they're only based upon .equ; but this can not solve my issue.

>> Also, it's difficult to find documentation on how to use it.
> 
> In my experience, it usually takes only minutes to figure out (to a
> first approximation) how individual undocumented gas capabilities
> behave, so the lack of documentation is not practically significant.
> I've just assumed that it works in a reasonable way, tried variations
> until the errors go away, and the objdump or .lst output is to my
> satisfaction. Job done, time for coffee, and it is quicker than
> writing long emails.

What I didn't write was: I did find out how to use it, but it seems to me like it can do more than documented.
And while searching, I ran into documentation that mentioned 'struct' capabilites that the plain GNU Assembler did not support.
-I do not recall exactly, but I think this one was an extended GAS from Texas Instruments.

> What was it you found didn't work?
It works fine, I do not have any problems getting it to work as expected.
The reason for my post is mainly:
1: Make it possible to nest structures
2: Most important of all: Allow identical member names in multiple structures, eg.
   struct Dog { uint16_t legs; uint16_t heads; uint16_t tails; };
   struct Bird {uint16_t legs; uint16_t wings; uint16_t heads; };

3: While we're at it, it might make sense to include unions in my proposal.


Of course, if you make up the names yourself, there's no problem, you can easily choose a different name.
But if you're using someone else's hardware-registers, and these have identical member names (such as many ARM chips do), you're in trouble, because the names are usually short and they sometimes have values that differ.

In my example, I have a LPC1768, which has 4 timers and 5 UARTs. One of the members have the same name, for instance MCR.
The UART structure also has a member named IER, which is used in many other structures (Interrupt Enable Register, as you probably guessed by now).

Here's an example; the two structures I am referring to:

typedef struct
{
  __IO uint32_t IR;
  __IO uint32_t TCR;
  __IO uint32_t TC;
  __IO uint32_t PR;
  __IO uint32_t PC;
  __IO uint32_t MCR;
  __IO uint32_t MR0;
  __IO uint32_t MR1;
  __IO uint32_t MR2;
  __IO uint32_t MR3;
  __IO uint32_t CCR;
  __I  uint32_t CR0;
  __I  uint32_t CR1;
       uint32_t RESERVED0[2];
  __IO uint32_t EMR;
       uint32_t RESERVED1[12];
  __IO uint32_t CTCR;
} LPC_TIM_TypeDef;

typedef struct
{
  union {
  __I  uint8_t  RBR;
  __O  uint8_t  THR;
  __IO uint8_t  DLL;
       uint32_t RESERVED0;
  };
  union {
  __IO uint8_t  DLM;
  __IO uint32_t IER;
  };
  union {
  __I  uint32_t IIR;
  __O  uint8_t  FCR;
  };
  __IO uint8_t  LCR;
       uint8_t  RESERVED1[3];
  __IO uint8_t  MCR;
       uint8_t  RESERVED2[3];
  __I  uint8_t  LSR;
       uint8_t  RESERVED3[3];
  __I  uint8_t  MSR;
       uint8_t  RESERVED4[3];
  __IO uint8_t  SCR;
       uint8_t  RESERVED5[3];
  __IO uint32_t ACR;
       uint32_t RESERVED6;
  __IO uint32_t FDR;
       uint32_t RESERVED7;
  __IO uint8_t  TER;
       uint8_t  RESERVED8[27];
  __IO uint8_t  RS485CTRL;
       uint8_t  RESERVED9[3];
  __IO uint8_t  ADRMATCH;
       uint8_t  RESERVED10[3];
  __IO uint8_t  RS485DLY;
       uint8_t  RESERVED11[3];
  __I  uint8_t  FIFOLVL;
} LPC_UART1_TypeDef;


Love
Jens

 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]