🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.atari.st
Article #36307

Re: Mfpint() and interrupts

#36307
From: Allan Pratt
Date: Tue, 31 Jan 1989 18:08
37 lines
2232 bytes
In article <8901302240.AA10005@ucbvax.Berkeley.EDU>
ACPS5589@RYERSON.BITNET (George Borges) writes:

> How can I install my own interrupt routine (in C) for the Ring Indicator
> line and the Carrier Detect line?  Currently, my routines DO execute but
> the program bombs (usually two or three of them) immediately afterwards.

You can't do it in C unless your compiler or library have some tricks. 
Specifically, C routines end with RTS (return from subroutine) while
interrupt handlers need to end with RTE (return from exception).  MWC
has a library call, I think, which arranges for the calling procedure to
end with RTE rather than RTS -- I think it plays games with the stack to
achieve this.  Check their documentation. 

However, the problem goes even deeper.  Interrupt handlers must not
change any registers (except SR; that's on the exception frame).  Most C
compilers can't be told to save & restore *all* the registers they use. 

Usually, if I *really* want to have the exception handler in C, I have a
little assembly language to save registers, call the C procedure, then
restore the registers and RTE:

	_ring:	movem.l	d0-d2/a0-a2,-(sp)	; alcyon clobbers these
		jsr	_myring
		movem.l	(sp)+,d0-d2/a0-a2
		rte

Then use "extern int ring()" and "Mfpint(xx,ring)" to install it.

Better still, do the installation in assembly, so you can read & store
the old handler's address, and restore it when you leave.  Mfpint
(foolishly) doesn't return the old value of the vector, so you can't use
it to save & restore things. 

============================================
Opinions expressed above do not necessarily	-- Allan Pratt, Atari Corp.
reflect those of Atari Corp. or anyone else.	  ...ames!atari!apratt
Technical Details
Message-ID: <1328@atari.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!oliveb!pyramid!decwrl!sun!imagen!atari!apratt
References: <Info-Atari16@SCORE.STANFORD.EDU> <8901302240.AA10005@ucbvax.Berkeley.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!oliveb!pyramid!decwrl!sun!imagen!atari!apratt
From: apratt@atari.UUCP (Allan Pratt)
Newsgroups: comp.sys.atari.st
Subject: Re: Mfpint() and interrupts
Message-ID: <1328@atari.UUCP>
Date: 31 Jan 89 18:08:38 GMT
References: <Info-Atari16@SCORE.STANFORD.EDU> <8901302240.AA10005@ucbvax.Berkeley.EDU>
Reply-To: apratt@atari.UUCP (Allan Pratt)
Organization: Atari (US) Corporation, Sunnyvale, California
Lines: 37