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]
Other format: [Raw text]

Re: Free BSD ioctl problem (Renesas EDOSK2674)


Hello Andrew,

> > ...
> >        hw_addr: ff:ff:ff:ff:ff:ff
>                   ^^^^^^^^^^^^^^^^^
>
> You should probably take a look at this. Using the broadcast address
> is not good.
>
>         Andrew
>

you should propably read my complete posting ;o) - i wrote the problem is
the ioctl function. But I will try to explain it more clear:

During initialisation of network in init_all_network_interfaces the function
build_bootp_record is called which sets up the bootp_record.
I do not use a hw boradcast address - I use the mac address stored in eeprom
of my Renesas EDOSK2674. But the function build_bootp_record does not fill
the bootp_record correctly. Why? Because it calls the function ioctl in
order to get the hardware address. This is the call in build_bootp_record
for the hardware mac address:

if (s >= 0) {
        strcpy(ifr.ifr_name, if_name);
        if (ioctl(s, SIOCGIFHWADDR, &ifr) >= 0) {
            bcopy(ifr.ifr_hwaddr.sa_data, bp->bp_chaddr, bp->bp_hlen);
        }

The ioctl function does not work correctly because the declaration in
various header files (i.e. ioctl.h) differs from the definition in io.cxx.

This is the declaration with variable argument list (i.e. in ioctl.h):

int ioctl __P((int, unsigned long, ...));

This is the definition in io.cxx with fixed argument list:

__externC int ioctl( int fd, CYG_ADDRWORD com, CYG_ADDRWORD data )
{
    ...
}

When the function is called then the function arguments where pushed onto
the stack because a variable argument list is expected because of the
declaration of the ioctl function. This is how the assembler code looks like
before the ioctl function call:

...
mov.l er2, @-er7                       // push arg3 on stack
mov.l #0xc0306964, er2
mov.l er2, @-er7                       // push arg2 on stack
mov.l @(oxffec:16,er6), er0       // move arg1 in er0
jsr @0x44a6a8:24                     // call ioctl function

The register er7 is the stack pointer. So the arguments 2 and 3 are pushed
onto stack and argument 1 is in register er0. And this is the assembler code
in the function ioctl immediately after the jsr instruction above is
executed:

mov.l er6, @-er7                   // save frame pointer
mov.l er7,er6
add.l #0xffffffe4,er7
mov.l er0,@(0xfffc:16,er6)     // get arg 1 from er0
mov.l er1,@(0xfff8:16,er6)     // get arg 2 from er1
mov.l er2,@(0xfff4:16,er6)     // get arg 3 from er2

So you can see, the function sets up the stack and then copies the function
arguments from the registers er0, er1 and er2 onto stack. But because of the
different function declaration the registers er0, er1 and er2 do not contain
the expected values. Now I changed the function declaration in a way that it
matches the definition:

Changed function declaration:

int ioctl __P((int, unsigned long, unsigned long));

Now the  assembler code before the function call of ioctl function looks
this way:

...
mov.l er6, er2                            // store arg 3 in er2
add.l #0xffffffb0, er2
mov.l @(0xfff8:16,er6), er1       // store arg 2 in er1
mov.l er2,er0                             // store arg 1 in er0
jsr @0x44a6a8:24                     // call ioctl function

Now the function arguments are stored where the ioctl function expects them
to be an I get the following output:
...
       flags: 0x0
       hw_addr: 00:00:87:d6:34:b9
     client IP: 192.168.101.152

Now my hw address is set properly and init_all_network_interfaces works like
expected.

So I repeat my question: Why differs the function declaration from function
definition and what should I do in order to fix this problem?

Thank you very much and regards,

Uwe

eCos port for Renesas H8S family
http://www.htwm.de/ukindler/ecos



-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


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