[comp.sys.atari.st] Cntrl-C Exception Handling

kerly@udel.EDU (Philip Kerly) (10/31/88)

Hello,
   I've got a problem that I've been working on for several days that has
left me perplexed.  Hopefully, someone on the net can help me out.
   I've been trying to write a Cntrl-C interrupt handler without much 
success.  I'm using Mark Williams's C compiler for setting the exception
address.  This is working fine.  I know that I'm getting to the function
that I've referenced when setting the exception address.  I'm also using
an assembly routine written by Mark Williams Co. called setrte() which is
the first thing that is called in the interrupt service routine.  This all
appears to be working correctly when I invoke the interrupt within the 
software using a trap #4.  However, if I remove the trap #4 and try to
invoke the interrupt using Cntrl-C from the keyboard the system crashes.
  I have several questions:
  1.  Does a trap #4 invoke the same response as a Cntrl-C interrupt from
the keyboard? (i.e. Is the stack adjusted the same way?)
  2.  When an interrupt is invoked and the status register is placed on the
stack, does this register reflect the status before the interrupt or does
it reflect the status due to the interrput.
   The code I've been working with is below.  It's very short so there maybe
some hackers that have Mark Williams C that would be interested in taking a 
look at it.  Thanks in advance for any time you may expend looking this code.


                                                  Phil

#include <osbind.h>
#include <signal.h>
#include <stdio.h>

sig_catch()
   {
   setrte();               /*<-------- can be found in Mark Williams C   */
   printf ("THERE\n");              /* disks under /src directory.  It's */
   }                                /* found in setrte.s                 */

main ()
   {
   signal (SIGINT, sig_catch);      /* signal and SIGINT is delcared in  */
   for (;;)                         /* signal.h                          */
       printf ("HERE\n");
   }

apratt@atari.UUCP (Allan Pratt) (11/01/88)

In article <5078@louie.udel.EDU> kerly@udel.EDU (Philip Kerly) writes:
> an assembly routine written by Mark Williams Co. called setrte() which is

Your ^C handler routine should end with RTS, not RTE.  Don't call setrte();
just end your function (or use "return;").

The ^C handler vector is meant to be used to clean things up as you are
being terminated.  In particular, if you have interrupt service routines
installed, your ^C handler should un-install them.  Your ^C handler is
called if you get bombs, too.  In fact, it's called no matter HOW you
terminate: it's even called when you call Pterm(). 

If you really want to trap ^C and *not* exit, you should know that
the terminate handler vector gets called from Supervisor mode.  
You can use setjmp/longjmp to get back to your program, as long as
your setjmp/longjmp save the SR and SP's properly.  I don't know
if MWC's do.

============================================
Opinions expressed above do not necessarily	-- Allan Pratt, Atari Corp.
reflect those of Atari Corp. or anyone else.	  ...ames!atari!apratt