/
sie.c
2160 lines (1796 loc) · 78.7 KB
/
sie.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
/* SIE.C (C) Copyright Jan Jaeger, 1999-2012 */
/* (C) and others 2013-2021 */
/* Interpretive Execution */
/* */
/* Released under "The Q Public License Version 1" */
/* (http://www.hercules-390.org/herclic.html) as modifications to */
/* Hercules. */
/* */
/* This module contains the SIE instruction as described in */
/* SA22-7095-01 IBM S/370 Extended Architecture Interpretive */
/* Execution, and SC24-5594-02 and SC24-5965-00 Enterprise */
/* Systems Architecture / Extended Configuration Principles */
/* of Operation. */
#include "hstdinc.h"
// #define SIE_DEBUG
#define _SIE_C_
#define _HENGINE_DLL_
#include "hercules.h"
#include "opcode.h"
#include "inline.h"
#include "sie.h"
DISABLE_GCC_UNUSED_SET_WARNING;
#if defined( _FEATURE_SIE )
#if !defined( COMPILE_THIS_ONLY_ONCE )
#define COMPILE_THIS_ONLY_ONCE
/*-------------------------------------------------------------------*/
/* non-ARCH_DEP section: due to above COMPILE_THIS_ONLY_ONCE guard, */
/* the below header section is compiled only ONCE, *before* */
/* the very first architecture is ever built. */
/*-------------------------------------------------------------------*/
/* The ARCH_DEP section (compiled multiple times, once for each */
/* architecture) follows AFTER the COMPILE_THIS_ONLY_ONCE section. */
/*-------------------------------------------------------------------*/
#if defined( SIE_DEBUG )
static const char* sie_icode_2str( int icode );
#endif
/*-------------------------------------------------------------------*/
/* static function forward references */
/*-------------------------------------------------------------------*/
static int s370_run_sie( REGS* regs );
static int s390_run_sie( REGS* regs );
#if defined( _900 )
static int z900_run_sie( REGS* regs );
#endif
/*-------------------------------------------------------------------*/
/* 'run_sie' function table */
/*-------------------------------------------------------------------*/
static int (*run_sie[ NUM_GEN_ARCHS ])( REGS* regs) =
{
#if defined( _ARCH_NUM_0 )
#if 370 == _ARCH_NUM_0
s370_run_sie,
#elif 390 == _ARCH_NUM_0
s390_run_sie,
#else // 900 == _ARCH_NUM_0
z900_run_sie,
#endif
#endif
#if defined( _ARCH_NUM_1 )
#if 370 == _ARCH_NUM_1
s370_run_sie,
#elif 390 == _ARCH_NUM_1
s390_run_sie,
#else // 900 == _ARCH_NUM_1
z900_run_sie,
#endif
#endif
#if defined( _ARCH_NUM_2 )
#if 370 == _ARCH_NUM_2
s370_run_sie,
#elif 390 == _ARCH_NUM_2
s390_run_sie,
#else // 900 == _ARCH_NUM_2
z900_run_sie,
#endif
#endif
};
/*-------------------------------------------------------------------*/
/* SIE helper macros */
/*-------------------------------------------------------------------*/
#define STATEBK ((SIEBK *)GUESTREGS->siebk)
#define SIE_I_STOP( _guestregs ) \
((_guestregs)->siebk->v & SIE_V_STOP)
#define SIE_I_EXT( _guestregs ) \
(((_guestregs)->siebk->v & SIE_V_EXT) \
&& ((_guestregs)->psw.sysmask & PSW_EXTMASK))
#define SIE_I_HOST( _hostregs ) \
IC_INTERRUPT_CPU( _hostregs )
/*-------------------------------------------------------------------*/
/* SIE debugging */
/*-------------------------------------------------------------------*/
#if defined( SIE_DEBUG_PERFMON )
static int sie_perfmon[ 1 + 0x40 + -SIE_MAX_NEG_DEBUG ];
#define SIE_PERFMON( _code ) \
do { \
sie_perfmon[ (_code) + -SIE_MAX_NEG_DEBUG ]++; \
} while(0)
#define SIE_PERF_PGMINT \
(code <= 0 ? code : (((code-1) & 0x3F)+1))
void* sie_perfmon_disp()
{
static const char* dbg_name[] =
{
/* -31 */ "SIE re-dispatch state descriptor",
/* -30 */ "SIE exit",
/* -29 */ "SIE run",
/* -28 */ "SIE runloop 1",
/* -27 */ "SIE runloop 2",
/* -26 */ "SIE interrupt check",
/* -25 */ "SIE execute instruction",
/* -24 */ "SIE unrolled execute",
/* -23 */ NULL,
/* -22 */ NULL,
/* -21 */ NULL,
/* -20 */ NULL,
/* -19 */ NULL,
/* -18 */ NULL,
/* -17 */ "SIE intercept I/O instruction",
/* -16 */ "SIE intercept I/O interrupt pending",
/* -15 */ "SIE intercept I/O interrupt",
/* -14 */ "SIE intercept PER interrupt",
/* -13 */ "SIE validity check",
/* -12 */ "SIE intercept external interrupt pending",
/* -11 */ "SIE intercept machine check interrupt",
/* -10 */ "SIE intercept restart interrupt",
/* -9 */ "SIE intercept stop request",
/* -8 */ "SIE intercept virtual machine wait",
/* -7 */ "SIE intercept I/O interrupt request",
/* -6 */ "SIE intercept external interrupt request",
/* -5 */ "SIE intercept instruction completion",
/* -4 */ "SIE intercept instruction",
/* -3 */ "SIE host program interrupt",
/* -2 */ "SIE host interrupt",
/* -1 */ "SIE no intercept",
/* 0 */ "SIE entry",
/* 01 */ "SIE intercept Operation exception",
/* 02 */ "SIE intercept Privileged-operation exception",
/* 03 */ "SIE intercept Execute exception",
/* 04 */ "SIE intercept Protection exception",
/* 05 */ "SIE intercept Addressing exception",
/* 06 */ "SIE intercept Specification exception",
/* 07 */ "SIE intercept Data exception",
/* 08 */ "SIE intercept Fixed-point-overflow exception",
/* 09 */ "SIE intercept Fixed-point-divide exception",
/* 0A */ "SIE intercept Decimal-overflow exception",
/* 0B */ "SIE intercept Decimal-divide exception",
/* 0C */ "SIE intercept HFP-exponent-overflow exception",
/* 0D */ "SIE intercept HFP-exponent-underflow exception",
/* 0E */ "SIE intercept HFP-significance exception",
/* 0F */ "SIE intercept HFP-floating-point-divide exception",
/* 10 */ "SIE intercept Segment-translation exception",
/* 11 */ "SIE intercept Page-translation exception",
/* 12 */ "SIE intercept Translation-specification exception",
/* 13 */ "SIE intercept Special-operation exception",
/* 14 */ "SIE intercept Pseudo-page-fault exception",
/* 15 */ "SIE intercept Operand exception",
/* 16 */ "SIE intercept Trace-table exception",
/* 17 */ "SIE intercept ASN-translation exception",
/* 18 */ "SIE intercept Page access exception",
/* 19 */ "SIE intercept Vector/Crypto operation exception",
/* 1A */ "SIE intercept Page state exception",
/* 1B */ "SIE intercept Page transition exception",
/* 1C */ "SIE intercept Space-switch event",
/* 1D */ "SIE intercept Square-root exception",
/* 1E */ "SIE intercept Unnormalized-operand exception",
/* 1F */ "SIE intercept PC-translation specification exception",
/* 20 */ "SIE intercept AFX-translation exception",
/* 21 */ "SIE intercept ASX-translation exception",
/* 22 */ "SIE intercept LX-translation exception",
/* 23 */ "SIE intercept EX-translation exception",
/* 24 */ "SIE intercept Primary-authority exception",
/* 25 */ "SIE intercept LFX-translation exception",
/* 26 */ "SIE intercept LSX-translation exception",
/* 27 */ "SIE intercept Control-switch exception",
/* 28 */ "SIE intercept ALET-specification exception",
/* 29 */ "SIE intercept ALEN-translation exception",
/* 2A */ "SIE intercept ALE-sequence exception",
/* 2B */ "SIE intercept ASTE-validity exception",
/* 2C */ "SIE intercept ASTE-sequence exception",
/* 2D */ "SIE intercept Extended-authority exception",
/* 2E */ "SIE intercept LSTE-sequence exception",
/* 2F */ "SIE intercept ASTE-instance exception",
/* 30 */ "SIE intercept Stack-full exception",
/* 31 */ "SIE intercept Stack-empty exception",
/* 32 */ "SIE intercept Stack-specification exception",
/* 33 */ "SIE intercept Stack-type exception",
/* 34 */ "SIE intercept Stack-operation exception",
/* 35 */ NULL,
/* 36 */ NULL,
/* 37 */ NULL,
/* 38 */ "SIE intercept ASCE-type exception",
/* 39 */ "SIE intercept Region-first-translation exception",
/* 3A */ "SIE intercept Region-second-translation exception",
/* 3B */ "SIE intercept Region-third-translation exception",
/* 3C */ NULL,
/* 3D */ NULL,
/* 3E */ NULL,
/* 3F */ NULL,
/* 40 */ "SIE intercept Monitor event"
};
if (sie_perfmon[ SIE_PERF_ENTER + -SIE_MAX_NEG_DEBUG ])
{
int i;
for (i=0; i < 0x61; i++)
if (sie_perfmon[i])
// "Counted %5u %s events"
WRMSG( HHC02285, "I", sie_perfmon[i], dbg_name[i] );
// "Average instructions / SIE invocation: %5u"
WRMSG( HHC02286, "I",
(sie_perfmon[ SIE_PERF_EXEC + -SIE_MAX_NEG_DEBUG ] +
sie_perfmon[ SIE_PERF_EXEC_U + -SIE_MAX_NEG_DEBUG ] * 7)
/ sie_perfmon[ SIE_PERF_ENTER + -SIE_MAX_NEG_DEBUG ] );
}
else
// "No SIE performance data"
WRMSG( HHC02287, "I" );
}
#else
#define SIE_PERFMON(_code)
#endif
#endif /* !defined( COMPILE_THIS_ONLY_ONCE ) */
/*-------------------------------------------------------------------*/
/* ARCH_DEP section: compiled multiple times, once for each arch. */
/*-------------------------------------------------------------------*/
//-------------------------------------------------------------------
// ARCH_DEP() code
//-------------------------------------------------------------------
// ARCH_DEP (build-architecture / FEATURE-dependent) functions here.
// All BUILD architecture dependent (ARCH_DEP) function are compiled
// multiple times (once for each defined build architecture) and each
// time they are compiled with a different set of FEATURE_XXX defines
// appropriate for that architecture. Use #ifdef FEATURE_XXX guards
// to check whether the current BUILD architecture has that given
// feature #defined for it or not. WARNING: Do NOT use _FEATURE_XXX.
// The underscore feature #defines mean something else entirely. Only
// test for FEATURE_XXX. (WITHOUT the underscore)
//-------------------------------------------------------------------
// (some needed helper macros...)
#undef SIE_I_WAIT
#if defined(_FEATURE_WAITSTATE_ASSIST)
#define SIE_I_WAIT(_guestregs) \
(WAITSTATE(&(_guestregs)->psw) && !((_guestregs)->siebk->ec[0] & SIE_EC0_WAIA))
#else
#define SIE_I_WAIT(_guestregs) \
(WAITSTATE(&(_guestregs)->psw))
#endif
#undef SIE_I_IO
#if defined( FEATURE_BCMODE )
#define SIE_I_IO(_guestregs) \
(((_guestregs)->siebk->v & SIE_V_IO) \
&& ((_guestregs)->psw.sysmask \
& (ECMODE(&(_guestregs)->psw) ? PSW_IOMASK : 0xFE) ))
#else
#define SIE_I_IO(_guestregs) \
(((_guestregs)->siebk->v & SIE_V_IO) \
&& ((_guestregs)->psw.sysmask & PSW_IOMASK ))
#endif
#endif /* defined( _FEATURE_SIE ) */
#if defined( FEATURE_SIE )
/*-------------------------------------------------------------------*/
/* B214 SIE - Start Interpretive Execution [S] */
/*-------------------------------------------------------------------*/
DEF_INST( start_interpretive_execution )
{
int b2; /* Values of R fields */
RADR effective_addr2; /* address of state desc. */
int n; /* Loop counter */
U16 lhcpu; /* Last Host CPU address */
U64 sie_state; /* Last SIE state */
int lpsw_xcode; /* xcode from load_psw */
volatile int icode = 0; /* interrupt code */
/* (why is this volatile?!) */
bool same_cpu, same_state; /* boolean helper flags */
U64 dreg;
#if defined( FEATURE_VIRTUAL_ARCHITECTURE_LEVEL )
U32 fld; /* Facility List Designator */
#if !defined( OPTION_SIE2BK_FLD_COPY)
int i; /* (work) */
#endif
#endif
//-----------------------------------------------------------
// IMPORTANT SIE PROGRAMMING NOTE!
//-----------------------------------------------------------
// NOTE: Our execution architectural mode is that of the SIE
// HOST and our 'regs' variable is pointing the the HOST's
// registers. Since the GUEST could be running in a completely
// different architecture from the HOST, if you need to call
// a ARCH_DEP function for the GUEST (passing it GUESTREGS),
// you must TAKE SPECIAL CARE to ensure the correct version
// of that function is called! You cannot simply call the
// "ARCH_DEP" version of that function as they are for the
// architectue of the HOST, not the GUEST! (i.e. you cannot
// call a "z900_xxx" function expecting it to work correctly
// if the GUEST is supposed to call "s390_xxx" functions!)
//-----------------------------------------------------------
S( inst, regs, b2, effective_addr2 );
PER_ZEROADDR_XCHECK( regs, b2 );
TXF_INSTR_CHECK( regs );
PRIV_CHECK( regs );
SIE_INTERCEPT( regs );
PTT_SIE( "SIE", regs->GR(14), regs->GR(15), effective_addr2);
SIE_PERFMON( SIE_PERF_ENTER );
#if !defined( FEATURE_001_ZARCH_INSTALLED_FACILITY ) && !defined( FEATURE_MULTIPLE_CONTROLLED_DATA_SPACE )
if (!regs->psw.amode || !PRIMARY_SPACE_MODE( ®s->psw ))
ARCH_DEP( program_interrupt )( regs, PGM_SPECIAL_OPERATION_EXCEPTION );
#endif
if (0
|| (effective_addr2 & (sizeof(SIEBK)-1)) != 0
#if defined( FEATURE_001_ZARCH_INSTALLED_FACILITY )
|| (effective_addr2 & PREFIXING_900_MASK) == 0
|| (effective_addr2 & PREFIXING_900_MASK) == regs->PX_900
#elif defined( FEATURE_S390_DAT )
|| (effective_addr2 & PREFIXING_390_MASK) == 0
|| (effective_addr2 & PREFIXING_390_MASK) == regs->PX_390
#else
|| (effective_addr2 & PREFIXING_370_MASK) == 0
|| (effective_addr2 & PREFIXING_370_MASK) == regs->PX_370
#endif
)
ARCH_DEP( program_interrupt )( regs, PGM_SPECIFICATION_EXCEPTION );
/* Perform serialization and checkpoint synchronization */
PERFORM_SERIALIZATION( regs );
PERFORM_CHKPT_SYNC( regs );
#if defined( SIE_DEBUG )
LOGMSG( "SIE: state descriptor " F_RADR "\n", effective_addr2 );
ARCH_DEP( display_inst )( regs, regs->instinvalid ? NULL : regs->ip );
#endif
if (effective_addr2 > regs->mainlim - (sizeof( SIEBK ) - 1))
ARCH_DEP( program_interrupt )( regs, PGM_ADDRESSING_EXCEPTION );
/*
* As long as regs->sie_active is off, no serialization is
* required for GUESTREGS. sie_active should always be off here.
* Any other thread looking at sie_active holds the intlock.
*/
PTT_SIE( "SIE h,g,a", regs->host, regs->guest, regs->sie_active );
if (regs->sie_active)
{
OBTAIN_INTLOCK( regs );
{
regs->sie_active = 0;
}
RELEASE_INTLOCK( regs );
}
/* Initialize guestregs if first time */
if (!GUESTREGS)
{
PTT_SIE( "SIE calloc g", 0, 0, 0 );
if (!(GUESTREGS = calloc_aligned( sizeof( REGS ), 4096 )))
{
// "Processor %s%02X: error in function %s: %s"
WRMSG( HHC00813, "E", PTYPSTR( regs->cpuad ), regs->cpuad, "calloc()", strerror( errno ));
return;
}
cpu_init( regs->cpuad, GUESTREGS, regs );
TXF_ALLOCMAP( GUESTREGS );
}
/* Direct pointer to state descriptor block */
GUESTREGS->siebk = (void*)(regs->mainstor + effective_addr2);
/* Set the guest's execution arch_mode and load its PSW */
#if defined( FEATURE_001_ZARCH_INSTALLED_FACILITY )
if (STATEBK->mx & SIE_MX_ESAME)
{
GUESTREGS->arch_mode = ARCH_900_IDX;
GUESTREGS->program_interrupt = &z900_program_interrupt;
lpsw_xcode = z900_load_psw( GUESTREGS, STATEBK->psw );
}
#else /* !defined( FEATURE_001_ZARCH_INSTALLED_FACILITY ) */
if (STATEBK->m & SIE_M_370)
{
#if defined(_370)
GUESTREGS->arch_mode = ARCH_370_IDX;
GUESTREGS->program_interrupt = &s370_program_interrupt;
lpsw_xcode = s370_load_psw(GUESTREGS, STATEBK->psw);
#else
/* Validity intercept when 370 mode not installed */
SIE_SET_VI(SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_370NI, GUESTREGS);
STATEBK->c = SIE_C_VALIDITY;
return;
#endif
}
#endif /* !defined( FEATURE_001_ZARCH_INSTALLED_FACILITY ) */
else
#if !defined( FEATURE_001_ZARCH_INSTALLED_FACILITY )
if (STATEBK->m & SIE_M_XA)
#endif
{
GUESTREGS->arch_mode = ARCH_390_IDX;
GUESTREGS->program_interrupt = &s390_program_interrupt;
lpsw_xcode = s390_load_psw(GUESTREGS, STATEBK->psw);
}
#if !defined( FEATURE_001_ZARCH_INSTALLED_FACILITY )
else
{
/* Validity intercept for invalid mode */
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_MODE, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
return;
}
#endif
/* Prefered guest indication */
GUESTREGS->sie_pref = (STATEBK->m & SIE_M_VR) ? 1 : 0;
/* Load prefix from state descriptor... (Using 'PX_L' is okay
since prefix is always a FWORD regardless of architecture) */
FETCH_FW( GUESTREGS->PX_L, STATEBK->prefix );
#if defined( FEATURE_REGION_RELOCATE )
if (STATEBK->mx & SIE_MX_RRF)
{
RADR mso, msl, eso = 0, esl = 0;
if (STATEBK->zone >= FEATURE_SIE_MAXZONES)
{
/* Validity intercept for invalid zone */
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_AZNNI, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
return;
}
mso = (sysblk.zpb[ STATEBK->zone ].mso & 0xFFFFF) << 20;
msl = (sysblk.zpb[ STATEBK->zone ].msl & 0xFFFFF) << 20;
eso = (sysblk.zpb[ STATEBK->zone ].eso & 0xFFFFF) << 20;
esl = (sysblk.zpb[ STATEBK->zone ].esl & 0xFFFFF) << 20;
if (mso > msl)
{
/* Validity intercept for invalid zone */
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_MSDEF, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
return;
}
/* Ensure addressing exceptions on incorrect zone defs */
if (0
|| mso > regs->mainlim
|| msl > regs->mainlim
)
mso = msl = 0;
#if defined( SIE_DEBUG )
LOGMSG( "SIE: zone %d: mso=" F_RADR " msl=" F_RADR "\n", STATEBK->zone, mso, msl );
#endif
GUESTREGS->sie_pref = 1;
GUESTREGS->sie_mso = 0;
GUESTREGS->mainstor = &sysblk.mainstor[mso];
GUESTREGS->mainlim = msl - mso;
GUESTREGS->storkeys = ARCH_DEP( get_ptr_to_storekey )( mso );
GUESTREGS->sie_xso = eso;
GUESTREGS->sie_xsl = esl;
GUESTREGS->sie_xso *= (XSTORE_INCREMENT_SIZE >> XSTORE_PAGESHIFT);
GUESTREGS->sie_xsl *= (XSTORE_INCREMENT_SIZE >> XSTORE_PAGESHIFT);
}
else
#endif /* defined( FEATURE_REGION_RELOCATE ) */
{
GUESTREGS->mainstor = sysblk.mainstor;
GUESTREGS->storkeys = sysblk.storkeys;
if (STATEBK->zone)
{
/* Validity intercept for invalid zone */
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_AZNNZ, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
return;
}
#if defined( FEATURE_001_ZARCH_INSTALLED_FACILITY )
/* Load main storage origin */
FETCH_DW( GUESTREGS->sie_mso, STATEBK->mso );
GUESTREGS->sie_mso &= SIE2_MS_MASK;
/* Load main storage extent */
FETCH_DW( GUESTREGS->mainlim, STATEBK->mse );
GUESTREGS->mainlim |= ~SIE2_MS_MASK;
if (GUESTREGS->sie_mso > GUESTREGS->mainlim)
{
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_MSDEF, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
return;
}
/* Calculate main storage size */
GUESTREGS->mainlim -= GUESTREGS->sie_mso;
#else /* !defined( FEATURE_001_ZARCH_INSTALLED_FACILITY ) */
/* Load main storage origin */
FETCH_HW( GUESTREGS->sie_mso, STATEBK->mso );
GUESTREGS->sie_mso <<= 16;
/* Load main storage extent */
FETCH_HW( GUESTREGS->mainlim, STATEBK->mse );
GUESTREGS->mainlim = ((GUESTREGS->mainlim + 1) << 16) - 1;
#endif /* defined( FEATURE_001_ZARCH_INSTALLED_FACILITY ) */
/* Load expanded storage origin */
GUESTREGS->sie_xso = STATEBK->xso[0] << 16
| STATEBK->xso[1] << 8
| STATEBK->xso[2];
GUESTREGS->sie_xso *= (XSTORE_INCREMENT_SIZE >> XSTORE_PAGESHIFT);
/* Load expanded storage limit */
GUESTREGS->sie_xsl = STATEBK->xsl[0] << 16
| STATEBK->xsl[1] << 8
| STATEBK->xsl[2];
GUESTREGS->sie_xsl *= (XSTORE_INCREMENT_SIZE >> XSTORE_PAGESHIFT);
}
/* Validate Guest prefix */
if (GUESTREGS->PX > GUESTREGS->mainlim)
{
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_PFOUT, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
return;
}
/* System Control Area Origin */
FETCH_FW( GUESTREGS->sie_scao, STATEBK->scao );
GUESTREGS->sie_scao &= SIEISCAM;
#if defined( FEATURE_001_ZARCH_INSTALLED_FACILITY )
{
/* For ESAME insert the high word of the address */
U32 sie_scaoh;
FETCH_FW( sie_scaoh, STATEBK->scaoh );
GUESTREGS->sie_scao |= (RADR)sie_scaoh << 32;
}
#endif
if (GUESTREGS->sie_scao > regs->mainlim)
{
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_SCADR, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
return;
}
/* Validate MSO */
if (GUESTREGS->sie_mso)
{
/* Preferred guest must have zero MSO */
if (GUESTREGS->sie_pref)
{
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_MSONZ, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
return;
}
/* MCDS guest must have zero MSO */
if (STATEBK->mx & SIE_MX_XC)
{
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_MSODS, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
return;
}
}
GUESTREGS->sie_fld = false; // (default until we learn otherwise)
#if defined( FEATURE_VIRTUAL_ARCHITECTURE_LEVEL )
/* Set Virtual Architecture Level (Facility List) */
/* SIE guest facilities by default start out same as host's */
memcpy( GUESTREGS->facility_list, HOSTREGS->facility_list, STFL_HERC_BY_SIZE );
/* Fetch address of optional SIE guest facility list designator */
FETCH_FW( fld, STATEBK->fld );
if (0
|| (U64)fld > regs->mainlim /* (beyond end of main storage?) */
|| (fld & ~0x7ffffff8) /* (above 2GB or not DW aligned?) */
)
{
/* ZZ: FIXME
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_??ADR, GUESTREGS );
*/
STATEBK->c = SIE_C_VALIDITY;
return;
}
if (fld)
{
GUESTREGS->sie_fld = true;
#if defined( OPTION_SIE2BK_FLD_COPY)
/* If a facility list designator was provided
then it defines the SIE guest facility bits.
*/
memcpy( GUESTREGS->facility_list, ®s->mainstor[ fld ], STFL_HERC_BY_SIZE );
#else /* !defined( OPTION_SIE2BK_FLD_COPY) */
/* If a facility list designator was provided
then it's used as a mask to clear the SIE
guest facility bits which shouldn't be on.
*/
for (i=0; i < (int) STFL_IBM_BY_SIZE; i++)
GUESTREGS->facility_list[i] &= regs->mainstor[ fld + i ];
#endif /* defined( OPTION_SIE2BK_FLD_COPY) */
}
/* Prevent certain facility bits from being masked */
BIT_ARRAY_SET( GUESTREGS->facility_list, STFL_001_ZARCH_INSTALLED );
if (ARCH_900_IDX == GUESTREGS->arch_mode)
BIT_ARRAY_SET( GUESTREGS->facility_list, STFL_002_ZARCH_ACTIVE );
else
BIT_ARRAY_CLR( GUESTREGS->facility_list, STFL_002_ZARCH_ACTIVE );
#endif /* defined( FEATURE_VIRTUAL_ARCHITECTURE_LEVEL ) */
/* Reference and Change Preservation (RCP) Origin if high-order
0x80 bit is off. Otherwise (high-order 0x80 bit is on, which
it usually is for VM/ESA and z/VM), then the field ACTUALLY
contains various Execution Control flags such as Storage Key
Assist (SKA), etc.
*/
FETCH_FW( GUESTREGS->sie_rcpo, STATEBK->rcpo );
#if !defined( FEATURE_001_ZARCH_INSTALLED_FACILITY )
if (!GUESTREGS->sie_rcpo && !GUESTREGS->sie_pref)
{
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_RCZER, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
return;
}
#endif
/* Load the CPU timer */
FETCH_DW( dreg, STATEBK->cputimer );
set_cpu_timer( GUESTREGS, dreg );
/* Load the TOD clock offset for this guest */
FETCH_DW( GUESTREGS->sie_epoch, STATEBK->epoch );
GUESTREGS->tod_epoch = regs->tod_epoch + TOD_high64_to_ETOD_high56( GUESTREGS->sie_epoch );
/* Load the clock comparator */
FETCH_DW( GUESTREGS->clkc, STATEBK->clockcomp );
GUESTREGS->clkc = TOD_high64_to_ETOD_high56( GUESTREGS->clkc ); /* Internal Hercules format */
/* Load TOD Programmable Field */
FETCH_HW( GUESTREGS->todpr, STATEBK->todpf );
/* Load the guest registers */
memcpy( GUESTREGS->gr, regs->gr, 14 * sizeof( regs->gr [0] ));
memcpy( GUESTREGS->ar, regs->ar, 16 * sizeof( regs->ar [0] ));
memcpy( GUESTREGS->fpr, regs->fpr, 32 * sizeof( regs->fpr[0] ));
#if defined( FEATURE_BINARY_FLOATING_POINT )
GUESTREGS->fpc = regs->fpc;
#endif
/* Load GR14 and GR15 */
FETCH_W( GUESTREGS->GR(14), STATEBK->gr14 );
FETCH_W( GUESTREGS->GR(15), STATEBK->gr15 );
/* Load control registers */
for (n=0; n < 16; n++)
FETCH_W( GUESTREGS->CR( n ), STATEBK->cr[ n ]);
/* Remember whether CPU or state is different from last time */
FETCH_HW( lhcpu, STATEBK->lhcpu );
sie_state = SIE_STATE( GUESTREGS );
same_cpu = (regs->cpuad == lhcpu);
same_state = (effective_addr2 == sie_state);
/* Regardless, set both of them to their proper current value */
SIE_STATE( GUESTREGS ) = effective_addr2;
STORE_HW( STATEBK->lhcpu, regs->cpuad );
/*----------------------------------------*/
/* Maybe purge the guest's TLB/ALB or not */
/*----------------------------------------*/
#if !defined( OPTION_SIE_PURGE_DAT_ALWAYS )
/*
* If this is not the same last host cpu that dispatched
* this state descriptor then clear the guest TLB entries.
*/
if (!same_cpu || !same_state)
{
SIE_PERFMON( SIE_PERF_ENTER_F );
/* Purge guest TLB entries */
switch (GUESTREGS->arch_mode)
{
case ARCH_370_IDX: s370_purge_tlb( GUESTREGS ); break;
case ARCH_390_IDX: s390_purge_tlb( GUESTREGS ); s390_purge_alb( GUESTREGS ); break;
case ARCH_900_IDX: z900_purge_tlb( GUESTREGS ); z900_purge_alb( GUESTREGS ); break;
default: CRASH();
}
}
#else // defined( OPTION_SIE_PURGE_DAT_ALWAYS )
/*
* ALWAYS purge guest TLB entries (Ivan 2016-07-30)
*/
switch (GUESTREGS->arch_mode)
{
case ARCH_370_IDX: s370_purge_tlb( GUESTREGS ); break;
case ARCH_390_IDX: s390_purge_tlb( GUESTREGS ); s390_purge_alb( GUESTREGS ); break;
case ARCH_900_IDX: z900_purge_tlb( GUESTREGS ); z900_purge_alb( GUESTREGS ); break;
default: CRASH();
}
#endif // defined( OPTION_SIE_PURGE_DAT_ALWAYS )
/* Initialize interrupt mask and state */
ARCH_DEP( set_guest_ic_mask )( GUESTREGS );
SET_IC_INITIAL_STATE( GUESTREGS );
SET_IC_PER( GUESTREGS );
/* Initialize accelerated address lookup values */
ARCH_DEP( set_guest_aea_mode )( GUESTREGS );
ARCH_DEP( set_guest_aea_common )( GUESTREGS );
ARCH_DEP( invalidate_guest_aia )( GUESTREGS );
GUESTREGS->breakortrace = regs->breakortrace;
/* Must do setjmp(progjmp) here since the 'translate_addr' further
below may result in longjmp(progjmp) for addressing exceptions.
*/
if (!(icode = setjmp( GUESTREGS->progjmp )))
{
/*
* Set sie_active to 1. This means other threads
* may now access guestregs when holding intlock.
* This is the *ONLY* place sie_active is set to 1!
*/
PTT_SIE( "SIE a=1", 0, 0, 0 );
OBTAIN_INTLOCK( regs );
{
regs->sie_active = 1;
}
RELEASE_INTLOCK( regs );
/* Get PSA pointer and ensure PSA is paged in */
if (GUESTREGS->sie_pref)
{
GUESTREGS->psa = (PSA_3XX*)(GUESTREGS->mainstor + GUESTREGS->PX);
GUESTREGS->sie_px = GUESTREGS->PX;
}
else
{
/* NOTE: longjmp(progjmp) for addressing exception is possible
here. Thus the need for doing setjmp(progjmp) further above.
*/
/* Translate where this SIE guest's absolute storage begins
(which is a host virtual address) to a host real address.
*/
if (ARCH_DEP( translate_addr )( GUESTREGS->sie_mso + GUESTREGS->PX,
USE_PRIMARY_SPACE, regs, ACCTYPE_SIE ))
{
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_PFACC, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
PTT_SIE( "SIE a=0", 0, 0, 0 );
OBTAIN_INTLOCK( regs );
{
regs->sie_active = 0;
}
RELEASE_INTLOCK( regs );
return;
}
/* Convert host real address to host absolute address */
GUESTREGS->sie_px = apply_host_prefixing( regs, regs->dat.raddr );
if (regs->dat.protect || GUESTREGS->sie_px > regs->mainlim)
{
SIE_SET_VI( SIE_VI_WHO_CPU, SIE_VI_WHEN_SIENT, SIE_VI_WHY_PFACC, GUESTREGS );
STATEBK->c = SIE_C_VALIDITY;
PTT_SIE( "SIE a=0", 0, 0, 0 );
OBTAIN_INTLOCK( regs );
{
regs->sie_active = 0;
}
RELEASE_INTLOCK( regs );
return;
}
GUESTREGS->psa = (PSA_3XX*)(GUESTREGS->mainstor + GUESTREGS->sie_px);
}
OBTAIN_INTLOCK( regs );
{
/* Intialize guest timers... */
/* CPU timer */
if (CPU_TIMER( GUESTREGS ) < 0)
ON_IC_PTIMER( GUESTREGS );
/* Clock comparator */
if (TOD_CLOCK( GUESTREGS ) > GUESTREGS->clkc)
ON_IC_CLKC( GUESTREGS );
#if !defined( FEATURE_001_ZARCH_INSTALLED_FACILITY )
/* Interval timer if S/370 and timer is enabled */
if (1
&& (STATEBK->m & SIE_M_370)
&& !(STATEBK->m & SIE_M_ITMOF)
)
{
S32 itimer, olditimer;
U32 residue;
/* Set the interval timer pending according to
the T bit in the state control
*/
if (STATEBK->s & SIE_S_T)
ON_IC_ITIMER( GUESTREGS );
/* Fetch the residue from the state descriptor */
FETCH_FW( residue, STATEBK->residue );
/* Fetch the timer value from location 80 */
FETCH_FW( olditimer, GUESTREGS->psa->inttimer );
/* Bit position 23 of the interval timer is decremented
once for each multiple of 3,333 usecs containded in
bit position 0-19 of the residue counter.
*/
itimer = olditimer - ((residue / 3333) >> 4);
/* Store the timer back */
STORE_FW( GUESTREGS->psa->inttimer, itimer );
/* Set interrupt flag and interval timer interrupt pending
if the interval timer went from positive to negative
*/
if (itimer < 0 && olditimer >= 0)
ON_IC_ITIMER( GUESTREGS );
}
#endif /* !defined( FEATURE_001_ZARCH_INSTALLED_FACILITY ) */
}
RELEASE_INTLOCK( regs );
/* Early exceptions associated with the guest load_psw() */
if (lpsw_xcode)
{
PTT_SIE( "*SIE > pgmint", lpsw_xcode, 0, 0 );
GUESTREGS->program_interrupt( GUESTREGS, lpsw_xcode );
}
/* Run SIE in guest's architecture mode */
PTT_SIE( "SIE > run_sie", GUESTREGS->arch_mode, 0, 0 );
icode = run_sie[ GUESTREGS->arch_mode ]( regs );
PTT_SIE( "SIE < run_sie", icode, 0, 0 );
} /* if (setjmp(GUESTREGS->progjmp)) */
/* Exit from SIE mode */
PTT_SIE( "SIE > sie_exit", icode, 0, 0 );
ARCH_DEP( sie_exit )( regs, icode );
PTT_SIE( "SIE < sie_exit", 0, 0, 0 );
/* Perform serialization and checkpoint synchronization */
PERFORM_SERIALIZATION( regs );
PERFORM_CHKPT_SYNC( regs );
/* Return back to host instruction processing */
PTT_SIE( "SIE progjmp", 0, 0, 0 );
longjmp( regs->progjmp, SIE_NO_INTERCEPT );
} /* end of start_interpretive_execution instruction */
#endif /* defined( FEATURE_SIE ) */
#if defined( _FEATURE_SIE )
/*-------------------------------------------------------------------*/
/* run_sie */
/*-------------------------------------------------------------------*/
/* Execute guest instructions... */
/*-------------------------------------------------------------------*/
static int ARCH_DEP( run_sie )( REGS* regs )
{
BYTE* ip; /* instruction pointer */
int icode; /* SIE longjmp intercept code */
int i;
const INSTR_FUNC* current_opcode_table;
//---------------------------------------------------------
// CRITICAL SIE PROGRAMMING NOTE!
//---------------------------------------------------------
//
// Our 'regs' variable always points the HOST's regs (i.e.
// regs == HOSTREGS && regs->host is always true), even though
// we are actually RUNNING (executing) in GUEST architecture
// mode!!
//
// That is to say, if the host is, for example, z900 (z/VM)
// but the guest it wants to execute is a 390 guest, the above
// "start_interpretive_execution" instruction function calls
// the "s390_run_sie" function (because it wants to execute
// the guest in 390 mode), but it passed its own HOST regs to
// this function!
//
// So even though our function's build architecture is 390
// (i.e. even though our function's build architecture is that
// of the GUEST's), our 'regs' pointer is nevertheless still
// pointing to the z/VM HOST's registers!! GUESTREGS must be
// used to access the GUEST's register context!!
//
// What this means is that SPECIAL CARE must be taken when
// invoking macros or calling functions on behalf of the HOST
// (i.e. when using 'regs' or HOSTREGS instead of GUESTREGS)
// since many of our macros and functions are architecture
// dependent, relying on the regs they were called with to
// always match that of the current build architecture, which,
// as explained, is NOT necessarily always true in our case!!
//
//---------------------------------------------------------
//-----------------------------------------------------------
// IMPORTANT SIE PROGRAMMING NOTE!
//-----------------------------------------------------------
// NOTE: Our execution architectural mode is that of the SIE
// GUEST, not the HOST! If you need to call a function on
// behalf of the HOST (passing it 'regs'), you must be careful
// to ensure the correct version of that function is called!
// You cannot simply call the "ARCH_DEP" version of a function
// as they are for the architectue of the GUEST, not the HOST!
// (e.g. you cannot call a "s390_xxxx" function expecting it
// to work correctly if the HOST function that SHOULD have been
// called should have been "z900_xxxx"!) YOU HAVE BEEN WARNED!
//-----------------------------------------------------------
PTT_SIE( "run_sie h,g,a", regs->host, regs->guest, regs->sie_active );