Page 1 of 1

portiaravr.c

PostPosted: Wed Dec 15, 2004 1:52 am
by MiM
In lines 91+92 and 166+167 of this file there is the 16-bit stack pointer loaded using 2 subsequent instructions:

asm("OUT 0x3D,Rxx ");
asm("OUT 0x3E,Ryy ");

However this looks like a potentially dangerous operation as there is a risk of an interrupt occurence just between those 2 instructions while the stack pointer holds an incorrect value. To avoid it I think the stack pointer load should better look like this:

__disable_interrupt();
asm("OUT 0x3D,Rxx ");
asm("OUT 0x3E,Ryy ");
__enable_interrupt();


Re: portiaravr.c

PostPosted: Wed Dec 15, 2004 2:42 am
by aek
You are absolutely right.

Wrap them with interrupt disabling (as you propose) and you'll be alright.

The gcc and ImageCraft ports handle it properly in OSCtxSw(), but not in OSDispatch().

How embarassing -- what was I thinking?

------------------


Re: portiaravr.c

PostPosted: Fri Dec 17, 2004 1:27 am
by aek
OK, we've issued a Service Bulletin SB-26 for this problem.

Patch files will be posted to the various download directories shortly.

------------------

[This message has been edited by aek (edited December 17, 2004).]


Re: portiaravr.c

PostPosted: Fri Dec 17, 2004 8:09 am
by aek
Minor correction to MiM's observation:
quote:
In lines 91+92 and 166+167 of this file there is the 16-bit stack pointer loaded using 2 subsequent instructions:
No change is necessary to OSCtxSw() in portiaravr.c (lines 166 & 167) because interrupts are already disabled at the start of OSCtxSw() (IN R17,0x3F, CLI), and are re-enabled at the end (OUT 0x3F,R17). Adding a wrapper there will not hurt anything, though ...

With this observation, it's simply OSDispatch() in all three ports that is incorrect and needs the CLI/SEI "wrapper" around the write to the 16-bit SP.

------------------


Re: portiaravr.c

PostPosted: Fri Dec 17, 2004 8:50 am
by Kelly Painter
This sounds like something I should be concerned about. How should the Imagecraft port OSDispatch() be modified to be interrupt safe?

Thanks,
Kelly


Re: portiaravr.c

PostPosted: Fri Dec 17, 2004 8:52 am
by aek
I'm working on a set of patches for all the AVR compilers we support ... stay tuned ...

------------------