#342 PIC backend: pointer passing arg smash

closed-out-of-date
Scott Dattalo
5
2003-04-11
2002-05-09
Linas Vepstas
No

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
1088c1088,1096
< 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);

Discussion

  • Scott Dattalo
    Scott Dattalo
    2003-04-11

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