MMIX Instruction Set |
||||
Content
|
General InformationTRIP and TRAP General
Special register rA records the current status information about arithmetic
exceptions. Its least significant byte contains eight "event" bits called DVWIOUZX from left to right,
where D stands for integer divide check, V for integer overflow, W for float-to-fix overflow, I for invalid
operation, O for floating overflow, U for floating underflow, Z for floating division by zero, and X for floating
inexact. The next least significant byte of rA contains eight "enable" bits with the same names DVWIOUZX
and the same meanings. When an exceptional condition occurs, there are two cases: If the corresponding
enable bit is 0, the corresponding event bit is set to 1. But if the corresponding enable bit is 1, MMIX
interrupts its current instruction stream and executes a special "exception handler." Thus, the event bits
record exceptions that have not been "tripped." The execution of MMIX programs can be interrupted in several ways. We have just seen that arithmetic exceptions will cause interrupts if they are enabled; so will illegal or privileged instructions, or instructions that are emulated in software instead of provided by the hardware. Input/output operations or external timers are another common source of interrupts; the operating system knows how to deal with all gadgets that might be hooked up to an MMIX processor chip. Interrupts occur also when memory accesses fail-for example if memory is nonexistent or protected. Power failures that force the machine to use its backup battery power in order to keep running in an emergency, or hardware failures like parity errors, all must be handled as gracefully as possible. Users can also force interrupts to happen by giving explicit TRAP or TRIP instructions:
Non-catastrophic interrupts in MMIX are always precise, in the sense that all legal instructions before a certain point have effectively been executed, and no instructions after that point have yet been executed. The current instruction, which may or may not have been completed at the time of interrupt and which may or may not need to be resumed after the interrupt has been serviced, is put into the special execution register rX, and its operands (if any) are placed in special registers rY and rZ. The address of the following instruction is placed in the special where-interrupted register rW. The instruction in rX might not be the same as the instruction in location rW - 4; for example, it might be an instruction that branched or jumped to rW. It might also be an instruction inserted internally by the MMIX processor. (For example, the computer silently inserts an internal instruction that increases L before an instruction like ADD $9,$1,$0 if L is currently less than 10. If an interrupt occurs, between the inserted instruction and the ADD, the instruction in rX will say ADD, because an internal instruction retains the identity of the actual command that spawned it; but rW will point to the real ADD command.) When an instruction has the normal meaning "set $X to the result of $Y op $Z" or "set $X to the result of $Y op Z," special registers rY and rZ will relate in the obvious way to the Y and Z operands of the instruction; but this is not always the case. For example, after an interrupted store instruction, the first operand rY will hold the virtual memory address ($Y plus either $Z or Z), and the second operand rZ will be the octabyte to be stored in memory (including bytes that have not changed, in cases like STB). In other cases the actual contents of rY and rZ are defined by each implementation of MMIX, and programmers should not rely on their significance.
Some instructions take an unpredictable and possibly long amount of time, so it may be necessary to
interrupt them in progress. For example, the FREM instruction (floating point remainder) is extremely
difficult to compute rapidly if its first operand has an exponent of 2046 and its second operand has an
exponent of 1. In such cases the rY and rZ registers saved during an interrupt show the current state of
the computation, not necessarily the original values of the operands. The value of rY rem rZ will still be
the desired remainder, but rY may well have been reduced to a number that has an exponent closer to the
exponent of rZ. After the interrupt has been processed, the remainder computation will continue where it
left off. Three kinds of interruption are possible: trips, forced traps, and dynamic traps. We will discuss each of these in turn. TRIPA TRIP instruction puts itself into the right half of the execution register rX, and sets the 32 bits of the left half to #80000000. (Therefore rX is negative; this fact will tell the RESUME command not to TRIP again.) The special registers rY and rZ are set to the contents of the registers specfied by the Y and Z fields of the TRIP command, namely $Y and $Z. Then $255 is placed into the special bootstrap register rB, and $255 is set to rJ. MMIX now takes its next instruction from virtual memory address 0. Arithmetic exceptions interrupt the computation in essentially the same way as TRIP, if they are enabled. The only difference is that their handlers begin at the respective addresses 16, 32, 48, 64, 80, 96, 112, and 128, for exception bits D, V, W, I, O, U, Z, and X of rA; registers rY and rZ are set to the operands of the interrupted instruction as explained earlier. A 16-byte block of memory is just enough for a sequence of commands like PUSHJ 255,Handler; PUT rJ,$255; GET $255,rB; RESUME which will invoke a user's handler. And if the user does not choose to provide a custom-designed handler, the operating system provides a default handler via the instructions A trip handler might simply record the fact that tripping occurred. But the handler for an arithmetic interrupt might want to change the default result of a computation. In such cases, the handler should place the desired substitute result into rZ, and it should change the most significant byte of rX from #80 to #02. This will have the desired effect, because of the rules of RESUME explained below, unless the exception occurred on a command like STB or STSF. (A bit more work is needed to alter the effect of a command that stores into memory.) Instructions in negative virtual locations do not invoke trip handlers, either for TRIP or for arithmetic exceptions. Such instructions are reserved for the operating system, as we will see. FORCED TRAP
A TRAP instruction interrupts the computation essentially like TRIP, but with the following modifications: The third and final kind of interrupt is called a dynamic trap. Such interruptions occur when one or more of the 64 bits in the special interrupt request register rQ have been set to 1, and when at least one corresponding bit of the special interrupt mask register rK is also equal to 1. The bit positions of rQ and rK have the general form
Negative addresses are for the use of the operating system only; a security violation occurs if an instruction
in a nonnegative address is executed without the rwxnkbsp bits of rK all set to 1. (In such cases the s bits
of both rQ and rK are set to 1.)
The eight "machine" bits of rQ and rK represent the most urgent kinds of interrupts. The rightmost
bit stands for power failure, the next for memory parity error, the next for nonexistent memory, the next
for rebooting, etc. Interrupts that need especially quick service, like requests from a high-speed network,
also are allocated bit positions near the right end. Low priority I/O devices like keyboards are assigned to
bits at the left. The allocation of input/output devices to bit positions will differ from implementation to
implementation, depending on what devices are available. GET $0,rQ; LDOU $1,savedK; AND $0,$0,$1; SUBU $1,$0,1; SADD $2,$1,$0; ANDN $1,$0,$1 the highest-priority offending bit will be in $1 and its position will be in $2.) If the interrupted instruction contributed 1s to any of the rwxnkbsp bits of rQ, the corresponding bits are set to 1 also in rXX. A dynamic trap handler might be able to use this information (although it should service higher-priority interrupts first if the right half of rQ ∧ rK is nonzero). The rules of MMIX are rigged so that only the operating system can execute instructions with interrupts suppressed. Therefore the operating system can in fact use instructions that would interrupt an ordinary program. Control of register rK turns out to be the ultimate privilege, and in a sense the only important one. An instruction that causes a dynamic trap is usually executed before the interruption occurs. However, an instruction that traps with bits x, k, or b does nothing; a load instruction that traps with r or n loads zero; a store instruction that traps with any of rwxnkbsp stores nothing. RESUME
After a trip handler or trap handler has done its thing, it generally invokes the following command.
RESUME Z "resume after interrupt"; the X and Y fields must be zero.
If the Z field of this instruction is zero, MMIX will use the information found in special registers rW, rX, rY,
and rZ to restart an interrupted computation. If the execution register rX is negative, it will be ignored and
instructions will be executed starting at virtual address rW; otherwise the instruction in the right half of
the execution register will be inserted into the program as if it had appeared in location rW - 4, subject to
certain modifications that we will explain momentarily, and the next instruction will come from rW.
If the Z field of RESUME is 1 and if this instruction appears in a negative location, registers rWW, rXX,
rYY, and rZZ are used instead of rW, rX, rY, and rZ. Also, just before resuming the computation, mask
register rK is set to $255 and $255 is set to rBB. (Only the operating system gets to use this feature.)
An interrupt handler within the operating system might choose to allow itself to be interrupted. In such
cases it should save the contents of rBB, rWW, rXX, rYY, and rZZ on some kind of stack, before making rK
nonzero. Then, before resuming whatever caused the base level interrupt, it must again disable all interrupts;
this can be done with TRAP, because the trap handler can tell from the virtual address in rWW that it has
been invoked by the operating system. Once rK is again zero, the contents of rBB, rWW, rXX, rYY, and rZZ
are restored from the stack, the outer level interrupt mask is placed in $255, and RESUME 1 finishes the job.
Values of Z greater than 1 are reserved for possible later definition. Therefore they cause an illegal
instruction interrupt (that is, they set the "b" bit of rQ) in the present version of MMIX. LDA $0,Loc; PUT rW,$0; LDTU $1,Inst; PUT rX,$1; RESUME will execute an almost arbitrary instruction Inst as if it had been in location Loc-4, and then will jump to location Loc (assuming that Inst doesn't branch elsewhere). See also: |
Please help to keep this site up to date! If you want to point out important material or projects that are not listed here, if you find errors or want to suggest improvements, please send email to