forked from SDL-Hercules-390/hyperion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu.c
2126 lines (1851 loc) · 72.3 KB
/
cpu.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
/* CPU.C (c) Copyright Roger Bowler, 1994-2009 */
/* ESA/390 CPU Emulator */
/* Interpretive Execution - (c) Copyright Jan Jaeger, 1999-2009 */
/* z/Architecture support - (c) Copyright Jan Jaeger, 1999-2009 */
// $Id$
/*-------------------------------------------------------------------*/
/* This module implements the CPU instruction execution function of */
/* the S/370 and ESA/390 architectures, as described in the manuals */
/* GA22-7000-03 System/370 Principles of Operation */
/* SA22-7201-06 ESA/390 Principles of Operation */
/* SA22-7832-00 z/Architecture Principles of Operation */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* Additional credits: */
/* Nullification corrections by Jan Jaeger */
/* Set priority by Reed H. Petty from an idea by Steve Gay */
/* Corrections to program check by Jan Jaeger */
/* Light optimization on critical path by Valery Pogonchenko */
/* OSTAILOR parameter by Jay Maynard */
/* CPU timer and clock comparator interrupt improvements by */
/* Jan Jaeger, after a suggestion by Willem Konynenberg */
/* Instruction decode rework - Jan Jaeger */
/* Modifications for Interpretive Execution (SIE) by Jan Jaeger */
/* Basic FP extensions support - Peter Kuschnerus v209*/
/* ASN-and-LX-reuse facility - Roger Bowler, June 2004 @ALR*/
/*-------------------------------------------------------------------*/
// $Log$
// Revision 1.209 2009/01/23 11:46:20 bernard
// copyright notice
//
// Revision 1.208 2009/01/09 23:25:59 ivan
// Fix monitor code location when the monitor call occurs during the interception of a z/Arch SIE guest
//
// Revision 1.207 2008/12/21 02:51:58 ivan
// Place the configuration in system check-stop state when a READ SCP INFO
// is issued from a CPU that is not a CP Engine.
//
// Revision 1.206 2008/12/05 11:26:00 jj
// Fix SIE psw update when host interrupt occurs durng guest processing
//
// Revision 1.205 2008/11/04 05:56:31 fish
// Put ensure consistent create_thread ATTR usage change back in
//
// Revision 1.204 2008/11/03 15:31:57 rbowler
// Back out consistent create_thread ATTR modification
//
// Revision 1.203 2008/10/18 09:32:20 fish
// Ensure consistent create_thread ATTR usage
//
// Revision 1.202 2008/10/07 22:24:35 gsmith
// Fix zero ilc problem after branch trace
//
// Revision 1.201 2008/08/13 21:21:55 gsmith
// Fix bad guest IA after host interrupt during branch trace
//
// Revision 1.200 2008/04/11 14:28:15 bernard
// Integrate regs->exrl into base Hercules code.
//
// Revision 1.199 2008/04/09 07:35:32 bernard
// allign to Rogers terminal ;-)
//
// Revision 1.198 2008/04/08 17:12:29 bernard
// Added execute relative long instruction
//
// Revision 1.197 2008/02/19 11:49:19 ivan
// - Move setting of CPU priority after spwaning timer thread
// - Added support for Posix 1003.1e capabilities
//
// Revision 1.196 2008/02/12 18:23:39 jj
// 1. SPKA was missing protection check (PIC04) because
// AIA regs were not purged.
//
// 2. BASR with branch trace and PIC16, the pgm old was pointing
// 2 bytes before the BASR.
//
// 3. TBEDR , TBDR using R1 as source, should be R2.
//
// 4. PR with page crossing stack (1st page invalid) and PSW real
// in stack, missed the PIC 11. Fixed by invoking abs_stck_addr
// for previous stack entry descriptor before doing the load_psw.
//
// Revision 1.195 2007/12/10 23:12:02 gsmith
// Tweaks to OPTION_MIPS_COUNTING processing
//
// Revision 1.194 2007/12/07 12:08:51 rbowler
// Enable B9xx,EBxx opcodes in S/370 mode for ETF2 (correction)
//
// Revision 1.193 2007/12/02 16:22:09 rbowler
// Enable B9xx,EBxx opcodes in S/370 mode for ETF2
//
// Revision 1.192 2007/11/22 03:49:01 ivan
// Store Monitor code DOUBLEWORD when MC invoked under z/Architecture
// (previously only a fullword was stored)
//
// Revision 1.191 2007/11/18 22:18:51 rbowler
// Permit FEATURE_IMMEDIATE_AND_RELATIVE to be activated in S/370 mode
//
// Revision 1.190 2007/11/02 20:19:20 ivan
// Remove longjmp in process_interrupt() when cpu is STOPPING and a store status
// was requested - leads to a CPU in the STOPPED state that is still executing
// instructions.
//
// Revision 1.189 2007/08/06 22:14:53 gsmith
// process_interrupt returns if nothing happens
//
// Revision 1.188 2007/08/06 22:14:07 gsmith
// rework CPU execution loop
//
// Revision 1.187 2007/08/06 22:12:49 gsmith
// cpu thread exitjmp
//
// Revision 1.186 2007/08/06 22:10:47 gsmith
// reposition process_trace for readability
//
// Revision 1.185 2007/06/23 00:04:05 ivan
// Update copyright notices to include current year (2007)
//
// Revision 1.184 2007/06/22 02:22:50 gsmith
// revert config_cpu.pat due to problems in testing
//
// Revision 1.183 2007/06/20 03:52:19 gsmith
// configure_cpu now returns when the CPU is fully configured
//
// Revision 1.182 2007/06/06 22:14:57 gsmith
// Fix SYNCHRONIZE_CPUS when numcpu > number of host processors - Greg
//
// Revision 1.181 2007/04/09 23:07:42 gsmith
// call cpu_uninit() on run_cpu exit
//
// Revision 1.180 2007/03/25 04:20:36 gsmith
// Ensure started_mask CPU bit is off for terminating cpu thread - Fish by Greg
//
// Revision 1.179 2007/03/13 01:43:37 gsmith
// Synchronize started cpu
//
// Revision 1.178 2007/01/16 01:45:33 gsmith
// Tweaks to instruction stepping/tracing
//
// Revision 1.177 2007/01/09 23:18:21 gsmith
// Tweaks to cpuloop
//
// Revision 1.176 2007/01/04 23:12:03 gsmith
// remove thunk calls for program_interrupt
//
// Revision 1.175 2007/01/04 01:08:41 gsmith
// 03 Jan 2007 single_cpu_dw fetch/store patch for ia32
//
// Revision 1.174 2007/01/03 14:21:41 rbowler
// Reinstate semantics of 'g' command changed by hsccmd rev 1.197
//
// Revision 1.173 2006/12/30 16:15:57 gsmith
// 2006 Dec 30 Fix cpu_init to call set_jump_pointers for all arches
//
// Revision 1.172 2006/12/21 22:39:38 gsmith
// 21 Dec 2006 Range for s+, t+ - Greg Smith
//
// Revision 1.171 2006/12/21 01:45:01 gsmith
// 20 Dec 2006 Fix instruction display in program interrupt - Greg Smithh
//
// Revision 1.170 2006/12/20 23:37:29 rbowler
// ip_pat cpu.c rev 1.168 duplicated 2 lines from rev 1.167
//
// Revision 1.169 2006/12/20 10:52:08 rbowler
// cpu.c(294) : warning C4101: 'ip' : unreferenced local variable
//
// Revision 1.168 2006/12/20 04:26:19 gsmith
// 19 Dec 2006 ip_all.pat - performance patch - Greg Smith
//
// Revision 1.167 2006/12/17 21:54:24 rbowler
// Display DXC in msg HHCCP014I for PIC7
//
// Revision 1.166 2006/12/08 09:43:19 jj
// Add CVS message log
//
#include "hstdinc.h"
#if !defined(_HENGINE_DLL_)
#define _HENGINE_DLL_
#endif
#if !defined(_CPU_C_)
#define _CPU_C_
#endif
#include "hercules.h"
#include "opcode.h"
#include "inline.h"
/*-------------------------------------------------------------------*/
/* Put a CPU in check-stop state */
/* Must hold the system intlock */
/*-------------------------------------------------------------------*/
void ARCH_DEP(checkstop_cpu)(REGS *regs)
{
regs->cpustate=CPUSTATE_STOPPING;
regs->checkstop=1;
ON_IC_INTERRUPT(regs);
}
/*-------------------------------------------------------------------*/
/* Put all the CPUs in the configuration in check-stop state */
/*-------------------------------------------------------------------*/
void ARCH_DEP(checkstop_config)(void)
{
int i;
for(i=0;i<MAX_CPU;i++)
{
if(IS_CPU_ONLINE(i))
{
ARCH_DEP(checkstop_cpu)(sysblk.regs[i]);
}
}
WAKEUP_CPUS_MASK(sysblk.waiting_mask);
}
/*-------------------------------------------------------------------*/
/* Store current PSW at a specified address in main storage */
/*-------------------------------------------------------------------*/
void ARCH_DEP(store_psw) (REGS *regs, BYTE *addr)
{
/* Ensure psw.IA is set */
if (!regs->psw.zeroilc)
SET_PSW_IA(regs);
#if defined(FEATURE_BCMODE)
if ( ECMODE(®s->psw) ) {
#endif /*defined(FEATURE_BCMODE)*/
#if !defined(FEATURE_ESAME)
STORE_FW ( addr,
( (regs->psw.sysmask << 24)
| ((regs->psw.pkey | regs->psw.states) << 16)
| ( ( (regs->psw.asc)
| (regs->psw.cc << 4)
| (regs->psw.progmask)
) << 8
)
| regs->psw.zerobyte
)
);
if(unlikely(regs->psw.zeroilc))
STORE_FW ( addr + 4, regs->psw.IA | (regs->psw.amode ? 0x80000000 : 0) );
else
STORE_FW ( addr + 4,
( (regs->psw.IA & ADDRESS_MAXWRAP(regs)) | (regs->psw.amode ? 0x80000000 : 0) )
);
#endif /*!defined(FEATURE_ESAME)*/
#if defined(FEATURE_BCMODE)
} else {
STORE_FW ( addr,
( (regs->psw.sysmask << 24)
| ((regs->psw.pkey | regs->psw.states) << 16)
| (regs->psw.intcode)
)
);
if(unlikely(regs->psw.zeroilc))
STORE_FW ( addr + 4,
( ( (REAL_ILC(regs) << 5)
| (regs->psw.cc << 4)
| regs->psw.progmask
) << 24
) | regs->psw.IA
);
else
STORE_FW ( addr + 4,
( ( (REAL_ILC(regs) << 5)
| (regs->psw.cc << 4)
| regs->psw.progmask
) << 24
) | (regs->psw.IA & ADDRESS_MAXWRAP(regs))
);
}
#elif defined(FEATURE_ESAME)
STORE_FW ( addr,
( (regs->psw.sysmask << 24)
| ((regs->psw.pkey | regs->psw.states) << 16)
| ( ( (regs->psw.asc)
| (regs->psw.cc << 4)
| (regs->psw.progmask)
) << 8
)
| (regs->psw.amode64 ? 0x01 : 0)
| regs->psw.zerobyte
)
);
STORE_FW ( addr + 4,
( (regs->psw.amode ? 0x80000000 : 0 )
| regs->psw.zeroword
)
);
STORE_DW ( addr + 8, regs->psw.IA_G );
#endif /*defined(FEATURE_ESAME)*/
} /* end function ARCH_DEP(store_psw) */
/*-------------------------------------------------------------------*/
/* Load current PSW from a specified address in main storage */
/* Returns 0 if valid, 0x0006 if specification exception */
/*-------------------------------------------------------------------*/
int ARCH_DEP(load_psw) (REGS *regs, BYTE *addr)
{
INVALIDATE_AIA(regs);
regs->psw.zeroilc = 1;
regs->psw.sysmask = addr[0];
regs->psw.pkey = (addr[1] & 0xF0);
regs->psw.states = (addr[1] & 0x0F);
#if defined(FEATURE_BCMODE)
if ( ECMODE(®s->psw) ) {
#endif /*defined(FEATURE_BCMODE)*/
SET_IC_ECMODE_MASK(regs);
/* Processing for EC mode PSW */
regs->psw.intcode = 0;
regs->psw.asc = (addr[2] & 0xC0);
regs->psw.cc = (addr[2] & 0x30) >> 4;
regs->psw.progmask = (addr[2] & 0x0F);
regs->psw.amode = (addr[4] & 0x80) ? 1 : 0;
#if defined(FEATURE_ESAME)
regs->psw.zerobyte = addr[3] & 0xFE;
regs->psw.amode64 = addr[3] & 0x01;
regs->psw.zeroword = fetch_fw(addr+4) & 0x7FFFFFFF;
regs->psw.IA = fetch_dw (addr + 8);
regs->psw.AMASK = regs->psw.amode64 ? AMASK64
: regs->psw.amode ? AMASK31 : AMASK24;
#else /*!defined(FEATURE_ESAME)*/
regs->psw.zerobyte = addr[3];
regs->psw.amode64 = 0;
regs->psw.IA = fetch_fw(addr + 4) & 0x7FFFFFFF;
regs->psw.AMASK = regs->psw.amode ? AMASK31 : AMASK24;
#endif /*!defined(FEATURE_ESAME)*/
/* Bits 0 and 2-4 of system mask must be zero */
if ((addr[0] & 0xB8) != 0)
return PGM_SPECIFICATION_EXCEPTION;
#if defined(FEATURE_ESAME)
/* For ESAME, bit 12 must be zero */
if (NOTESAME(®s->psw))
return PGM_SPECIFICATION_EXCEPTION;
/* Bits 24-30 must be zero */
if (regs->psw.zerobyte)
return PGM_SPECIFICATION_EXCEPTION;
/* Bits 33-63 must be zero */
if ( regs->psw.zeroword )
return PGM_SPECIFICATION_EXCEPTION;
#else /*!defined(FEATURE_ESAME)*/
/* Bits 24-31 must be zero */
if ( regs->psw.zerobyte )
return PGM_SPECIFICATION_EXCEPTION;
/* For ESA/390, bit 12 must be one */
if (!ECMODE(®s->psw))
return PGM_SPECIFICATION_EXCEPTION;
#endif /*!defined(FEATURE_ESAME)*/
#ifndef FEATURE_DUAL_ADDRESS_SPACE
/* If DAS feature not installed then bit 16 must be zero */
if (SPACE_BIT(®s->psw))
return PGM_SPECIFICATION_EXCEPTION;
#endif /*!FEATURE_DUAL_ADDRESS_SPACE*/
#ifndef FEATURE_ACCESS_REGISTERS
/* If not ESA/370 or ESA/390 then bit 17 must be zero */
if (AR_BIT(®s->psw))
return PGM_SPECIFICATION_EXCEPTION;
#endif /*!FEATURE_ACCESS_REGISTERS*/
/* Check validity of amode and instruction address */
#if defined(FEATURE_ESAME)
/* For ESAME, bit 32 cannot be zero if bit 31 is one */
if (regs->psw.amode64 && !regs->psw.amode)
return PGM_SPECIFICATION_EXCEPTION;
/* If bit 32 is zero then IA cannot exceed 24 bits */
if (!regs->psw.amode && regs->psw.IA > 0x00FFFFFF)
return PGM_SPECIFICATION_EXCEPTION;
/* If bit 31 is zero then IA cannot exceed 31 bits */
if (!regs->psw.amode64 && regs->psw.IA > 0x7FFFFFFF)
return PGM_SPECIFICATION_EXCEPTION;
#else /*!defined(FEATURE_ESAME)*/
#ifdef FEATURE_BIMODAL_ADDRESSING
/* For 370-XA, ESA/370, and ESA/390,
if amode=24, bits 33-39 must be zero */
if (!regs->psw.amode && regs->psw.IA > 0x00FFFFFF)
return PGM_SPECIFICATION_EXCEPTION;
#else /*!FEATURE_BIMODAL_ADDRESSING*/
/* For S/370, bits 32-39 must be zero */
if (addr[4] != 0x00)
return PGM_SPECIFICATION_EXCEPTION;
#endif /*!FEATURE_BIMODAL_ADDRESSING*/
#endif /*!defined(FEATURE_ESAME)*/
#if defined(FEATURE_BCMODE)
} else {
SET_IC_BCMODE_MASK(regs);
/* Processing for S/370 BC mode PSW */
regs->psw.intcode = fetch_hw (addr + 2);
regs->psw.cc = (addr[4] & 0x30) >> 4;
regs->psw.progmask = (addr[4] & 0x0F);
FETCH_FW(regs->psw.IA, addr + 4);
regs->psw.IA &= 0x00FFFFFF;
regs->psw.AMASK = AMASK24;
regs->psw.zerobyte = 0;
regs->psw.asc = 0;
regs->psw.amode64 = regs->psw.amode = 0;
}
#endif /*defined(FEATURE_BCMODE)*/
#if defined(FEATURE_MULTIPLE_CONTROLLED_DATA_SPACE)
/* Bits 5 and 16 must be zero in XC mode */
if( SIE_STATB(regs, MX, XC)
&& ( (regs->psw.sysmask & PSW_DATMODE) || SPACE_BIT(®s->psw)) )
return PGM_SPECIFICATION_EXCEPTION;
#endif /*defined(FEATURE_MULTIPLE_CONTROLLED_DATA_SPACE)*/
regs->psw.zeroilc = 0;
/* Check for wait state PSW */
if (WAITSTATE(®s->psw) && CPU_STEPPING_OR_TRACING_ALL)
{
char buf[40];
WRITEMSG(HHCCP043I, str_psw(regs, buf));
}
TEST_SET_AEA_MODE(regs);
return 0;
} /* end function ARCH_DEP(load_psw) */
/*-------------------------------------------------------------------*/
/* Load program interrupt new PSW */
/*-------------------------------------------------------------------*/
void (ATTR_REGPARM(2) ARCH_DEP(program_interrupt)) (REGS *regs, int pcode)
{
PSA *psa; /* -> Prefixed storage area */
REGS *realregs; /* True regs structure */
RADR px; /* host real address of pfx */
int code; /* pcode without PER ind. */
int ilc; /* instruction length */
#if defined(FEATURE_ESAME)
/** FIXME : SEE ISW20090110-1 */
void *zmoncode=NULL; /* special reloc for z/Arch */
/* FIXME : zmoncode not being initialized here raises
a potentially non-initialized warning in GCC..
can't find why. ISW 2009/02/04 */
/* mon call SIE intercept */
#endif
#if defined(FEATURE_INTERPRETIVE_EXECUTION)
int sie_ilc=0; /* SIE instruction length */
#endif
#if defined(_FEATURE_SIE)
int nointercept; /* True for virtual pgmint */
#endif /*defined(_FEATURE_SIE)*/
#if defined(OPTION_FOOTPRINT_BUFFER)
U32 n;
#endif /*defined(OPTION_FOOTPRINT_BUFFER)*/
char dxcstr[8]={0}; /* " DXC=xx" if data excptn */
static char *pgmintname[] = {
/* 01 */ "Operation exception",
/* 02 */ "Privileged-operation exception",
/* 03 */ "Execute exception",
/* 04 */ "Protection exception",
/* 05 */ "Addressing exception",
/* 06 */ "Specification exception",
/* 07 */ "Data exception",
/* 08 */ "Fixed-point-overflow exception",
/* 09 */ "Fixed-point-divide exception",
/* 0A */ "Decimal-overflow exception",
/* 0B */ "Decimal-divide exception",
/* 0C */ "HFP-exponent-overflow exception",
/* 0D */ "HFP-exponent-underflow exception",
/* 0E */ "HFP-significance exception",
/* 0F */ "HFP-floating-point-divide exception",
/* 10 */ "Segment-translation exception",
/* 11 */ "Page-translation exception",
/* 12 */ "Translation-specification exception",
/* 13 */ "Special-operation exception",
/* 14 */ "Pseudo-page-fault exception",
/* 15 */ "Operand exception",
/* 16 */ "Trace-table exception",
/* 17 */ "ASN-translation exception",
/* 18 */ "Page access exception",
/* 19 */ "Vector/Crypto operation exception",
/* 1A */ "Page state exception",
/* 1B */ "Page transition exception",
/* 1C */ "Space-switch event",
/* 1D */ "Square-root exception",
/* 1E */ "Unnormalized-operand exception",
/* 1F */ "PC-translation specification exception",
/* 20 */ "AFX-translation exception",
/* 21 */ "ASX-translation exception",
/* 22 */ "LX-translation exception",
/* 23 */ "EX-translation exception",
/* 24 */ "Primary-authority exception",
/* 25 */ "Secondary-authority exception",
/* 26 */ "LFX-translation exception", /*@ALR*/
/* 27 */ "LSX-translation exception", /*@ALR*/
/* 28 */ "ALET-specification exception",
/* 29 */ "ALEN-translation exception",
/* 2A */ "ALE-sequence exception",
/* 2B */ "ASTE-validity exception",
/* 2C */ "ASTE-sequence exception",
/* 2D */ "Extended-authority exception",
/* 2E */ "LSTE-sequence exception", /*@ALR*/
/* 2F */ "ASTE-instance exception", /*@ALR*/
/* 30 */ "Stack-full exception",
/* 31 */ "Stack-empty exception",
/* 32 */ "Stack-specification exception",
/* 33 */ "Stack-type exception",
/* 34 */ "Stack-operation exception",
/* 35 */ "Unassigned exception",
/* 36 */ "Unassigned exception",
/* 37 */ "Unassigned exception",
/* 38 */ "ASCE-type exception",
/* 39 */ "Region-first-translation exception",
/* 3A */ "Region-second-translation exception",
/* 3B */ "Region-third-translation exception",
/* 3C */ "Unassigned exception",
/* 3D */ "Unassigned exception",
/* 3E */ "Unassigned exception",
/* 3F */ "Unassigned exception",
/* 40 */ "Monitor event" };
/* 26 */ /* was "Page-fault-assist exception", */
/* 27 */ /* was "Control-switch exception", */
/* If called with ghost registers (ie from hercules command
then ignore all interrupt handling and report the error
to the caller */
if(regs->ghostregs)
longjmp(regs->progjmp, pcode);
PTT(PTT_CL_PGM,"*PROG",pcode,(U32)(regs->TEA & 0xffffffff),regs->psw.IA_L);
/* program_interrupt() may be called with a shadow copy of the
regs structure, realregs is the pointer to the real structure
which must be used when loading/storing the psw, or backing up
the instruction address in case of nullification */
#if defined(_FEATURE_SIE)
realregs = SIE_MODE(regs)
? sysblk.regs[regs->cpuad]->guestregs
: sysblk.regs[regs->cpuad];
#else /*!defined(_FEATURE_SIE)*/
realregs = sysblk.regs[regs->cpuad];
#endif /*!defined(_FEATURE_SIE)*/
/* Prevent machine check when in (almost) interrupt loop */
realregs->instcount++;
/* Release any locks */
if (sysblk.intowner == realregs->cpuad)
RELEASE_INTLOCK(realregs);
if (sysblk.mainowner == realregs->cpuad)
RELEASE_MAINLOCK(realregs);
/* Ensure psw.IA is set and aia invalidated */
INVALIDATE_AIA(realregs);
#if defined(FEATURE_INTERPRETIVE_EXECUTION)
if(realregs->sie_active)
INVALIDATE_AIA(realregs->guestregs);
#endif /*defined(FEATURE_INTERPRETIVE_EXECUTION)*/
/* Set instruction length (ilc) */
ilc = realregs->psw.zeroilc ? 0 : REAL_ILC(realregs);
if (realregs->psw.ilc == 0 && !realregs->psw.zeroilc)
{
/* This can happen if BALR, BASR, BASSM or BSM
program checks during trace */
ilc = realregs->execflag ? realregs->exrl ? 6 : 4 : 2;
realregs->ip += ilc;
realregs->psw.IA += ilc;
realregs->psw.ilc = ilc;
}
#if defined(FEATURE_INTERPRETIVE_EXECUTION)
if(realregs->sie_active)
{
sie_ilc = realregs->guestregs->psw.zeroilc
? 0 : REAL_ILC(realregs->guestregs);
if (realregs->guestregs->psw.ilc == 0
&& !realregs->guestregs->psw.zeroilc)
{
sie_ilc = realregs->guestregs->execflag ?
realregs->guestregs->exrl ? 6 : 4 : 2;
realregs->guestregs->psw.ilc = sie_ilc;
}
}
#endif /*defined(FEATURE_INTERPRETIVE_EXECUTION)*/
/* Set `execflag' to 0 in case EXecuted instruction program-checked */
realregs->execflag = 0;
#if defined(FEATURE_INTERPRETIVE_EXECUTION)
if(realregs->sie_active)
realregs->guestregs->execflag = 0;
#endif /*defined(FEATURE_INTERPRETIVE_EXECUTION)*/
/* Unlock the main storage lock if held */
if (realregs->cpuad == sysblk.mainowner)
RELEASE_MAINLOCK(realregs);
/* Remove PER indication from program interrupt code
such that interrupt code specific tests may be done.
The PER indication will be stored in the PER handling
code */
code = pcode & ~PGM_PER_EVENT;
/* If this is a concurrent PER event then we must add the PER
bit to the interrupts code */
if( OPEN_IC_PER(realregs) )
pcode |= PGM_PER_EVENT;
/* Perform serialization and checkpoint synchronization */
PERFORM_SERIALIZATION (realregs);
PERFORM_CHKPT_SYNC (realregs);
#if defined(FEATURE_INTERPRETIVE_EXECUTION)
/* Host protection and addressing exceptions must be
reflected to the guest */
if(realregs->sie_active &&
(code == PGM_PROTECTION_EXCEPTION
|| code == PGM_ADDRESSING_EXCEPTION
#if defined(_FEATURE_MULTIPLE_CONTROLLED_DATA_SPACE)
|| code == PGM_ALET_SPECIFICATION_EXCEPTION
|| code == PGM_ALEN_TRANSLATION_EXCEPTION
|| code == PGM_ALE_SEQUENCE_EXCEPTION
|| code == PGM_EXTENDED_AUTHORITY_EXCEPTION
#endif /*defined(_FEATURE_MULTIPLE_CONTROLLED_DATA_SPACE)*/
) )
{
#if defined(SIE_DEBUG)
logmsg(_("program_int() passing to guest code=%4.4X\n"),pcode);
#endif /*defined(SIE_DEBUG)*/
realregs->guestregs->TEA = realregs->TEA;
realregs->guestregs->excarid = realregs->excarid;
realregs->guestregs->opndrid = realregs->opndrid;
#if defined(_FEATURE_PROTECTION_INTERCEPTION_CONTROL)
realregs->guestregs->hostint = 1;
#endif /*defined(_FEATURE_PROTECTION_INTERCEPTION_CONTROL)*/
(realregs->guestregs->program_interrupt) (realregs->guestregs, pcode);
}
#endif /*defined(FEATURE_INTERPRETIVE_EXECUTION)*/
/* Back up the PSW for exceptions which cause nullification,
unless the exception occurred during instruction fetch */
if ((code == PGM_PAGE_TRANSLATION_EXCEPTION
|| code == PGM_SEGMENT_TRANSLATION_EXCEPTION
#if defined(FEATURE_ESAME)
|| code == PGM_ASCE_TYPE_EXCEPTION
|| code == PGM_REGION_FIRST_TRANSLATION_EXCEPTION
|| code == PGM_REGION_SECOND_TRANSLATION_EXCEPTION
|| code == PGM_REGION_THIRD_TRANSLATION_EXCEPTION
#endif /*defined(FEATURE_ESAME)*/
|| code == PGM_TRACE_TABLE_EXCEPTION
|| code == PGM_AFX_TRANSLATION_EXCEPTION
|| code == PGM_ASX_TRANSLATION_EXCEPTION
|| code == PGM_LX_TRANSLATION_EXCEPTION
|| code == PGM_LFX_TRANSLATION_EXCEPTION /*@ALR*/
|| code == PGM_LSX_TRANSLATION_EXCEPTION /*@ALR*/
|| code == PGM_LSTE_SEQUENCE_EXCEPTION /*@ALR*/
|| code == PGM_EX_TRANSLATION_EXCEPTION
|| code == PGM_PRIMARY_AUTHORITY_EXCEPTION
|| code == PGM_SECONDARY_AUTHORITY_EXCEPTION
|| code == PGM_ALEN_TRANSLATION_EXCEPTION
|| code == PGM_ALE_SEQUENCE_EXCEPTION
|| code == PGM_ASTE_VALIDITY_EXCEPTION
|| code == PGM_ASTE_SEQUENCE_EXCEPTION
|| code == PGM_ASTE_INSTANCE_EXCEPTION /*@ALR*/
|| code == PGM_EXTENDED_AUTHORITY_EXCEPTION
|| code == PGM_STACK_FULL_EXCEPTION
|| code == PGM_STACK_EMPTY_EXCEPTION
|| code == PGM_STACK_SPECIFICATION_EXCEPTION
|| code == PGM_STACK_TYPE_EXCEPTION
|| code == PGM_STACK_OPERATION_EXCEPTION
|| code == PGM_VECTOR_OPERATION_EXCEPTION)
&& !realregs->instinvalid)
{
realregs->psw.IA -= ilc;
realregs->psw.IA &= ADDRESS_MAXWRAP(realregs);
#if defined(FEATURE_INTERPRETIVE_EXECUTION)
/* When in SIE mode the guest instruction causing this
host exception must also be nullified */
if(realregs->sie_active && !realregs->guestregs->instinvalid)
{
realregs->guestregs->psw.IA -= sie_ilc;
realregs->guestregs->psw.IA &= ADDRESS_MAXWRAP(realregs->guestregs);
}
#endif /*defined(FEATURE_INTERPRETIVE_EXECUTION)*/
}
/* The OLD PSW must be incremented on the following
exceptions during instfetch */
if(realregs->instinvalid &&
( code == PGM_PROTECTION_EXCEPTION
|| code == PGM_ADDRESSING_EXCEPTION
|| code == PGM_SPECIFICATION_EXCEPTION
|| code == PGM_TRANSLATION_SPECIFICATION_EXCEPTION ))
{
realregs->psw.IA += ilc;
realregs->psw.IA &= ADDRESS_MAXWRAP(realregs);
}
/* Store the interrupt code in the PSW */
realregs->psw.intcode = pcode;
/* Call debugger if active */
HDC2(debug_program_interrupt, regs, pcode);
/* Trace program checks other then PER event */
if(code && (CPU_STEPPING_OR_TRACING(realregs, ilc)
|| sysblk.pgminttr & ((U64)1 << ((code - 1) & 0x3F))))
{
BYTE *ip;
#if defined(OPTION_FOOTPRINT_BUFFER)
if(!(sysblk.insttrace || sysblk.inststep))
for(n = sysblk.footprptr[realregs->cpuad] + 1 ;
n != sysblk.footprptr[realregs->cpuad];
n++, n &= OPTION_FOOTPRINT_BUFFER - 1)
ARCH_DEP(display_inst)
(&sysblk.footprregs[realregs->cpuad][n],
sysblk.footprregs[realregs->cpuad][n].inst);
#endif /*defined(OPTION_FOOTPRINT_BUFFER)*/
char buf1[10] = "";
char buf2[10] = "";
#if defined(_FEATURE_SIE)
if (SIE_MODE(realregs))
strcpy(buf1, "SIE: ");
#endif /*defined(_FEATURE_SIE)*/
#if defined(SIE_DEBUG)
strcpy(buf2, MSTRING(_GEN_ARCH));
strcat(buf2, " ");
#endif /*defined(SIE_DEBUG)*/
if (code == PGM_DATA_EXCEPTION)
sprintf(dxcstr, " DXC=%2.2X", regs->dxc);
WRITEMSG(HHCCP014I, buf1, buf2,
PTYPSTR(sysblk.ptyp[realregs->cpuad]), realregs->cpuad,
pgmintname[ (code - 1) & 0x3F], pcode, ilc, dxcstr);
/* Calculate instruction pointer */
ip = realregs->instinvalid ? NULL
: (realregs->ip - ilc < realregs->aip)
? realregs->inst : realregs->ip - ilc;
ARCH_DEP(display_inst) (realregs, ip);
}
realregs->instinvalid = 0;
#if defined(FEATURE_INTERPRETIVE_EXECUTION)
/* If this is a host exception in SIE state then leave SIE */
if(realregs->sie_active)
ARCH_DEP(sie_exit) (realregs, SIE_HOST_PGMINT);
#endif /*defined(FEATURE_INTERPRETIVE_EXECUTION)*/
/* Absolute address of prefix page */
px = realregs->PX;
/* If under SIE use translated to host absolute prefix */
#if defined(_FEATURE_SIE)
if(SIE_MODE(regs))
px = regs->sie_px;
#endif
#if defined(_FEATURE_SIE)
if(!SIE_MODE(regs) ||
/* Interception is mandatory for the following exceptions */
(
#if defined(_FEATURE_PROTECTION_INTERCEPTION_CONTROL)
!(code == PGM_PROTECTION_EXCEPTION
&& (!SIE_FEATB(regs, EC2, PROTEX)
|| realregs->hostint))
#else /*!defined(_FEATURE_PROTECTION_INTERCEPTION_CONTROL)*/
code != PGM_PROTECTION_EXCEPTION
#endif /*!defined(_FEATURE_PROTECTION_INTERCEPTION_CONTROL)*/
#if defined (_FEATURE_PER2)
&& !((pcode & PGM_PER_EVENT) && SIE_FEATB(regs, M, GPE))
#endif /* defined (_FEATURE_PER2) */
&& code != PGM_ADDRESSING_EXCEPTION
&& code != PGM_SPECIFICATION_EXCEPTION
&& code != PGM_SPECIAL_OPERATION_EXCEPTION
#ifdef FEATURE_VECTOR_FACILITY
&& code != PGM_VECTOR_OPERATION_EXCEPTION
#endif /*FEATURE_VECTOR_FACILITY*/
#if defined(FEATURE_MULTIPLE_CONTROLLED_DATA_SPACE)
&& !(code == PGM_ALEN_TRANSLATION_EXCEPTION
&& SIE_FEATB(regs, MX, XC))
&& !(code == PGM_ALE_SEQUENCE_EXCEPTION
&& SIE_FEATB(regs, MX, XC))
&& !(code == PGM_EXTENDED_AUTHORITY_EXCEPTION
&& SIE_FEATB(regs, MX, XC))
#endif /*defined(FEATURE_MULTIPLE_CONTROLLED_DATA_SPACE)*/
/* And conditional for the following exceptions */
&& !(code == PGM_OPERATION_EXCEPTION
&& SIE_FEATB(regs, IC0, OPEREX))
&& !(code == PGM_PRIVILEGED_OPERATION_EXCEPTION
&& SIE_FEATB(regs, IC0, PRIVOP))
#ifdef FEATURE_BASIC_FP_EXTENSIONS
&& !(code == PGM_DATA_EXCEPTION
&& (regs->dxc == 1 || regs->dxc == 2)
&& (regs->CR(0) & CR0_AFP)
&& !(regs->hostregs->CR(0) & CR0_AFP))
#endif /*FEATURE_BASIC_FP_EXTENSIONS*/
/* Or all exceptions if requested as such */
&& !SIE_FEATB(regs, IC0, PGMALL) )
)
{
#endif /*defined(_FEATURE_SIE)*/
/* Set the main storage reference and change bits */
STORAGE_KEY(px, regs) |= (STORKEY_REF | STORKEY_CHANGE);
/* Point to PSA in main storage */
psa = (void*)(regs->mainstor + px);
#if defined(_FEATURE_SIE)
#if defined(FEATURE_ESAME)
/** FIXME : SEE ISW20090110-1 */
if(code == PGM_MONITOR_EVENT)
{
zmoncode=psa->moncode;
}
#endif
nointercept = 1;
}
else
{
/* This is a guest interruption interception so point to
the interruption parm area in the state descriptor
rather then the PSA, except for the operation exception */
if(code != PGM_OPERATION_EXCEPTION)
{
psa = (void*)(regs->hostregs->mainstor + SIE_STATE(regs) + SIE_IP_PSA_OFFSET);
/* Set the main storage reference and change bits */
STORAGE_KEY(SIE_STATE(regs), regs->hostregs) |= (STORKEY_REF | STORKEY_CHANGE);
#if defined(FEATURE_ESAME)
/** FIXME : SEE ISW20090110-1 */
if(code == PGM_MONITOR_EVENT)
{
PSA *_psa;
_psa=(void *)(regs->hostregs->mainstor + SIE_STATE(regs) + SIE_II_PSA_OFFSET);
zmoncode=_psa->ioid;
}
#endif
}
else
{
/* Point to PSA in main storage */
psa = (void*)(regs->mainstor + px);
/* Set the main storage reference and change bits */
STORAGE_KEY(px, regs) |= (STORKEY_REF | STORKEY_CHANGE);
}
nointercept = 0;
}
#endif /*defined(_FEATURE_SIE)*/
#if defined(_FEATURE_PER)
/* Handle PER or concurrent PER event */
/* Throw out Stor Alter PER if merged with nullified/suppressed rupt */
if ( IS_IC_PER_SA(realregs) && !IS_IC_PER_STURA(realregs) &&
(realregs->ip[0] != 0x0E) &&
!(code == 0x00 || code == 0x06 || code == 0x08 || code == 0x0A ||
code == 0x0C || code == 0x0D || code == 0x0E || code == 0x1C ||
code == 0x40) )
OFF_IC_PER_SA(realregs);
if( OPEN_IC_PER(realregs) )
{
if( CPU_STEPPING_OR_TRACING(realregs, ilc) )
WRITEMSG(HHCCP015I, PTYPSTR(sysblk.ptyp[regs->cpuad]),
regs->cpuad, pcode, IS_IC_PER(realregs) >> 16,
(realregs->psw.IA - ilc) & ADDRESS_MAXWRAP(realregs) );
realregs->perc |= OPEN_IC_PER(realregs) >> ((32 - IC_CR9_SHIFT) - 16);
/* Positions 14 and 15 contain zeros if a storage alteration
event was not indicated */
//FIXME: is this right??
if( !(OPEN_IC_PER_SA(realregs))
|| (OPEN_IC_PER_STURA(realregs)) )
realregs->perc &= 0xFFFC;
STORE_HW(psa->perint, realregs->perc);
STORE_W(psa->peradr, realregs->peradr);
if( IS_IC_PER_SA(realregs) && ACCESS_REGISTER_MODE(&realregs->psw) )
psa->perarid = realregs->peraid;
#if defined(_FEATURE_SIE)
/* Reset PER pending indication */
if(nointercept)
OFF_IC_PER(realregs);
#endif
}
else
{
pcode &= 0xFF7F;
}
#endif /*defined(_FEATURE_PER)*/
#if defined(FEATURE_BCMODE)
/* For ECMODE, store extended interrupt information in PSA */
if ( ECMODE(&realregs->psw) )
#endif /*defined(FEATURE_BCMODE)*/
{
/* Store the program interrupt code at PSA+X'8C' */
psa->pgmint[0] = 0;
psa->pgmint[1] = ilc;
STORE_HW(psa->pgmint + 2, pcode);
/* Store the exception access identification at PSA+160 */
if ( code == PGM_PAGE_TRANSLATION_EXCEPTION
|| code == PGM_SEGMENT_TRANSLATION_EXCEPTION
#if defined(FEATURE_ESAME)
|| code == PGM_ASCE_TYPE_EXCEPTION
|| code == PGM_REGION_FIRST_TRANSLATION_EXCEPTION
|| code == PGM_REGION_SECOND_TRANSLATION_EXCEPTION
|| code == PGM_REGION_THIRD_TRANSLATION_EXCEPTION
#endif /*defined(FEATURE_ESAME)*/
|| code == PGM_ALEN_TRANSLATION_EXCEPTION
|| code == PGM_ALE_SEQUENCE_EXCEPTION
|| code == PGM_ASTE_VALIDITY_EXCEPTION
|| code == PGM_ASTE_SEQUENCE_EXCEPTION
|| code == PGM_ASTE_INSTANCE_EXCEPTION /*@ALR*/
|| code == PGM_EXTENDED_AUTHORITY_EXCEPTION
#ifdef FEATURE_SUPPRESSION_ON_PROTECTION
|| code == PGM_PROTECTION_EXCEPTION
#endif /*FEATURE_SUPPRESSION_ON_PROTECTION*/
)
{
psa->excarid = regs->excarid;
if(regs->TEA | TEA_MVPG)
psa->opndrid = regs->opndrid;
realregs->opndrid = 0;
}
#if defined(FEATURE_ESAME)
/* Store the translation exception address at PSA+168 */
if ( code == PGM_PAGE_TRANSLATION_EXCEPTION
|| code == PGM_SEGMENT_TRANSLATION_EXCEPTION
|| code == PGM_ASCE_TYPE_EXCEPTION
|| code == PGM_REGION_FIRST_TRANSLATION_EXCEPTION
|| code == PGM_REGION_SECOND_TRANSLATION_EXCEPTION
|| code == PGM_REGION_THIRD_TRANSLATION_EXCEPTION
#ifdef FEATURE_SUPPRESSION_ON_PROTECTION
|| code == PGM_PROTECTION_EXCEPTION
#endif /*FEATURE_SUPPRESSION_ON_PROTECTION*/
)
{
STORE_DW(psa->TEA_G, regs->TEA);
}
/* Store the translation exception address at PSA+172 */
if ( code == PGM_AFX_TRANSLATION_EXCEPTION
|| code == PGM_ASX_TRANSLATION_EXCEPTION
|| code == PGM_PRIMARY_AUTHORITY_EXCEPTION
|| code == PGM_SECONDARY_AUTHORITY_EXCEPTION
|| code == PGM_SPACE_SWITCH_EVENT
|| code == PGM_LX_TRANSLATION_EXCEPTION
|| code == PGM_LFX_TRANSLATION_EXCEPTION /*@ALR*/
|| code == PGM_LSX_TRANSLATION_EXCEPTION /*@ALR*/
|| code == PGM_LSTE_SEQUENCE_EXCEPTION /*@ALR*/
|| code == PGM_EX_TRANSLATION_EXCEPTION)
{
STORE_FW(psa->TEA_L, regs->TEA);
}
#else /*!defined(FEATURE_ESAME)*/
/* Store the translation exception address at PSA+144 */
if ( code == PGM_PAGE_TRANSLATION_EXCEPTION
|| code == PGM_SEGMENT_TRANSLATION_EXCEPTION
|| code == PGM_AFX_TRANSLATION_EXCEPTION
|| code == PGM_ASX_TRANSLATION_EXCEPTION
|| code == PGM_PRIMARY_AUTHORITY_EXCEPTION
|| code == PGM_SECONDARY_AUTHORITY_EXCEPTION
|| code == PGM_SPACE_SWITCH_EVENT
|| code == PGM_LX_TRANSLATION_EXCEPTION
|| code == PGM_EX_TRANSLATION_EXCEPTION
#ifdef FEATURE_SUPPRESSION_ON_PROTECTION
|| code == PGM_PROTECTION_EXCEPTION
#endif /*FEATURE_SUPPRESSION_ON_PROTECTION*/
)
{
STORE_FW(psa->tea, regs->TEA);