• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Development Tools » TI C/C++ Compiler » TI C/C++ Compiler - Forum » Dynamic section sizing at link time
Share
TI C/C++ Compiler
  • Forum
Options
  • Subscribe via RSS

Forums

Dynamic section sizing at link time

  • Mateja Putic11728
    Posted by Mateja Putic11728
    on Mar 25 2010 21:09 PM
    Intellectual275 points

    I am trying to allocate space for a heap structure that is to be used by user-managed dynamic memory allocation (as opposed to compiler-managed) .  I would like for this structure to take up the rest of remaining RAM, no matter what it may be.  I want this structure to be resized accordingly as my codebase changes and global variables may come and go through different firmware revisions.  

    Does anyone have an idea for the "right" way to do this?

    My idea right now is to have a section for this structure in the linker command file that places it at _STACK_END, effectively at the beginning (LBA) of the remaining space.  However, I'm having a hard time figuring out how to make the size of this section available at runtime.

    Any help would be appreciated.

    Thanks,

    Mateja

    CCS Version:  4.1.3.00038
    Target:  MSP430F2618
    Debugger:  FET430UIF

    Embedded Hacker Blog

    linker sections dynamic
    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Mateja Putic11728
    Posted by Mateja Putic11728
    on Mar 29 2010 09:32 AM
    Intellectual275 points
    Any takers? I would very much appreciate someone's ideas on this. Thanks! Mateja

    CCS Version:  4.1.3.00038
    Target:  MSP430F2618
    Debugger:  FET430UIF

    Embedded Hacker Blog

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • George Mock
    Posted by George Mock
    on Mar 29 2010 09:56 AM
    Guru51565 points

    There is no built-in feature of the linker for a dynamically sized section.  This is a cool idea, and I've been thinking about it ...

    -George

     


    TI C/C++ Compiler Forum Moderator
    Please click Verify Answer on the best reply to your question.
    The Compiler Wiki answers most common questions.
    Track an issue with SDOWP. Enter your bug id in the "Find Record ID" box.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Mateja Putic11728
    Posted by Mateja Putic11728
    on Mar 29 2010 10:17 AM
    Intellectual275 points
    If it's not a built-in feature, then there's a workaround, it's just a matter of finding it. Where there's a will, there's a way, I'm going to keep digging on this one. Mateja

    CCS Version:  4.1.3.00038
    Target:  MSP430F2618
    Debugger:  FET430UIF

    Embedded Hacker Blog

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • George Mock
    Posted by George Mock
    on Mar 30 2010 10:42 AM
    Guru51565 points

    I found one way to create a "section" where the size is whatever is left of a given memory range.  I use quotes to indicate an ordinary section is not created.

    Here is a linker command file ...

    #define MEM_START 0x200
    #define MEM_LEN   0xFDE0
    myheap_end = MEM_START + MEM_LEN;
    
    /* SPECIFY THE SYSTEM MEMORY MAP */
    
    MEMORY
    {
        SFR(R)           : origin = 0x0000, length = 0x0010
        PERIPHERALS_8BIT : origin = 0x0010, length = 0x00F0
        PERIPHERALS_16BIT: origin = 0x0100, length = 0x0100
        MEM(RW)          : origin = MEM_START, length = MEM_LEN
        VECTORS(R)       : origin = 0xFFE0, length = 0x001E
        RESET            : origin = 0xFFFE, length = 0x0002
    }
    
    /* SPECIFY THE SECTIONS ALLOCATION INTO MEMORY */
    
    SECTIONS
    {
        .intvecs : {} > VECTORS          /* INTERRUPT VECTORS                 */
        GROUP {
          .bss                           /* GLOBAL & STATIC VARS              */
          .sysmem                        /* DYNAMIC MEMORY ALLOCATION AREA    */
          .stack                         /* SOFTWARE SYSTEM STACK             */
    
          .text                          /* CODE                              */
          .cinit                         /* INITIALIZATION TABLES             */
          .const                         /* CONSTANT DATA                     */
          .cio                           /* C I/O BUFFER                      */
    
          .pinit                         /* C++ CONSTRUCTOR TABLES            */
        } > MEM, END(myheap_start)
        .reset   : > RESET
    }
    

    All of the interesting stuff is in red.  And here is some example C code ...

    #include <stdio.h>
    
    extern unsigned myheap_start, myheap_end;
    
    main()
    {
        unsigned myheap_length;
        myheap_length = (unsigned) &myheap_end - (unsigned) &myheap_start;
    
        printf("myheap_start:  %x\n", &myheap_start);
        printf("myheap_end:    %x\n", &myheap_end);
        printf("myheap_length: %x\n", myheap_length);
    }
    

    The net effect is that whatever part of the MEM memory range that is not used is left to a "section" that is starts at myheap_start, ends at myheap_end, and has length myheap_length.  The #define's allow you to define the start and length of MEM in single spot, then use it as needed.  The purpose of the GROUP is so you can use the END operator to mark the end of the group, which is the same as the start of the custom heap.  An unnecessary side effect is that everything in the GROUP will be allocated to memory in that exact order.  But all other methods I can think of for developing the heap start address have even worse problems.

    Thanks and regards,

    -George

     


    TI C/C++ Compiler Forum Moderator
    Please click Verify Answer on the best reply to your question.
    The Compiler Wiki answers most common questions.
    Track an issue with SDOWP. Enter your bug id in the "Find Record ID" box.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • Mateja Putic11728
    Posted by Mateja Putic11728
    on Mar 31 2010 08:06 AM
    Intellectual275 points
    George, Thanks for the follow-up, I'll give it a try and will post back. Mateja

    CCS Version:  4.1.3.00038
    Target:  MSP430F2618
    Debugger:  FET430UIF

    Embedded Hacker Blog

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use