#1513 pointer to pdata memory not correctly initialized

closed-fixed
5
2013-05-25
2009-03-02
No

within an array of code pointers a pointer to pdata memory space is not correctly initialized:

-----8<---------------------------------------------------------------------
__data unsigned char idd;
__idata unsigned char idi;
__xdata unsigned char idx;
__pdata unsigned char idp;
__code unsigned char idc = 0x34;

unsigned char * __code ap[5] = {&idd, &idi, &idx, &idp, &idc };

void main (void){}
----->8---------------------------------------------------------------------

results in:

-----8<---------------------------------------------------------------------
2 ; File Created by SDCC : free open source ANSI-C Compiler
3 ; Version 2.9.0 #5400 (Mar 2 2009) (UNIX)
..
7 .optsdcc -mmcs51 --model-small
..
148 .area CONST (CODE)
006A 151 _ap:
006A 08 00 40 152 .byte _idd,(_idd >> 8),#0x40
006D 09 00 40 153 .byte _idi,(_idi >> 8),#0x40
0070 01 00 00 154 .byte _idx,(_idx >> 8),#0x00
0073 00 00 40 155 .byte _idp,(_idp >> 8),#0x40
0076 69 00 80 156 .byte _idc,(_idc >> 8),#0x80
----->8---------------------------------------------------------------------

The memory spaces of the pointers to idp and idi/idd
(__pdata and __idata/__data) are initialized to #0x40.
While #0x40 is fine for both idi and idd, the memory space for idp
should have been #0x60.

Discussion

  • Robert Larice

    Robert Larice - 2009-03-10

    I suggest the following patch + testcase.
    Yet I tried it only for mcs51, and just for the attached
    testcase, not the whole suite.

    Robert Larice

    ----->8-----------
    Index: src/SDCCglue.c
    ===================================================================
    --- src/SDCCglue.c (Revision 5406)
    +++ src/SDCCglue.c (Arbeitskopie)
    @@ -370,6 +370,8 @@
    DCL_TYPE (val->type) = CPOINTER;
    DCL_PTR_CONST (val->type) = port->mem.code_ro;
    }
    + else if (SPEC_SCLS (expr->left->etype) == S_PDATA)
    + DCL_TYPE (val->type) = PPOINTER;
    else if (SPEC_SCLS (expr->left->etype) == S_XDATA)
    DCL_TYPE (val->type) = FPOINTER;
    else if (SPEC_SCLS (expr->left->etype) == S_XSTACK)
    Index: support/regression/tests/bug2655200.c
    ===================================================================
    --- support/regression/tests/bug2655200.c (Revision 0)
    +++ support/regression/tests/bug2655200.c (Revision 0)
    @@ -0,0 +1,58 @@
    +/*
    + */
    +
    +/*
    + * [ 2655200 ] pointer to pdata memory not correctly initialized
    + * http://sourceforge.net/tracker/index.php?func=detail&group_id=599&atid=100599&aid=2655200
    + *
    + * test_array[..] = &thing_pdata
    + * was incorrect
    + *
    + * SDCCclue.c(initPointer)
    + * ... SPEC_SCLS (expr->left->etype) == S_PDATA)
    + * was not handeled
    + */
    +
    +#include <testfwk.h>
    +#include <stdint.h>
    +
    +#ifdef __mcs51
    +
    +__code char thing_code = 0;
    +__data char thing_data;
    +__idata char thing_idata;
    +__xdata char thing_xdata;
    +__pdata char thing_pdata;
    +
    +char * __code test_array[] = {
    + &thing_code,
    + &thing_data, &thing_idata, &thing_xdata, &thing_pdata,
    +};
    +
    +char *gime_thing_code() { return &thing_code; }
    +char *gime_thing_data() { return &thing_data; }
    +char *gime_thing_idata() { return &thing_idata; }
    +char *gime_thing_xdata() { return &thing_xdata; }
    +char *gime_thing_pdata() { return &thing_pdata; }
    +
    +void
    +testBug(void)
    +{
    + ASSERT(test_array[0] == gime_thing_code());
    + ASSERT(test_array[1] == gime_thing_data());
    + ASSERT(test_array[2] == gime_thing_idata());
    + ASSERT(test_array[3] == gime_thing_xdata());
    + ASSERT(test_array[4] == gime_thing_pdata());
    +}
    +
    +#else
    +
    +void testBug(void) { ASSERT(1); }
    +
    +#endif
    +
    +/*
    + * Local Variables:
    + * compile-command: "make -C .. ALL_TESTS='./tests/bug2655200.c'"
    + * End:
    + */

    -----<8-----------

     
  • Frieder Ferlemann

    thanks a lot!

    A similar fix is needed near line 432 in src/SDCCglue.c

    otherwise this compiles
    ----->8-----------
    __pdata unsigned char adp[3];

    unsigned char * __code ap[] = { adp, (unsigned char *)adp };

    void main (void){}
    -----<8-----------

    to:

    ----->8-----------
    0069 138 _ap:
    0069 00 00 60 139 .byte _adp,(_adp >> 8),#0x60
    006C 00 00 40 140 .byte _adp,(_adp >> 8),#0x40
    -----<8-----------

    again thanks a lot!

     
  • Borut Ražem

    Borut Ražem - 2009-03-11

    Frieder, is this a candidate for 2.9.0?

    You know the rules: lo risk, ...

    If yes, can you apply and commit the patch?

    Borut

     
  • Frieder Ferlemann

    > Frieder, is this a candidate for 2.9.0?

    Yes, it should be safe to apply. Although I'm not familiar with that part of the compiler.

    (I can commit it later today or tomorrow)

     
  • Frieder Ferlemann

    applied modified patch from Robert Larice which fixes the original report (and my report from 2009-03-11)

    There is a problem left which affects mcs51 with --model-medium if the memory space is not explicitly specified. I added a testpoint for this in support/regression/tests/bug2655200.c (line 55, disabled for SDCC_MODEL_MEDIUM).

     
  • Maarten Brock

    Maarten Brock - 2009-10-05

    Fixed in SDCC 2.9.3 #5534

     
  • Maarten Brock

    Maarten Brock - 2009-10-05
    • milestone: --> fixed
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks