-
Notifications
You must be signed in to change notification settings - Fork 0
/
archlvl.c
380 lines (318 loc) · 13.1 KB
/
archlvl.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
/* ARCHLVL.C (C) Copyright Jan Jaeger, 2010-2012 */
/* (C) Copyright "Fish" (David B. Trout), 2018 */
/* Architecture Level functions */
/* */
/* Released under "The Q Public License Version 1" */
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */
#include "hstdinc.h"
#define _ARCHLVL_C_
#define _HENGINE_DLL_
#include "hercules.h"
#include "opcode.h" // Need DEF_INST
/*-------------------------------------------------------------------*/
/* (delineates ARCH_DEP from non-arch_dep) */
/*-------------------------------------------------------------------*/
#if !defined( _GEN_ARCH )
// _ARCH_NUM_0 has been built.
// Now build the other architectures...
#if defined( _ARCH_NUM_1 )
#define _GEN_ARCH _ARCH_NUM_1
#include "archlvl.c"
#endif
#if defined( _ARCH_NUM_2 )
#undef _GEN_ARCH
#define _GEN_ARCH _ARCH_NUM_2
#include "archlvl.c"
#endif
/*-------------------------------------------------------------------*/
/* (delineates ARCH_DEP from non-arch_dep) */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* ACTUAL Architecture bit-masks */
/*-------------------------------------------------------------------*/
#undef NONE
#undef S370
#undef E390
#undef Z900
#undef Z390
#undef MALL
#define NONE 0x00 /* NO architectures or disabled */
#define S370 0x80 /* S/370 architecture */
#define E390 0x40 /* ESA/390 architecture */
#define Z900 0x20 /* z/Arch architecture */
#define Z390 (E390|Z900) /* BOTH ESA/390 and z/Arch */
#define MALL (S370|Z390) /* All architectures */
/*-------------------------------------------------------------------*/
/* Architecture Level Table */
/*-------------------------------------------------------------------*/
static ARCHTAB archtab[] =
{
//---------------------------------------------------------
//
// The "_ARCH_nnn_NAME" entries MUST come first. The
// 'get_archtab_by_arch' function expects it.
//
// The FIRST entry is our DEFAULT initial startup archi-
// tecture set by the 'init_default_archmode' function.
//
//---------------------------------------------------------
#if defined( _900 )
AT( _ARCH_900_NAME, ARCH_900_IDX, Z900 ) // "z/Arch" feat900.h
#endif
#if defined( _390 )
AT( _ARCH_390_NAME, ARCH_390_IDX, E390 ) // "ESA/390" feat390.h
#endif
#if defined( _370 )
AT( _ARCH_370_NAME, ARCH_370_IDX, S370 ) // "S/370" feat370.h
#endif
// Other supported names come afterwards, in any order.
#if defined( _370 )
AT( "S370", ARCH_370_IDX, S370 )
AT( "370", ARCH_370_IDX, S370 )
#endif
#if defined( _390 )
AT( "ESA390", ARCH_390_IDX, E390 )
AT( "E390", ARCH_390_IDX, E390 )
AT( "E/390", ARCH_390_IDX, E390 )
AT( "ESA", ARCH_390_IDX, E390 )
AT( "S/390", ARCH_390_IDX, E390 )
AT( "OS/390", ARCH_390_IDX, E390 )
AT( "S390", ARCH_390_IDX, E390 )
AT( "OS390", ARCH_390_IDX, E390 )
AT( "390", ARCH_390_IDX, E390 )
#endif
#if defined( _900 )
AT( "zArch", ARCH_900_IDX, Z900 )
AT( "z", ARCH_900_IDX, Z900 )
AT( "900", ARCH_900_IDX, Z900 )
AT( "Z900", ARCH_900_IDX, Z900 )
AT( "z/900", ARCH_900_IDX, Z900 )
AT( "ESAME", ARCH_900_IDX, Z900 )
AT( "ESA/ME", ARCH_900_IDX, Z900 )
#endif
};
/*-------------------------------------------------------------------*/
/* init_default_archmode (public) */
/*-------------------------------------------------------------------*/
void init_default_archmode()
{
// Called ONCE by bldcfg.c 'build_config' during system startup.
sysblk.arch_mode = archtab[0].num; // (always the first entry)
}
/*-------------------------------------------------------------------*/
/* get_archtab_by_arch */
/*-------------------------------------------------------------------*/
const ARCHTAB* get_archtab_by_arch( int archnum )
{
// An "Architecture mode" (archmode, arch_mode) is the same
// thing as an "Architecture number" (archnum, arch_num),
// which is simply an index value determined at build time
// depending on which architectures that Hercules was built
// with support for (ARCH_nnn_IDX #defined by featchk.h) and
// is used to index into architecture dependent tables such as
// the sysblk.facility_list and the opcode tables in opcode.c
size_t i;
for (i=0; i < _countof( archtab ); i++)
if (archtab[i].num == archnum)
return &archtab[i];
return NULL;
}
/*-------------------------------------------------------------------*/
/* get_archtab_by_name */
/*-------------------------------------------------------------------*/
const ARCHTAB* get_archtab_by_name( const char* name )
{
size_t i;
for (i=0; i < _countof( archtab ); i++)
if (strcasecmp( archtab[i].name, name ) == 0)
return &archtab[i];
return NULL;
}
/*-------------------------------------------------------------------*/
/* get_arch_name_by_arch */
/*-------------------------------------------------------------------*/
const char* get_arch_name_by_arch( int archnum )
{
const ARCHTAB* at = get_archtab_by_arch( archnum );
return at ? at->name : NULL;
}
/*-------------------------------------------------------------------*/
/* get_arch_name (public) */
/*-------------------------------------------------------------------*/
const char* get_arch_name( REGS* regs )
{
int archnum = regs ? regs->arch_mode : sysblk.arch_mode;
return get_arch_name_by_arch( archnum );
}
/*-------------------------------------------------------------------*/
/* get_archmode_by_name */
/*-------------------------------------------------------------------*/
static int get_archmode_by_name( const char* archname )
{
const ARCHTAB* at = get_archtab_by_name( archname );
return at ? at->num : -1;
}
/*-------------------------------------------------------------------*/
/* archlvl_cmd (public) */
/*-------------------------------------------------------------------*/
/* */
/* ARCHLVL S/370 | ESA/390 | z/ARCH */
/* */
/*-------------------------------------------------------------------*/
int archlvl_cmd( int argc, char* argv[], char* cmdline )
{
U64 old_mainsize = sysblk.mainsize;
U64 new_mainsize = sysblk.mainsize;
int old_arch_mode = sysblk.arch_mode;
int new_arch_mode = sysblk.arch_mode;
bool any_started; // (true if any cpus are still started)
UNREFERENCED( cmdline );
UPPER_ARGV_0( argv );
/*-----------------------------------------------------*/
/* Display Architecture Mode? */
/*-----------------------------------------------------*/
if (argc < 2)
{
// "%-14s: %s"
WRMSG( HHC02203, "I", "ARCHLVL", get_arch_name( NULL ));
return 0;
}
#if 0 // Enable the below on/after 2019-12-31
/* Too many arguments? */
if (argc > 2)
{
// "Invalid command usage. Type 'help %s' for assistance."
WRMSG( HHC02299, "E", argv[0] );
return -1;
}
/*-----------------------------------------------------*/
/* Make sure all CPUs are deconfigured or stopped */
/*-----------------------------------------------------*/
any_started = are_any_cpus_started();
#else // Below is DEPRECATED; replace with above on/after 2019-12-31
/* Too many arguments? */
if (argc > 4)
{
// "Invalid command usage. Type 'help %s' for assistance."
WRMSG( HHC02299, "E", argv[0] );
return -1;
}
/*-----------------------------------------------------*/
/* Query Facility? */
/*-----------------------------------------------------*/
if (CMD( argv[1], QUERY, 1 ))
{
int rc = facility_query( argc, argv ) ? 0 : -1;
// "Note: Enabling/Disabling/Querying facilities via 'ARCHLVL' is deprecated."
// " Please use the new FACILITY command instead."
WRMSG( HHC00887, "W" );
WRMSG( HHC00888, "W" );
return rc;
}
/*-----------------------------------------------------*/
/* Make sure all CPUs are deconfigured or stopped */
/*-----------------------------------------------------*/
any_started = are_any_cpus_started();
/*-----------------------------------------------------*/
/* Enable/Disable Facility? */
/*-----------------------------------------------------*/
if (0
|| CMD( argv[1], ENABLE, 3 )
|| CMD( argv[1], DISABLE, 3 )
)
{
int rc;
if (sysblk.ipled)
{
// "Available facilities cannot be changed once system is IPLed"
WRMSG( HHC00889, "E" );
return -1;
}
if (any_started)
{
// "All CPU's must be stopped %s"
WRMSG( HHC02253, "E", "to modify a facility" );
return HERRCPUONL;
}
rc = facility_enable_disable( argc, argv );
// "Note: Enabling/Disabling/Querying facilities via 'ARCHLVL' is deprecated."
// " Please use the new FACILITY command instead."
WRMSG( HHC00887, "W" );
WRMSG( HHC00888, "W" );
return rc;
}
#endif // Delete the above on/after 2019-12-31
/*-----------------------------------------------------*/
/* Set Architecture */
/*-----------------------------------------------------*/
if (any_started)
{
// "All CPU's must be stopped %s"
WRMSG( HHC02253, "E", "to switch architectures" );
return HERRCPUONL;
}
/* Determine new architecture mode */
if ((new_arch_mode = get_archmode_by_name( argv[1] )) < 0)
{
// "ARCHLVL '%s' is invalid"
WRMSG( HHC00895, "E", argv[1] );
return -1;
}
/* Nothing for us to do unless the architecture changed */
if (new_arch_mode != old_arch_mode )
{
/* Re-configure storage if MAINSIZE needs to be adjusted */
if ((new_mainsize = adjust_mainsize( new_arch_mode, sysblk.mainsize )) != old_mainsize)
configure_storage( new_mainsize >> SHIFT_4K );
/* Switch to the new architecture mode as requested */
OBTAIN_INTLOCK( NULL );
{
/* Perform system reset to switch architecture mode */
static const bool clear = false, ipl = false;
system_reset( new_arch_mode, clear, ipl, sysblk.pcpu );
/* (ensure dummyregs matches new architecture) */
sysblk.dummyregs.arch_mode = sysblk.arch_mode;
}
RELEASE_INTLOCK( NULL );
}
/* ALWAYS do an "initial_cpu_reset()" for all processors */
initial_cpu_reset_all();
/* Display results */
if (argc > 1 && MLVL( VERBOSE ))
{
// "%-14s set to %s"
WRMSG( HHC02204, "I", "ARCHLVL", get_arch_name_by_arch( sysblk.arch_mode ));
if (new_mainsize != old_mainsize)
{
char memsize[64];
bool increased = (new_mainsize > old_mainsize);
fmt_memsize_KB( sysblk.mainsize >> SHIFT_KIBIBYTE, memsize, sizeof( memsize ));
// "MAINSIZE %screased to %s architectural %simim"
WRMSG( HHC17006, "W", increased ? "in" : "de", memsize,
increased ? "min" : "max" );
}
}
/* If S/370 archmode was just set, force LPARNUM to BASIC.
Else if LPARNUM is BASIC, change it back to LPARNUM 1
if archmode is z/Arch. Else (ARCH_390_IDX) leave it alone.
The user can override this automatic LPARNUM switching
via their own subsequent LPARNUM stmt/cmd if such auto-
matic behavior is not desired.
*/
if (1
&& ARCH_370_IDX == sysblk.arch_mode
&& om_basic != sysblk.operation_mode
)
panel_command( "-LPARNUM BASIC" );
else if (1
&& ARCH_900_IDX == sysblk.arch_mode
&& om_basic == sysblk.operation_mode
)
{
panel_command( "-LPARNUM 1" );
panel_command( "-CPUIDFMT 0" );
}
return 0;
}
#endif /* !defined( _GEN_ARCH ) */