[comp.sys.amiga.tech] software "exceptions"

crash@ckctpa.UUCP (Frank J. Edwards) (08/02/89)

I've been trying to use the Amiga's signalling system to cause an
"exception" (thats CBM's term, not Motorola's).  The idea is not
to have to perform a Wait() for the CLOSEWINDOW gadget or to
poll the tc_SigRecvd member of the Task Control Block...

Perhaps someone can shed some light on why my exception handler
doesn't work.  The code that I *was* going to use was much more
ambitious than this.  In trying to make something work, I've gotten
it simplified down to what you see here:

Compiled under Manx 3.6a with
 % cc setup.c
 % ln test.o setup.o -o test -lc
 % test
 <Visit from the "Task Held" requester follows...>
--------------------------------------------------------------------

long flag;

#asm
_except:
	moveq.l	#99,d1		; this is to let me know it worked!
	move.l	d1,_flag
	rts
#endasm

setup_excp(port)
struct MsgPort *port;
{
	extern void except_hndlr(), (*old_handler)();
	struct Task *FindTask(), *task;

	sig = 1L << port->mp_SigBit;
	task = FindTask(0L);

	/*
	 *  old_handler is used at termination to put back
	 *  the address that used to be there...
	 */
	old_handler = (void (*)()) task->tc_ExceptCode;
	SetExcept(sig, sig);
	(void (*)()) task->tc_ExceptCode = except_hndlr;

	/*
	 *  Now whenever I receive a message on "port",
	 *  my exception handler should be called...
	 *
	 *  The Signal() call *forces* me to get a signal.
	 *  [Although testing seems to indicate that there
	 *  may be a bug in the Manx stub for Signal() since
	 *  the tc_SigRecvd variable doesn't change!]
	 */
	Signal( task, sig );

	Delay( 50L );
	printf("flag = %ld\n", flag);
	return( 0 );
}
--------------------------------------------------------------------

Well, if you see the problem please let me know!  I'm tear'in my
hair out try to find it (and I can't afford to lose much more :-)

Thanks net.folks!

--
#include <std/disclaimer.h>	/* My employer isn't even involved! */

Frank J. Edwards		ComputerKnowledge Corporation
2677 Arjay Court		12740 Hillcrest Rd, Suite 212
Palm Harbor, FL  34684-4505	Dallas, TX  75230      (800) 385-9700

crash@ckctpa.UUCP (Frank J. Edwards) (08/03/89)

>"Frank J. Edwards" <crash@ckctpa.uucp> writes in message <143@ckctpa.UUCP>
>> I've been trying to use the Amiga's signalling system to cause an
>> "exception" (thats CBM's term, not Motorola's).
>
> Actually, CBM's term is Software Interrupt last time I checked.
>
> Valentin

No, a software interrupt *IS* a software interrupt
	(flag bit in the MsgPort structure is PA_SOFTINT);
an exception is analagous to the Un*x signals
	(flag bit is PA_SIGNAL plus tc_SigExcept bit must be set);
and a trap *IS* a trap
	(no MsgPort equivalent).

Concerning CBMs terminology, I guess "2 out of 3 ain't bad!!"  :-)
--
#include <std/disclaimer.h>	/* My employer isn't even involved! */

Frank J. Edwards		ComputerKnowledge Corporation
2677 Arjay Court		12740 Hillcrest Rd, Suite 212
Palm Harbor, FL  34684-4505	Dallas, TX  75230      (800) 385-9700

crash@ckctpa.UUCP (Frank J. Edwards) (08/03/89)

In article <7526@cbmvax.UUCP> jesup@cbmvax.UUCP (Randell Jesup) writes:
>In article <143@ckctpa.UUCP> crash@ckctpa.UUCP (Frank J. Edwards) writes:
>>I've been trying to use the Amiga's signalling system to cause an
>>"exception" (thats CBM's term, not Motorola's).  The idea is not
>>to have to perform a Wait() for the CLOSEWINDOW gadget or to
>>poll the tc_SigRecvd member of the Task Control Block...
>...
>>Compiled under Manx 3.6a with
>>long flag;
>>
>>#asm
>>_except:
>>	moveq.l	#99,d1		; this is to let me know it worked!
>>	move.l	d1,_flag
>>	rts
>>#endasm
>
>	I suspect the Manx assembler is referencing flag off of A4, which of
>course has a random value.  The Manx AS is rather nasty about changing your
>code without asking you to what it "knows" is right.  Try large code/data 
>or some such (I don't use manx).
>
>-- 
>Randell Jesup, Keeper of AmigaDos, Commodore Engineering.

Yes, that's probably it.  I'll check the assembler code generated.

And later ...

>	Oh yes, standard disclaimer: you can't assume that your program
>isn't in a ROM routine with resources locked, so you can't safely change
>the PC of the program (unless you're 101% certain it can't have anything
>locked).

Good point.  AmigaDOS isn't re-entrant, is it?

I had hoped, at least in the case of CLOSEWINDOW, that since my handler
ran in user-mode it could take care of task cleanup (memory allocations,
windows, screens, etc) and then call exit().  But exit() calls Close()
and probably other DOS/Exec routines so that's not safe.

Hmmm.  Sounds like no matter what I do, I'm required to set a flag and
process it in the normal execution of the program.  Which means I'm back
to polling a flag variable somewhere ... might as well be tc_SigRecvd.

--
#include <std/disclaimer.h>	/* My employer isn't even involved! */

Frank J. Edwards		ComputerKnowledge Corporation
2677 Arjay Court		12740 Hillcrest Rd, Suite 212
Palm Harbor, FL  34684-4505	Dallas, TX  75230      (800) 385-9700

451061@UOTTAWA.BITNET (Valentin Pepelea) (08/03/89)

"Frank J. Edwards" <crash@ckctpa.uucp> writes in message <143@ckctpa.UUCP>

> I've been trying to use the Amiga's signalling system to cause an
> "exception" (thats CBM's term, not Motorola's).

Actually, CBM's term is Software Interrupt last time I checked.

> Perhaps someone can shed some light on why my exception handler
> doesn't work.

I can't, but I'm sure that Carl Sassenrath, the Exec's chief designer can.
He has published a book called "Guru's Guide #1: Interrupts". A must-have
for hackers like you. Look in a recent Amiga Whirled for an ad in the
classifieds section.

Valentin
_________________________________________________________________________
"An  operating  system  without         Name:   Valentin Pepelea
 virtual memory is an operating         Phonet: (613) 231-7476 (New!)
 system without virtue."                Bitnet: 451061@Uottawa.bitnet
                                        Usenet: Use cunyvm.cuny.edu gate
         - Ancient Inca Proverb         Planet: 451061@acadvm1.UOttawa.CA

jesup@cbmvax.UUCP (Randell Jesup) (08/03/89)

In article <143@ckctpa.UUCP> crash@ckctpa.UUCP (Frank J. Edwards) writes:
>I've been trying to use the Amiga's signalling system to cause an
>"exception" (thats CBM's term, not Motorola's).  The idea is not
>to have to perform a Wait() for the CLOSEWINDOW gadget or to
>poll the tc_SigRecvd member of the Task Control Block...
...
>Compiled under Manx 3.6a with
>long flag;
>
>#asm
>_except:
>	moveq.l	#99,d1		; this is to let me know it worked!
>	move.l	d1,_flag
>	rts
>#endasm

	I suspect the Manx assembler is referencing flag off of A4, which of
course has a random value.  The Manx AS is rather nasty about changing your
code without asking you to what it "knows" is right.  Try large code/data 
or some such (I don't use manx).

-- 
Randell Jesup, Keeper of AmigaDos, Commodore Engineering.
{uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.cbm.commodore.com  BIX: rjesup  
Common phrase heard at Amiga Devcon '89: "It's in there!"

jesup@cbmvax.UUCP (Randell Jesup) (08/03/89)

In article <143@ckctpa.UUCP> crash@ckctpa.UUCP (Frank J. Edwards) writes:
>I've been trying to use the Amiga's signalling system to cause an
>"exception" (thats CBM's term, not Motorola's).  The idea is not
>to have to perform a Wait() for the CLOSEWINDOW gadget or to
>poll the tc_SigRecvd member of the Task Control Block...

	Oh yes, standard disclaimer: you can't assume that your program
isn't in a ROM routine with resources locked, so you can't safely change the
PC of the program (unless you're 101% certain it can't have anything locked).

-- 
Randell Jesup, Keeper of AmigaDos, Commodore Engineering.
{uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.cbm.commodore.com  BIX: rjesup  
Common phrase heard at Amiga Devcon '89: "It's in there!"

jesup@cbmvax.UUCP (Randell Jesup) (08/05/89)

In article <148@ckctpa.UUCP> crash@ckctpa.UUCP (Frank J. Edwards) writes:
>In article <7526@cbmvax.UUCP> jesup@cbmvax.UUCP (Randell Jesup) writes:
>>	Oh yes, standard disclaimer: you can't assume that your program
>>isn't in a ROM routine with resources locked, so you can't safely change
>>the PC of the program (unless you're 101% certain it can't have anything
>>locked).
>
>Good point.  AmigaDOS isn't re-entrant, is it?

	Sure it is, but you can't change the PC of the program safely in most
cases, since some of the 'state' (what's locked, etc) is dependent on what
the PC is (i.e. if you hijack the PC while it's between a LockIBase() and
an UnLockIBase(), IBase is locked forever).

>I had hoped, at least in the case of CLOSEWINDOW, that since my handler
>ran in user-mode it could take care of task cleanup (memory allocations,
>windows, screens, etc) and then call exit().  But exit() calls Close()
>and probably other DOS/Exec routines so that's not safe.

	The other thing to remember is that exceptions have (I think) and
interrupt-like context - no memory allocation, etc.

>Hmmm.  Sounds like no matter what I do, I'm required to set a flag and
>process it in the normal execution of the program.  Which means I'm back
>to polling a flag variable somewhere ... might as well be tc_SigRecvd.

	Yup.  Exceptions are a kind-of nice idea that didn't really end
up being very useful.

-- 
Randell Jesup, Keeper of AmigaDos, Commodore Engineering.
{uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.cbm.commodore.com  BIX: rjesup  
Common phrase heard at Amiga Devcon '89: "It's in there!"