forked from rbowler/spinhawk
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bldcfg.c
1826 lines (1625 loc) · 64.1 KB
/
bldcfg.c
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
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* BLDCFG.C (c) Copyright Roger Bowler, 1999-2009 */
/* ESA/390 Configuration Builder */
/* Interpretive Execution - (c) Copyright Jan Jaeger, 1999-2009 */
/*-------------------------------------------------------------------*/
/* This module builds the configuration tables for the Hercules */
/* ESA/390 emulator. It reads information about the processors */
/* and I/O devices from a configuration file. It allocates */
/* main storage and expanded storage, initializes control blocks, */
/* and creates detached threads to handle console attention */
/* requests and to maintain the TOD clock and CPU timers. */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Additional credits: */
/* TOD clock offset contributed by Jay Maynard */
/* Dynamic device attach/detach by Jan Jaeger */
/* OSTAILOR parameter by Jay Maynard */
/* PANRATE parameter by Reed H. Petty */
/* CPUPRIO parameter by Jan Jaeger */
/* HERCPRIO, TODPRIO, DEVPRIO parameters by Mark L. Gaubatz */
/* z/Architecture support - (c) Copyright Jan Jaeger, 1999-2009 */
/* $(DEFSYM) symbol substitution support by Ivan Warren */
/* Patch for ${var=def} symbol substitution (hax #26), */
/* and INCLUDE <filename> support (modified hax #27), */
/* contributed by Enrico Sorichetti based on */
/* original patches by "Hackules" */
/*-------------------------------------------------------------------*/
#include "hstdinc.h"
#if !defined(_BLDCFG_C_)
#define _BLDCFG_C_
#endif
#if !defined(_HENGINE_DLL_)
#define _HENGINE_DLL_
#endif
#include "hercules.h"
#include "devtype.h"
#include "opcode.h"
#include "hostinfo.h"
#if defined(OPTION_FISHIO)
#include "w32chan.h"
#endif // defined(OPTION_FISHIO)
#if defined( OPTION_TAPE_AUTOMOUNT )
#include "tapedev.h"
#endif
#if !defined(_GEN_ARCH)
#if defined(_ARCHMODE3)
#define _GEN_ARCH _ARCHMODE3
#include "bldcfg.c"
#undef _GEN_ARCH
#endif
#if defined(_ARCHMODE2)
#define _GEN_ARCH _ARCHMODE2
#include "bldcfg.c"
#undef _GEN_ARCH
#endif
typedef struct _DEVARRAY
{
U16 cuu1;
U16 cuu2;
} DEVARRAY;
typedef struct _DEVNUMSDESC
{
BYTE lcss;
DEVARRAY *da;
} DEVNUMSDESC;
/*-------------------------------------------------------------------*/
/* Static data areas */
/*-------------------------------------------------------------------*/
#define MAX_INC_LEVEL 8 /* Maximum nest level */
static int inc_level; /* Current nesting level */
// following commented out ISW 20061009 : Not referenced anywhere.
// static int inc_fname[MAX_INC_LEVEL]; /* filename (base or incl) */
static int inc_stmtnum[MAX_INC_LEVEL]; /* statement number */
static int inc_ignore_errors = 0; /* 1==ignore include errors */
#ifdef EXTERNALGUI
static char buf[1024]; /* Config statement buffer */
#else /*!EXTERNALGUI*/
static char buf[256]; /* Config statement buffer */
#endif /*EXTERNALGUI*/
static char *keyword; /* -> Statement keyword */
static char *operand; /* -> First argument */
static int addargc; /* Number of additional args */
static char *addargv[MAX_ARGS]; /* Additional argument array */
/*-------------------------------------------------------------------*/
/* Subroutine to parse an argument string. The string that is passed */
/* is modified in-place by inserting null characters at the end of */
/* each argument found. The returned array of argument pointers */
/* then points to each argument found in the original string. Any */
/* argument that begins with '#' comment indicator causes early */
/* termination of the parsing and is not included in the count. Any */
/* argument found that starts with a quote or apostrophe causes */
/* all characters up to the next quote or apostrophe to be */
/* included as part of that argument. The quotes/apostrophes them- */
/* selves are not considered part of any argument and are ignored. */
/* p Points to string to be parsed. */
/* maxargc Maximum allowable number of arguments. (Prevents */
/* overflowing the pargv array) */
/* pargv Pointer to buffer for argument pointer array. */
/* pargc Pointer to number of arguments integer result. */
/* Returns number of arguments found. (same value as at *pargc) */
/*-------------------------------------------------------------------*/
DLL_EXPORT int parse_args (char* p, int maxargc, char** pargv, int* pargc)
{
for (*pargc = 0; *pargc < MAX_ARGS; ++*pargc) addargv[*pargc] = NULL;
*pargc = 0;
*pargv = NULL;
while (*p && *pargc < maxargc)
{
while (*p && isspace(*p)) p++; if (!*p) break; // find start of arg
if (*p == '#') break; // stop on comments
*pargv = p; ++*pargc; // count new arg
while (*p && !isspace(*p) && *p != '\"' && *p != '\'') p++; if (!*p) break; // find end of arg
if (*p == '\"' || *p == '\'')
{
char delim = *p;
if (p == *pargv) *pargv = p+1;
while (*++p && *p != delim) {}; if (!*p) break; // find end of quoted string
}
*p++ = 0; // mark end of arg
pargv++; // next arg ptr
}
return *pargc;
}
void delayed_exit (int exit_code)
{
/* Delay exiting is to give the system
* time to display the error message. */
fflush(stderr);
fflush(stdout);
usleep(100000);
// hdl_shut();
do_shutdown();
fflush(stderr);
fflush(stdout);
usleep(100000);
exit(exit_code);
}
/* storage configuration routine. To be moved *JJ */
static void config_storage(unsigned mainsize, unsigned xpndsize)
{
int off;
/* Obtain main storage */
sysblk.mainsize = mainsize * 1024 * 1024ULL;
sysblk.mainstor = calloc((size_t)(sysblk.mainsize + 8192), 1);
if (sysblk.mainstor != NULL)
sysblk.main_clear = 1;
else
sysblk.mainstor = malloc((size_t)(sysblk.mainsize + 8192));
if (sysblk.mainstor == NULL)
{
logmsg(_("HHCCF031S Cannot obtain %dMB main storage: %s\n"),
mainsize, strerror(errno));
delayed_exit(1);
}
/* Trying to get mainstor aligned to the next 4K boundary - Greg */
off = (uintptr_t)sysblk.mainstor & 0xFFF;
sysblk.mainstor += off ? 4096 - off : 0;
/* Obtain main storage key array */
sysblk.storkeys = calloc((size_t)(sysblk.mainsize / STORAGE_KEY_UNITSIZE), 1);
if (sysblk.storkeys == NULL)
{
sysblk.main_clear = 0;
sysblk.storkeys = malloc((size_t)(sysblk.mainsize / STORAGE_KEY_UNITSIZE));
}
if (sysblk.storkeys == NULL)
{
logmsg(_("HHCCF032S Cannot obtain storage key array: %s\n"),
strerror(errno));
delayed_exit(1);
}
/* Initial power-on reset for main storage */
storage_clear();
#if 0 /*DEBUG-JJ-20/03/2000*/
/* Mark selected frames invalid for debugging purposes */
for (i = 64 ; i < (sysblk.mainsize / STORAGE_KEY_UNITSIZE); i += 2)
if (i < (sysblk.mainsize / STORAGE_KEY_UNITSIZE) - 64)
sysblk.storkeys[i] = STORKEY_BADFRM;
else
sysblk.storkeys[i++] = STORKEY_BADFRM;
#endif
if (xpndsize != 0)
{
#ifdef _FEATURE_EXPANDED_STORAGE
/* Obtain expanded storage */
sysblk.xpndsize = xpndsize * (1024*1024 / XSTORE_PAGESIZE);
sysblk.xpndstor = calloc(sysblk.xpndsize, XSTORE_PAGESIZE);
if (sysblk.xpndstor)
sysblk.xpnd_clear = 1;
else
sysblk.xpndstor = malloc((size_t)sysblk.xpndsize * XSTORE_PAGESIZE);
if (sysblk.xpndstor == NULL)
{
logmsg(_("HHCCF033S Cannot obtain %dMB expanded storage: "
"%s\n"),
xpndsize, strerror(errno));
delayed_exit(1);
}
/* Initial power-on reset for expanded storage */
xstorage_clear();
#else /*!_FEATURE_EXPANDED_STORAGE*/
logmsg(_("HHCCF034W Expanded storage support not installed\n"));
#endif /*!_FEATURE_EXPANDED_STORAGE*/
} /* end if(sysblk.xpndsize) */
}
#if defined( OPTION_TAPE_AUTOMOUNT )
/*-------------------------------------------------------------------*/
/* Add directory to AUTOMOUNT allowed/disallowed directories list */
/* */
/* Input: tamdir pointer to work character array of at least */
/* MAX_PATH size containing an allowed/disallowed */
/* directory specification, optionally prefixed */
/* with the '+' or '-' indicator. */
/* */
/* ppTAMDIR address of TAMDIR ptr that upon successful */
/* completion is updated to point to the TAMDIR */
/* entry that was just successfully added. */
/* */
/* Output: upon success, ppTAMDIR is updated to point to the TAMDIR */
/* entry just added. Upon error, ppTAMDIR is set to NULL and */
/* the original input character array is set to the inter- */
/* mediate value being processed when the error occurred. */
/* */
/* Returns: 0 == success */
/* 1 == unresolvable path */
/* 2 == path inaccessible */
/* 3 == conflict w/previous */
/* 4 == duplicates previous */
/* 5 == out of memory */
/* */
/*-------------------------------------------------------------------*/
DLL_EXPORT int add_tamdir( char *tamdir, TAMDIR **ppTAMDIR )
{
int rc, rej = 0;
char dirwrk[ MAX_PATH ] = {0};
*ppTAMDIR = NULL;
if (*tamdir == '-')
{
rej = 1;
memmove (tamdir, tamdir+1, MAX_PATH);
}
else if (*tamdir == '+')
{
rej = 0;
memmove (tamdir, tamdir+1, MAX_PATH);
}
/* Convert tamdir to absolute path ending with a slash */
#if defined(_MSVC_)
/* (expand any embedded %var% environment variables) */
rc = expand_environ_vars( tamdir, dirwrk, MAX_PATH );
if (rc == 0)
strlcpy (tamdir, dirwrk, MAX_PATH);
#endif
if (!realpath( tamdir, dirwrk ))
return (1); /* ("unresolvable path") */
strlcpy (tamdir, dirwrk, MAX_PATH);
/* Verify that the path is valid */
if (access( tamdir, R_OK | W_OK ) != 0)
return (2); /* ("path inaccessible") */
/* Append trailing path separator if needed */
rc = strlen( tamdir );
if (tamdir[rc-1] != *PATH_SEP)
strlcat (tamdir, PATH_SEP, MAX_PATH);
/* Check for duplicate/conflicting specification */
for (*ppTAMDIR = sysblk.tamdir;
*ppTAMDIR;
*ppTAMDIR = (*ppTAMDIR)->next)
{
if (strfilenamecmp( tamdir, (*ppTAMDIR)->dir ) == 0)
{
if ((*ppTAMDIR)->rej != rej)
return (3); /* ("conflict w/previous") */
else
return (4); /* ("duplicates previous") */
}
}
/* Allocate new AUTOMOUNT directory entry */
*ppTAMDIR = malloc( sizeof(TAMDIR) );
if (!*ppTAMDIR)
return (5); /* ("out of memory") */
/* Fill in the new entry... */
(*ppTAMDIR)->dir = strdup (tamdir);
(*ppTAMDIR)->len = strlen (tamdir);
(*ppTAMDIR)->rej = rej;
(*ppTAMDIR)->next = NULL;
/* Add new entry to end of existing list... */
if (sysblk.tamdir == NULL)
sysblk.tamdir = *ppTAMDIR;
else
{
TAMDIR *pTAMDIR = sysblk.tamdir;
while (pTAMDIR->next)
pTAMDIR = pTAMDIR->next;
pTAMDIR->next = *ppTAMDIR;
}
/* Use first allowable dir as default */
if (rej == 0 && sysblk.defdir == NULL)
sysblk.defdir = (*ppTAMDIR)->dir;
return (0); /* ("success") */
}
#endif /* OPTION_TAPE_AUTOMOUNT */
/*-------------------------------------------------------------------*/
/* Subroutine to read a statement from the configuration file */
/* The statement is then parsed into keyword, operand, and */
/* additional arguments. The output values are: */
/* keyword Points to first word of statement */
/* operand Points to second word of statement */
/* addargc Contains number of additional arguments */
/* addargv An array of pointers to each additional argument */
/* Returns 0 if successful, -1 if end of file */
/*-------------------------------------------------------------------*/
static int read_config (char *fname, FILE *fp)
{
int i; /* Array subscript */
int c; /* Character work area */
int stmtlen; /* Statement length */
#if defined( OPTION_ENHANCED_CONFIG_SYMBOLS )
int inc_dollar; /* >=0 Ndx of dollar */
int inc_lbrace; /* >=0 Ndx of lbrace + 1 */
int inc_colon; /* >=0 Ndx of colon */
int inc_equals; /* >=0 Ndx of equals */
char *inc_envvar; /* ->Environment variable */
#endif // defined( OPTION_ENHANCED_CONFIG_SYMBOLS )
int lstarted; /* Indicate if non-whitespace*/
/* has been seen yet in line */
char *cnfline; /* Pointer to copy of buffer */
#if defined(OPTION_CONFIG_SYMBOLS)
char *buf1; /* Pointer to resolved buffer*/
#endif /*defined(OPTION_CONFIG_SYMBOLS)*/
#if defined( OPTION_ENHANCED_CONFIG_SYMBOLS )
inc_dollar = -1;
inc_lbrace = -1;
inc_colon = -1;
inc_equals = -1;
#endif // defined( OPTION_ENHANCED_CONFIG_SYMBOLS )
while (1)
{
/* Increment statement number */
inc_stmtnum[inc_level]++;
/* Read next statement from configuration file */
for (stmtlen = 0, lstarted = 0; ;)
{
/* Read character from configuration file */
c = fgetc(fp);
/* Check for I/O error */
if (ferror(fp))
{
logmsg(_("HHCCF001S Error reading file %s line %d: %s\n"),
fname, inc_stmtnum[inc_level], strerror(errno));
delayed_exit(1);
}
/* Check for end of file */
if (stmtlen == 0 && (c == EOF || c == '\x1A'))
return -1;
/* Check for end of line */
if (c == '\n' || c == EOF || c == '\x1A')
break;
/* Ignore nulls and carriage returns */
if (c == '\0' || c == '\r') continue;
/* Check if it is a white space and no other character yet */
if(!lstarted && isspace(c)) continue;
lstarted=1;
/* Check that statement does not overflow buffer */
if (stmtlen >= (int)(sizeof(buf) - 1))
{
logmsg(_("HHCCF002S File %s line %d is too long\n"),
fname, inc_stmtnum[inc_level]);
delayed_exit(1);
}
#if defined( OPTION_ENHANCED_CONFIG_SYMBOLS )
/* inc_dollar already processed? */
if (inc_dollar >= 0)
{
/* Left brace already processed? */
if (inc_lbrace >= 0)
{
/* End of variable spec? */
if (c == '}')
{
/* Terminate it */
buf[stmtlen] = '\0';
/* Terminate var name if we have a inc_colon specifier */
if (inc_colon >= 0)
{
buf[inc_colon] = '\0';
}
/* Terminate var name if we have a default value */
if (inc_equals >= 0)
{
buf[inc_equals] = '\0';
}
/* Reset statement index to start of variable */
stmtlen = inc_dollar;
/* Get variable value */
inc_envvar = getenv (&buf[inc_lbrace]);
/* Variable unset? */
if (inc_envvar == NULL)
{
/* Substitute default if specified */
if (inc_equals >= 0)
{
inc_envvar = &buf[inc_equals+1];
}
}
else // (environ variable defined)
{
/* Have ":=" specification? */
if (/*inc_colon >= 0 && */inc_equals >= 0)
{
/* Substitute default if value is NULL */
if (strlen (inc_envvar) == 0)
{
inc_envvar = &buf[inc_equals+1];
}
}
}
/* Have a value? (environment or default) */
if (inc_envvar != NULL)
{
/* Check that statement does not overflow buffer */
if (stmtlen+strlen(inc_envvar) >= sizeof(buf) - 1)
{
logmsg(_("HHCCF002S File %s line %d is too long\n"),
fname, inc_stmtnum[inc_level]);
delayed_exit(1);
}
/* Copy to buffer and update index */
stmtlen += sprintf (&buf[stmtlen], "%s", inc_envvar);
}
/* Reset indexes */
inc_equals = -1;
inc_colon = -1;
inc_lbrace = -1;
inc_dollar = -1;
continue;
}
else if (c == ':' && inc_colon < 0 && inc_equals < 0)
{
/* Remember possible start of default specifier */
inc_colon = stmtlen;
}
else if (c == '=' && inc_equals < 0)
{
/* Remember possible start of default specifier */
inc_equals = stmtlen;
}
}
else // (inc_lbrace < 0)
{
/* Remember start of variable name */
if (c == '{')
{
inc_lbrace = stmtlen + 1;
}
else
{
/* Reset inc_dollar specifier if immediately following
character is not a left brace */
inc_dollar = -1;
}
}
}
else // (inc_dollar < 0)
{
/* Enter variable substitution state */
if (c == '$')
{
inc_dollar = stmtlen;
}
}
#endif // defined( OPTION_ENHANCED_CONFIG_SYMBOLS )
/* Append character to buffer */
buf[stmtlen++] = c;
} /* end for(stmtlen) */
/* Remove trailing blanks and tabs */
while (stmtlen > 0 && (buf[stmtlen-1] == SPACE
|| buf[stmtlen-1] == '\t')) stmtlen--;
buf[stmtlen] = '\0';
/* Ignore comments and null statements */
if (stmtlen == 0 || buf[0] == '*' || buf[0] == '#')
continue;
cnfline = strdup(buf);
/* Parse the statement just read */
#if defined(OPTION_CONFIG_SYMBOLS)
/* Perform variable substitution */
/* First, set some 'dynamic' symbols to their own values */
set_symbol("CUU","$(CUU)");
set_symbol("cuu","$(cuu)");
set_symbol("CCUU","$(CCUU)");
set_symbol("ccuu","$(ccuu)");
/* VERISION will be set here, earlier than in @PJJ */
/* console.c in order to make it usable in the @PJJ */
/* hercules configuration file. @PJJ */
set_symbol("VERSION", VERSION);
buf1=resolve_symbol_string(buf);
if(buf1!=NULL)
{
if(strlen(buf1)>=sizeof(buf))
{
logmsg(_("HHCCF002S File %s line %d is too long\n"),
fname, inc_stmtnum[inc_level]);
free(buf1);
delayed_exit(1);
}
strcpy(buf,buf1);
/* Free buf1 as explicitly stated to be needed in @PJJ */
/* resolve_symbol_string. @PJJ */
free(buf1);
}
#endif /*defined(OPTION_CONFIG_SYMBOLS)*/
parse_args (buf, MAX_ARGS, addargv, &addargc);
#if defined(OPTION_DYNAMIC_LOAD)
if(config_command)
{
if( config_command(addargc, (char**)addargv, cnfline) )
{
free(cnfline);
continue;
}
}
#endif /*defined(OPTION_DYNAMIC_LOAD)*/
if( !ProcessConfigCommand (addargc, (char**)addargv, cnfline) )
{
free(cnfline);
continue;
}
free(cnfline);
/* Move the first two arguments to separate variables */
keyword = addargv[0];
operand = addargv[1];
addargc = (addargc > 2) ? (addargc-2) : (0);
for (i = 0; i < MAX_ARGS; i++)
{
if (i < (MAX_ARGS-2)) addargv[i] = addargv[i+2];
else addargv[i] = NULL;
}
break;
} /* end while */
return 0;
} /* end function read_config */
static inline S64 lyear_adjust(int epoch)
{
int year, leapyear;
U64 tod = hw_clock();
if(tod >= TOD_YEAR)
{
tod -= TOD_YEAR;
year = (tod / TOD_4YEARS * 4) + 1;
tod %= TOD_4YEARS;
if((leapyear = tod / TOD_YEAR) == 4)
year--;
year += leapyear;
}
else
year = 0;
if(epoch > 0)
return (((year % 4) != 0) && (((year % 4) - (epoch % 4)) <= 0)) ? -TOD_DAY : 0;
else
return (((year % 4) == 0 && (-epoch % 4) != 0) || ((year % 4) + (-epoch % 4) > 4)) ? TOD_DAY : 0;
}
DLL_EXPORT char *config_cnslport = "3270";
/*-------------------------------------------------------------------*/
/* Function to build system configuration */
/*-------------------------------------------------------------------*/
void build_config (char *fname)
{
int rc; /* Return code */
int i; /* Array subscript */
int scount; /* Statement counter */
int cpu; /* CPU number */
int count; /* Counter */
FILE *inc_fp[MAX_INC_LEVEL]; /* Configuration file pointer*/
char *sserial; /* -> CPU serial string */
char *smodel; /* -> CPU model string */
char *sversion; /* -> CPU version string */
char *smainsize; /* -> Main size string */
char *sxpndsize; /* -> Expanded size string */
char *smaxcpu; /* -> Maximum number of CPUs */
char *snumcpu; /* -> Number of CPUs */
char *snumvec; /* -> Number of VFs */
char *sengines; /* -> Processor engine types */
char *ssysepoch; /* -> System epoch */
char *syroffset; /* -> System year offset */
char *stzoffset; /* -> System timezone offset */
char *shercprio; /* -> Hercules base priority */
char *stodprio; /* -> Timer thread priority */
char *scpuprio; /* -> CPU thread priority */
char *sdevprio; /* -> Device thread priority */
char *slogofile; /* -> 3270 logo file */
#if defined(_FEATURE_ECPSVM)
char *secpsvmlevel; /* -> ECPS:VM Keyword */
char *secpsvmlvl; /* -> ECPS:VM level (or 'no')*/
int ecpsvmac; /* -> ECPS:VM add'l arg cnt */
#endif /*defined(_FEATURE_ECPSVM)*/
#if defined(OPTION_SHARED_DEVICES)
char *sshrdport; /* -> Shared device port nbr */
#endif /*defined(OPTION_SHARED_DEVICES)*/
U16 version = 0x00; /* CPU version code */
int dfltver = 1; /* Default version code */
U32 serial; /* CPU serial number */
U16 model; /* CPU model number */
unsigned mainsize; /* Main storage size (MB) */
unsigned xpndsize; /* Expanded storage size (MB)*/
U16 maxcpu; /* Maximum number of CPUs */
U16 numcpu; /* Number of CPUs */
U16 numvec; /* Number of VFs */
#if defined(OPTION_SHARED_DEVICES)
U16 shrdport; /* Shared device port number */
#endif /*defined(OPTION_SHARED_DEVICES)*/
S32 sysepoch; /* System epoch year */
S32 tzoffset; /* System timezone offset */
S32 yroffset; /* System year offset */
S64 ly1960; /* Leap offset for 1960 epoch*/
int hercprio; /* Hercules base priority */
int todprio; /* Timer thread priority */
int cpuprio; /* CPU thread priority */
int devprio; /* Device thread priority */
DEVBLK *dev; /* -> Device Block */
char *sdevnum; /* -> Device number string */
char *sdevtype; /* -> Device type string */
int devtmax; /* Max number device threads */
#if defined(_FEATURE_ECPSVM)
int ecpsvmavail; /* ECPS:VM Available flag */
int ecpsvmlevel; /* ECPS:VM declared level */
#endif /*defined(_FEATURE_ECPSVM)*/
BYTE c; /* Work area for sscanf */
char *styp; /* -> Engine type string */
char *styp_values[] = {"CP","CF","AP","IL","??","IP"}; /* type values */
BYTE ptyp; /* Processor engine type */
#ifdef OPTION_SELECT_KLUDGE
int dummyfd[OPTION_SELECT_KLUDGE]; /* Dummy file descriptors --
this allows the console to
get a low fd when the msg
pipe is opened... prevents
cygwin from thrashing in
select(). sigh */
#endif
char hlogofile[FILENAME_MAX+1] = ""; /* File name from HERCLOGO */
char pathname[MAX_PATH]; /* file path in host format */
/* Initialize SETMODE and set user authority */
SETMODE(INIT);
#ifdef OPTION_SELECT_KLUDGE
/* Reserve some fd's to be used later for the message pipes */
for (i = 0; i < OPTION_SELECT_KLUDGE; i++)
dummyfd[i] = dup(fileno(stderr));
#endif
/* Open the base configuration file */
hostpath(pathname, fname, sizeof(pathname));
inc_level = 0;
inc_fp[inc_level] = fopen (pathname, "r");
if (inc_fp[inc_level] == NULL)
{
logmsg(_("HHCCF003S Open error file %s: %s\n"),
fname, strerror(errno));
delayed_exit(1);
}
inc_stmtnum[inc_level] = 0;
/* Set the default system parameter values */
serial = 0x000001;
model = 0x0586;
mainsize = 2;
xpndsize = 0;
maxcpu = 0;
numcpu = 0;
numvec = MAX_CPU_ENGINES;
sysepoch = 1900;
yroffset = 0;
tzoffset = 0;
#if defined(_390)
sysblk.arch_mode = ARCH_390;
#else
sysblk.arch_mode = ARCH_370;
#endif
#if defined(_900)
sysblk.arch_z900 = ARCH_900;
#endif
sysblk.pgminttr = OS_NONE;
sysblk.timerint = DEFAULT_TIMER_REFRESH_USECS;
#if defined( HTTP_SERVER_CONNECT_KLUDGE )
sysblk.http_server_kludge_msecs = 10;
#endif // defined( HTTP_SERVER_CONNECT_KLUDGE )
hercprio = DEFAULT_HERCPRIO;
todprio = DEFAULT_TOD_PRIO;
cpuprio = DEFAULT_CPU_PRIO;
devprio = DEFAULT_DEV_PRIO;
devtmax = MAX_DEVICE_THREADS;
sysblk.kaidle = KEEPALIVE_IDLE_TIME;
sysblk.kaintv = KEEPALIVE_PROBE_INTERVAL;
sysblk.kacnt = KEEPALIVE_PROBE_COUNT;
#if defined(_FEATURE_ECPSVM)
ecpsvmavail = 0;
ecpsvmlevel = 20;
#endif /*defined(_FEATURE_ECPSVM)*/
#if defined(OPTION_SHARED_DEVICES)
shrdport = 0;
#endif /*defined(OPTION_SHARED_DEVICES)*/
#if defined(_FEATURE_ASN_AND_LX_REUSE)
sysblk.asnandlxreuse = 0; /* ASN And LX Reuse is defaulted to DISABLE */
#endif
#ifdef PANEL_REFRESH_RATE
sysblk.panrate = PANEL_REFRESH_RATE_SLOW;
#endif
/* Initialize locks, conditions, and attributes */
initialize_lock (&sysblk.todlock);
initialize_lock (&sysblk.mainlock);
sysblk.mainowner = LOCK_OWNER_NONE;
initialize_lock (&sysblk.intlock);
initialize_lock (&sysblk.iointqlk);
sysblk.intowner = LOCK_OWNER_NONE;
initialize_lock (&sysblk.sigplock);
// initialize_detach_attr (&sysblk.detattr); // (moved to impl.c)
// initialize_join_attr (&sysblk.joinattr); // (moved to impl.c)
initialize_condition (&sysblk.cpucond);
for (i = 0; i < MAX_CPU_ENGINES; i++)
initialize_lock (&sysblk.cpulock[i]);
initialize_condition (&sysblk.sync_cond);
initialize_condition (&sysblk.sync_bc_cond);
#if defined(OPTION_INSTRUCTION_COUNTING)
initialize_lock (&sysblk.icount_lock);
#endif
#ifdef OPTION_PTTRACE
ptt_trace_init (0, 1);
#endif
#if defined(_FEATURE_MESSAGE_SECURITY_ASSIST)
/* Initialize the wrapping key registers lock */
initialize_lock(&sysblk.wklock);
#endif /*defined(_FEATURE_MESSAGE_SECURITY_ASSIST)*/
#if defined(OPTION_FISHIO)
InitIOScheduler // initialize i/o scheduler...
(
sysblk.arch_mode, // (for calling execute_ccw_chain)
&sysblk.devprio, // (ptr to device thread priority)
MAX_DEVICE_THREAD_IDLE_SECS, // (maximum device thread wait time)
devtmax // (maximum #of device threads allowed)
);
#else // !defined(OPTION_FISHIO)
initialize_lock (&sysblk.ioqlock);
initialize_condition (&sysblk.ioqcond);
/* Set max number device threads */
sysblk.devtmax = devtmax;
sysblk.devtwait = sysblk.devtnbr =
sysblk.devthwm = sysblk.devtunavail = 0;
#endif // defined(OPTION_FISHIO)
/* Default the licence setting */
losc_set(PGM_PRD_OS_RESTRICTED);
/* Default CPU type CP */
for (i = 0; i < MAX_CPU_ENGINES; i++)
sysblk.ptyp[i] = SCCB_PTYP_CP;
/* Cap the default priorities at zero if setuid not available */
#if !defined(NO_SETUID)
if (sysblk.suid != 0)
{
#endif /*!defined(NO_SETUID)*/
if (hercprio < 0)
hercprio = 0;
if (todprio < 0)
todprio = 0;
if (cpuprio < 0)
cpuprio = 0;
if (devprio < 0)
devprio = 0;
#if !defined(NO_SETUID)
}
#endif /*!defined(NO_SETUID)*/
/*****************************************************************/
/* Parse configuration file system parameter statements... */
/*****************************************************************/
for (scount = 0; ; scount++)
{
/* Read next record from the configuration file */
while (inc_level >= 0 && read_config (fname, inc_fp[inc_level]))
{
fclose (inc_fp[inc_level--]);
}
if (inc_level < 0)
{
logmsg(_("HHCCF004S No device records in file %s\n"),
fname);
delayed_exit(1);
}
#if defined( OPTION_ENHANCED_CONFIG_INCLUDE )
if (strcasecmp (keyword, "ignore") == 0)
{
if (strcasecmp (operand, "include_errors") == 0)
{
logmsg( _("HHCCF081I %s Will ignore include errors .\n"),
fname);
inc_ignore_errors = 1 ;
}
continue ;
}
/* Check for include statement */
if (strcasecmp (keyword, "include") == 0)
{
if (++inc_level >= MAX_INC_LEVEL)
{
logmsg(_( "HHCCF082S Error in %s line %d: "
"Maximum nesting level (%d) reached\n"),
fname, inc_stmtnum[inc_level-1], MAX_INC_LEVEL);
delayed_exit(1);
}
logmsg( _("HHCCF083I %s Including %s at %d.\n"),
fname, operand, inc_stmtnum[inc_level-1]);
hostpath(pathname, operand, sizeof(pathname));
inc_fp[inc_level] = fopen (pathname, "r");
if (inc_fp[inc_level] == NULL)
{
inc_level--;
if ( inc_ignore_errors == 1 )
{
logmsg(_("HHCCF084W %s Open error ignored file %s: %s\n"),
fname, operand, strerror(errno));
continue ;
}
else
{
logmsg(_("HHCCF085S %s Open error file %s: %s\n"),
fname, operand, strerror(errno));
delayed_exit(1);
}
}
inc_stmtnum[inc_level] = 0;
continue;
}
#endif // defined( OPTION_ENHANCED_CONFIG_INCLUDE )
/* Exit loop if first device statement found */
if (strlen(keyword) <= 4
&& sscanf(keyword, "%x%c", &rc, &c) == 1)
break;
/* ISW */
/* Also exit if keyword contains '-', ',' or '.' */
/* Added because device statements may now be a compound device number specification */
if(strchr(keyword,'-'))
{
break;
}
if(strchr(keyword,'.'))
{
break;
}
if(strchr(keyword,','))
{
break;
}
/* Also exit if keyword contains ':' (added by Harold Grovesteen jan2008) */
/* Added because device statements may now contain channel set or LCSS id */
if(strchr(keyword,':'))
{
break;
}
/* Clear the operand value pointers */
sserial = NULL;
smodel = NULL;
sversion = NULL;
smainsize = NULL;
sxpndsize = NULL;
smaxcpu = NULL;
snumcpu = NULL;
snumvec = NULL;
sengines = NULL;
ssysepoch = NULL;
syroffset = NULL;
stzoffset = NULL;
shercprio = NULL;
stodprio = NULL;
scpuprio = NULL;
sdevprio = NULL;
slogofile = NULL;
#if defined(_FEATURE_ECPSVM)
secpsvmlevel = NULL;
secpsvmlvl = NULL;
ecpsvmac = 0;
#endif /*defined(_FEATURE_ECPSVM)*/
#if defined(OPTION_SHARED_DEVICES)
sshrdport = NULL;
#endif /*defined(OPTION_SHARED_DEVICES)*/