Chapter Contents

Previous

Next
Code Generation Conventions

Register Conventions and Patch Writing

The following sections describe register conventions and patch writing.


The Patch Area

By default, the compiler generates a patch area in each compiled module. This patch area provides space for you to apply maintenance to your modules in object code or load module form (zaps).

The patch area is generated in the first 4096 bytes of a CSECT known as the constants CSECT for the compilation. The constants CSECT is permanently addressed by general register 4, so the patch area is always addressable. The default patch area is 1/64 the size of the generated code for the compilation, rounded up to a multiple of 8 bytes, with a minimum size of 24 bytes and a maximum size of 256 bytes. The patch area is generated as a series of S-cons (address constants in base-displacement form). Each SCON contains its own address in base-displacement form, using register 4 as a base register. This minimizes errors in patch-writing, both for branches to the patch area and for branches within it.

To find the patch area for a module, look near the end of the OMD listing for the constants CSECT. (See Compiler-generated Names.) The patch area is found at the end of the CSECT or just before 4096 bytes if the CSECT exceeds 4096 bytes in size. It is easily recognized by its distinctive S-con format.

It is possible, for very large compilations, or when the zapspace option is specified, for more patch space to be required than the compiler can generate in the first 4096 bytes of the patch area. In this case, the compiler will generate one or more secondary patch areas later in the constants CSECT. These areas have the form of S-cons, using register 0 as the base register. Because these areas are not in the first 4K of the constants section, they are not directly addressable but can be branched to from the previous patch area.

The zapspace option

The zapspace compiler option can be used to alter the size of the compiler-generated patch area. The size of the patch area can be increased or its generation suppressed.

The zapspace option accepts an integer value between 0 and 22, inclusive, that specifies the factor by which the default patch area size is to be multiplied. If the factor is 0, then no patch area is generated. For example, if the default patch area is 48 bytes and the zapspace option specifies a factor of 3, then the patch area actually generated is 144 bytes long. In no case does the compiler generate more than 512 bytes of patch area.

The zapmin option

The zapmin compiler option can be used to specify the minimum size of the compiler-generated patch area.

The zapmin option accepts an integer value that specifies the number of bytes in the patch area. The default is 24. For example,

zapmin(64)

ensures that the patch area is at least 64 bytes.

In no case does the compiler generate more than 512 bytes of patch area.


Register Conventions

The following list summarizes register conventions. You need this information if you are writing patches.

The best way to write a zap is to examine other code in the function that does something similar to what is required and to model the zap on that code.

General register 1 (R1) can be used as a scratch register for zaps unless it is already directly used in the zapped code or a function call sequence (which sets R1) is being zapped. The compiler never remembers the value in R1 across statements. If it is not possible to use R1, you should be aware that values can be kept in registers for a large number of statements, including conditional branches and function calls. The best register use for a zap (other than R1) is a register that is set soon after the zap without being used between the zap and the code that sets the register to a new value (that is, one in which the existing value is discarded).


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.