...access section addresses from C or C++?

Comments

7 comments

  • Avatar
    John Wood

    I'm using CrossStudio 1.3 for MSP430, and want to use the start and end of my CODE section in my C code. I've tried using &__CODE_end__ without success. Have I got a wrong character somewhere, or does this not work in my version?

     

    Thanks John

    0
    Comment actions Permalink
  • Avatar
    Stephen Hersey

    The above reference code works for CrossWorks 2.0, but generates a compiler warning when used under Crossworks 2.1; since I'm required to compile using "-Wall", this generates an error and kills my build. Is there a simple solution other than disabling the -Wall option?

     

    I'd like to try casting the void object to a uint8_t in order to take its address, as in the sample below, but I'm unsure if this is wise, being somewhat unfamiliar with entities of type void. Will this code work reliably and safely?

     

    extern void __text_start__;
    
    void
    func(void)
    {
      unsigned long *ptr = &(uint8_t)(__text_start__);
      ...
    }
    0
    Comment actions Permalink
  • Avatar
    Stephen Hersey

    Well, the casting trick I mention above won't work; the compiler complains that __text_start__ is not a complete type.

    I've also tried the #pragma GCC diagnostic  ignore "-Werror" route, but while the compiler WILL complain if the pragma is malformed, it WON'T actually prevent the compiler error on the original reference code, regardless of what the GCC docs say about diagnostic pragmas overriding command-line options. The best solution now appears to be to set the "Treat warnings as errors" property for the affected files to "No" in the Properties pane of the IDE.

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    Try

    extern unsigned __text_start__[];

    should be okay with C nor sure about C++

    0
    Comment actions Permalink
  • Avatar
    Stephen Hersey

    Thanks! That seems to work. As I'm working in C, C++ isn't an issue.

    If I understand the situation correctly, we could declare __text_start__ to be of any type we please here. Since all that we do is take its address, the fact that there's no actual variable (just an address with that name) won't matter, and the compiler and linker will be happy.

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    Correct. I'm moving over to use the unsigned[]  This was Paul's suggestion as it avoids warnings (in context I use it) and doesn't look too odd.

    0
    Comment actions Permalink
  • Avatar
    Jgros

    For those working with the MSP430 the syntax is

     

    extern unsigned char __begin_SECTIONNAME[];

    extern unsigned char __end_SECTIONNAME[];

     

    if you had a section called SECTIONNAME in your section placement file.

    0
    Comment actions Permalink

Please sign in to leave a comment.