This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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]

Ping : H8/300 ABI Document


Hi,

Please review change suggested in H8 ABI document from following link,
http://gcc.gnu.org/ml/gcc/2004-03/msg01325.html

Regards,
Anil Paranjpe

-----Original Message-----
From: Anil Paranjape 
Sent: Tuesday, March 23, 2004 3:24 PM
To: 'Kazu Hirata'; gnuh8@gnuh8.org.uk
Cc: 'gcc@gcc.gnu.org'
Subject: RE: ABI Document


Hi,

Please find following sentence from  http://gcc.gnu.org/projects/h8300-abi.html,

Structure Alignment
Unless __attribute__ ((packed)) is attached to the declaration of a struct, each structure member is aligned 
to a multiple of 2 bytes on H8/300 and of 4 bytes on H8/300H and H8S.

I think this is slightly misleading statement. 
Consider following testcase,

struct test {
  unsigned short a;         /* Address 0,1 */
  unsigned short b;         /* Address 2,3 */
};
  struct test t;
int  main (void)
{
  t.b = 1;
  return 0;
}

Compiler options passed are 
-ms -ms2600 -fverbose-asm -S

Generated assembly for above testcase is following,
        .file   "test.c"
        .h8300s
        .section .text
        .align 1
        .global _main
_main:
        mov.l   er6,@-er7       ;#,
        mov.l   er7,er6 ;#,
        mov.w   #1,r2   ;#, tmp17
        mov.w   r2,@_t+2        ;# tmp17, t.b
        sub.w   r2,r2   ;# <result>
        mov.w   r2,r0   ;# <result>, <result>
        mov.l   @er7+,er6       ;#,
        rts
        .size   _main, .-_main
        .comm   _t,4,2
        .end
        .ident  "GCC: (GNU) 3.4.0 20040303 (prerelease)"

Analysis:

Assuming above mentioned structure alignment is true then instruction "mov.w   r2,@_t+2" used for accessing t.b in generated assembly should be wrong. The instruction should be "mov.w   r2,@_t+4".
According to structure alignment every structure member is aligned to 4 bytes . So padding mentioned in following structure definition should be correct,
struct test {
  unsigned short a;         /* Address 0,1 (2,3 padding) */
  unsigned short b;         /* Address 4,5 (6,7 padding) */
};

But actually it is not the case. By default structure is aligned to 4 byte boundary. 
So instruction for accessing t.b in generated assembly is correct.
The default alignment of structure is 4 bytes unless __attribute__ ((packed)) is used.

I suggest to change the text of structure alignment in ABI document like following,

Structure Alignment
Unless __attribute__ ((packed)) is attached to the declaration of a struct or union, each structure or union is aligned 
to a multiple of 2 bytes on H8/300 and of 4 bytes on H8/300H and H8S. The compiler inserts padding to maintain the alignment of its members. The sizeof a structure is always multiple of its alignment and this may require tail padding. 


Regards,
Anil Paranjpe

-----Original Message-----
From: Kazu Hirata [mailto:kazu@cs.umass.edu]
Sent: Monday, January 19, 2004 11:22 AM
To: gnuh8@gnuh8.org.uk
Subject: ABI Document


Hi,

I just added a document describing H8 ABI for GCC.

http://gcc.gnu.org/projects/h8300-abi.html

I'll try to make it complete over time.  Suggestions, questions, etc,
are all welcome.

Maybe interrupt function handling needs to be described.

Kazu Hirata

-- 
GNUH8 Mailing List | If you encounter difficulties using this service
                   | email: listmaster@gnuh8.org.uk
                   | http://www.gnuh8.org.uk/


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