Skip to main content
yagov
Associate II
April 15, 2010
Question

how to compile program using only relative jumps?

  • April 15, 2010
  • 4 replies
  • 932 views
Posted on April 15, 2010 at 06:42

how to compile program using only relative jumps?

    This topic has been closed for replies.

    4 replies

    mrost9
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 13:47

    The first thing the program contains, is the  interrupt vector.

    The interrupt vector already contains the stack pointer and pointers to your interrupt service routines.These pointers are absolute adresses already.

    Your copy algorithm needs to update each interrupt pointer with the new location.

    It would be easier to use the bootloader approach, where you have loader and program at fixed locations in the flash. There is an AppNote from ST that explains how to jump between the two locations.

    It's quite easy, as long as you don't intend to do a mass erase.

    You can erase and program the flash sector by sector, so you can update your program from the bootloader and the bootloader from your program.

    damh
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:47

    With GCC it is ''-fPIC'' for Position Indipendent Code. You have to change the data and absolute jumps (like interrupt table) yourself. The interrupt table (and the rest of Position Dependent Data) should be changed before writing it to flash. Otherwise you need to create the interrupt table in RAM and after every restart. If you correct them before flashing, you only have to change the interrupt table base address.

    yagov
    yagovAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:47

    The interrupts will be turned off before the ''reprogramming'' - thank you for this remark.

    I agree that the use of constan areas of program is a variant  of decision of the problem.

    Another variant - write a loader part using assambler (and commands with relative jumps only).
    yagov
    yagovAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:47

    Very, very, very thanks!