Fixed Function Locations

  • robert

    How do i or is their an easy way to fix the location of a function?  I was thinking their might be some linker command (as is apparently the case with Keil), but looking at the linker documentation, I didn't really see any help with this type of thing.

    • Patryk

      Look for codeseg (pragma and command line option) in SDCC manual. You need to:
      - put your function in separate file,
      - use --codeseg MY_FUNC in command line to compile that file or put codeseg pragma at begin of it:
        #pragma codeseg MY_FUNC
      - pass option to linker:
        directly: -b MY_FUNC=0x1000
        or indirectly through SDCC: -Wl-bMY_FUNC=0x1000 or "-Wl -bMY_FUNC=0x1000"

    • Maarten Brock
      Maarten Brock

      But why would you want this?

      If you really need something like this I think it's better to create a jump-table in asm.

    • GrahamNZ

      To Maarten, and all SDCC users,
      Many newer processors have embedded firmware that allows writing to their Flash code memory. An example of this is the LPC9xx family from NXP.

      There are two supporting entry points:
      1) Supports programming through serial download
      2) Lower level support for erasing and writing blocks of Flash.

      The entry points are fixed in (high) memory, typically 0xFF03.

      Of the suggested methods I would use the asm jump table approach as I feel it is a more robust option than specifying a raft of command line parameters.

      Comments and working code samples welcome,

      • Maarten Brock
        Maarten Brock

        Isn't this the opposite of the original question? That was about putting your own function at a fixed address. For that I recommend to use a jumptable.

        But jumping to (prefab) functions at fixed addresses can easily be done with function pointers (as also recently discussed on the user mailing list).