[comp.sys.amiga.tech] Exception Processing

451061@UOTTAWA.BITNET (Valentin Pepelea) (01/19/89)

In message 3703@crash.cts.com, billk@pnet01.cts.com (Bill Kelly) writes:
> Well, I guess that about wraps it up for Amiga Interrupts...
> Next question, please?  :-)

What about about exception processing, oh venerable Guru? I need to
simulate a 680x0 coprocessor interface, and therefore need to do some
F-line instruction emulation. I *have* to use the autovectors rather
than the Exec interrupt facility, so please don t suggest an alternative.

The question is, what happens to the 68000 then? I understand that a7
gets switched with the exception stack pointer. Now, is my Amiga still
multitasking, can I call an AmigaDOS function in order load a file from
disk?

If we are still multitasking, what if another task encounters an F-line
instruction simoultaneously? Will then both tasks have their A7 register
loaded with the same exception stack pointer?

The problem I have is that I will absolutely need to do some disk I/O
during exception processing.

                                                    Valentin
_________________________________________________________________________
"An  operating  system  without         Name: Valentin Pepelea
 virtual memory is an operating         Phone: (613) 233-1821
 system without virtue."                Bitnet: 451061@uottawa
                                        Usenet: Look at the header
         - Ancient Inca Proverb         Planet: Earth

billk@pnet01.cts.com (Bill W. Kelly) (01/20/89)

451061@UOTTAWA.BITNET (Valentin Pepelea) writes:
>
>In message 3703@crash.cts.com, billk@pnet01.cts.com (Bill Kelly) writes:
>> Well, I guess that about wraps it up for Amiga Interrupts...
>> Next question, please?  :-)
>
>What about about exception processing, oh venerable Guru? I need to
>simulate a 680x0 coprocessor interface, and therefore need to do some
>F-line instruction emulation. I *have* to use the autovectors rather
>than the Exec interrupt facility, so please don t suggest an alternative.

Ok.  Well, are you going to check whether the processor is greater than or
equal to 68010 and if so look in VBR (the vector base register) to see where
the exception vectors really are?  (Or you going to assume that your program
is only going to be run on a 68000? (Or that VBR will always be zero?))

If your program is going to be released into the public domain then you may
just want to take your chances and not worry about this.  I don't know.

>The question is, what happens to the 68000 then? I understand that a7
>gets switched with the exception stack pointer.

Essentially, yes.  Here's a more detailed description of exception processing:

First of all, an internal copy is made of the processor status register.  Then
the S bit (supervisor bit in the status register) is asserted, which puts the
processor into supervisor state.  The T (trace) bit is negated to disable
instruction tracing during the exception.  (For the reset and interrupt
exceptions, the interrupt priority mask is also updated.)

Next, the vector number of the exception is determined.  The vector number is
used to determine the address of the exception vector.  (On a 68000, the
vector number is shifted left by two to get the address.  On 68010 and above,
the contents of VBR is also added to this to get the address.)   An exception
stack frame is created.  (The size and contents of the stack frame depends not
only on the exception, but on the processor.  68010 and above stack frames can
contain more information than 68000 stack frames.)  

Then, the PC and the saved copy of the status register are pushed onto the
supervisor stack.  (The PC usually points to the next unexecuted instruction,
except in the case of address errors and bus errors in which case the PC is
unpredictable.)  

Finally, the new PC is fetched from the exception vector and the processor
starts executing code at this address.  (The address of the exception-code,
that is.)

>Now, is my Amiga still
>multitasking, cann I call an AmigaDOS function in order load a file from
>disk?

No.

No, the processor is in supervisor privilege state.  Your "task" is not
running anymore.  An exception routine is running (possibly yours).  Exception
handling code is supposed to do its job as fast as possible and then RTE so
that the system can get back to whatever it was doing before it was so rudely
interrupted.   You cannot (and, I assure you, you do not want to) call
AmigaDOS from an exception.  You can call a select few Exec routines.
Exception handling code should execute in milliseconds, not seconds!

>If we are still multitasking, what if another task encounters an F-line
>instruction simoultaneously? Will then both tasks have their A7 register
>loaded with the same exception stack pointer?

This cannot happen, for reasons stated above.

>The problem I have is that I will absolutely need to do some disk I/O
>during exception processing.

You really don't, I assure you.

Instead, how about signalling your process?  That way the exception handling
code can do its job quickly.  Your process will wake up when its time comes
and do the necessary disk I/O and whatever else it needs to do.  

You could also Cause() a software interrupt from exception code, but this is
not all that useful in this case because you need to be a process to call
AmigaDOS.  

Also, you might look into TASK exceptions.  Your task/process can take
exception when certain signals are received.  This kind of exception is very
different from a 68000 exception.   With task exceptions, multitasking
continues uninterrupted.  

Ok, you might try this out:

Have your 68000 Line-F exception handling code Signal() your process with a
signal that you will take exception to.  (See the SigExcept() function.)

Now, your task will be interrupted from whatever it's doing and will begin
executing the code pointed to be tc_ExceptCode.  Your TASK exception routine
can take as long as it wants to execute and should be able to call AmigaDOS.


By the way, I'm not entirely sure why you feel you NEED to patch the 68000
exception vectors yourself.  Like Interrupts, the Amiga operating system has
built-in support for 68000 exceptions too.  (These are called TRAPS on the
Amiga.)    


Basically, I suggest you read the chapter on "Tasks" in the Rom Kernal Manual
(or the "Exec" manual).  Also, you may want to read the MC68000 Programmer's
Reference Manual (by Motorola) to find out more about Exception Processing.

If you have any specific questions about 68000 exceptions, Amiga TASK
exceptions and Amiga TRAPS, please don't hesitate to ask.

                                                                Good luck,
                                                                Bill
--
Bill W. Kelly                                         billk@pnet01.cts.com
{nosc ucsd hplabs!hp-sdd}!crash!pnet01!billk   crash!pnet01!billk@nosc.mil

kim@uts.amdahl.com (Kim DeVaughn) (01/24/89)

In article <3741@crash.cts.com>, billk@pnet01.cts.com (Bill W. Kelly) writes:
> 
> Basically, I suggest you read the chapter on "Tasks" in the Rom Kernal Manual
> (or the "Exec" manual).  Also, you may want to read the MC68000 Programmer's
> Reference Manual (by Motorola) to find out more about Exception Processing.

Another EXCELLENT source of information is Carl Sasenrath's book that just
came out, "Meditation's #1: Interrupts" (I probably munged the spelling of
his name terribly).  Check in the small ads in the back of AmigaWorld for
the address ... about $15.

The 1st half of the book is mostly theory, background, etc.  The 2nd half
has many small code sequences, examples, and such.

Hopefully there will be several more in the "Meditation" series ... it's
something that's been sorely needed for a LONG time!  Recommended.

/kim

-- 
UUCP:  kim@amdahl.amdahl.com
  or:  {sun,decwrl,hplabs,pyramid,uunet,oliveb,ames}!amdahl!kim
DDD:   408-746-8462
USPS:  Amdahl Corp.  M/S 249,  1250 E. Arques Av,  Sunnyvale, CA 94086
BIX:   kdevaughn     GEnie:   K.DEVAUGHN     CIS:   76535,25