• AVR Freaks

LockedAbsolute functions, __section, @, __at not working

Author
lorenberg
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2015/11/20 02:23:29
  • Location: 0
  • Status: offline
2015/11/22 23:41:31 (permalink)
0

Absolute functions, __section, @, __at not working

Good morning everyone,
 
this is my first post on the forum and I really hope someone can help me fixing this problem which is driving me crazy!
 
I am working with a PIC18F25K22, using MPLABX IDE v3.15 with compiler XC8 1.35.
 
I need to write a bootloader for my application; by reading on the manual and following a microchip webinar, I was able to merge application and bootloader in a single project, to separate the application code from the bootloader with the proper offset and to constrain the bootloader code in its specific section.
 
Now, the only thing I was not able to do so far was to remap the interrupt functions!
According to the manual, to define an absolute function, we should simply use the syntax with void func_name() @ADDRESS{}.
 
To make things extremely easy, my current code is the following
 
#include <xc.h>

void redirect_isr_low(void);

void redirect_isr_high();


void redirect_isr_high() @0x0008
{
 asm("GOTO 0xA08");
}

void redirect_isr_low() @0x0018
{
 asm("GOTO 0xA18");
}

void main(void)
{
 while(1);
}

 
 
What this code does is to simply jump from the default interrupt locations (0x08, 0x18) to the redefined locations (0xA08, 0xA18)
Unluckily, when I analyse the program memory, I found a NOP at locations 0008 and 0018.
Same problem if instead of the '@' I use __at().
I then tried to define a section using the linker options, as indicated in the manual; namely I wrote in the linker options
 

-L-pisr_high=08h

 
and then in the code I declared the functions as
 

void __section("isr_high") redirect_isr_high()
{
    asm("GOTO 0xA08");
}

 
but this time I got a compilation error (450): psect "isr_high" was never defined, or is local.
I tried also the #pramga psect syntax which was suggested in the webinar, but also in that case I did not succeed.
 
So, at this point I ran out of ideas. As said in the beginning, what I need is to simply place the 2 functions in the default interrupt positions (0x08 and 0x18) so that when an interrupt occurs, control is immediately transferred to the remapped interrupt vectors, as it normally happens in a traditional bootloader.
 
Thank you very much to everyone who can help!
 
 
 
 
 
 
 
 
#1

7 Replies Related Threads

    1and0
    Access is Denied
    • Total Posts : 9489
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Absolute functions, __section, @, __at not working 2015/11/23 08:40:21 (permalink)
    +1 (1)
    Have you tried:
    void high_priority interrupt high_isr(void)
    {
     asm("GOTO 0xA08");
    }

    void low_priority interrupt low_isr(void)
    {
     asm("GOTO 0xA18");
    }

    #2
    mad_c
    Super Member
    • Total Posts : 1191
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re: Absolute functions, __section, @, __at not working 2015/11/23 15:04:50 (permalink)
    +1 (1)
    lorenberg
    Now, the only thing I was not able to do so far was to remap the interrupt functions!
    According to the manual, to define an absolute function, we should simply use the syntax with void func_name() @ADDRESS{}.

    Also in the manual, Section 5.8.4 Changing the Default Function Allocation  says:
     
    If this construct [use of @ address] is used with interrupt functions it will only affect the position of the code associated with the interrupt function body. The interrupt context switch code that precedes the function code will not be relocated, as it must be linked to the interrupt vector.
     
    It looks like you want the interrupt entry points to remain at the vector locations, so the example code already posted which does not make the interrupt functions absolute should work.
     
    Jeff.
     
    #3
    Ian.M
    Super Member
    • Total Posts : 13225
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re: Absolute functions, __section, @, __at not working 2015/11/23 20:10:02 (permalink)
    +2 (2)
    However, that will save the context before it reaches the GOTO which is highly undesirable.
    This works:

    #include <xc.h>

    #asm
          FNCALL _main,_redirect_isr_high
          FNCALL _main,_redirect_isr_low
    #endasm

    void redirect_isr_high() @0x0008
    {
     asm("GOTO 0xA08");
    }

    void redirect_isr_low() @0x0018
    {
     asm("GOTO 0xA18");
    }

    void main(void)
    {
     while(1);
    }

     
    The secret is:  The optimiser removes 'dead' code, so when it sees two functions that apparently never get called it usually omits them.  The virtually undocumented ASPIC directive FNCALL hints to the optimiser that the functions are actually called, in this case by main() so it cheerfully generates code for them:

    Addr Opc  Label    Disassembly
    ---- ---- -------- -----------
    0000 EF0F __ftpack GOTO 0x1e
    0002 F000          NOP
    0004 FFFF          NOP
    0006 FFFF          NOP
    0008 EF04          GOTO 0xa08
    000A F005          NOP
    000C 0012          RETURN 0
    000E FFFF          NOP
    0010 FFFF          NOP
    0012 FFFF          NOP
    0014 FFFF          NOP
    0016 FFFF          NOP
    0018 EF0C          GOTO 0xa18
    001A F005          NOP
    001C 0012          RETURN 0
    001E 0100          MOVLB 0
    0020 EF12          GOTO main

     
    @Mad_C: Please get proper documentation for ASPIC, with good examples, put together ASAP.  It deserves a manual of its own, not just a condensed chapter in the compiler manual.  Its ridiculous that one has to dig around on the old HiTech forums to figure this stuff out!
    post edited by Ian.M - 2015/11/23 20:36:08

    --
    NEW USERS: Posting images, links and code - workaround for restrictions.
    I also support http://picforum.ric323.com because this forum is sometimes too broken to use!
    #4
    lorenberg
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2015/11/20 02:23:29
    • Location: 0
    • Status: offline
    Re: Absolute functions, __section, @, __at not working 2015/11/23 23:39:24 (permalink)
    0
    Hello everyone and thanks for the quick and great answers!
     
    Actually, I found the last one from Ian.M the best one, because in fact I do not want to save the context before jumping to the remapped vectors. I forgot to explicitly mention it in my initial question.
     
    In any case, I tried the solution from Ian.M and it worked exactly as it is supposed to; I was also suspecting somehow the optimizer was removing unused code, but I did not know how to tell it not to do this.
     
    As for the first answer yes, that code was working too but as correctly pointed out, saving the context before jumping is highly undesirable for my application.
     
    Thanks everyone for the help!
    #5
    1and0
    Access is Denied
    • Total Posts : 9489
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Absolute functions, __section, @, __at not working 2015/11/24 07:02:36 (permalink)
    0
    Ian.M
    However, that will save the context before it reaches the GOTO which is highly undesirable.
    This works:

    I was thinking about the context after I posted the above.  Very nice solution!
     

    The secret is:  The optimiser removes 'dead' code, so when it sees two functions that apparently never get called it usually omits them.  The virtually undocumented ASPIC directive FNCALL hints to the optimiser that the functions are actually called, in this case by main() so it cheerfully generates code for them:

    The HITECH C Tools for the PIC18 MCU Manual has more detailed information on ASPIC directives.  FNCALL is on page 145.
     
     
    @Mad_C: Please get proper documentation for ASPIC, with good examples, put together ASAP.  It deserves a manual of its own, not just a condensed chapter in the compiler manual.  Its ridiculous that one has to dig around on the old HiTech forums to figure this stuff out!

    Agree. grin: grin
     
    #6
    mad_c
    Super Member
    • Total Posts : 1191
    • Reward points : 0
    • Joined: 2010/12/12 17:48:27
    • Location: Brisbane, Australia
    • Status: offline
    Re: Absolute functions, __section, @, __at not working 2015/11/24 15:08:06 (permalink)
    +3 (3)
    Ian.M
    The secret is:  The optimiser removes 'dead' code, so when it sees two functions that apparently never get called it usually omits them.  The virtually undocumented ASPIC directive FNCALL hints to the optimiser that the functions are actually called, in this case by main() so it cheerfully generates code for them:

    Hi,
     
    You're on the right track, but your solution is actually more complex that it needs to be.
     
    First, the reason the FNxxx directives are now no longer documented is that they have very limited affect. All these directives are used by the linker. They were very important when the linker did the memory allocation of (compiled) stack-based variables. The linked had to have an accurate knowledge of those functions which were root functions, and which functions where called. However, the linker no longer performs this allocation, and while it would be delighted that someone was kind enough to tell it that one function called another by way of the FNCALL directive, it will simply ignore this information.
     
    For a C function specified as 'interrupt', it will be considered a root function and never deleted by the compiler. For other non-interrupt C functions, they might be removed by the code generator if they are never called. However, the compiler will never remove a C function if it is referenced by assembly code. So, while your FNCALL directives will work in preventing the functions from being removed, that is not because you have used FNCALL. The following:
     
    #asm
          GLOBAL _redirect_isr_high
          GLOBAL _redirect_isr_low
    #endasm

     
    will work just as well. This is mentioned in the User's Guide How to, 3.4.5.2 HOW DO I STOP AN UNUSED FUNCTION BEING REMOVED? and there is also more information in Section 5.12.3.4 UNDEFINED SYMBOLS. This works for variables as well as functions---they are essentially made volatile if referenced in assembly code.
     
    Jeff.
    #7
    Ian.M
    Super Member
    • Total Posts : 13225
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re: Absolute functions, __section, @, __at not working 2015/11/24 16:34:31 (permalink)
    +1 (1)
    Thanks for the clarification and the polite hint to RTFM yet again!.
     
    TABLE 6-4: ASPIC ASSEMBLER DIRECTIVES still refers to FNCALL and FNROOT.   Depreciated directives should be marked as such,with enough of a note to figure out where to look them up if one runs into them in legacy code.

    --
    NEW USERS: Posting images, links and code - workaround for restrictions.
    I also support http://picforum.ric323.com because this forum is sometimes too broken to use!
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5