Getting storage

The EDCXGET routine is called to get storage from the operating system. The entry point name for this routine must be @@XGET; see Figure 1 for an example. It uses the following parameter:
R0
The requested length, in bytes. If the high-order bit is zero or if the request was made in 24-bit addressing mode, the storage will be allocated below the 16M line. If the high-order bit is on and the request is made in 31-bit addressing mode, storage will be allocated anywhere with a preference for storage above the 16M line if available.
Upon return, the following values are set:
R0
The length of the storage block acquired, in bytes.
R1
The address of the acquired area or NULL.
R15
A system dependent return code, which must be zero on success and non-zero otherwise.

This routine is not provided with a save area. In addition to the linkage registers, this routine may freely alter registers 2 and 4.

If you provide your own EDCXGET routine, it will be used when C library functions explicitly get storage. Whenever the library functions invoke operating system services, there may be implicit requests for storage that cannot be tailored.

Figure 1. Example of routine to get storage
* this is an example of a routine to get storage
@@XGET   TITLE  'Obtain memory as specified in R0'
EDCXGET  CSECT
EDCXGET  AMODE ANY
EDCXGET  RMODE ANY
@@XGET   DS    0H
         ENTRY @@XGET
         SPACE 1
         BALR  R2,R0
         USING *,R2
         LTR   R0,R0             Memory above or below?
         BNL   BELOW
         SLL   R0,1              Want memory anywhere
         SRL   R0,1
         LTR   R2,R2             are we running above the line?
         BNL   BELOW             no, so ignore above request
         GETMAIN RC,SP=0,LV=(R0),LOC=ANY
         LTR   R15,R15           Was it successful?
         BZR   R14               Yes...
         SR    R1,R1             No, indicate failure
         BR    R14
BELOW    DS    0H                Get memory below the line
         GETMAIN RC,SP=0,LV=(R0),LOC=BELOW
         LTR   R15,R15           Was it successful?
         BZR   R14               Yes...
         SR    R1,R1             no, indicate failure in R1
         BR    R14
*
R0       EQU   0
R1       EQU   1
R2       EQU   2
R4       EQU   4
R13      EQU   13
R14      EQU   14
R15      EQU   15