360 Assembly/360 Instructions/SVC

SVC — Supervisor Call — Opcode 0A / Decimal 10 — 2 byte RR Instruction. 


Format

edit
SVC number (where number is 0-255 decimal or X'00' to X'FF')
SVC 11


RR Instruction (2 bytes)
Byte 1
bits (0-7)
Byte 2
bits (8-15)
(in hex) Opcode
0A
Immediate Value
0..FF / (dec 0..255)
  • The argument is an immediate value from 0 to 255 (X'0' thru X'FF').


Availability

edit

The SVC instruction is available on all models, 360, 370 and z/System.


Purpose of Instruction

edit

This instruction is used to allow a program to call the operating system in order to request services. The operand is the Supervisor Call number, which is in the range 0 to 255 (decimal). The value of the operand is operating system dependent. Typically, a supervisor call is made after loading certain machine registers with values. Supervisor Calls may or may not return information. They may return the information in registers, or in specific fields which were passed in the original call.

In some cases, a supervisor call will never return. There are several possible reasons:

  • The SVC number (second byte) is invalid, because neither the operating system nor a local routine processes that SVC number, and the program has not established a recovery routine, (error handler) so the program/task is terminated.
  • The SVC number is not permitted to be used by this class of program, and the program has not established an error recovery routine, so the program/task is terminated.
  • The SVC number may be used by this class of program, but the user operating it lacks the privileges to do so, the program has not established an error recovery routine, so the program/task is terminated.
  • One of the above cases occurs and a recovery routine was established, and it is given control.
  • The call is in fact the operating system call to terminate the program.
  • The call is to a routine to transfer to another program.
  • The call is to log off the user (although this may be considered a type of program termination).
  • The call is to a routine to cause a shutdown of the machine.

Some operating systems have privileged SVCs which are not available to user programs, and not all operating systems use all SVC values.

Typical Usage

edit

Typically a supervisor call is used as part of an Operating System macro. For example, under MVS, VS/1, and z/OS the WTO macro issues an SVC 35. Some operating systems will provide services to various parts of itself by using a "privileged" supervisor call. The supervisor call is not technically a privileged instruction, it is that the operating system will not allow a non-privileged program to use that particular supervisor call and will either fault the program or return an error depending on what the supervisor call manager has been programmed to do.

For example, many operating systems have a macro call for a user program to request (and release) memory for itself. IBM OS/VS uses the "GETMAIN"/"FREEMAIN" macros, while Univac's VS/9 and Fujitsu's BS2000 use "REQM"/"RELM" while Linux uses the equivalent of the "malloc" function from the C language. However, if an operating system needed to store information in the operating system's own memory, such as information about a task, that the user program should not have access to, an operating system routine needing to do this could "reinvent the wheel" by rewriting the memory allocation code, which might introduce errors; it could create a fixed table which would limit the number of possible available "slots" for this purpose, or, if the operating system were one massive program it could call the memory allocation routine at a fixed address. An alternative to all of these is for the operating system to simply issue an SVC instruction on itself to request privileged memory (or a pointer to privileged memory.) This would eliminate having to have the entire operating system resident in memory all the time, and would allow the operating system to be dynamically loaded as needed. A non-privileged program attempting to use this "privileged" SVC would either receive an error code or would be treated as a program error, either transferring to the recovery routine or terminating the offending task.

Operation

edit

When a supervisor call instruction occurs, the program counter is advanced by two, the PSW is stored in the "Supervisor Call Old PSW Address," the supervisor call number is stored in the "Interrupt Number address", and the new PSW is loaded from the "Supervisor Call New PSW address" all of which differ from model to model. Execution continues at the program counter value retrieved from the Supervisor Call New PSW.

SVC Addresses Used (Decimal)
Machine SVC Old PSW Interrupt number SVC New PSW
360 Series 032-039 096-103
370 Series and z/System 320-335 136-139 [1] 448-463


[1] Bits 5 and 6 of byte 137 are set to 012 unless the SVC was the result of an EXECUTE instruction, then they are set to 102; the rest of the bits are cleared. Byte 139 contains the SVC number; everything else in bytes 136-139 are zeroed.

The supervisor call routine has access to the memory and registers of the calling routine, and can use these to retrieve arguments and/or return results. The registers used differ for each operating system, e.g. OS/VS1, MVS, and VM would usually use registers 0 and 1, (in rare cases register 2 as well), and sometimes 14 or 15; the same is true for the VS/9 operating system on the Univac 90/60, 90/70 and 90/80 mainframe computers, while Linux on S/390 uses registers 0 through 6 depending on the number of arguments and may use 14 or 15 in some instances. The register usage for supervisor calls is a convention established by general usage, not mandated by the hardware.

The supervisor call routine can exit in any of several ways:

  • it may be written as a type of subroutine, with various registers having certain information it might need, such as internal tables and such. It exits by returning by branching to the address in a register;
  • it may be written as a type of subroutine, and exits by using the operating system's SVC to terminate itself. There may also be a different privileged exit SVC that only operating system routines are allowed to use. Or, the same SVC terminates a non-privileged program, but acts like a return in the case of a privileged routine;
  • using the LPSW instruction from the address of the Supervisor Call Old PSW address to return to the instruction in the calling program after the SVC instruction;
  • executing a non-existent instruction, accessing non-existent memory, or some other unusual method.

The method the SVC will return information may be through registers or changes in memory, which the user pointed to via registers or argument lists in registers. The results and values are operating-system dependent.

Condition Codes

edit

Condition codes are changed to the value of the condition codes stored in the condition code bits of the PSW stored at the Supervisor Call New PSW address. When returning from the Supervisor call, the Supervisor routine in the operating system may choose to change any condition codes as a result of its operation. Otherwise the condition codes upon return to the program issuing the SVC will be the same as they were when the call was made.

Exceptions and Faults

edit

The Supervisor Call is a non-privileged instruction, and will not cause a program exception. The specific SVC number to use for any particular service is assigned by the operating system the program runs under, and if incorrect, the operating system may produce no noticeable result, unexpected, or undesired results, terminate the program, or transfer control to an exception routine.

Previous Instruction
BCR
360 Assembly Instructions   Next Instruction
BSM
Previous Opcode
09
Next Opcode
0B
360 Assembly Language
360 Family Introduction · Basic FAQ · 360 Family · 360 Architecture
360 Instruction Set 360 Instructions · Branch Instructions · Data Transfer Instructions · Control Flow Instructions · Arithmetic Instructions · Logic Instructions · Shift and Rotate Instructions · Priveleged Instructions · Other Instructions
Syntaxes and Assemblers 360 Assemblers· Pseudo Instructions
Instruction Extensions Floating Point · High-Level Languages