/*
 * Copyright (C) 1991 by the University of Waterloo.All rights reserved.
 *
 * obj370 -- symbolic definitions for accessing System/370 object
 *           (TEXT) files
 *
 * Ref. OS/VS - VM/370 Assembler Programmer's Guide, GC33-4021.
 */

#ifndef _OBJ370_H_INCLUDED
#define _OBJ370_H_INCLUDED

#define PUNCH_12_2_9    0x02    /* STX character */

#define __uint  unsigned int
#define __usint unsigned short int

typedef struct esd_item
  {
    char        esd_name[8];    /* 0x00: blank padded name */
    struct
      {
        __uint    esd_type : 8; /* 0x08: type code */
        __uint    esd_addr : 24;/* 0x09: address */
      }         esd__ta;
    struct
      {
        __uint    esd_align : 8;/* 0x0c: type code */
        __uint    esd_extra :24;/* 0x0d: length, LDID or blank */
      }         esd__ae;
  } esd_item;

/* values for esd_item.esd_type... */
#define ESDT_SD         0x00    /* section definition */
#define ESDT_LD         0x01    /* label definition */
#define ESDT_ER         0x02    /* strong external reference */
#define ESDT_PC         0x04    /* private code */
#define ESDT_CM         0x05    /* common control section */
#define ESDT_XD         0x06    /* external dummy section */
#define ESDT_WX         0x0a    /* weak external reference */

/* mask values for esd_item.esd_align... */
#define ESDA_RMODE_ANY  0x04    /* RMODE ANY */
#define ESDA_AMODE_24D  0x00    /* AMODE 24 (defaulted) */
#define ESDA_AMODE_24   0x01    /* AMODE 24 (specified) */
#define ESDA_AMODE_31   0x02    /* AMODE 31 */
#define ESDA_AMODE_ANY  0x03    /* AMODE ANY */

typedef struct esd_record
  {
    char        esd_punch;      /* 0x00: PUNCH_12_2_9 */
    char        esd_label[3];   /* 0x01: "ESD" */
    char        esd__unused1[6];/* 0x04: (blank) */
    __usint     esd_itemcnt;    /* 0x0a: variable field count (bytes) */
    char        esd__unused2[2];/* 0x0c: (blank) */
    __usint     esd_esdid;      /* 0x0e: ESDID of first item */
    esd_item    esd_items[3];   /* 0x10: 1-3 ESD items */
    char        esd__unused3[8];/* 0x40: (blank) */
    char        esd_deckid[8];  /* 0x48: deck id/sequence number */
  } esd_record;

typedef struct txt_record
  {
    char        txt_punch;      /* 0x00: PUNCH_12_2_9 */
    char        txt_label[3];   /* 0x01: "TXT" */
    struct
      {
        __uint    txt__unused1:8;/* 0x04: (blank) */
        __uint    txt_faddr :24;/* 0x05: &first instruction */
      }         txt__f;
    char        txt__unused2[2];/* 0x08: (blank) */
    __usint     txt_size;       /* 0x0a: data field length (bytes) */
    char        txt__unused3[2];/* 0x0c: (blank) */
    __usint     txt_esdid;      /* 0x0e: ESDID */
    char        txt_info[56];   /* 0x10: data field */
    char        txt_deckid[8];  /* 0x48: deck id/sequence number */
  } txt_record;

typedef struct rld_faddr
  {
    __uint      rld_flag : 8;   /* 0x00: flag byte */
    __uint      rld_addr : 24;  /* 0x01: address to be relocated */
  } rld_faddr;

typedef struct rld_entry
  {
    __usint     rld_relesdid;   /* 0x00: relocation ESDID */
    __usint     rld_posesdid;   /* 0x02: position ESDID */
    rld_faddr   rld__fa;        /* 0x04: flag/address */
  } rld_entry;

typedef struct rld_record
  {
    char        rld_punch;      /* 0x00: PUNCH_12_2_9 */
    char        rld_label[3];   /* 0x01: "RLD" */
    char        rld__unused1[6];/* 0x04: (blank) */
    __usint     rld_size;       /* 0x0a: data field length (bytes) */
    char        rld__unused2[4];/* 0x0c: (blank) */
    rld_entry   rld_data[7];    /* 0x10: data field */
    char        rld_deckid[8];  /* 0x48: deck id/sequence number */
  } rld_record;

typedef struct end_record
  {
    char        end_punch;      /* 0x00: PUNCH_12_2_9 */
    char        end_label[3];   /* 0x01: "END" */
    struct
      {
        __uint    end_unused1:8;/* 0x04: type code */
        __uint    end_entpt :24;/* 0x05: entry address */
      }         end__e;
    char        end__unused2[6];/* 0x08: (blank) */
    __usint     end_esdid;      /* 0x0e: ESDID of entry point */
    char        end__unused3[16];/* 0x10: (blank) */
    char        end_12;         /* 0x20: 1 or 2 */
    char        end_pgmid[10];  /* 0x21: program id */
    char        end_vers[2];    /* 0x2b: version level */
    char        end_mod[2];     /* 0x2d: modification level */
    char        end_yy[2];      /* 0x2f: modification level */
    char        end_ddd[3];     /* 0x31: modification level */
    char        end__unused4[20];/* 0x34: (blank) */
    char        end_deckid[8];  /* 0x48: deck id/sequence number */
  } end_record;

typedef struct sym_entry
  {
    struct
      {
        __uint    se_org   : 8; /* 0x00: organization */
        __uint    se_addr  :24; /* 0x01: entry address */
      }         se__oa;
    char        se_name[8];     /* 0x04: symbol name */
  } sym_entry;

typedef struct sym_record
  {
    char        sym_punch;      /* 0x00: PUNCH_12_2_9 */
    char        sym_label[3];   /* 0x01: "SYM" */
    char        sym__unused1[6];/* 0x04: (blank) */
    __usint     sym_size;       /* 0x0a: data field length (bytes) */
    char        sym__unused2[4];/* 0x0c: (blank) */
    char        sym_info[56];   /* 0x10: data field */
    char        sym_deckid[8];  /* 0x48: deck id/sequence number */
  } sym_record;

/* values for sym_entry data type... */
#define SYMDT_C         0x00
#define SYMDT_X         0x04
#define SYMDT_B         0x08
#define SYMDT_F         0x10
#define SYMDT_H         0x14
#define SYMDT_E         0x18
#define SYMDT_D         0x1c
#define SYMDT_AQ        0x20
#define SYMDT_Y         0x24
#define SYMDT_S         0x28
#define SYMDT_V         0x2c
#define SYMDT_P         0x30
#define SYMDT_Z         0x34
#define SYMDT_L         0x38

#undef __uint
#undef __usint

#endif /* _OBJ370_H_INCLUDED */