avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] bad address access - compiler-problem?


From: Mario Boller-Olfert
Subject: [avr-gcc-list] bad address access - compiler-problem?
Date: Wed, 8 May 2002 12:16:55 +0200

Hi,

I already send this problem to AVR-Freaks, but nobody seemed to be able to
help me.

I got a problem concerning GCC. I think there may be a compiler error. I am
not good in AVR-assembler, so some help would be fine. I try to give all
necessary information.

I try to write a little unix like device system. I will provide it as
freeware when I get it to run. In it is some code with these definitions:

----------------------
struct dirs {
    char *path;
    uint8_t major;
    uint8_t minor;
};

struct dirs dir[NO_DIRE] = {
{ "tty" , 0, 0 }, // UART 0
{ "ram" , 1, 0 }, // PCF8570, address 0
{ "par1", 2, 0 }, // PCF8574, address 0
{ "par2", 2, 1 }, // PCF8574, address 1
{ "ad0" , 3, 0 }, // PCF8591, address 0, 1. A/D-converter
{ "ad1" , 3, 1 }, // PCF8591, address 0, 2. A/D-converter
{ "ad2" , 3, 2 }, // PCF8591, address 0, 3. A/D-converter
{ "ad3" , 3, 3 }, // PCF8591, address 0, 4. A/D-converter
{ "da0" , 3,32 }, // PCF8591, address 0, D/A-converter
};

... some other code ...
for(j=0; j<NO_DIRE; j++) {
    if(! strcmp(path, dir[j].path) ) {
        filetable[i].major = dir[j].major;
        filetable[i].minor = dir[j].minor;
        cdev[filetable[i].major].pdopen(
        filetable[i].minor, mode);
        return i;
    }
}
.. even more code ...

The problem is at the call of strcmp.

"path" is a pointer to the string "tty". I execute this code in the
AVR-Studio 3.53 simulator. At the call of strcmp not the address of the
string value dir[j].path is transferred, but part of the string itself!

With optimization -O2 the assembler code near the strcmp looks like this (I
provide the listing instead of the disassembly code in AVR studio for better
readability):

166 006a C091 0000     lds r28,dir
167 006e D091 0000     lds r29,(dir)+1
168                .L17:
169                    .stabn 68,0,60,.LM11-open
170                .LM11:
171 0072 6881          ld r22,Y
172 0074 7981          ldd r23,Y+1
173 0076 9B2D          mov r25,r11
174 0078 8A2D          mov r24,r10
175 007a 00D0          rcall strcmp
176 007c 892B          or r24,r25
177 007e 51F0          breq .L24
178                .stabn 68,0,59,.LM12-open
179                .LM12:
180 0080 2496          adiw r28,4
181 0082 1F5F          subi r17,lo8(-(1))
182 0084 1930          cpi r17,lo8(9)
183 0086 A8F3          brlo .L17

After line 166, Y does not contain the address of dir, but the address of
the first string. So the load operations at lines 171 and 172 do not load
the address of the string, but part of the string itself.

At line 175, r22=r23=0x74='tt' instead of 0x006e, what would be the address
of the string.

So what can I do? With -O0 it is just the same. I also tried to define a
pointer to a dir-element myself, but it did not help. The compiler installed
is avrgcc_freaks20011214a.exe

Bye
Mario

avr-gcc-list at http://avr1.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]