This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to determine the END of the program at runtime?

Hi!

I switched to the SiLabs variety of 8051s, and now I can actually flash parts of the memory from inside my application to store some configuration data.

But: I'd like to safeguard my function against overwriting /erasing actual program code. So I need to find a way to determine the end of the code at runtime in order to prevent any accesses to flash below the boundary.

The BL51 pretty much mixxes all the code around in memory - if there was a way to tell him "Put THISVERYOBJECT at the end" I had a way to determine the End-of-Code-address.

Alternatively, is there a way to tell the linker to turn the statistics into runtime-accessable symbols? In "Ye Olden Days" (and on a different platform) I had a linker thet generated symbols like __CODESIZE__ and __DATASIZE__ that could easily be accessed from C.

Are there other paths to determine the code size? I thought about a script gobbling the linker map file and turning the "Program Size:"-line into C source, but this would imply the need for multiple compilation runs (and including a project related tool in the source repository, etc.), which I'd like to avoid.

Help!

Yours, Christian Treczoks

Parents
  • I haven't used SROM myself but I was thinking you might be able to use it to retrieve the end address of a certain section. Hmm, you don't even need this really.

    Is it possible to create your linker file such that all sections are linked in a certain order and create a "sentinel" section? Sections (C166) are called segements on C51 I noticed.

    The SEGMENTS directive even has a "LAST" parameter.

    http://www.keil.com/support/man/docs/lx51/lx51_segments.htm

    If you can make sure the classes are ordered in a certain way and you use the LAST parameter on the SEGMENTS directive to put a sentinel segment at the last positition of the last class you can drop a single variable in the segment. &variable should be the end address.

    My EUR 0.02...

    --
    Joost

Reply
  • I haven't used SROM myself but I was thinking you might be able to use it to retrieve the end address of a certain section. Hmm, you don't even need this really.

    Is it possible to create your linker file such that all sections are linked in a certain order and create a "sentinel" section? Sections (C166) are called segements on C51 I noticed.

    The SEGMENTS directive even has a "LAST" parameter.

    http://www.keil.com/support/man/docs/lx51/lx51_segments.htm

    If you can make sure the classes are ordered in a certain way and you use the LAST parameter on the SEGMENTS directive to put a sentinel segment at the last positition of the last class you can drop a single variable in the segment. &variable should be the end address.

    My EUR 0.02...

    --
    Joost

Children