Channel Status Word

The Channel Status Word (CSW) is used to provide the status of an I/O device or the status of the last I/O operation completed.  The CSW is updated when an I/O interruption occurs or as a result of an I/O command.  The CSW is available for use until the next I/O interrupt occurs or until another I/O command causes it to be replaced.

When an I/O interruption updates the CSW the I/O device causing the interruption is identified in the Old PSW as the interruption code when operating in BC mode.

The CSW has the following format:

Protection Key (Bits 0-3) indicates the protection key used for the I/O operation.

Logout Pending (L) (Bit 5) When set to one it indicates that an I/O instruction cannot be executed until a pending logout condition has been cleared.

Deferred Condition Code (CC) (Bits 6-7) Indicate a different condition code available for a Start I/O Fast Release after a condition code of zero was returned.

CCW Address (Bits 8-31) Indicate an address eight bytes greater than the last CCW used.

Status (Bits 32-47) These bits identify the condition that caused the CSW to be stored.

  • 32 Attention – The device has detected an asynchronous condition significant to the program
  • 33 Status Modifier – Indicates the device cannot provide its current status in response to a TEST I/O, when the control unit is busy, when the normal sequence of commands has to be modified or when command retry is to be initiated.
  • 34 Control Unit End – Indicates the control unit has become available for use for another operation.
  • 35 Busy – Indicates the I/O device cannot execute the command because it is executing a previously initiated operation or because there is a pending interrupt condition.
  • 36 Channel End – Indicates completion of the portion of an I/O operation involving the transfer of data or control information between the I/O device and the channel.  When command chaining is used Channel End is generated only for the last operation.
  • 37 Device End – Indicates the completion of an I/O operation by the device.  When command chaining is used only the Device End condition for the last operation in the chain is reported.
  • 38 Unit Check – Indicates the I/O device or control unit has detected an unusual condition and additional detail information is available to a sense command.
  • 39 Unit Exception – Indicates a condition reported by an I/O device that does not usually occur.
  • 40 Program Controlled Interruption – This condition is generated when a channel fetches a CCW with the PCI flag set.
  • 41 Incorrect Length – Indicates the number of bytes in storage assigned to the I/O operation is not equal to the number of bytes requested by the device.
  • 42 Program Check – Indicates a programming error in the channel program.  Can occur as a result of an invalid address in the CAW or a TIC CCW, an invalid command code, an invalid count in a CCW, an invalid data address, an invalid CAW format, an invalid CCW format or an invalid sequence of CCWs.
  • 43 Protection Exception – Indicates the channel attempted to access storage that is prohibited by storage protection.
  • 44 Channel Data Check – Indicates a machine error has occurred causing a parity error.
  • 45 Channel Control Check – Indicates a machine error.
  • 46 Interface Control Check – Indicates an invalid signal occurred on the I/O interface.
  • 47 Chaining Check – Indicates a channel overrun during data chaining operations.

Count (Bits 48-63) Contain the residual count for the last CCW.

[Next – I/O Machine Instructions]

Sense Command

The sense command is used to receive both the status of the device and any information about any unusual or error condition for the last operation of the device.

Although sense information is specific to each device usually the first six bits of sense data give information about the conditions detected in the last operation.

Command Reject (Bit 0) indicates the device has detected a programming error.  The device is unable to execute the command because it is invalid for the device or the device cannot currently execute the command (for example the device is write protected).  Command reject can also indicate an invalid sequence of commands.

Intervention Required (Bit 1) The operation could not be executed because the device requires some type of intervention (for example printer needs paper) or the device is in a not ready state.

Bus Out Check (Bit 2) The device has received data with an invalid parity.

Equipment Check (Bit 3) Indicates the device has detected an equipment malfunction.

Data Check (Bit 4) Indicates the device has detected a data error other than those causing a Bus Out Check.

Overrun (Bit 5) Indicates the channel has failed to respond on time to a request from the device.

The final type of CCW command code is the Transfer In Channel (TIC).  It is a branching instruction for the channel command.  Normally when  command chaining is active CCWs are executed sequentially.  A TIC will cause the next CCW to be fetched from the data location specified by the data address in the TIC CCW.  The first CCW pointed to by the CAW cannot be TIC nor can a TIC specify a branch to another TIC CCW.

[Next – Channel Status Word]

Channel Command Word

Each CCW is 64 bits (8 BYTES) in length and has the following format:

Command Code (Bits 0-7) Specifies the I/O operation to be performed.

Data Address (Bits 8-31) Specifies the location in main storage for the data associated with the I/O operation.

Chain Data Flag (CD) (Bit 32) When set to one indicates the chaining of data.  It causes the storage area of the next CCW to be used with the current I/O operation.  The use of data chaining allows data to be transferred to or from noncontiguous areas of storage in a single I/O operation.

Command Chain (CC) (Bit 33) When set to one, and when the CD flag is set to zero, indicates the chaining of commands.  When the operation of the current CCW is complete and Command Chaining is active, the next CCW will become the new current I/O operation.

Suppress Length Indication (SLI) (Bit 34) When set to one and the CD flag is set to zero, the incorrect length indication is suppressed.

Skip (SKIP) (Bit 35) When set to one the transfer of information is suppressed for read and sense operations.

Program Controlled Interrupt (PCI) (Bit 36) When set to one the channel will generate an interruption condition when the CCW begins execution in the channel.

Indirect Data Address (IDA) (Bit 37) When set to one indicates indirect addressing.  The data address of the CCW points to an Indirect Address List instead of directly to the data.

Count (Bits 48-63) Specifies the number of bytes to be used for the I/O operation.

Bits 38-47 should always be set to zeros.

Channel command codes are specific to each individual device but fall into general categories: Write, Read, Read Backward, Control and Sense.  Write transfers data from the processor storage to the device, read and read backward transfer data from the device to processor storage.  Control operations are specific to each device and generally do not involve data transfer but the data address in the CCW may point to an area in storage related to the control operation.

[Next – Sense Command]

 

Input Output Basics

I/O operations on S/370 are used to transfer information to and from I/O devices which are attached to channels.  There are many types of I/O devices including card readers, card punches, printers,  tape devices, terminals and disk storage devices.

A channel attached device can be thought of as a very simple computer that uses a very limited programming language.  The programming instructions are called Channel Command Words (CCW).  A CCW indicates the operation to be performed (such as read a card or print a line), the data location in the processor memory and the length of the data operation.  In addition there are some flags that may be set in the CCW to further indicate how to execute the requested operation.

Each individual device type has a set of commands that it will respond to.  An invalid command will result in an execution error of the channel program.  When writing channel programs it is necessary to know the programming specifications for each specific device being used.

An I/O operation is initiated by building a channel program consisting of one or more CCWs.  The address of the channel program is placed in a fixed position in low storage called the Channel Address Word (CAW).  An I/O operation is initiated using the Start I/O (SIO) instruction. This instruction along with all other I/O commands can only be executed when operating in privileged mode.

When the channel program is complete an I/O interrupt will be generated if interrupts are enabled.  If interrupts are disabled for the device, the interrupt will be queued.  A queued I/O interrupt can be cleared either by enabling interrupts or using the Test I/O (TIO) instruction.

When the pending I/O interrupt condition for a device is cleared the Channel Status Word (CSW) in low storage will be updated providing information on the completion status of the I/O operation.

[Next – Channel Command Word]

Interruptions

The interruption is a mechanism to signal the CPU when certain conditions exist. For I/O interruptions the CPU is signaled when some event happens with an I/O device such as I/O operation complete or an error condition.  By using interruptions the CPU can initiate an I/O operation and does not have to continuously check the status to see if it has completed.  Instead when the I/O operation is complete the CPU will be signaled with an interrupt.

There are several classes of interrupts defined in the System 370 architecture.  Each interrupt class has two specific locations in low memory used to hold PSWs.  When an interrupt occurs the current CPU PSW is stored in the Old PSW location for the interrupt class and is replaced with the value of the New PSW location.

By loading a New PSW the state of the CPU is changed enabling the interruption condition to be handled.  When interruption handling is complete the Old PSW can be used to restore execution of the interrupted program.

Some interruptions can be “Masked” – that is ignored depending on settings in the current PSW.  For example while an I/O interruption is being processed all other I/O interruptions should be masked until completion of the current I/O interruption processing.

The classes of interruptions are:

Machine-Check Interruption Indicates an equipment malfunction.  When this interruption occurs the Old PSW is stored in location 48 and a new PSW is fetched from location 112.

Program Interruption Results from an error during the execution of a program (such as an invalid operation code or attempt to execute a privileged instruction while in problem state).  When this interruption occurs the Old PSW is stored in location 40 and a new PSW is fetched from location 104.

Supervisor Call Interruption Occurs when a Supervisor Call (SVC) instruction is executed. When this interruption occurs the Old PSW is stored in location 32 and a new PSW is fetched from location 96.

External Interruption Signals the CPU to conditions outside the system.  These interruptions include the operator pressing the Interrupt Key or when the Interval Timer is decremented and goes from a positive value to a negative value.  When this interruption occurs the Old PSW is stored in location 24 and a new PSW is fetched from location 88.

Input/Output Interruption Allows the CPU to be notified of various conditions for I/O devices and channels.  When this interruption occurs the Old PSW is stored in location 56 and a new PSW is fetched from location 120.  In addition a Channel Status Word (CSW) is stored at location 64.

Restart Interruption Allows the CPU to respond to an interruption generated by the operator pressing the restart key.  When this interruption occurs the Old PSW is stored in location 8 and a new PSW is fetched from location 0 (zero).

[Next – Input Output Basics]

Program Status Word

The Program Status Word (PSW) contains information about the current execution state of the processor.  Certain actions cause the complete PSW to be stored or loaded.  Others operate on only a portion of the PSW.

The Load PSW instruction (LPSW) will load a new value into the PSW and replace the old contents.  Interrupts cause the current PSW contents to be stored at a specific location and a new PSW to be loaded.  The locations for storing the old PSW and fetching the new PSW are defined in low storage with the actual address depending on the specific interrupt.

In 370 mode there are two different forms of the PSW – Basic Control (BC) and Extended Control (EC).  The BC PSW is essentially the same format as initially introduced on the System 360.  When bit 12 of the PSW is zero the PSW is in BC mode.  For now we will only concern ourselves with the BC PSW.

The BC PSW consists of 64 bits (8 bytes or 2 words) with the following layout:

Bits 0-5        Channel Masks 0-5
Bit  6          Input/Output Mask (IO)
Bit  7          External Mask (E)
Bits 8-11       Protection Key
Bit  12         BC/EC Control
Bit  13         Machine Check Mask (M)
Bit  14         Wait State (W)
Bit  15         Problem State (P)
Bits 16-31      Interruption Code
Bits 32-33      Instruction Length Code (ILC)
Bits 34-35      Condition Code (CC)
Bits 36-39      Program Mask
Bits 40-63      Instruction Address

Channel Masks 0-5 (Bits 0-5) Control whether the CPU  is enabled for I/O interruptions from channels 0-5.  When the bit is zero the corresponding channel cannot cause an I/O interruption.  When the bit is one an interruption can occur.

Input/Output Mask (IO) (Bit 6) Controls whether the CPU is enabled for I/O interruptions from channels 6 and higher.  When the bit is zero these channels cannot cause an I/O interruption.  When the bit is one interruptions may occur if the channel interruption is enabled in control register (CR) 2.  Setting the I/O mask bit in the PSW to zero has the same effect as setting all the bits in CR 2 to zero.  Initially CR 2 contains a value of one in all bits therefore enabling all interrupts on channels 6 and higher when the IO Mask bit is set to one.

External Mask (E) (Bit 7) Controls whether the CPU is enabled for external interruptions.  When set to one interruptions are enabled.

Protection Key (Bits 8-11) The protection key is compared to the page storage key when storing to memory or when fetching and the page is protected against fetching.  A PSW protection key of zero can access any page.

Extended Control Mode (Bit 12) Indicates the format of the PSW and the mode of operation of the CPU.  For Basic Control (BC) the bit is set to zero, for Extended Control (EC) the bit is set to one.

Machine Check Mask (M) (Bit 13) Controls whether the CPU is enabled for machine check interruptions.  When set to one interruptions are enabled.

Wait State (W) (Bit 14) When the Wait bit is set to one the CPU is in the wait state and no instructions are executed.  When set to zero it is in running state.

Problem State (P) (Bit 15) When set to one the CPU is in problem state and any attempt to execute a privileged instruction will fail.  When set to zero the CPU is in supervisor state.

Interruption Code (Bits 16-31) When an old PSW is stored as a result of a program, supervisor call, external or I/O interruption these bits identify the cause of the interruption.  These bits are ignored when a new PSW is loaded.

Instruction Length Code (ILC) (Bits 32-33) Indicates the length of the last executed instruction when a program or supervisor call interruption occurs or when a Branch And Link is executed.  The contents of these bits are ignored when a new PSW is loaded.

Condition Code (CC) (Bits 34-35) Condition code.

Program Mask (Bits 36-39) Each bit is associated with a program exception interruption. When the bit is zero an interruption will not occur.  Bit 36: Fixed-point overflow. Bit 37: Decimal overflow. Bit 38: Exponent underflow. Bit 39: Significance.

Instruction Address (Bits 40-63) Contains the address of the next instruction to be executed.

[ Next – Interruptions ]

Initial Program Load

On the IBM 360/20 there was a blue button on the CPU console labeled “IPL.”  On the 370/158 you initiated an IPL using the integrated operator console (a 3270 device with a light pen).  The end result was the same – the IPL function of the processor was invoked.

The device to be used for the IPL process is specified by the operator prior to invoking the IPL function.  It might have been specified using the dials and switches or it may have been specified on the operator console.

When the IPL function is initiated the processor issues a read command to the IPL device.  This read command reads 24 bytes of data.  Yes! That’s all, 24 bytes.  But this is enough to get the process started.

It can’t be just any 24 bytes of data.  It has to be 24 bytes of very specific data.  To understand the IPL process we have to understand two hardware data structures – the Program Status Word (PSW) and Channel Command Word (CCW).  This is because the 24 bytes read by the IPL process must be an eight-byte PSW followed by two eight-bytes CCWs.

In the next section we will explore the PSW so we have a better understanding of how to get our initial program loader up and running.

[ Next – Program Status Word ]

Card Loader

To run a Bare Metal program we must have some way to get our program into the processor and ready for execution.  We could take the approach I used on the 370/158 that didn’t have any I/O devices except the operator console.  On that system I used the Storage Alter function to enter my program in hex.  (This was also a familiar technique used on early microprocessors)

There are a couple of problems doing this.  First is that it can be very time consuming.  Another problem is this process is very error prone – easy to get lost when entering a long string of hex.  Then there is the problem of making code changes.  You can write patches to the code already entered or you start from the beginning and enter everything again.  In my 370/158 days I avoided starting over from the beginning.  I would spend a few minutes each day adding to the existing code in memory.  As it was patched and re-patched it became difficult to keep up with.  I finally gave up when the system had to be shut down due to some maintenance to the facility.  I just couldn’t bring myself to start entering hex from the beginning.

Fortunately the designers of the System 360/370 processors give us an easier way – if we have an input device.  We can IPL from cards, tape or a disk drive.

We will begin with an IPL from a card reader since it is probably the easiest.  At least from the standpoint of an old timer like myself who is very familiar with decks of cards.

Our initial goal  is to create a small set of cards containing the necessary instructions to load an object deck into memory and cause it to begin execution.

[ Next – IPL Initial Program Load ]

Introduction

This site is devoted to exploring how to program an IBM 370 Mainframe at the “Bare Metal” level.  This is how to program without any preexisting supervisor or operating system code.

It is assumed that the reader is familiar with the basics of the IBM 360/370 architecture.  The IBM System/370 Principles of Operation (POPS) is the base level document.  I am  using GA22-7000-5 (Fifth Edition, August 1976).

I first became interested in programming without an operating system  in 1975.  I was learning to program on a IBM 360 Model 20.  The model 20 was a very limited version of the 360 architecture.  It was a half-word machine and only had eight half-word registers.  The system I was using had a total of 12K of memory.  It did have a 2311 disk and a Disk Operating System (DOS).  I was programming in assembler and quickly found that I didn’t have much of the 12K of memory left over after loading in the operating system routines.

I decided that I needed to learn how to live without the resident DOS code.  I began to experiment and learn the basics.  The biggest issue was how to do Input/Output (I/O).  I quickly learned how to access the various devices using Channel Command Words (CCW).  The 360/20 didn’t use SIO (Start I/O) – it used an instruction called XIO (eXecute I/O) which did pretty much the same as SIO.  It also used an instruction called TIOB (Test I/O and Branch) which combined the function of  TIO (Test I/O) with a branch instruction.

From then on I used the Model 20 mostly without any Operating System.  This fun all came to an end when I moved on to larger systems running production applications under more complex operating systems (MVT, MFT, VS1, SVS, and MVS).

In the early 1980’s I was a systems programmer at a facility upgrading from a 370/158 to an 3033.  When the upgrade was completed the 370/158 remained in the computer room and was powered up to serve as a backup in case there were problems with the new processor.  There were no I/O devices connected to the 158 except for the integrated operator console.

Since the machine was just sitting in the corner of the room idling I decided to start programming it through the operator console using the Storage Alter function.

I began with very simple programs which evolved into larger, more complex programs over time.

When I left the 158 behind I lost the ability to program a 370 mainframe at the bare metal level until years later when I discovered the Hercules emulator.

With Hercules I now have my own personal IBM mainframe to once again play with.  Not only do I have a mainframe but I have my choice of peripheral devices to attach.

One final question – what does TXXOS mean?  When I first started playing with bare metal programming on Hercules I called my mini-operating system TXOS.  It was a bit of an inside joke on a “very short” OS.  When I decided to register a domain name I picked TXXOS.com – bottom line is it really doesn’t mean anything but I needed a domain name.

[ Next – Card Loader]