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

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

[avr-gcc-list] one-byte stack bug in tiny26


From: Svein E. Seldal
Subject: [avr-gcc-list] one-byte stack bug in tiny26
Date: Tue, 27 Apr 2004 09:42:23 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113

Hi,

I'm using tiny26 with gcc (3.3.2). As we all know, the tiny26 has only
one byte stack. My problem arises because of this code:

        void func(void)
        {
                unsigned char array[4];

                array[0] = 1;
                array[1] = 2;
        }

When the function is initialized, gcc copies SPL and SPH (which is
reserved) into YREG in the function prolog.

In the tiny26 the SPH register is reserved; It contains bogus data, making YREG into an invalid pointer. When the array is allocated on top of the frame, using the YREG pointer, accesses to or from the array data is invalid becuase of the corrupted YREG framepointer.

The -mtiny-stack option, does not help either. SPL and SPH is still loaded/unloaded in the function's prologues and epiloges.

I found this:

http://www.avr1.org/pipermail/avr-gcc-list/2001-October/000895.html

where it is stated that the loading/unloading of the two stack bytes in the function prologue is intentional, despite the usage of the -mtiny-stack option.

According to the datasheet, the register of SPH is reserved. This implies that we cannot predict the contents of that register, thus gcc should never read SPH on this target. (Even if its done intentional.)


Svein





reply via email to

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