[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] one-byte stack bug in tiny26
From: |
Peeter Vois |
Subject: |
Re: [avr-gcc-list] one-byte stack bug in tiny26 |
Date: |
Tue, 27 Apr 2004 19:37:53 +0300 |
would
void func(void)
{
static unsigned char array[4];
array[0] =1;
array[1] =2;
}
help? if inside the scope variable declaration is not
static the C compiler will reserve memory inside stack.
Ühel ilusal kenal päeval Tue, 27 Apr 2004 09:42:23 +0200
"Svein E. Seldal" <address@hidden> kirjutas:
> 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
>
>
>
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list