This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


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

64 bit mips arch, and __DEVTAB__



I'm working on porting eCos to a 64 bit mips cpu and have encountered
a problem with the DEVTAB_ENTRY macro defined in
io/common/current/include/devtab.h. It would appear that gcc is aligning
each piece of data added to the .devtab section on 8 byte boundries.
This
causes a space between entries and causes the loop in cyg_io_init() in
io/commmon/current/iosys.c to fail.

Depending on whether it is legitimate to assume that there is no padding
for data objects added separately to a section with the section
__attribute__,
this may be a compiler issue rather than a eCos issue.

A simple work around exists, by just adding another field to the
cyg_devtab_entry
structure.



Here is a simple example of the problem.

--- bug.h ---

typedef struct cyg_devtab_entry {
    const char        *name;
    const char        *dep_name;
    void              *handlers;
    int              (*init)();
    int              (*lookup)();
    void              *priv;
    unsigned long     status;
} cyg_devtab_entry_t;

extern cyg_devtab_entry_t __DEVTAB__[], __DEVTAB_END__;

#define DEVTAB_ENTRY(_l,_name,_dep_name,_handlers,_init,_lookup,_priv) 
\
cyg_devtab_entry_t _l __attribute__ ((section(".devtab"))) = {         
\
   _name,                                                              
\
   _dep_name,                                                          
\
   _handlers,                                                          
\
   _init,                                                              
\
   _lookup,                                                            
\
   _priv                                                               
\
};

--- bug.c ---
#include "bug.h"

int
f()
{
    return 0;
}

DEVTAB_ENTRY(a, "a", "a", (void *)1, f, f, (void *)1);
DEVTAB_ENTRY(b, "b", "b", (void *)1, f, f, (void *)1);

void
_start()
{
    cyg_devtab_entry_t *t;

    for (t = &__DEVTAB__[0]; t != &__DEVTAB_END__; t++) {
        if (t->init(t)) {
            t->status = 1;
        } else {
            // What to do if device init fails?
            t->status = 0;  // Device not [currently] available
        }

    }
}

--- target.ld ---
     SECTIONS
     {
       . = 0x10000;
       .text ALIGN(0x4) : { *(.text) }
       . = 0x8000000;
       .data ALIGN(0x8) : {
                *(.data);
                . = ALIGN (8);
                __DEVTAB__ = ABSOLUTE(.);
                KEEP (*(SORT (.devtab*)))
                __DEVTAB_END__ = ABSOLUTE(.);
        }
       .bss ALIGN(0x8) : { *(.bss) }
     }

--- Makefile ---
CC = mips64-unknown-elf-gcc
CFLAGS = -v \
        -ffunction-sections \
        -fdata-sections \
        -Ttarget.ld \
        -nostartfiles

bug: bug.o bug.h
        $(CC) -c $(CFLAGS) bug.c
        $(CC) $(CFLAGS) bug.o -o $@

--- Make output ---
mips64-unknown-elf-gcc -v -ffunction-sections -fdata-sections
-Ttarget.ld -nostartfiles   -c bug.c -o bug.o
Reading specs from
/home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/cpp -lang-c
-v -D__GNUC__=2 -D__GNUC_MINOR__=95 -Dmips -DMIPSEB -DR4000 -D_mips
-D_MIPSEB -D_R4000 -D__mips__ -D__MIPSEB__ -D__R4000__ -D___mips__
-D_MIPSEB -D_R4000 -D__mips -D__MIPSEB -D__R4000 -D___mips
-D__LANGUAGE_C -D_LANGUAGE_C -DLANGUAGE_C -D__SIZE_TYPE__=unsigned int
-D__PTRDIFF_TYPE__=int -U__mips -D__mips=3 -D__mips64 bug.c
/tmp/ccCyvoQ1.i
GNU CPP version 2.95.2 19991024 (release) [AL 1.1, MM 40] BSD Mips
#include "..." search starts here:
#include <...> search starts here:
 /home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/include

/home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/../../../../mips64-unknown-elf/include
End of search list.
The following default directories have been omitted from the search
path:

/home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/../../../../include/g++-3

/home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/../../../../mips64-unknown-elf/sys-include
End of omitted list.
 /home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/cc1
/tmp/ccCyvoQ1.i -quiet -dumpbase bug.c -version -ffunction-sections
-fdata-sections -o /tmp/cciIREaT.s
GNU C version 2.95.2 19991024 (release) (mips64-unknown-elf) compiled by
GNU C version 2.95.2 19991024 (release).
 /home/yotta/software/mips64-unknown-elf/bin/as -v -o bug.o
/tmp/cciIREaT.s
GNU assembler version 2.10 (mips64-unknown-elf) using BFD version 2.10
mips64-unknown-elf-gcc -c -v -ffunction-sections -fdata-sections
-Ttarget.ld -nostartfiles bug.c
Reading specs from
/home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/cpp -lang-c
-v -D__GNUC__=2 -D__GNUC_MINOR__=95 -Dmips -DMIPSEB -DR4000 -D_mips
-D_MIPSEB -D_R4000 -D__mips__ -D__MIPSEB__ -D__R4000__ -D___mips__
-D_MIPSEB -D_R4000 -D__mips -D__MIPSEB -D__R4000 -D___mips
-D__LANGUAGE_C -D_LANGUAGE_C -DLANGUAGE_C -D__SIZE_TYPE__=unsigned int
-D__PTRDIFF_TYPE__=int -U__mips -D__mips=3 -D__mips64 bug.c
/tmp/cciE8dn5.i
GNU CPP version 2.95.2 19991024 (release) [AL 1.1, MM 40] BSD Mips
#include "..." search starts here:
#include <...> search starts here:
 /home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/include

/home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/../../../../mips64-unknown-elf/include
End of search list.
The following default directories have been omitted from the search
path:

/home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/../../../../include/g++-3

/home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/../../../../mips64-unknown-elf/sys-include
End of omitted list.
 /home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/cc1
/tmp/cciE8dn5.i -quiet -dumpbase bug.c -version -ffunction-sections
-fdata-sections -o /tmp/cc0I4j8Z.s
GNU C version 2.95.2 19991024 (release) (mips64-unknown-elf) compiled by
GNU C version 2.95.2 19991024 (release).
 /home/yotta/software/mips64-unknown-elf/bin/as -v -o bug.o
/tmp/cc0I4j8Z.s
GNU assembler version 2.10 (mips64-unknown-elf) using BFD version 2.10
mips64-unknown-elf-gcc -v -ffunction-sections -fdata-sections
-Ttarget.ld -nostartfiles bug.o -o bug
Reading specs from
/home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2/collect2 -o
bug -L/home/yotta/software/lib/gcc-lib/mips64-unknown-elf/2.95.2
-L/home/yotta/software/mips64-unknown-elf/lib bug.o -lgcc -lgcc
-Ttarget.ld

--- objdump of bug.o ---
[ things to note in the objdump
[     size of .devtab section is 60 bytes (28 + 4 bytes pad + 4 bytes)
[     b starts at a 32 byte offset from the start of .devtab
[     the loop increments by 28 bytes (start+0x70)
bug.o:     file format elf32-bigmips

Sections:
Idx Name          Size      VMA               LMA               File
off  Algn
  0 .text         00000000  0000000000000000  0000000000000000 
00000034  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  0000000000000000  0000000000000000 
00000034  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  0000000000000000  0000000000000000 
00000034  2**0
                  ALLOC
  3 .reginfo      00000018  0000000000000000  0000000000000000 
00000034  2**2
                  CONTENTS, READONLY, LINK_ONCE_SAME_SIZE
  4 .mdebug       0000027c  0000000000000000  0000000000000000 
0000004c  2**2
                  CONTENTS, READONLY, DEBUGGING
  5 .text.f       00000024  0000000000000000  0000000000000000 
000002c8  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
  6 .devtab       0000003c  0000000000000000  0000000000000000 
000002f0  2**3
                  CONTENTS, ALLOC, LOAD, RELOC, DATA
  7 .sdata        0000000a  0000000000000000  0000000000000000 
00000330  2**3
                  CONTENTS, ALLOC, LOAD, DATA
  8 .text._start  00000090  0000000000000000  0000000000000000 
0000033c  2**2
                  CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
Disassembly of section .text:
Disassembly of section .data:
Disassembly of section .text.f:

0000000000000000 <f>:
   0:   27bdfff8        addiu   $sp,$sp,-8
   4:   ffbe0000        sd      $s8,0($sp)
   8:   03a0f02d        move    $s8,$sp
   c:   08000005        j       14 <f+0x14>
  10:   0000102d        move    $v0,$zero
  14:   03c0e82d        move    $sp,$s8
  18:   dfbe0000        ld      $s8,0($sp)
  1c:   03e00008        jr      $ra
  20:   27bd0008        addiu   $sp,$sp,8
Disassembly of section .devtab:

0000000000000000 <a>:
        ...
   8:   00000001        0x1
        ...
  14:   00000001        0x1
        ...

0000000000000020 <b>:
  20:   00000008        jr      $zero
  24:   00000008        jr      $zero
  28:   00000001        0x1
        ...
  34:   00000001        0x1
  38:   00000000        nop
Disassembly of section .sdata:

0000000000000000 <.sdata>:
   0:   61000000        daddi   $zero,$t0,0
   4:   00000000        nop
   8:   Address 0x8 is out of bounds.

Disassembly of section .text._start:

0000000000000000 <_start>:
   0:   27bdffc8        addiu   $sp,$sp,-56
   4:   ffbf0030        sd      $ra,48($sp)
   8:   ffbe0028        sd      $s8,40($sp)
   c:   03a0f02d        move    $s8,$sp
  10:   00000000        nop
  14:   3c020000        lui     $v0,0x0
  18:   64420000        daddiu  $v0,$v0,0
  1c:   afc20020        sw      $v0,32($s8)
  20:   8fc20020        lw      $v0,32($s8)
  24:   3c030000        lui     $v1,0x0
  28:   64630000        daddiu  $v1,$v1,0
  2c:   14430003        bne     $v0,$v1,3c <_start+0x3c>
  30:   00000000        nop
  34:   0800001f        j       7c <_start+0x7c>
  38:   00000000        nop
  3c:   8fc20020        lw      $v0,32($s8)
  40:   8c43000c        lw      $v1,12($v0)
  44:   0060f809        jalr    $v1
  48:   8fc40020        lw      $a0,32($s8)
  4c:   10400005        beqz    $v0,64 <_start+0x64>
  50:   00000000        nop
  54:   8fc20020        lw      $v0,32($s8)
  58:   24030001        li      $v1,1
  5c:   0800001b        j       6c <_start+0x6c>
  60:   ac430018        sw      $v1,24($v0)
  64:   8fc20020        lw      $v0,32($s8)
  68:   ac400018        sw      $zero,24($v0)
  6c:   8fc20020        lw      $v0,32($s8)
  70:   2443001c        addiu   $v1,$v0,28
  74:   08000008        j       20 <_start+0x20>
  78:   afc30020        sw      $v1,32($s8)
  7c:   03c0e82d        move    $sp,$s8
  80:   dfbf0030        ld      $ra,48($sp)
  84:   dfbe0028        ld      $s8,40($sp)
  88:   03e00008        jr      $ra
  8c:   27bd0038        addiu   $sp,$sp,56


So is this just by coding in eCos, or a compiler bug?

-- 
Chris Morrow	YottaYotta Inc.
email:		cmorrow@yottayotta.com
phone:		(780) 439 9000 ext 227
web:		http://www.yottayotta.com

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