Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!uwvax!per2!dag From: dag@per2.UUCP (Daniel A. Glasser) Newsgroups: comp.sys.atari.st Subject: Re: Mfpint() Summary: Don't use GEMDOS functions from within an interrupt handler! Message-ID: <825@per2.UUCP> Date: 15 Feb 89 17:10:27 GMT References: <8902140121.AA03228@ucbvax.Berkeley.EDU> Organization: Persoft Inc., Madison, WI Lines: 88 In article <8902140121.AA03228@ucbvax.Berkeley.EDU>, ACPS5589@RYERSON.BITNET (George Borges) writes: > ----------------------------Original message---------------------------- > Thanks to those two folks who replied to me. However, I *still* > cannot get Mfpint() to work properly. Perhaps I am somewhat dense. > Here's what I'm trying to do: > .... > Jenabint( 14 ); /* enable ring indicator interrupt on MFP chip */ > Mfpint( 14, interrupt ); /* set vector to point to my function */ > > ... print stuff on screen in endless loop.... > > interrupt() > { > setrte(); /* in MWC 2.0 .. return from exception rather than rts */ > Cconws("RING!!!"); > } > > And that's basically it. I disable the interrupt after it occurs. > The interrupt routine *does* execute but my program bombs (usually 2 or 3 > of them). > > George Borges Okay, here's the straight dope from the dope who wrote the setrte function for MWC... You cannot safely use GEMDOS functions from within an interrupt routine. GEMDOS is not reentrant. The docs have the misleading language saying that the GEMDOS functions cannot be called recursively, but what they mean is that you cannot reenter GEMDOS while a GEMDOS function is in progress. When you trap to GEMDOS to do the Cconws you are entering GEMDOS. The GEMDOS trap handler puts the current context information into a fixed location, sets its own stack to another fixed location, and does what you asked. If a GEMDOS function is active when this happens, the return context gets overwritten as does the GEMDOS stack. This is not what you, or anybody else, wants. Although, technically, you can call BIOS and XBIOS functions from interrupt level routines, it is not a good idea in general. It is better to set flags for the application "user-mode" routines to deal with. The example in the MWC manual does use Cconws, but it is an example of how to catch a processor exception which will not occur in the execution of any GEMDOS routines (that I know of). Here is an example of how to use setrte() on an interrupt based on some external interrupt: short ringing; main() { ... Mfpint(14, interrupt); ringing = 0; Jenabint(14); for (;;) { ... while (ringing--) { /* don't wory about ints. */ Cconws("Ring!!!"); /* we'll catch it next time */ } ... } Jdisint(14); } interrupt() { setrte(); ++ringing; /* Atomic update */ } I've not had a chance to check this out, but it should work. Note also that your stack space is limited when you are in an interrupt routine. You don't know what you may be interrupting. Don't waste time in a interrupt routine. Daniel Glasser -- _____________________________________________________________________________ Daniel A. Glasser One of those things that goes uwvax!persoft!dag "BUMP!!!(ouch)" in the night. ---Persoft, Inc.---------465 Science Drive-------Madison, WI 53711-----------