[PicForth] Another macro related issue- suspend/restore-interrupts vanishes when used in a macro word

Alex Holden alex at linuxhacker.org
Mon Nov 29 13:40:59 CET 2004


I think this one may be a bug in PicForth. I came across it by accident 
while I was reading the disassembly looking for the cause of a different 
bug (which turned out to be a stack leak in my code)- I'm glad I found 
it though because it could have caused my program to randomly break at 
some point in the future when an interrupt happened to arrive at the 
wrong time. If a word defined within a macro block uses 
suspend-interrupts and restore-interrupts, the calls are not present in 
the generated assembly. For example:

include picisr.fs
: criticalsection ;
macro
: test1 suspend-interrupts criticalsection restore-interrupts ;
target
main : test2 test1 ;

Note that test2 compiles to a simple jump to criticalsection with no 
calls to suspend/restore-interrupts around it:

0x0000  018A    clrf    0x0A
0x0001  281A    goto    0x01A   ; (init-picforth)
         ; name: (isr-save)
         ; max return-stack depth: 0
0x0004  00FF    movwf   0x7F
0x0005  0E03    swapf   0x03,w
0x0006  0183    clrf    0x03
0x0007  00A2    movwf   0x22
0x0008  080A    movf    0x0A,w
0x0009  00A3    movwf   0x23
         ; name: suspend-interrupts
         ; max return-stack depth: 0
0x000D  0AA5    incf    0x25,f
0x000E  0B25    decfsz  0x25,w
0x000F  0008    return
0x0010  080B    movf    0x0B,w
0x0011  00A4    movwf   0x24
0x0012  138B    bcf     0x0B,7
0x0013  0008    return
         ; name: restore-interrupts
         ; max return-stack depth: 0
0x0014  0BA5    decfsz  0x25,f
0x0015  0008    return
0x0016  1BA4    btfsc   0x24,7
0x0017  178B    bsf     0x0B,7
0x0018  0008    return
         ; name: criticalsection
         ; max return-stack depth: 0
0x0019  0008    return
         ; name: (init-picforth)
         ; max return-stack depth: 0
0x001A  3036    movlw   0x36
0x001B  0084    movwf   0x04
0x001C  01A5    clrf    0x25
         ; name: test2
         ; max return-stack depth: 0
0x001D  2819    goto    0x019   ; criticalsection

-- 
------------ Alex Holden - http://www.linuxhacker.org ------------
If it doesn't work, you're not hitting it with a big enough hammer


More information about the PicForth mailing list