z/OS MVS Programming: Callable Services for High-Level Languages
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


C/370 example program

z/OS MVS Programming: Callable Services for High-Level Languages
SA23-1377-02

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include "CSRLJC.H"

#define FALSE 0
#define TRUE  1

/* REG0TO13 is the assembler assist routine (below) to extract
   registers 0 through 13, for C/370 addressability */
#pragma linkage(REG0TO13,OS)

int          rcode;
int          i;
unsigned int regs??(14??);  /* Register save area */
jmp_buf      JumpBuffer;    /* Buffer for setjmp/longjmp */
L16J         L16JParmArea;  /* L16J parameter list structure */

/* Function prototype for function to be called via L16J */
void L16JPrg();

/* Invoke a C/370 function via L16J Callable Services */
main()
{
  /* Start by initializing the entire L16J parameter list */
  memset(&L16JParmArea,'\0',sizeof(L16J));

  /* The following fields were implicitly initialized to zero
     by the preceding statement:
       L16JParmArea.Version
       L16JParmArea.SubPool
       L16JParmArea.AreaToFree
       L16JParmArea.LengthToFree
     These field do not need to be explicitly set unless a value
     other than zero is required */

  /* Place parameter list length size into parameter list */
  L16JParmArea.Length = sizeof(L16J);

  /* Create a Problem State/Key 8 PSW */
  L16JParmArea.u3.s1.PSWByte0to3 = 0x078D1000;
  L16JParmArea.u3.s1.u4.PSWAddr = (void *) &L16JPrg;

  /* Mode data */
  L16JParmArea.u3.s1.u4.s2.PSWAmode = 1;
  L16JParmArea.u5.s4.ProcessARs = 1;

  /* Call assembler assist routine to obtain current register
     values */
  REG0TO13(&regs);

  /* Place register values into parameter list */
  for (i=0;i<14;i++)
     L16JParmArea.u1.GR??(i??)= regs??(i??);

  /* Register 14 is not being used in this linkage, but we
     have set it to zero for this example */
  L16JParmArea.u1.GRAddr??(14??) = 0;

  /* Set register 15 for entry to routine */
  L16JParmArea.u1.GRAddr??(15??) = (void *) &L16JPrg;

  printf("L16JC - Call L16J to invoke L16JPrg\n");

  /* Use setjmp to allow return to this point in program. If
     setjmp is being called for the first time, invoke L16JPrg
     via L16J Callable Services.  If returning from longjmp,
     skip call to L16J services and complete processing. */
  if (!setjmp(JumpBuffer))
  {
    csrl16j (&L16JParmArea,&rcode);

    /* Demonstrate use of L16J C/370 declares */
    switch (rcode)
    {
      /* Select on a particular return code value */
      case CSRL16J_BAD_PSW:
        printf("L16JC - L16J unsuccessful, bad PSW\n");
        break;
      /* Default error processing */
      default:
        printf("L16JC - L16J unsuccessful, RC = %d\n",rcode);
        break;
    }
  }
  printf("L16JC - Returned from L16JPrg\n");
}

/* The routine below receives control via L16J Callable Services.
   control is passed back to main via longjmp. */
void L16JPrg(void)
{
  printf("L16JC - L16JPrg got control\n");
  longjmp(JumpBuffer,1);
}

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014