From: SourceForge.net <no...@so...> - 2004-08-05 08:17:42
|
Bugs item #1003390, was opened at 2004-08-04 18:32 Message generated for change (Settings changed) made by maartenbrock You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1003390&group_id=599 Category: msc51(8051) target >Group: non bugs >Status: Closed Resolution: Rejected Priority: 5 Submitted By: Frieder Ferlemann (frief) Assigned to: Nobody/Anonymous (nobody) Summary: IRQ preamble might save wrong register bank Initial Comment: This problem only occurs if functions are declared with the "using" keyword. (SDCC 2.4.3 #785) Source and some generated assembly follows: #include <8052.h> volatile unsigned char ms; #pragma save #pragma nooverlay void some_function(void) reentrant { ms++; } #pragma restore // IRQ preamble eventually pushes wrong register bank here if interrupt // occurs while register bank0 is not selected void some_irq( void ) interrupt 1 { some_function(); } void not_bank0_function() using 3 { unsigned char i=ms; while(--i) // allocated to r2 in bank 3 (0x1a) ms--; } void main( void ) { while(1) not_bank0_function(); } #if 0 ;irq.c:16: void some_irq( void ) interrupt 1 ; ----------------------------------------- ; function some_irq ; ----------------------------------------- _some_irq: push acc push b push dpl push dph ; ;*** pushing/setting psw should be done here?! ; push (0+2) push (0+3) push (0+4) push (0+5) push (0+6) push (0+7) push (0+0) push (0+1) push psw mov psw,#0x00 ;irq.c:18: some_function(); ; genCall lcall _some_function 00101$: pop psw pop (0+1) pop (0+0) pop (0+7) pop (0+6) pop (0+5) pop (0+4) pop (0+3) pop (0+2) ; ;*** popping psw should be done here?! ; pop dph pop dpl pop b pop acc reti #endif ---------------------------------------------------------------------- Comment By: Frieder Ferlemann (frief) Date: 2004-08-05 09:47 Message: Logged In: YES user_id=589052 As you mildly put it: "I don't think there is a problem." You're right (and it is OK not to save registerbank 2 in my second example). Sorry for the noise! ---------------------------------------------------------------------- Comment By: Frieder Ferlemann (frief) Date: 2004-08-05 09:35 Message: Logged In: YES user_id=589052 > Or perhaps I have misunderstood the problem? Sorry, I didn't put it correctly and my proposed "fix" was wrong. Still we have a problem with saving the wrong register bank, the following IRQ code saves register bank 0 while it uses (and changes) register bank 2: #include <8052.h> volatile unsigned char ms; void some_function(void); void some_irq( void ) interrupt 1 using 2 { unsigned char i=ms; while(--i) ms--; some_function(); } void not_bank0_function() using 2 { unsigned char i=ms; while(--i) // allocated to r2 in bank 3 (0x1a) ms--; } #if 0 ;irq.c:9: void some_irq( void ) interrupt 1 using 2 ; ----------------------------------------- ; function some_irq ; ----------------------------------------- _some_irq: ar2 = 0x12 ar3 = 0x13 ar4 = 0x14 ar5 = 0x15 ar6 = 0x16 ar7 = 0x17 ar0 = 0x10 ar1 = 0x11 push acc push b push dpl push dph push (0+2) *** saving registerbank 0 push (0+3) push (0+4) push (0+5) push (0+6) push (0+7) push (0+0) push (0+1) push psw mov psw,#0x10 ;irq.c:11: unsigned char i=ms; ; genAssign mov r2,_ms *** this is now using r2 of registerbank 2 ;irq.c:12: while(--i) ; genAssign 00101$: ; genMinus ; genMinusDec dec r2 ; genIfx mov a,r2 ; genIfxJump ; Peephole 110 removed ljmp by inverse jump logic jz 00103$ 00108$: ;irq.c:13: ms--; ; genMinus ; genMinusDec dec _ms ; Peephole 112.b changed ljmp to sjmp sjmp 00101$ 00103$: ;irq.c:14: some_function(); ; genCall mov psw,#0x00 lcall _some_function mov psw,#0x10 00104$: pop psw pop (0+1) pop (0+0) pop (0+7) pop (0+6) pop (0+5) pop (0+4) pop (0+3) pop (0+2) pop dph pop dpl pop b pop acc reti #endif ---------------------------------------------------------------------- Comment By: Erik Petrich (epetrich) Date: 2004-08-04 19:45 Message: Logged In: YES user_id=635249 You are expecting this sequence instead? _some_irq: push acc push b push dpl push dph push psw mov psw,#0x00 push (0+2) push (0+3) push (0+4) push (0+5) push (0+6) push (0+7) push (0+0) push (0+1) ;irq.c:18: some_function(); ; genCall lcall _some_function 00101$: pop (0+1) pop (0+0) pop (0+7) pop (0+6) pop (0+5) pop (0+4) pop (0+3) pop (0+2) pop psw pop dph pop dpl pop b pop acc reti If so, I don't think there is a problem. The push/pop instructions use the absolute addresses of the registers. Thus they save and restore r0 through r7 of register bank 0 regardless of which register bank is currently selected. Or perhaps I have misunderstood the problem? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1003390&group_id=599 |