2

I'd like to have an interrupt routine in SRAM on a LPC1768. I'm using a GCC toolchain similar to Yagarto. Currently I can do the following from C:

NVIC_SetVector(TIMER0_IRQn, interruptTest);

...Then in my assembly file:

    .text
/* .section    .fastcode */
    .global     interruptTest
    .func       interruptTest
    .thumb_func
interruptTest:
    ldr         r0,=(LPC_TIM0 + IR)    /* point to Timer 0's Interrupt Register */
    mov         r1,#(1 << 0)           /* Interrupt Pending bit for MR0 int */
    str         r1,[r0]                /* Clear it */

    bx          lr

    .size       interruptTest, . - interruptTest
    .endfunc

Now this works just fine, the pointer to the 'interruptTest' function is odd. However, when I enable the '.section .fastcode' bit, then the pointer to the interrupt becomes even instead of odd.

My question is: How do I correctly make the interrupt routine be recognized as a thumb function ?

artless noise
  • 21,212
  • 6
  • 68
  • 105
  • 1
    Add `.thumb` somewhere? `.section .fastcode` is some linker section. I see that it is code with different LMA/VMA from some googling; but I am not sure you refer to the same. Do you have more information on `.fastcode`? Is it like [this question](http://stackoverflow.com/questions/13831462/understanding-the-location-counter-of-gnu-linker-scripts)? – artless noise May 03 '13 at 17:31
  • I've already tried adding '.thumb' right above '.thumb_func', but it made no difference, so I left it out to avoid confusion. The .text section still works, without modifying anything else. The linker-script I've been using is here: [link](http://openlcb.sourceforge.net/trunk/scratchpads/dgoodman/OpenLCB_Template/makesection/LPC17xx.ld) –  May 03 '13 at 23:25
  • Note: I had to fix the linker-script, so the BSS section does not overwrite the .fastcode and .data sections. I've sent bug-reports to the author about this. –  May 04 '13 at 00:21

1 Answers1

3

Got it!

Inserting '.type interruptTest,%function' makes it work.

So the final source should be:

    .section    .fastcode,"ax",%progbits
    .global     interruptTest
    .func       interruptTest
    .type       interruptTest,%function
    .thumb_func
interruptTest:
    ldr         r0,=(LPC_TIM0 + IR)    /* point to Timer 0's Interrupt Register */
    mov         r1,#(1 << 0)           /* Interrupt Pending bit for MR0 int */
    str         r1,[r0]                /* Clear it */

    bx          lr

    .size       interruptTest, . - interruptTest
    .endfunc

Important: The "ax",%progbits were added to the .section directive, because otherwise the section will sometimes be ignored.