-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathhdl.h
348 lines (266 loc) · 11.9 KB
/
hdl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/* HDL.H (c) Copyright Jan Jaeger, 2003-2012 */
/* Hercules Dynamic Loader */
#ifndef _HDL_H
#define _HDL_H
#include "hercules.h"
#if !defined(_MSVC_)
#define _HDL_UNUSED __attribute__ ((unused))
#else
#define _HDL_UNUSED
#endif
#ifndef _HDL_C_
#ifndef _HUTIL_DLL_
#define HDL_DLL_IMPORT DLL_IMPORT
#else /* _HUTIL_DLL_ */
#define HDL_DLL_IMPORT extern
#endif /* _HUTIL_DLL_ */
#else
#define HDL_DLL_IMPORT DLL_EXPORT
#endif
#ifndef _HDLMAIN_C_
#ifndef _HENGINE_DLL_
#define HDM_DLL_IMPORT DLL_IMPORT
#else /* _HENGINE_DLL_ */
#define HDM_DLL_IMPORT extern
#endif /* _HENGINE_DLL_ */
#else
#define HDM_DLL_IMPORT DLL_EXPORT
#endif
/*********************************************************************/
struct _HDLSHD;
typedef struct _HDLSHD {
struct _HDLSHD *next;
char* shdname; /* identifying name */
void (*shdcall) (void *); /* Entry to be called */
void *shdarg; /* Optional argument */
} HDLSHD;
HDL_DLL_IMPORT void hdl_adsc(char*, void *, void *);/* Add shutdown routine */
HDL_DLL_IMPORT int hdl_rmsc(void *, void *); /* Remove shutdown routine */
HDL_DLL_IMPORT void hdl_shut(void); /* Call all shutdown routines*/
DLL_EXPORT DEVHND *hdl_ghnd(const char *devname); /* Get device handler */
/*********************************************************************/
#if !defined(OPTION_DYNAMIC_LOAD)
#define HDL_DEVICE_SECTION \
DLL_EXPORT DEVHND *hdl_ghnd(const char *devtype) \
{
#define HDL_DEVICE( _devname, _devhnd ) \
if(!strcasecmp( QSTR(_devname), devtype )) \
return &(_devhnd);
#define END_DEVICE_SECTION \
return NULL; \
}
#else /* defined(OPTION_DYNAMIC_LOAD) */
/*********************************************************************/
#if !defined(HDL_USE_LIBTOOL)
#define dlinit()
#else
#define dlinit() lt_dlinit()
#define dlopen(_name, _flags) lt_dlopen(_name)
#define dlsym(_handle, _symbol) lt_dlsym(_handle, _symbol)
#define dlclose(_handle) lt_dlclose(_handle)
#define dlerror() lt_dlerror()
#define RTLD_NOW 0
#endif
// extern char *(*hdl_device_type_equates)(char *);
typedef struct _HDLDEV { /* Device entry */
char *name; /* Device type name */
DEVHND *hnd; /* Device handlers */
struct _HDLDEV *next; /* Next entry */
} HDLDEV;
typedef struct _HDLINS { /* Instruction entry */
int opcode; /* Opcode */
int archflags; /* Architecture flags */
char *instname; /* Instruction name */
void *instruction; /* Instruction routine */
void *original; /* Original instruction */
struct _HDLINS *next; /* Next entry */
} HDLINS;
struct _HDLDEP;
typedef struct _HDLDEP { /* Dependency entry */
char *name; /* Dependency name */
char *version; /* Version */
int size; /* Structure/module size */
struct _HDLDEP *next; /* Next entry */
} HDLDEP;
typedef struct _HDLPRE { /* Preload list entry */
char *name; /* Module name */
int flag; /* Load flags */
} HDLPRE;
struct _MODENT;
typedef struct _MODENT { /* External Symbol entry */
void (*fep)(); /* Function entry point */
char *name; /* Function symbol name */
int count; /* Symbol load count */
struct _MODENT *modnext; /* Next entry in chain */
} MODENT;
struct _DLLENT;
typedef struct _DLLENT { /* DLL entry */
char *name; /* load module name */
void *dll; /* DLL handle (dlopen) */
int flags; /* load flags */
int (*hdldepc)(void *); /* hdl_depc */
int (*hdlreso)(void *); /* hdl_reso */
int (*hdlinit)(void *); /* hdl_init */
int (*hdlddev)(void *); /* hdl_ddev */
int (*hdldins)(void *); /* hdl_dins */
int (*hdlfini)(); /* hdl_fini */
struct _MODENT *modent; /* First symbol entry */
struct _HDLDEV *hndent; /* First device entry */
struct _HDLINS *insent; /* First instruction entry */
struct _DLLENT *dllnext; /* Next entry in chain */
} DLLENT;
#if defined(MODULESDIR)
#define HDL_DEFAULT_PATH MODULESDIR
#else
#define HDL_DEFAULT_PATH "hercules"
#endif
/* SHLIBEXT defined by ISW in configure.ac/config.h */
#if defined( HDL_BUILD_SHARED ) && defined( LTDL_SHLIB_EXT )
#define HDL_MODULE_SUFFIX LTDL_SHLIB_EXT
#else
#if defined( LT_MODULE_EXT )
#define HDL_MODULE_SUFFIX LT_MODULE_EXT
#elif defined( _MSVC_ )
#define HDL_MODULE_SUFFIX ".dll"
#else
#define HDL_MODULE_SUFFIX ".la"
#endif
#endif
#if defined( HDL_MODULE_SUFFIX )
#define HDL_SUFFIX_LENGTH (sizeof(HDL_MODULE_SUFFIX) - 1)
#else
#define HDL_SUFFIX_LENGTH 0
#endif
DLL_EXPORT
int hdl_load(char *, int); /* load dll */
#define HDL_LOAD_DEFAULT 0x00000000
#define HDL_LOAD_MAIN 0x00000001 /* Hercules MAIN module flag */
#define HDL_LOAD_NOUNLOAD 0x00000002 /* Module cannot be unloaded */
#define HDL_LOAD_FORCE 0x00000004 /* Override dependency check */
#define HDL_LOAD_NOMSG 0x00000008 /* Do not issue not found msg*/
#define HDL_LOAD_WAS_FORCED 0x00000010 /* Module load was forced */
#define HDL_INSTARCH_370 0x00000001
#define HDL_INSTARCH_390 0x00000002
#define HDL_INSTARCH_900 0x00000004
#define HDL_INSTARCH_ALL (HDL_INSTARCH_370|HDL_INSTARCH_390|HDL_INSTARCH_900)
DLL_EXPORT
int hdl_dele(char *); /* Unload dll */
DLL_EXPORT
void hdl_list(int); /* list all loaded modules */
#define HDL_LIST_DEFAULT 0x00000000
#define HDL_LIST_ALL 0x00000001 /* list all references */
DLL_EXPORT
void hdl_dlst(); /* list all dependencies */
DLL_EXPORT
void hdl_main(); /* Main initialization rtn */
DLL_EXPORT
char *hdl_setpath(char *, int); /* Set module path */
DLL_EXPORT
void * hdl_fent(char *); /* Find entry name */
DLL_EXPORT
void * hdl_nent(void *); /* Find next in chain */
/* The following statement should be void *(*unresolved)(void) = NULL*/
static void **unresolved _HDL_UNUSED = NULL;
#define UNRESOLVED *unresolved
#define HDL_DEPC hdl_depc
#define HDL_RESO hdl_reso
#define HDL_INIT hdl_init
#define HDL_FINI hdl_fini
#define HDL_DDEV hdl_ddev
#define HDL_DINS hdl_dins
#define HDL_HDTP hdt
#define HDL_DEPC_Q QSTR( HDL_DEPC )
#define HDL_RESO_Q QSTR( HDL_RESO )
#define HDL_INIT_Q QSTR( HDL_INIT )
#define HDL_FINI_Q QSTR( HDL_FINI )
#define HDL_DDEV_Q QSTR( HDL_DDEV )
#define HDL_DINS_Q QSTR( HDL_DINS )
#define HDL_HDTP_Q QSTR( HDL_HDTP )
#define HDL_FINDSYM(_name) \
hdl_fent( (_name) )
#define HDL_FINDNXT(_ep) \
hdl_nent( &(_ep) )
#define HDL_DEPENDENCY_SECTION \
DLL_EXPORT int HDL_DEPC(int (*hdl_depc_vers)(char *, char *, int) _HDL_UNUSED ) \
{ \
int hdl_depc_rc = 0;
#define HDL_DEPENDENCY(_comp) \
if (hdl_depc_vers( QSTR(_comp), HDL_VERS_ ## _comp, HDL_SIZE_ ## _comp)) \
hdl_depc_rc = 1;
#define END_DEPENDENCY_SECTION \
return hdl_depc_rc; }
#define HDL_REGISTER_SECTION \
DLL_EXPORT void HDL_INIT(int (*hdl_init_regi)(char *, void *) _HDL_UNUSED ) \
{
/* register this epname, as ep = addr of this var or func... */
#define HDL_REGISTER( _epname, _varname ) \
(hdl_init_regi)( QSTR(_epname), &(_varname) );
#define END_REGISTER_SECTION \
}
#define HDL_DEVICE_SECTION \
DLL_EXPORT void HDL_DDEV(int (*hdl_init_ddev)(char *, void *) _HDL_UNUSED ) \
{
#define HDL_DEVICE( _devname, _devhnd ) \
(hdl_init_ddev)( QSTR(_devname), &(_devhnd) );
#define END_DEVICE_SECTION \
}
#define HDL_INSTRUCTION_SECTION \
DLL_EXPORT void HDL_DINS(int (*hdl_init_dins)(int, int, void *, void *) _HDL_UNUSED ) \
{
#if defined(_370)
#define HDL_370_DEFINST( _arch, _opcode, _instruction) \
do { \
if( (_arch) & HDL_INSTARCH_370 ) \
(hdl_init_dins)( _arch, _opcode, QSTR(_instruction), &(s370_ ## _instruction) ); \
} while(0);
#else
#define HDL_370_DEFINST( _arch, _opcode, _instruction)
#endif
#if defined(_390)
#define HDL_390_DEFINST( _arch, _opcode, _instruction) \
do { \
if( (_arch) & HDL_INSTARCH_390 ) \
(hdl_init_dins)( _arch, _opcode, QSTR(_instruction), &(s390_ ## _instruction) ); \
} while(0);
#else
#define HDL_390_DEFINST( _arch, _opcode, _instruction)
#endif
#if defined(_900)
#define HDL_900_DEFINST( _arch, _opcode, _instruction) \
do { \
if( (_arch) & HDL_INSTARCH_900 ) \
(hdl_init_dins)( _arch, _opcode, QSTR(_instruction), &(z900_ ## _instruction) ); \
} while(0);
#else
#define HDL_900_DEFINST( _arch, _opcode, _instruction)
#endif
#define HDL_DEFINST( _arch, _opcode, _instruction ) \
do { \
HDL_370_DEFINST(( (_arch) & HDL_INSTARCH_370), _opcode, _instruction); \
HDL_390_DEFINST(( (_arch) & HDL_INSTARCH_390), _opcode, _instruction); \
HDL_900_DEFINST(( (_arch) & HDL_INSTARCH_900), _opcode, _instruction); \
} while(0);
#define END_INSTRUCTION_SECTION \
}
#define HDL_RESOLVER_SECTION \
DLL_EXPORT void HDL_RESO(void *(*hdl_reso_fent)(char *) _HDL_UNUSED ) \
{
#define HDL_RESOLVE(_name) \
(_name) = (hdl_reso_fent)(QSTR(_name));
/* set this ptrvar, to this ep value... */
#define HDL_RESOLVE_PTRVAR( _ptrvar, _epname ) \
(_ptrvar) = (hdl_reso_fent)(QSTR(_epname));
#define END_RESOLVER_SECTION \
}
#define HDL_FINAL_SECTION \
DLL_EXPORT int HDL_FINI() \
{ \
int rc = 0;
#define END_FINAL_SECTION \
return rc; \
}
#endif /* defined(OPTION_DYNAMIC_LOAD) */
#define PROGRAM_INTERRUPT(_regs, _interruption_code) \
((_regs)->program_interrupt) ((_regs),(_interruption_code))
/*********************************************************************/
#endif /* _HDL_H */