At 4:03 PM -0800 3/22/99, Scott Johnson wrote:
>This is basically a subroutine call but by number instead of by address.

Basically, yes, but that glosses over a lot.

The trap opcode generates an exception which calls an exception handler.
For the OS traps, we've installed a trap dispatcher to handle that
exception.  The handler looks at the next word after the program counter to
figure out which trap is being called, then looks up the address of that
function in the trap table.  It then pushes that address on the stack in
place of the old return address and returns from the exception.  The CPU
branches to the OS routine instead of back to your code.

Note that the compiler still has to set up the stack (push all the
parameters) before executing the trap instruction, because the OS call will
expect to find them on the stack, so it does a bit more than just insert
the two words.

Finally, the trap dispatcher is also used for shared library calls, in
which case it uses the library's dispatch table instead of the OS one.

                                --Bob


Reply via email to