From: daniel pralle (daniel.pralle_at_stud.uni-hannover.de)
Date: 2001-03-10 14:41:18
On Wed, 7 Mar 2001, Ullrich von Bassewitz wrote: > > Have a look at the following routine. It has the purpose to increment the > stack. I've made it samewhat simpler than the last example (which was the > actual routine minus 65C02 code and was optimized for speed): > > incsp: inc sp ; Increment low byte > ; <-- Assume interrupt here > bne @L1 ; Jump if no overflow > inc sp+1 ; Overflow, increment high byte > @L1: rts > > Now assume that the value of the stackpointer is $CBFF. This means that the > low byte will overflow and the high byte has to be incremented, too. The final > value (after calling the function) should be $CC00. > > If an interrupt occurs after incrementing the low byte (marked with an arrow), > the value of the stack pointer at this point is $DB00 - which is not only > wrong, but may also be outside the stack area. > > Now, if you call a C function, this C function will use the stack, and this > means that it will use an invalid stack pointer. > > The problem here is, that the increment of the stack pointer is not atomic, so > it may have an invalid value if the routine is interrupted. What about making it ATOMIC with SEI and CLI? There is a way to mask out the NMIs aswell on the ATARI and on the other system also, if not the possible interupts could limited to maskable interupts. daniel ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo_at_musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:39 CET