1 /* HTYPES.H     (c) Copyright Roger Bowler, 1999-2009                */
2 /*              Hercules Type Definitions                            */
3 
4 #ifndef _HTYPES_H_
5 #define _HTYPES_H_
6 /*
7     Try to pull in as many typedef's as possible
8     from the provided system headers for whatever
9     system we're building on...
10 */
11 #ifndef HAVE_INTTYPES_H
12   #ifdef HAVE_U_INT
13     #define  uint8_t   u_int8_t
14     #define  uint16_t  u_int16_t
15     #define  uint32_t  u_int32_t
16     #define  uint64_t  u_int64_t
17   #else
18     #error Unable to find fixed-size data types
19   #endif
20 #endif
21 
22 #ifndef HAVE_U_INT8_T
23   #ifdef HAVE_INTTYPES_H
24     typedef  uint8_t   u_int8_t;
25     typedef  uint16_t  u_int16_t;
26     typedef  uint32_t  u_int32_t;
27     typedef  uint64_t  u_int64_t;
28   #else
29     #error Unable to define u_intNN_t data types
30   #endif
31 #endif
32 
33 typedef  int8_t     S8;         // signed 8-bits
34 typedef  int16_t    S16;        // signed 16-bits
35 typedef  int32_t    S32;        // signed 32-bits
36 typedef  int64_t    S64;        // signed 64-bits
37 
38 typedef  uint8_t    U8;         // unsigned 8-bits
39 typedef  uint16_t   U16;        // unsigned 16-bits
40 typedef  uint32_t   U32;        // unsigned 32-bits
41 typedef  uint64_t   U64;        // unsigned 64-bits
42 
43 #ifndef  _MSVC_                 // (MSVC typedef's it too)
44 typedef  uint8_t    BYTE;       // unsigned byte       (1 byte)
45 #endif
46 typedef  uint8_t    HWORD[2];   // unsigned halfword   (2 bytes)
47 typedef  uint8_t    FWORD[4];   // unsigned fullword   (4 bytes)
48 typedef  uint8_t    DBLWRD[8];  // unsigned doubleword (8 bytes)
49 typedef  uint8_t    QWORD[16];  // unsigned quadword   (16 bytes)
50 
51 /*-------------------------------------------------------------------*/
52 /* Format size modifiers for printf and scanf                        */
53 /*-------------------------------------------------------------------*/
54 
55 #if defined(_MSVC_)
56   #define  I16_FMT                  "h"
57   #define  I32_FMT                 "I32"
58   #define  I64_FMT                 "I64"
59 #elif defined(__PRI_64_LENGTH_MODIFIER__) // MAC
60   #define  I16_FMT                  "h"
61   #define  I32_FMT                  ""
62   #define  I64_FMT                  __PRI_64_LENGTH_MODIFIER__
63 #elif defined(SIZEOF_LONG) && SIZEOF_LONG >= 8
64   #define  I16_FMT                  "h"
65   #define  I32_FMT                  ""
66   #define  I64_FMT                  "l"
67 #else // !defined(SIZEOF_LONG) || SIZEOF_LONG < 8
68   #define  I16_FMT                  "h"
69   #define  I32_FMT                  ""
70   #define  I64_FMT                  "ll"
71 #endif
72 
73 #define  I16_FMTx           "%4.4" I16_FMT "x"
74 #define  I32_FMTx           "%8.8" I32_FMT "x"
75 #define  I64_FMTx         "%16.16" I64_FMT "x"
76 
77 #define  I16_FMTX           "%4.4" I16_FMT "X"
78 #define  I32_FMTX           "%8.8" I32_FMT "X"
79 #define  I64_FMTX         "%16.16" I64_FMT "X"
80 
81 #if defined(SIZEOF_INT_P) && SIZEOF_INT_P >= 8
82  #define FMT_PFX_P        "%16.16"
83 #else // !defined(SIZEOF_INT_P) || SIZEOF_INT_P < 8
84  #define FMT_PFX_P          "%8.8"
85 #endif
86 
87 #if defined(__PRI_64_LENGTH_MODIFIER__) // MAC
88  #define UINT_PTR_FMT              PRIuPTR
89  #define      PTR_FMTx   FMT_PFX_P PRIxPTR
90  #define      PTR_FMTX   FMT_PFX_P PRIXPTR
91 #elif defined(SIZEOF_INT_P) && SIZEOF_INT_P >= 8
92  #define UINT_PTR_FMT              I64_FMT
93  #define      PTR_FMTx             I64_FMTx
94  #define      PTR_FMTX             I64_FMTX
95 #else // !defined(SIZEOF_INT_P) || SIZEOF_INT_P < 8
96  #define UINT_PTR_FMT              I32_FMT
97  #define      PTR_FMTx             I32_FMTx
98  #define      PTR_FMTX             I32_FMTX
99 #endif
100 
101 #if defined(SIZEOF_SIZE_T) && SIZEOF_SIZE_T >= 8
102  #define FMT_PFX_Z        "%16.16"
103 #else // !defined(SIZEOF_INT_P) || SIZEOF_INT_P < 8
104  #define FMT_PFX_Z          "%8.8"
105 #endif
106 
107 #if defined(__PRI_64_LENGTH_MODIFIER__) // MAC
108  #define   SIZE_T_FMT              PRIuPTR
109  #define   SIZE_T_FMTx   FMT_PFX_Z PRIxPTR
110  #define   SIZE_T_FMTX   FMT_PFX_Z PRIXPTR
111 #elif defined(SIZEOF_SIZE_T) && SIZEOF_SIZE_T >= 8
112   #define  SIZE_T_FMT              I64_FMT
113   #define  SIZE_T_FMTx             I64_FMTx
114   #define  SIZE_T_FMTX             I64_FMTX
115 #else // !defined(SIZEOF_SIZE_T) || SIZEOF_SIZE_T < 8
116   #define  SIZE_T_FMT              I32_FMT
117   #define  SIZE_T_FMTx             I32_FMTx
118   #define  SIZE_T_FMTX             I32_FMTX
119 #endif
120 
121 /*-------------------------------------------------------------------*/
122 /* Socket stuff                                                      */
123 /*-------------------------------------------------------------------*/
124 
125 #ifndef _BSDTYPES_DEFINED
126   #ifndef HAVE_U_CHAR
127     typedef unsigned char   u_char;
128   #endif
129   #ifndef HAVE_U_SHORT
130     typedef unsigned short  u_short;
131   #endif
132   #ifndef HAVE_U_INT
133     typedef unsigned int    u_int;
134   #endif
135   #ifndef HAVE_U_LONG
136     typedef unsigned long   u_long;
137   #endif
138   #define _BSDTYPES_DEFINED
139 #endif
140 
141 #ifndef HAVE_SOCKLEN_T
142   typedef  unsigned int     socklen_t;
143 #endif
144 
145 #ifndef HAVE_IN_ADDR_T
146   typedef  unsigned int     in_addr_t;
147 #endif
148 
149 /* FIXME : THAT'S WRONG ! BUT IT WORKS FOR THE TIME BEING */
150 #if defined(_MSVC_)
151 #ifndef HAVE_USECONDS_T
152   typedef  long             useconds_t;
153 #endif
154 #endif
155 
156 #if !defined( HAVE_STRUCT_IN_ADDR_S_ADDR ) && !defined( _WINSOCK_H )
157   struct in_addr
158   {
159     in_addr_t  s_addr;
160   };
161 #endif
162 
163   // (The following are simply to silence some compile time warnings)
164 #ifdef _MSVC_
165   typedef  char               GETSET_SOCKOPT_T;
166   typedef  const char *const *EXECV_ARG2_ARGV_T;
167 #else
168   typedef  void         GETSET_SOCKOPT_T;
169   typedef  char *const *EXECV_ARG2_ARGV_T;
170 #endif
171 
172 #if defined( OPTION_SCSI_TAPE ) && !defined( HAVE_SYS_MTIO_H )
173   struct mt_tape_info
174   {
175      long t_type;    /* device type id (mt_type) */
176      char *t_name;   /* descriptive name */
177   };
178   #define MT_TAPE_INFO   { { 0, NULL } }
179 #endif
180 
181 /*-------------------------------------------------------------------*/
182 /* Primary Hercules Control Structures                               */
183 /*-------------------------------------------------------------------*/
184 
185 typedef struct SYSBLK    SYSBLK;    // System configuration block
186 typedef struct REGS      REGS;      // CPU register context
187 typedef struct VFREGS    VFREGS;    // Vector Facility Registers
188 typedef struct ZPBLK     ZPBLK;     // Zone Parameter Block
189 typedef struct DEVBLK    DEVBLK;    // Device configuration block
190 typedef struct IOINT     IOINT;     // I/O interrupt queue
191 
192 typedef struct DEVDATA   DEVDATA;   // xxxxxxxxx
193 typedef struct DEVGRP    DEVGRP;    // xxxxxxxxx
194 typedef struct DEVHND    DEVHND;    // xxxxxxxxx
195 typedef struct SHRD      SHRD;      // xxxxxxxxx
196 
197 #ifdef EXTERNALGUI
198 typedef struct GUISTAT   GUISTAT;   // EXTERNALGUI Device Status Ctl
199 #endif
200 
201 /*-------------------------------------------------------------------*/
202 /* Secondary Device and I/O Control Related Structures               */
203 /*-------------------------------------------------------------------*/
204 
205 typedef struct CKDDASD_DEVHDR   CKDDASD_DEVHDR;   // Device header
206 typedef struct CKDDASD_TRKHDR   CKDDASD_TRKHDR;   // Track header
207 typedef struct CKDDASD_RECHDR   CKDDASD_RECHDR;   // Record header
208 typedef struct CCKDDASD_DEVHDR  CCKDDASD_DEVHDR;  // Compress device header
209 typedef struct CCKD_L2ENT       CCKD_L2ENT;       // Level 2 table entry
210 
211 typedef struct CCKD_FREEBLK     CCKD_FREEBLK;     // Free block
212 typedef struct CCKD_IFREEBLK    CCKD_IFREEBLK;    // Free block (internal)
213 typedef struct CCKD_RA          CCKD_RA;          // Readahead queue entry
214 
215 typedef struct CCKDBLK          CCKDBLK;          // Global cckd dasd block
216 typedef struct CCKDDASD_EXT     CCKDDASD_EXT;     // Ext for compressed ckd
217 
218 typedef struct COMMADPT         COMMADPT;         // Comm Adapter
219 typedef struct bind_struct      bind_struct;      // Socket Device Ctl
220 
221 typedef struct TAPEMEDIA_HANDLER  TAPEMEDIA_HANDLER;  // (see tapedev.h)
222 typedef struct TAPEAUTOLOADENTRY  TAPEAUTOLOADENTRY;  // (see tapedev.h)
223 typedef struct TAMDIR             TAMDIR;             // (see tapedev.h)
224 
225 /*-------------------------------------------------------------------*/
226 /* Device handler function prototypes                                */
227 /*-------------------------------------------------------------------*/
228 
229 typedef int   DEVIF  (DEVBLK *dev, int argc, char *argv[]);
230 typedef void  DEVQF  (DEVBLK *dev, char **class, int buflen,
231                                    char *buffer);
232 typedef void  DEVXF  (DEVBLK *dev, BYTE code, BYTE flags,
233                                    BYTE chained, U16 count,
234                                    BYTE prevcode, int ccwseq,
235                                    BYTE *iobuf, BYTE *more,
236                                    BYTE *unitstat, U16 *residual);
237 typedef int   DEVCF  (DEVBLK *dev);
238 typedef void  DEVSF  (DEVBLK *dev);
239 typedef int   DEVRF  (DEVBLK *dev, int ix, BYTE *unitstat);
240 typedef int   DEVWF  (DEVBLK *dev, int rcd, int off, BYTE *buf,
241                                    int len, BYTE *unitstat);
242 typedef int   DEVUF  (DEVBLK *dev);
243 typedef void  DEVRR  (DEVBLK *dev);
244 typedef int   DEVSA  (DEVBLK *dev, U32 qmask);
245 typedef int   DEVSR  (DEVBLK *dev, void *file);
246 
247 /*-------------------------------------------------------------------*/
248 /* Device handler description structures                             */
249 /*-------------------------------------------------------------------*/
250 
251 typedef BYTE *DEVIM;                    /* Immediate CCW Codes Table */
252 
253 #endif // _HTYPES_H_
254