Traumflug / simulavr

A fork of SimulAVR (http://www.nongnu.org/simulavr/) for handling contributions. The practical SIMINFO mechanism implemented here wasn't accepted upstream, but is crucial for Teacup Firmware simulations, so this fork will stay ... and follow upstream. Default branch is 'traumflug', master here matches master on nongnu.org.
GNU General Public License v2.0
40 stars 26 forks source link

Fix interrupt handling with CLI / OUT SREG #9

Closed mhx closed 9 years ago

mhx commented 9 years ago

When an interrupt is detected and queued to be executed after the next statement and the next statement is either CLI or any other instruction that clears the global interrupt flag (OUT SREG, ...), the interrupt handler will still be called /after/ global interrupts have been disabled. This basically means that code that was meant to be uninterruptible (protected by CLI / SEI) can now be interrupted as the RETI will jump back to the first instruction after CLI and will even leave interrupts enabled.

This change aims to fix the problem by checking the current instruction before preparing interrupts. If the instructions will clear the interrupt flag, interrupt preparation will be skipped.

See also: https://savannah.nongnu.org/bugs/index.php?45941

mhx commented 9 years ago

Fixed instead by http://git.savannah.gnu.org/cgit/simulavr.git/commit/?id=ba6f5ec10c91c9586b70b3d4dcc0424ca44bbcad

Traumflug commented 9 years ago

Not so fast, please :-)

Having the fix upstream is always better, that's why I wasn't in a hurry. Just rebased the fork so one gets this fix there, too. Thank you very much for fixing this.

mhx commented 9 years ago

I only closed this pull request as the upstream fix is different from mine :-)

Traumflug commented 9 years ago

Hmm. With the upstream patch applied I experience lots of interrupt losses with code which seemingly works fine on a real controller. I've opened issue #10 for it.