• Keine Ergebnisse gefunden

Restrictions in Branching

Im Dokument PA-RISC 2.0 (Seite 82-90)

It is illegal for a BRANCH with GATE instruction to execute in the delay slot of a taken branch instruction. The PSW B-bit ensures that this sequence is not permitted. Whenever a branch is taken, the PSW B-bit is set to 1 and, if the next instruction is aBRANCH withGATE, an illegal instruction trap occurs.

400 LDW 0(r15), r4 ; target of IA-relative branch instruction

404 STW r4, 0(r18)

EXECUTION SEQUENCE

Location Instruction Comment

100 STW r7, 0(r8) ; priv = 0

104 BV r0(r7) ; priv = 0

108 BLR r4, r0 ; priv = 0

200 LDW 0(r3), r11 ; priv = 2 decreased by branch vectored instr 400 LDW 0(r15), r4 ; priv = 0 changed back by IA-relative branch

404 STW r4, 0(r18) ; priv = 0

PROGRAM SEGMENT

Location Instruction Comment

100 STW r7, 0(r8) ; non-branch instruction

104 BV r0(r7) ; branch vectored to location 200 I1

108 BLR r4, r0 ; IA-relative branch to location 400 I2

10C ADD r2,r6, r9 ; next instruction in linear code sequence

. .

. .

. .

200 LDW 0(r3), r11 ; target of branch vectored instruction I3

204 ADD r11,r12, r14 ;

. .

PROGRAM SEGMENT

Figure 4-3. Branch in the Delay slot of a Branch

Nullification

A nullified instruction is an instruction that is skipped over. It has no effect on the machine state (except that the IA queues advance and the X-bit, N-bit, and B-bit in the PSW are set to 0). The recovery counter is not decremented for a nullified instruction. Nullified instructions do not take group 3 interruptions (although they may take group 1, 2, or 4 interruptions).

All branch instructions and most computational instructions can nullify the execution of the following instruction. For branch instructions, nullification can be specified explicitly. In the case of computational instructions, nullification is performed conditionally based on the outcome of a test.

Instruction Execution

Instruction flow involves calculating the address of the current instruction and then fetching, decoding, and executing that instruction. This process involves performing the sequence of events listed below regardless of the instruction type. (Although these events are listed in sequence, many of them may occur in parallel. It is only necessary that they appear to be logically sequential.) In the description that follows, the values of the PSW bits are the values that exist before the instruction is executed. Changes to the PSW bits only affect instructions after the current instruction. This flow of instruction execution is shown in Figure 4-4.

1. If the PSW M-bit is 0, then high priority machine checks (HPMCs) may occur.

2. The processor checks for group 2 interruptions:

a. A power failure interrupt that is not masked by the PSW I-bit.

b. A recovery counter trap. This trap is enabled when the PSW R-bit) is 1 and the most-significant bit of the recovery counter is 1.

c. An external interrupt or low-priority machine check, both of which are unmasked by the PSW I-bit.

. .

. .

400 LDW 0(r15), r4 ; target of IA-relative branch instruction I4

404 STW r4, 0(r18) ; I5

EXECUTION SEQUENCE

Location Instruction Comment

100 STW r7, 0(r8) ;

104 BV r0(r7) ; schedules execution at 200 after delay instr I1 108 BLR r4, r0 ; schedules execution at 400 after delay instr I2 200 LDW 0(r3), r11 ; target of first branch executes out of context I3 400 LDW 0(r15), r4 ; target of second branch (is a non-branch) I4 404 STW r4, 0(r18) ; next instruction is in linear code sequence I5

d. A performance monitor interrupt that is not masked by the PSW F-bit.

3. Depending on the state of the PSW N-bit, one of two events occur:

a. If the current instruction is nullified (the PSW N-bit is 1), group 3 interruptions must not be Figure 4-4. Interruption Processing

taken. The instruction address queue is advanced and the back of the queue is written with the new front element + 4. The privilege level is the same as the new front element. The PSW X-bit, N-X-bit, and B-bit are set to 0.

b. If the current instruction is not nullified (the PSW N-bit is 0), then the instruction is fetched using the front elements of the instruction address (IA) queues. If a group 3 interruption occurs during execution, the processor rolls back the effect of the current instruction by restoring the beginning state and takes the interruption. If the PSW C-bit is 1, virtual address translation of the instruction address is performed. The PSW P-bit enables protection checking. On a split TLB system, the instruction TLB is used for instruction address translation. The fetching of the current instruction may result in an instruction TLB miss fault/instruction page fault or an instruction memory protection trap.

The Recovery Counter is decremented if the PSW R-bit is 1. The current instruction is executed and the PSW X-bit is set to 0. If the next instruction is to be nullified, the PSW N-bit is set to 1, and the instruction address queues are updated. The nature of that update depends on whether the current instruction is a taken branch:

• For a taken branch: the instruction address queues are advanced, the back of the queue is loaded with the target address including the privilege level which is computed by the branch instruction, and the PSW B-bit is set to 1.

• For a branch that is not taken: the instruction address queues are advanced, the back of the instruction address offset queue is written with the new front element + 4, the privilege level of the back element is set the same as the new front element, and the PSW B-bit is set to 0.

• If the current instruction is aRETURN FROM INTERRUPTION instruction, the IA queues and the PSW are updated with the new values and the following instruction is executed based on these new values.

4. Group 4 traps are handled after execution is complete. If the new privilege level is lower than that of the just completed instruction and the PSW L-bit was 1, a lower-privilege transfer trap is taken.

If the new privilege level is higher than that of the just completed instruction and the PSW H-bit was 1, a higher-privilege transfer trap is taken. The term “new privilege” level refers to the privilege level at which the following instruction executes.

If neither transfer trap is taken, the instruction just completed is a taken branch, and the PSW T-bit was 1, then a taken branch trap occurs.

Instruction Pipelining

The architecture permits implementations to prefetch up to seven instructions from the cache (including branch prediction) beyond the instruction currently executing. Instructions may modify resources which affect instruction fetch on the machine they are executing on. Instruction fetch resources include protection identifier registers, the PSW, and TLB entries. When such an event takes place, it affects instructions that are fetched 8 instructions later (at the latest), or after the next RETURN FROM INTERRUPTION instruction, whichever occurs first.

Instructions may also modify resources on other processors in a multiprocessor system, which affect the

instruction fetch of the target processors. When such an event takes place (the modification of the resource is acknowledged), it affects instructions that are fetched, on the target processors, after they have finished executing 8 instructions (at the latest) except as noted below.

When a processor executes an instruction which purges an instruction TLB entry in other processors, the target processors must acknowledge completing the purge. The target processors may not complete a move-in, which was initiated using the purged translation, after acknowledging the removal.

Acknowledgment of a data TLB purge request from another processor must not be made until after the purge has logically been performed.

Modification of code, while discouraged, may be performed using the following protocol:

1. Modify the code in the data cache.

2. Flush the modified code from the data cache.

3. Issue aSYNCHRONIZE CACHES instruction to ensure the flush is completed and subsequent move-in will observe the memory version.

4. Flush the location of the modified code from the instruction cache.

5. Issue aSYNCHRONIZE CACHES instruction to ensure the flush is completed.

6. Delay at least an additional seven instructions or execute a RETURN FROM INTERRUPTION instruction.

In a multiprocessor system, software must ensure that no other processor is executing code that is in the process of being modified.

5 Interruptions

Interruptions are anomalies that occur during instruction processing, causing transfer of the flow control to an interruption handling routine. In the process, the hardware automatically saves certain processor state. Upon completion of interruption processing, a RETURN FROM INTERRUPTION instruction is executed, which restores the saved processor state, and the execution proceeds with the interrupted instruction.

From the viewpoint of response to interruptions, the processor behaves as if it were not pipelined. That is, it behaves as if a single instruction is fetched and executed, and any interruption conditions raised by that instruction are handled at that time. If there are none, the next instruction is fetched, and so on.

Interrupt Classes

Faults, traps, interrupts, and checks are the different classes of interruptions that may happen during instruction processing. Definitions of the four classes of interruptions are as follows:

Fault The current instruction requests a legitimate action which cannot be carried out due to a system problem, such as the absence of a page from main memory. After the system problem has been corrected, the faulting instruction will execute normally. Faults are synchronous with respect to the instruction stream.

Trap Traps include two sorts of possibilities: either the function requested by the current instruction cannot or should not be carried out, or system intervention is desired by the user before or after the instruction is executed. Examples of the first type include arithmetic operations that result in signed overflow and instructions executed with insufficient privilege for their intended function. Such instructions are normally not re-executed. Examples of the second type include the debugging support traps. Traps are synchronous with respect to the instruction stream.

Interrupt An external entity (for example, an I/O device or the power supply) requires attention.

Interrupts are asynchronous with respect to the instruction stream.

Check The processor has detected an internal malfunction. Checks can be either synchronous or asynchronous with respect to the instruction stream.

All four classes of interruptions are handled in the same way. The interruptions are categorized into four groups based on their priorities:

Group 1: 1 High-priority machine check Group 2: 2 Power failure interrupt

3 Recovery counter trap 4 External interrupt

5 Low-priority machine check 29 Performance monitor interrupt

The interruption numbers in the above list are the individual vector numbers that determine which interruption handler is invoked for each interruption. The group numbers determine when the particular interruption will be processed during the course of instruction execution. The order the interruptions are listed within each group (not the interruption numbers) determines the priority of simultaneous interruptions (from highest to lowest).

Interruption Handling

Interruption handling is implemented as a fast context switch (which is much simpler than a complete process swap). When an interruption occurs, the hardware takes the following actions:

1. The PSW in effect at the time of the interruption is saved in the IPSW. For group 2 and 3 interruptions, the saved PSW is the value at the beginning of execution. For group 4 interruptions, the saved PSW is the value after the execution of the instruction.

2. The defined bits in the PSW are set as follows:

W Set to the value of the default width bit.

E Set to the value of the default endian bit.

Group 3: 6 Instruction TLB miss fault/Instruction page fault 7 Instruction memory protection trap

15 Data TLB miss fault/Data page fault 16 Non-access instruction TLB miss fault

17 Non-access data TLB miss fault/Non-access data page fault 26 Data memory access rights trap

27 Data memory protection ID trap 28 Unaligned data reference trap

18 Data memory protection trap/Unaligned data reference trap 19 Data memory break trap

20 TLB dirty bit trap 21 Page reference trap 22 Assist emulation trap Group 4: 23 Higher-privilege transfer trap

24 Lower-privilege transfer trap 25 Taken branch trap

M Set to 1 if the interruption is a high-priority machine check; otherwise, set to 0.

all other bits Set to 0 (interrupts are masked, absolute accesses are enabled, etc.).

3. IA information in the IIA queues is frozen (as a result of setting the PSW Q-bit to 0 in step 2 above).

In order to enable restarting of instructions in the presence of delayed branching, at least two addresses must be saved, pointing to the next two instructions to be executed after returning from the interruption. The hardware, therefore, maintains IIA Space and IIA Offset queues, which have two elements and contain the addresses and privilege levels of these instructions. The IIA queues are kept up-to-date whenever the Q-bit in the PSW is 1. When an interruption is taken, the addresses of the pending instructions are preserved in the queues. The elements of the queues may be obtained by reading the IIASQ and IIAOQ registers (CRs 17 and 18, respectively).

4. The current privilege level is set to the highest privilege level (zero).

5. Information about the interrupting instruction is saved in the Interruption Parameter Registers (IPRs) if the PSW Q-bit was 1 at the time of the interruption. If the PSW Q-bit was 0, the IPRs are unchanged. If the details of an instruction associated with the interruption are potentially useful in processing it, the instruction is loaded into the Interruption Instruction Register (IIR or CR 19). If there is an address associated with the interruption, it is loaded into the Interruption Space and Interruption Offset registers (ISR or CR 20, and IOR or CR 21). See “Interruption Parameter Registers (IPRs)” on page 2-15 for a description of the format of these registers.

6. General registers 1, 8, 9, 16, 17, 24, and 25 are copied to the shadow registers if the PSW Q-bit was 1 at the time of the interruption. If the PSW Q-bit was 0, the shadow registers are unchanged.

7. Execution begins at the address given by:

Interruption Vector Address + (32 * interruption_number)

Interruption_number is the unique integer value assigned to that particular interruption. Vectoring is accomplished by performing an indexed branch into the Interruption Vector Table indexed by this integer. The Interruption Vector Table contains the first eight instructions of each of the interruption handling routines. The value in the Interruption Vector Address register (CR 14) must be aligned on a 2 Kbyte boundary.

Programming Note

It is the responsibility of interruption handlers to unmask external interrupts (by setting the PSW I-bit to 1) as soon as possible, so as to minimize the worst-case latency of external interrupts.

Instruction Recoverability

When execution of instructions is interrupted, the minimal processor state that is required to be saved and restored is that necessary to correctly continue execution of the instruction stream after processing of the interruption. Processor state is defined to include any register contents, PSW bits, or other information that may affect the operation performed by an instruction. For example, if an interruption is

taken immediately before anADD instruction, its source registers must be restored, but its target register need not be (unless it is also one of the source registers).

Im Dokument PA-RISC 2.0 (Seite 82-90)