#342 PIC backend: pointer passing arg smash

Scott Dattalo
Linas Vepstas

In certain rare cases, the stack is smashed. Sorry, no simple test
case. The bug occured when

1) the virtual stack addres was set to 0x38
2) the C program was large enough to have data above 0x38
3) a void func (const char *) routine was called.

The const char * pointer was passed in W (high addres bits) and
in s0x38 (low adress bits). Unfortuantely, it was received with
a r0x38 instead of the correct s0x38. Don't know why.

Setting the virtual stack address above any real RAM on the PIC
fixes the problem.

The following patch does the trick:

Index: pcode.c

RCS file: /cvsroot/sdcc/sdcc/src/pic/pcode.c,v
retrieving revision 1.27
diff -r1.27 pcode.c
< initStack(0x38, 8);
> /* Note:
> * The virtual stack is placed higher than any real memory in the PIC.
> * If it is placed in low memory, then there are certain cases (pointer
> * passing) where it gets smashed (due to a bug elsewhere??). The bug
> * I saw was during function entry with a const char * pointer, and then
> * popRegFromIdx generated an r0x reference instead of the * correct
> * s0x reference.
> */
> initStack(0x888, 8);


  • Scott Dattalo
    Scott Dattalo

    • labels: --> pic14 target
    • assigned_to: nobody --> sdattalo
    • status: open --> closed-out-of-date