If changing ARs without using the linkage stack

An AR mode program must specify SYSSTATE ASCENV=AR.

When a program that changes ARs and has chosen not to use the linkage stack receives control, the target program saves the GPRs and ARs into the 216-byte (or larger) doubleword-aligned caller-provided save area pointed to by GPR 13 (and AR 13 when the caller is in AR mode). The format of this area is shown in Figure 1. As indicated by this figure, the contents of each GPR, except GPR 13, must be saved in a specific location within the save area. GPR 13 is not saved into the save area; it holds the address of the save area. Similarly, the contents of each AR, except AR 13, must be saved in a specific location within the save area. AR 13 is not saved into the save area; it holds the ALET of the save area.

Figure 1. Format of the Format 7 save area (F7SA)
Word
Contents
0
Used by language products.
1
Value of "F7SA". "F7SA", stored by a program in its save area, indicates how the program has saved the calling program's registers, in this case saving the 64-bit GPRs and the ARs in the caller-provided save area whose address is in words 32-33 of this save area.
2 - 3
64-bit GPR 14 (return address).
4 - 5
64-bit GPR 15.
6 - 31
64-bit GPRs 0 - 12.
32 - 33
Address of previous save area (stored by a program in its save area).
34 - 35
Address of next save area (stored by target program within caller's save area).
36 - 50
ARs 14, 15, 0-12.
51
ALET of previous save area.
52
ASC mode of calling program.
53
Undefined.
You can save 64-bit GPRs with a store-multiple (STMG) instruction. Use the following STMG instruction to place the contents of all GPRs except GPR 13 into the proper words of the save area:
STMG 14,12,8(13)
You can save ARs with a store-access-register-multiple (STAM) instruction. Use the following STAM instruction to place the contents of all AR into the proper words of the save area:
STAM 14,12,144(13)

Later, the program can use the LAM and LMG instructions to restore ARs and GPRs and return to the caller.

Whether or not the target program creates its own save area, it must save the address of the calling program's save area. If the target program creates a save area it:
  1. Stores the 64-bit address of the calling program's save area (the address passed in 64-bit GPR 13) into words 32 and 33 of its own save area.
  2. Stores the ASC mode of the calling program into word 52 of its own save area.
  3. Stores the ALET of the calling program's save area (the value in AR 13) into word 51 of its own save area
  4. Stores the address of its own save area (the address the target program will place in GPR 13) into words 34 and 35 of the calling program's save area.
  5. Saves the string "F7SA" into the 2nd word of its own save area. "F7SA" indicates how the target program has saved the calling program's registers, in this case saving the 64-bit GPRs and the ARs in the caller-provided save area whose address is in words 32-33 of this save area.

These steps enable the target program to find the calling program's save area when it needs it to restore the caller's registers, and they enable a trace backward from the most recent save area to previous save areas should one be necessary while examining a dump. If the target program is not creating a save area, it can keep the address of the calling program's save area in GPR 13 or store it in a location in virtual storage.

Use the IHASAVER macro to map the fields in the save area.

If your program is AR mode but the calling program is not known to be AR mode (it might be known to be primary ASC mode or it might be either primary ASC or AR mode), you need to save the calling program's mode on entry and restore it on exit.