dleroy@x102a.harris-atd.com (leroy david 01354) (11/17/89)
I'm new to writing exception handling routines for the 68000 and have run into severel problems. Basically I would like to know how to handle the stack within my exception handling routine as I think this is where my problems are arising. The scenario: I have a main routine and a counter interrupt handler both which were written in C. I went into the assembly source for the interrupt handler and changed RTS to RTE and placed an instruction to save all the registers at the beginning of the routine and restore them at the end. I'm also a beginner at 68000 assembly coding so I'm not sure these are the correct commands. movem.l d0-d7/a0-a6,-(a7) /* save registers */ disable_counter_interrupts /* do any processing here enable_counter_interrupts movem.l (a7)+,d0-d7/a0-a6 /* restore registers */ RTE When I have a very simple main routine with just a printf statement in it, this works fine. I have a counter interrupt occuring every 200ms and toggling a status light. When I add processing in the main loop however, the interrupts seem to occur about 3 or 4 times and then the processor seems to be off in the weeds somewhere. Whats going on here? How do I ensure that nothing I do in the interrupt service routine messes up registers used in the interrrupted routine. I know this opens a whole can of worms. Some further info, this is all being run in the supervisor mode and the interrupt service routine is not calling any routines used by the main routine. -- ______________________________________________________________________ Dave LeRoy | Harris Corporation - GASD | ARPANET: dleroy@x102a.harris-atd.com P.O. Box 94000 | UUCP : uunet!x102a!dleroy Melbourne, FL 32902 | (407) 727-4000 | ----------------------------------------------------------------------
rbt@cernvax.UUCP (roberto divia) (11/21/89)
In article <DLEROY.89Nov17093930@x102a.harris-atd.com> dleroy@x102a.harris-atd.com (leroy david 01354) writes: >I'm new to writing exception handling routines for the 68000 and have >run into severel problems. [...] > [...] When I add processing in the main loop >however, the interrupts seem to occur about 3 or 4 times and then the >processor seems to be off in the weeds somewhere. Easy and quick solution: the interrupt service routine should INCREMENT an interrupt counter and RTE, e.g.: IntE ADDQ.L #1,IntCtr ! Interrupt service routine: IntCtr must be RTE ! "imported" from C static int IntCtr = 0; ! This must be exported to ASM ... << enable interrupts >>; for (;;) { while (IntCtr != 0) { << serve the interrupt request >>; IntCtr--; } << other things >>; } You might have more then one interrupt counter. This will work fine if the interrupt doesn't require short response time. If interrupts are generated very fast and you don't mind loosing some of them, another method is the following: IntE MOVE.L #1,IntFlg ! Interrupt service routine: IntFlg must be RTE ! "imported" from C static int IntFlg = 0; ! This must be exported to ASM ... << enable interrupts >>; for (;;) { if (IntFlg != 0) { << serve the interrupt request >>; IntFlg = 0; } << other things >>; } +-----------------------+----------------------------------------------+ | Roberto Divia` | Love at first sight is one of the greatest | | ============= | labor-saving devices the world has ever seen | +-----------------------+----------------------------------------------+ | CERN : European Laboratory for Particle Physics, 1211 Geneva 23 | | Switzerland (CH) | +----------------------------------------------------------------------+