-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.HDL
697 lines (502 loc) · 21.6 KB
/
README.HDL
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
/*
Hercules Dynamic Loader
The dynamic loader is intended to supply a loading and linking
mechanism, whereby routines, commands, instructions and functions
can be dynamically added to hercules, without the need to rebuild
or even restart hercules.
The loader can be controlled by the following hercules commands:
ldmod <module list> - Load modules named in module list
rmmod <module list> - Unload modules named in list
lsmod - List all modules and entry points
lsdep - List all dependencies
The ldmod statement may also appear in the hercules
configuration file.
configuration statement:
modpath <pathname> - Specifies where modules are loaded from
The loader has 2 basic functions module load and module unload.
Module load:
int hdl_load(char *name, int flags);
Where name is the module name, this name may include the
path. If no path is given then the module is loaded from
the default library search order. Note that this is
different from the standard search order.
flags may be one of the following:
HDL_LOAD_DEFAULT or 0 - Default load
HDL_LOAD_MAIN - Reserved for hercules use
HDL_LOAD_NOUNLOAD - Module cannot be unloaded
HDL_LOAD_FORCE - Override dependency check
HDL_LOAD_NOMSG - Do not issue any error messages
This function returns a zero value when the load is successful.
Module unload:
int hdl_dele(char *name);
Where name is the name of the module that is to be unloaded.
This function returns a zero value when the unload is successful.
Resolving Symbols:
void * HDL_FINDSYM(char *symbolname);
This function will return the entry point of symbolname or
zero when the symbol cannot be resolved.
void * HDL_FINDNXT(current_entry point);
This function will return the previous entry point.
That is, the entry point which was current before the entry point
as identified by current_entry point was registered.
This function is intended to allow a module to call the original
routine. An example of this is given in the panel_command entry
as listed below.
There are some special considerations for systems that do not support
the concept of back-linking. Back-linking is the operating system
support of dynamically resolving unresolved external references in
a dynamic module, with the main module, or other loaded modules.
Cygwin does not support back-linking and Cygwin specials are listed
in this example with #if defined(WIN32).
Some additional notes:
Unload will remove all references to a specific module, but currently
it will not actually remove the loaded module from memory. This is
because there is no safe way (yet) to synchronize unloading of code
and, besides, it may still be in use. This should however pose no
practical limitations.
When a module lists a new dependency, that dependency will be regis-
tered. Unloading the module does not remove the dependency, this is
to be consistent with the previous note about unloading.
Diagnose F14 - dll interface
Purpose:
Allow external routines to be called from OS running under hercules
external routines must reside in hercules dll's
Instruction:
Format:
83 r1 r3 d2(b2)
r1: register containing real address of external routine name to be
called this routine name is defined as CL32, and is subject to
EBCDIC to ASCII translation under control of hercules codepages.
This parameter must be 32 byte aligned.
r3: register containing user parameter.
d2(b2): 0xF14
External routine:
void xxxx_diagf14_routine_name(int r1, int r3, REGS *regs);
xxxx_diagf14_ prefix to routine_name
xxxx being either s370, s390 or z900 depending on architecture mode.
The instruction is subject to machine malfunction checking.
The external routine may be interrupted when an extended wait or loop
occurs.
*/
#include "hercules.h"
#include "devtype.h"
#include "opcode.h"
/* Local definitions */
static void *gui_cpu_state(REGS *regs)
{
void *(*prev_cpu_state)(REGS *);
/* CPU status update processing */
/* Call higher level routine if one exists */
if((prev_cpu_state = HDL_FINDNXT(gui_cpu_state)))
return prev_cpu_state(regs);
return NULL;
}
void *ProcessCommand (char *command)
{
void * (*prev_panel_command)(char *);
if (strncasecmp(command,"ourcmd",6) == 0)
{
logmsg ("This is our command\n");
}
else
/* Call higher level command handler */
if((prev_panel_command = HDL_FINDNXT(ProcessCommand)))
return prev_panel_command(command);
return NULL;
}
/*
The dependency section is - for all intents and purposes - called
before the module is loaded. Its function is to check that there
are no incompatibilities between this module and the version of
hercules that we are running. Dependencies are identified by
name, this name is given on the HDL_DEPENDENCY statement.
Each dependency then has a version code, and a size code, where
the version code is a character string, and the size code an
integer value. If the version or size codes do not match with
those in the hercules main module, the module cannot be loaded.
The version is usually a character string that identifies the
version of the component, and the size is to be the size of
the component in the case of structures or unions.
Version and size should be coded as following:
#define HDL_VERS_SOMETHING "1.0"
#define HDL_SIZE_SOMETHING sizeof(SOMETHING)
where SOMETHING can be a structure or other component.
the associated dependency statement:
HDL_DEPENDENCY(SOMETHING);
When a dependency is given that has not yet been registered,
it will be registered, such that it can be checked in subsequent
module loads.
The dependency section is mandatory.
*/
HDL_DEPENDENCY_SECTION;
{
/* Define version dependencies that this module requires */
HDL_DEPENDENCY ( HERCULES );
HDL_DEPENDENCY ( SYSBLK );
HDL_DEPENDENCY ( REGS );
HDL_DEPENDENCY ( DEVBLK );
}
END_DEPENDENCY_SECTION;
/*
The registration exports labels and their associated entry points
to hercules, such that the symbols and associated entry points may
be known to hercules and any other module that may have been loaded.
The registration section is called once during module load.
If we have registered a function that is also called from this DLL,
then it must also be listed in the resolver section. This to ensure
that the symbol is properly resolved when other modules are loaded.
The registration section is optional.
*/
HDL_REGISTER_SECTION;
{
/* These are the entry points we export to Hercules
All functions and labels used this dll must be static
and non exportable, this to ensure that no foreign
names are included by the system loader on systems
that provide back-link support (mostly *nix systems)
*/
HDL_REGISTER ( daemon_task, external_gui_interface );
HDL_REGISTER ( debug_cpu_state, gui_cpu_state );
HDL_REGISTER ( panel_command, ProcessCommand );
}
END_REGISTER_SECTION;
/*
The resolver section imports the entry points of symbols that
have been previously registered.
When a symbol is requested that has not been previously registered
then the resolve function will search the loaded modules for
that symbol, and register it implicitly. This latter function
is mainly provided to support systems that do not have back-link
support (most notably Cygwin).
Entry points that are resolved should be indirect pointers, for
example the panel_command routine is defined as:
void *(*panel_command)(char *)
The resolver may be called multiple times, the first time it is
called is during module load, immediately after the registration
section is called. It is subsequently called when other modules
are loaded or unloaded.
When a symbol cannot be resolved it will be set to NULL.
The resolver section is optional.
*/
HDL_RESOLVER_SECTION;
{
/* These are Hercules's entry points that we need access to
these may be updated by other loadable modules, so we need
to resolve them here.
*/
HDL_RESOLVE ( panel_command );
HDL_RESOLVE ( debug_cpu_state );
HDL_RESOLVE_PTRVAR ( my_sysblk_ptr, sysblk );
}
END_RESOLVER_SECTION;
/*
The device section is to register device drivers with hercules.
It associates device types with device handlers
If a device handler is not registered for a specific device type
then and a loadable mode with the name of "hdtxxxx" (where xxxx
is the device type) exists then that module is loaded
Search order:
1) The most recently registered (ie loaded) device of the
requested device type.
2) Device driver in external loadable module, where the
module name is hdtxxxx (where xxxx is the device type
ie module name hdtlcs for device type LCS or hdt2703
for device type 2703)
3) If the device is listed in the alias table (hdteq.c)
then external module hdtyyyy will be loaded, where
yyyy is the base name as listed in hdteq.c.
The device name is always mapped to lower case when searching
for loadable modules.
The device section is optional
*/
HDL_DEVICE_SECTION;
{
HDL_DEVICE(1052,constty_device_hndinfo);
HDL_DEVICE(3215,constty_device_hndinfo);
}
END_DEVICE_SECTION;
/* The instruction section registers inserts optional instructions,
or modifies existing instructions.
Instructions are generally defined with DEF_INST(instname) which results
in an external reference of s370_instname, s390_instname and z900_instname.
If an instruction is not defined for a certain architecture mode then
UNDEF_INST(instname) must be used for that given architecture mode.
The instruction section is optional
*/
HDL_INSTRUCTION_SECTION;
{
HDL_DEFINST(HDL_INSTARCH_370,0xB2FE,new_B2FE_inst_doing_something);
HDL_DEFINST(HDL_INSTARCH_390|HDL_INSTARCH_900,0xB2FD,new_B2FD_inst_doing_something_else);
}
END_INSTRUCTION_SECTION;
/*
The final section is called once, when the module is unloaded
or when hercules terminates.
A dll can reject being unloaded by returning a non-zero value
in the final section.
The final section is intended to be used to perform cleanup or
indicate cleanup action to be taken. It may set a shutdown
flag that is used within this dll that all local functions
must now terminate.
The final section is optional
*/
HDL_FINAL_SECTION;
{
}
END_FINAL_SECTION;
Below is Fish's sample code...
/* Define version dependencies that this module requires...
**
** The following are the various Hercules structures whose layout your
** module depends on. The layout of the following structures (size and
** version) MUST match the layout that was used to build Hercules with.
** If the size/version of any of the following structures changes (and
** a new version of Hercules is built using the new layout), then YOUR
** module must also be built with the new layout as well. The layout of
** the structures as they were when your module is built MUST MATCH the
** layout as it was when the version of Hercules you're using was built.
** Further note that the below HDL_DEPENDENCY_SECTION is actually just
** a function that the hdl logic calls, and thus allows you to insert
** directly into the below section any specialized 'C' code you need.
*/
HDL_DEPENDENCY_SECTION;
{
HDL_DEPENDENCY(HERCULES);
HDL_DEPENDENCY(REGS);
HDL_DEPENDENCY(DEVBLK);
HDL_DEPENDENCY(SYSBLK);
HDL_DEPENDENCY(WEBBLK);
}
END_DEPENDENCY_SECTION;
/* Register re-bindable entry point with resident version, or UNRESOLVED
**
** The following section defines the entry points within Hercules that
** your module is overriding (replacing). Your module's functions will
** be called by Hercules instead of the normal Hercules function (if any).
** The functions defined below thus provide additional/new functionality
** above/beyond the functionality normally provided by Hercules. Be aware
** however that it is entirely possible for other dlls to subsequently
** override the same functions that you've overridden such that they end
** up being called before your override does and your override may thus
** not get called at all (depending on how their override is written).
** Note that the "entry-point name" does not need to correspond to any
** existing variable or function (i.e. the entry-point name is just that:
** a name, and nothing more. There does not need to be a variable defined
** anywhere in your module with that name). Further note that the below
** HDL_REGISTER_SECTION is actually just a function that the hdl logic
** calls, thus allowing you to insert directly into the below section
** any specialized 'C' code that you may need.
*/
HDL_REGISTER_SECTION;
{
/* register this as the address of
entry-point name, this var or func
*/
HDL_REGISTER( panel_command, my_panel_command );
HDL_REGISTER( panel_display, my_panel_display );
HDL_REGISTER( some_exitpoint, UNRESOLVED );
}
END_REGISTER_SECTION;
/* Resolve re-bindable entry point on module load or unload...
**
** The following entries "resolve" entry points that your module
** needs. These entries define the names of registered entry points
** that you need "imported" into your dll so that you may call them
** directly yourself. The HDL_RESOLVE_PTRVAR macro is used to auto-
** matically set one of your own pointer variables to the registered
** entry point's currently registered value (usually an address of
** a function or variable). Note that the HDL_RESOLVER_SECTION is
** actually just a function that the hdl logic calls, thus allowing
** you to insert directly into the below section any specialized 'C'
** code that you may need.
*/
HDL_RESOLVER_SECTION;
{
/* Herc's registered
entry points that
you need to call
directly yourself
*/
HDL_RESOLVE( config_command );
HDL_RESOLVE( some_exitpoint );
HDL_RESOLVE( debug_cpu_state );
HDL_RESOLVE( debug_program_interrupt );
HDL_RESOLVE( debug_diagnose );
/* The following illustrates how to use HDL_RESOLVE_PTRVAR
macro to retrieve the address of one of Herc's registered
entry points.
Your pointer- Herc's registered
variable name entry-point name
*/
HDL_RESOLVE_PTRVAR( my_sysblk_ptr, sysblk );
}
END_RESOLVER_SECTION;
/* The following section defines what should be done just before
** your module is unloaded. It is nothing more than a function that
** is called by hdl logic just before your module is unloaded, and
** nothing more. Thus you can place any 'C' code here that you want.
*/
HDL_FINAL_SECTION;
{
my_cleanup();
}
END_FINAL_SECTION;
/* DYNDIAG.C (c) Copyright Jan Jaeger, 2003 */
/* Hercules Dynamic Loader */
/* Sample diagf14 dll routine */
/* */
/* Assembler to call routine: */
/* */
/* LRA R1,=CL32'test' */
/* LRA R2,=X'01020304' USERPARM */
/* DC X'83120F14' DIAG R1,R2,X'F14' */
/* */
#include "hercules.h"
#include "opcode.h"
#include "inline.h"
void ARCH_DEP(diagf14_test) (int r1, int r3, REGS *regs)
{
U32 r3loc;
logmsg("diagf14: r3 = %8.8X\n",regs->GR_L(r3));
r3loc = ARCH_DEP(vfetch4) (regs->GR_L(r3), USE_REAL_ADDR, regs);
logmsg("diagf14: *r3 = %8.8X\n",r3loc);
}
#if !defined(_GEN_ARCH)
#if defined(_ARCHMODE2)
#define _GEN_ARCH _ARCHMODE2
#include "dyndiag.c"
#endif
#if defined(_ARCHMODE3)
#undef _GEN_ARCH
#define _GEN_ARCH _ARCHMODE3
#include "dyndiag.c"
#endif
HDL_DEPENDENCY_SECTION;
{
HDL_DEPENDENCY (HERCULES);
HDL_DEPENDENCY (REGS);
HDL_DEPENDENCY (DEVBLK);
HDL_DEPENDENCY (SYSBLK);
} END_DEPENDENCY_SECTION;
HDL_REGISTER_SECTION;
{
HDL_REGISTER(s370_diagf14_test,s370_diagf14_test);
HDL_REGISTER(s390_diagf14_test,s390_diagf14_test);
HDL_REGISTER(z900_diagf14_test,z900_diagf14_test);
} END_REGISTER_SECTION;
HDL_RESOLVER_SECTION;
{
} END_RESOLVER_SECTION;
HDL_FINAL_SECTION;
{
} END_FINAL_SECTION;
#endif /*!defined(_GEN_ARCH)*/
/* END DYNDIAG.C */
/* DYNCGI.C (c)Copyright Jan Jaeger, 2002-2003 */
/* HTTP cgi-bin routines */
/* This file contains cgi routines that may be executed on the */
/* server (ie under control of a hercules thread) */
/* */
/* */
/* Dynamically loaded cgi routines must be registered under the */
/* pathname that they are accessed with (ie /cgi-bin/test) */
/* All cgi pathnames must start with /cgi-bin/ */
/* */
/* */
/* The cgi-bin routines may call the following HTTP service routines */
/* */
/* char *cgi_variable(WEBBLK *webblk, char *name); */
/* This call returns a pointer to the cgi variable requested */
/* or a NULL pointer if the variable is not found */
/* */
/* char *cgi_cookie(WEBBLK *webblk, char *name); */
/* This call returns a pointer to the cookie requested */
/* or a NULL pointer if the cookie is not found */
/* */
/* char *cgi_username(WEBBLK *webblk); */
/* Returns the username for which the user has been authenticated */
/* or NULL if not authenticated (refer to auth/noauth parameter */
/* on the HTTPPORT configuration statement) */
/* */
/* char *cgi_baseurl(WEBBLK *webblk); */
/* Returns the url as requested by the user */
/* */
/* void html_header(WEBBLK *webblk); */
/* Sets up the standard html header, and includes the */
/* html/header.htmlpart file. */
/* */
/* void html_footer(WEBBLK *webblk); */
/* Sets up the standard html footer, and includes the */
/* html/footer.htmlpart file. */
/* */
/* int html_include(WEBBLK *webblk, char *filename); */
/* Includes an html file */
/* */
/* */
/* Jan Jaeger - 28/03/2002 */
#include "hstdinc.h"
#include "hercules.h"
#include "devtype.h"
#include "opcode.h"
#include "httpmisc.h"
#if defined(OPTION_HTTP_SERVER)
void cgibin_test(WEBBLK *webblk)
{
html_header(webblk);
hprintf(webblk->hsock, "<H2>Sample cgi routine</H2>\n");
html_footer(webblk);
}
HDL_DEPENDENCY_SECTION;
{
HDL_DEPENDENCY(HERCULES);
// HDL_DEPENDENCY(REGS);
// HDL_DEPENDENCY(DEVBLK);
// HDL_DEPENDENCY(SYSBLK);
HDL_DEPENDENCY(WEBBLK);
}
END_DEPENDENCY_SECTION;
HDL_REGISTER_SECTION;
{
HDL_REGISTER( /cgi-bin/test, cgibin_test );
}
END_REGISTER_SECTION;
HDL_RESOLVER_SECTION;
{
}
END_RESOLVER_SECTION;
HDL_FINAL_SECTION;
{
}
END_FINAL_SECTION;
#endif /*defined(OPTION_HTTP_SERVER)*/
/* TESTINS.C Test instruction */
#include "hercules.h"
#include "opcode.h"
/*-------------------------------------------------------------------*/
/* 0000 BARF - Barf [RR] */
/*-------------------------------------------------------------------*/
DEF_INST(barf)
{
int r1, r2; /* register values */
RR(inst, regs, r1, r2)
logmsg("Barf\n");
ARCH_DEP(program_interrupt)(regs, PGM_OPERATION_EXCEPTION);
}
#if !defined(_GEN_ARCH)
#if defined(_ARCHMODE2)
#define _GEN_ARCH _ARCHMODE2
#include "testins.c"
#endif
#if defined(_ARCHMODE3)
#undef _GEN_ARCH
#define _GEN_ARCH _ARCHMODE3
#include "testins.c"
#endif
HDL_DEPENDENCY_SECTION;
{
} END_DEPENDENCY_SECTION;
HDL_INSTRUCTION_SECTION;
{
HDL_DEFINST(HDL_INSTARCH_ALL,0x00,barf);
} END_INSTRUCTION_SECTION;
#endif /*!defined(_GEN_ARCH)*/