Table of Contents

Lock/Unlock (LOK)/OP=60

Format

OP AF BF A Syllable

OP = 60

AF Unused and reserved; can be specified as an indirect field length. A literal flag causes an invalid instruction fault (IEX = 21).
BF Instruction variant; can be indirect.

Variant Function
10 Event cause no interrupt
09 Event cause and reset
08 Event reset and wait
07 Test happened status
06 Event reset
05 Event wait
04 Event cause
02 Conditional lock
01 Unconditional lock
00 Unlock

All other BF values cause an invalid instruction fault (IEX = 26).

A is the address of the lock/event structure. Address can be indexed, indirect, or extended. The final address controller must be UN, or an invalid instruction fault (IEX = 03) occurs. The final address must be Mod-2, but the hardware does not check it.
If BF has a value of 00-02, A represents a lock structure.
If BF has a value of 04-10, A represents an event structure.

The lock structure format is as follows:

Information Digits
Lock status field 00-01
Lock owner field 02-05
Lock waiter link field 06-09
Lock number field 10-13
Lock number link field 14-17
Reserved 18-19
Note: The lowest memory address is 00.

The event structure format is as follows:

Information Digits
Event status field 00-01
Event owner field 02-05
Event waiter link field 06-09
Event designator field 10-13
Event count 14-19
Note: The lowest memory address is 00.

If any of the lock/event structure values contain undigits, an invalid instruction (IEX=07) occurs.

Note: This instruction only executes with the privileged enable set otherwise an invalid instruction fault (IEX=02) is reported.

Function

LOK examines the lock/event structure (A) and, depending on its value and the instruction variant (BF), modifies the lock/event structure (A) and associated lock fields in the reinstate list entry for the current task, and other tasks owning or contending for the lock or event.

The lock waiter link field and the event waiter link field provide the MCP kernel with the task number, which execution is linked to, for a specific change of the current lock or event structure.

The lock number field and the lock number link field implement a canonical lock algorithm to prevent deadlock situations. All locks are assigned a level number; a task that owns a lock at level n can only get a lock at level n+1 or greater. A lock at a level lower than n can be acquired only by a task that has released all locks at or above that level in reverse order from which it had acquired them.

The processor must determine if a lock is owned or available. If the owner field of the lock structure is zero, the lock is available. If the owner field is not zero, the lock is owned.

The processor must determine if an event has happened. If the event owner field is zero, the event has happened. If the event state field is not equal to zero, the event has not happened.

The event designator field ensures that the current structure is an event structure. A nonzero value in this field causes a fault.

Note: The equivalent field in a lock structure (lock number) is always a nonzero value.

The event count field identifies a particular occurrence of a particular event since the same structure can be used for multiple purposes over a period of time.

The machine-dependent lock status field of the lock/even structure (A) can also represent the status of the structure, with one value representing owned, and another representing available. The lock status field of the lock structure is not used to determine if the lock is available.

Variants

The variants are described as follows:

BF=00 Unlock

This variant releases a Lock and, if any task is waiting for this lock, causes an interrupt to the MCP kernel.

Obtain exclusive rights to the lock structure specified by the A address.

The value of the lock owner field must equal the current task number; otherwise, relinquish exclusive access rights to the lock structure, cause an invalid instruction fault (IEX=06) and terminate the instruction with no futher action.

Compare the lock number field of the lock structure (A) with the MCP canonical lock number field located in the reinstate list entry for the current task. If they are not equal, relinquish exclusive access rights to the lock structure; cause an invalid instruction fault (IEX=06) and terminate the instruction with no further action.

Otherwise, store zeros into the lock owner field of the lock structure (A) to indicate that this lock is available. It also stores the contents of the lock number link field of the lock structure (A) into the MCP canonical lock number field that is located in the reinstate list entry for the current task.

Examine the lock waiter link field of the lock structure. If it is equal to zero, set the Comparison flags to EQUAL, relinquish exclusive access rights to the lock structure and terminate the instruction with no further action.

If the lock waiter link field is not equal to zero, perform the following operations:

  1. Set the comparison flags to HIGH.
  2. Assemble and save, within the processor, the released contended lock value for future update of the instruction interrupt cause descriptor in the kernel data area.
  3. Assemble and save, within the processor, the pointer to the reinstate list entry of the task specified by the task number in the lock waiter link field of the lock structure (A). The pointer is to be used for update to the instruction interrupt cause extension descriptor (C7AAAAAA).
  4. Assemble and save, within the processor, the next instruction address. The next instruction address will be used to update the interrupt frame in the reinstate list entry for the current task.
  5. Relinquish exclusive access rights to the lock structure.
  6. Perform an interrupt procedure that reports an instruction interrupt in the interrupt descriptor in the kernel data area.

BF=01 Unconditional Lock

This variant competes for the lock specified by the Lock Structure (A) and, if the lock is owned, causes an interrupt to the MCP kernel.

Obtain exclusive rights to the lock structure specified by the A address.

Compare the lock number field of the lock structure (A) with the MCP canonical lock number field located in the reinstate list entry for the current task. If the lock number field is less than or equal to the MCP canonical lock number field, relinquish exclusive access rights to the lock structure, raise an invalid instruction fault (IEX=06) and terminate the instruction.

If the lock is available, perform the following operations:

  1. Store the active task number in the lock owner field.
  2. Copy the contents of the MCP canonical lock number field, that is located in the active reinstate list entry, into the lock number link field of the lock structure.
  3. Copy the contents of the lock number field of the lock structure into the MCP canonical lock number field that is located in the active reinstate list entry.
  4. Set the comparison flags to EQUAL.
  5. Relinquish exclusive access rights to the lock structure and terminate the instruction.

If the lock is owned, perfrom the following operations:

  1. Copy the lock owner field of the lock structure (A) into the task number owning field located in the reinstate list entry for the current task.
  2. Copy the lock waiter link field of the lock structure (A) to the next task in list field located in the reinstate list entry for the current task.
  3. Store the current task number into the lock waiter link field of the lock structure (A).
  4. Store the waiting lock value into the state indicator field located in the reinstate list entry for the current task.
  5. Set the comparison flags to LOW.
  6. Assemble and save, within the processor, the failed lock value for update of the instruction interrupt cause descriptor in the kernel data area.
  7. Assemble and save, within the processor the pointer to the reinstate list entry of the task specified by the task number in the lock owner field of the lock structure (A). The pointer is to be used for update to the instruction interrupt cause extension descriptor (C7AAAAAA).
  8. Assemble and save, within the processor, the next instruction address to point to the instruction following the current instruction for future update of the interrupt frame in the reinstate list entry for the current task.
  9. Relinquish exclusive access rights to the lock structure.
  10. Perform an interrupt procedure that reports an instruction interrupt in the interrupt descriptor in the kernel data area.

Ignore the trace enable toggle, even if trace is enabled. Do not perform a trace hardware call following this variant.

BF=02 Conditional Lock

This variant attempts to obtain the lock specified by the lock structure at the location specified by the A-address.

Obtain exclusive rights to the lock structure specified by the A address.

Compare the lock number field of the lock structure (A) with the MCP canonical lock number field located in the reinstate list entry for the current task.

If the lock number field is less than or equal to the MCP canonical lock number field, relinquish the exclusive access rights to the lock structure, cuase an instruction fault (IEX=06), and terminate the instruction.

If the lock is available, perform the lock available case of the unconditional lock variant, BF=01.

If the lock is owned, perform the following operations:

BF=04 Event Cause

This variant causes an event and signals all tasks awaiting the event that the event is available.

Obtain exclusive rights to the lock structure specified by the A address.

If the event designator field is not equal to zero, relinquish exclusive rights to the event structure, cause an invalid instruction fault (IEX=06), and terminate the instruction.

If the event is in the happened state, increment the event count field by one, or if the field is already at the maximum counter value, reset the counter to zero. Then set the comparison flags to EQUAL, relinquish the exclusive access rights to the event structure, and terminate the instruction.

If the event is in the not happened state, increment the event count field of the event structure (A) by one, or if the field is already at the maximum counter value, reset the counter to zero. Then set the event owner field to the happened state (zero).

Examine the event waiter link field of the event structure (A). If it is equal to zero, set the comparision flags to EQUAL, relinquish exclusive access rights to the event structure and terminate the instruction with no further action.

If the event waiter link field is not equal to zero, perform the following operations:

  1. Set the comparison flags to HIGH.
  2. Store zeros in the event waiter link field of the event structure.
  3. Assemble and save the released event value within the processor for future update of the instruction interrupt cause descriptor in the kernel data area.
  4. Assemble and save, within the processor, the pointer to the reinstate list entry of the task specified by the task number in the lock owner field of the lock structure (A). The pointer is to be used for update to the instruction interrupt cause extension descriptor (C7AAAAAA).
  5. Assemble and save, within the processor, the next instruction address to point to the instruction following the current instruction for future update of the interrupt frame in the reinstate list entry for the current task.
  6. Relinquish exclusive access rights to the event structure.
  7. Perform an interrupt procedure that reports an instruction interrupt in the interrupt descriptor in the kernel data are

BF=05 Event Wait

This variant causes the current task to wait until the specified event, if it is in the not happened state, is caused.

Obtain exclusive rights to the lock structure specified by the A address.

If the event designator field is not equal to zero, relinquish exclusive rights to the event structure, cause an invalid instruction fault (IEX=06), and terminate the instruction.

If the event is in the happened state, set the comparison flags to EQUAL, relinquish exclusive rights to the event structure, and terminate the instruction.

If the event is in the not happened state, perform the following operations:

  1. Copy the event owner field of the event structure (A) into the task number owning field located in the reinstate list entry for the current task.
  2. Copy the event waiter link field of the event structure (A) into the next task in list field located in the reinstate list entry for the current task.
  3. Store the current task number into the event waiter link field of the event structure (A).
  4. Store the waiting event value into the state indicator field located in the reinstate list entry for the current task.
  5. Set the comparison flags to LOW.
  6. Assemble and save, within the processor, the failed event value for future update of the instruction interrupt cause descriptor in the kernel data area.
  7. Assemble and save a 6-digit zero field for future update of the instruction interrupt cause extension descriptor (format 7000000).
  8. Assemble and save, within the processor, the next instruction address. The next instruction address will be used to update the interrupt frame in the reinstate list entry for the current task.
  9. Relinquish exclusive access rights to the event structure.
  10. Perform an interrupt procedure that reports an instruction interrupt in the interrupt descriptor in the kernel area.

Ignore the trace enable toggle, even if trace is enabled. Do not perform a trace hardware call following this variant.

BF=06 Event Reset

This variant resets the happened state of the event to the not happened state.

Obtain exclusive rights to the lock structure specified by the A address.

If the event designator field is not equal to zero, relinquishe exclusive rights to the event structure, cause an invalid instruction fault (IEX=06), and terminate the instruction.

If the event is in the not happened state, set the comparison flags to HIGH, relinquish exclusive rights to the event structure, and terminate the instruction.

If the event is in the happened state, store the current task number into the event owner field of the event structure (A) and store zeroes into the event waiter link field of the event structure (A).

Set the comparison flags to EQUAL, relinquish exclusive rights to the event structure, and terminate the instruction with no further action..

BF=07 Event Test Happened Status

This variant tests whether or not an event happened.

Obtain exclusive rights to the lock structure specified by the A address.

If the event designator field is not equal to zero, relinquish exclusive rights to the event structure, cause an invalid instruction fault (IEX=06), and terminate the instruction.

If the event is in the not happened state, set the comparison flags to HIGH, relinquish exclusive rights to the event structure, and terminate the instruction.

If the event is in the happened state, set the comparison flags to HIGH, relinquish exclusive rights to the event structure, and terminate the instruction.

BF=08 Event Reset and Wait

This variant resets an event structure to the not happened state and forces the current task to wait until the event has been caused.

Obtain exclusive rights to the lock structure specified by the A address.

If the event designator field is not equal to zero, LOK relinquishes exclusive rights to the event structure, causes an invalid instruction fault (IEX=06), and terminates the instruction.

If the event designator field is equal to zero, LOK does the following:

  1. Store the current task number into the event owner field of the event structure (A) and into the task owning field in the reinstated list entry for the current task.
  2. Copy the event waiter link field of the event structure (A) into the next task in list field located in the reinstate list entry for the current task.
  3. Store the waiting event value into the state indicator field located in the reinstate list entry for the current task.
  4. Set the comparison flags to LOW.
  5. Assemble and save, within the processor, the failed event value for future update of the instruction interrupt cause descriptor in the kernel data area.
  6. Assemble and save a 6-digit zero field for future update of the instruction interrupt cause extension descriptor (format C7000000).
  7. Assemble and save, within the processor, the next instruction address to point to the instruction following the current instruction for future update of the interrupt frame in the reinstate list entry for the current task.
  8. Relinquish the exclusive access rights to the event structure.
  9. Perform an interrupt procedure that reports an instruction interrupt in the interrupt descriptor in the kernel area.

Ignore the trace enable toggle, even if trace is enabled. Do not perform a trace hardware call following this variant.

BF=09 Event Cause and Reset

This variant causes an event that allows any task, waiting for the event, to continue processing and then leaves the event structure in the not happened state.

Obtain exclusive rights to the lock structure specified by the A address.

If the event designator field is not equal to zero, relinquish exclusive rights to the event structure, cause an invalid instruction fault (IEX=06), and terminate the instruction.

If the event designator field is equal to zero, increment the event count field of the event structure (A) by one, or if the field is already at the maximum counter value, reset the counter to zero. Then store the current task number into the event owner field of the event structure (A).

Examine the event waiter link field of the event structure (A).

If it is equal to zero, set the comparison flags to EQUAL, relinquish exclusive rights to the event structure, and terminate the instruction.

If it is not equal to zero, perform the following operations:

  1. Set the comparison flags to HIGH.
  2. Store zeros in the event waiter link field of the event structure.
  3. Assemble and save the released event value within the processor for future update of the instruction interrupt cause descriptor in the kernel data area.
  4. Assemble and save a 6-digit zero field for future update of the instruction interrupt cause extension descriptor (format C7000000).
  5. Assemble and save, within the processor, the next instruction address to point to the instruction following the current instruction for future update of the interrupt frame in the reinstate list entry for the current task.
  6. Relinquish exclusive access rights to the event structure.
  7. Perform an interrupt procedure that reports an instruction interrupt in the interrupt descriptor in the kernel data area.

BF=10 Event Cause No Interrupt

This variant causes an event and reports to the current task the head of the list of the tasks that are waiting for this event.

Obtain exclusive rights to the lock structure specified by the A address.

If the event designator field is not equal to zero, relinquish exclusive rights to the event structure, set the comparison flags to LOW, and terminate the instruction.

If the event is in the happened state, increment the event count field by one, or if the field is already at the maximum counter value, reset the counter to zero. Then set the comparison flags to EQUAL, relinquish the exclusive access rights to the event structure, and terminate the instruction.

If the event is in the not happened state, increment the event count field of the event structure, A, by one, or if the field is already at the maximum counter value, reset the counter to zero. Set the event owner field to the happened state (zero).

Examine the event waiter link field of the event structure (A).

If it is equal to zero, set the comparison flags to EQUAL, relinquish exclusive access rights to the event structure, and terminate the instruction.

If it is not equal to zero, perform the following operations:

  1. Use the event waiter link field of the event structure as an index into the reinstate list to locate a new specific reinstate list entry. The address of the specified reinstate list entry is stored in memory in the IX1 field, relative to base 0, for the current task (format C7AAAAAA).
  2. Set the event waiter link field of the event structure (A) to zero.
  3. Set the comparison flags to HIGH, relinquish exclusive access rights to the event structure and terminate the instruction with no further action.

Comparison Flags

The Comparison Flags are set according to the variant.