Having program knows its end in flash

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there any routine built into GCC that will allow it to know the end of its last memory location in flash (esentially the _etext location in the map file). I know in some compilers ther are API calls for this, but could not find it in the AVRGCC docs.

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

_etext is a public symbol (provided by the
linker), you can use it if you need.
Don't forget that .data initialization values
will follow _etext though.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In all processor io header files (ioxxxx.h), there are constants that are defined at the end of the file, including the symbol FLASHEND.

For example, the iom128.h file has these defined:

/* Constants */
#define SPM_PAGESIZE 256
#define RAMEND 0x10FF /* Last On-Chip SRAM Location */
#define XRAMEND 0xFFFF
#define E2END 0x0FFF
#define FLASHEND 0x1FFFF

Eric

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Eric, that tells me where flash ends, not where my program ends in flash. I think the information no-name provided is what I want if I can figure out how to access it.

Thanks to you both for your replies.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

(Sorry for the "noname", forgot to log in first.)

It's fairly simple to do so. Just use the
external symbol as an immediate value, e.g.

.global flashend
flashend:
   ldi r24, lo8(__data_load_end)
   ldi r25, hi8(__data_load_end)
   ret

The C prototype for the above would be

extern void *flashend(void);

If it makes you feel better, you could add

.extern __data_load_end

but that's basically a no-op in GNU assembler.

Note that __data_load_end is certainly more
what you want than _etext, since it takes
the data segment initialization values into
account (if any, otherwise it'll become
identical to _etext).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry for the confusion!
Eric