File: vm.c

package info (click to toggle)
hercules 3.07-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 14,572 kB
  • ctags: 18,225
  • sloc: ansic: 162,921; sh: 8,522; makefile: 781; perl: 202; sed: 16
file content (1713 lines) | stat: -rw-r--r-- 62,601 bytes parent folder | download | duplicates (3)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
/* VM.C         (c) Copyright Roger Bowler, 2000-2009                */
/*              ESA/390 VM Diagnose calls and IUCV instruction       */

/* Interpretive Execution - (c) Copyright Jan Jaeger, 1999-2009      */

// $Id: vm.c 5532 2009-12-11 19:28:19Z bernard $

/*-------------------------------------------------------------------*/
/* This module implements miscellaneous diagnose functions           */
/* described in SC24-5670 VM/ESA CP Programming Services             */
/* and SC24-5855 VM/ESA CP Diagnosis Reference                       */
/* and SC24-6084 z/VM 5.4 CP Programming Services.                   */
/*      Modifications for Interpretive Execution (SIE) by Jan Jaeger */
/* z/Architecture support - (c) Copyright Jan Jaeger, 1999-2009      */
/*-------------------------------------------------------------------*/

#include "hstdinc.h"

#if !defined(_HENGINE_DLL_)
#define _HENGINE_DLL_
#endif /*_HENGINE_DLL_*/

#if !defined(_VM_C_)
#define _VM_C_
#endif /* _VM_C_ */

#include "hercules.h"
#include "opcode.h"
#include "inline.h"
#include "commadpt.h"

#if defined(FEATURE_EMULATE_VM)

#if !defined(_VM_C)
#define _VM_C

/*-------------------------------------------------------------------*/
/* Internal macro definitions                                        */
/*-------------------------------------------------------------------*/
#define DEV024(_type,_cls,_typ) \
       { _type,_cls,_typ,0xC0 }
#define DEV210(_type,_cls,_typ) \
       { _type,_cls,_typ,0x40 }

/*-------------------------------------------------------------------*/
/* Synchronous Block I/O Parameter List                              */
/*-------------------------------------------------------------------*/
typedef struct _HCPSBIOP {
        HWORD   devnum;                 /* Device number             */
        BYTE    akey;                   /* Bits 0-3=key, 4-7=zeroes  */
        BYTE    type;                   /* I/O request type          */
        FWORD   blksize;                /* Fixed block size          */
        FWORD   sbiaddr;                /* Address of SBILIST        */
        FWORD   sbicount;               /* Number of SBILIST entries */
        FWORD   blkcount;               /* Number of blocks processed*/
        BYTE    unitstat;               /* Device status             */
        BYTE    chanstat;               /* Subchannel status         */
        HWORD   residual;               /* Residual byte count       */
        BYTE    lpm;                    /* Logical path mask         */
        BYTE    resv1[5];               /* Reserved bytes, must be 0 */
        HWORD   sensecount;             /* Number of sense bytes     */
        BYTE    resv2[24];              /* Reserved bytes, must be 0 */
        BYTE    sense[32];              /* Sense bytes               */
    } HCPSBIOP;

/* Definitions for I/O request type */
#define HCPSBIOP_WRITE        0x01
#define HCPSBIOP_READ         0x02

/*-------------------------------------------------------------------*/
/* Synchronous General I/O Parameter List                            */
/*-------------------------------------------------------------------*/
typedef struct _HCPSGIOP {
        HWORD   devnum;                 /* Device number             */
        BYTE    akey;                   /* Bits 0-3=key, 4-7=zeroes  */
        BYTE    flag;                   /* Flags                     */
        FWORD   resv1;                  /* Reserved word, must be 0  */
        FWORD   ccwaddr;                /* Address of channel program*/
        FWORD   resv2;                  /* Reserved word, must be 0  */
        FWORD   lastccw;                /* CCW address at interrupt  */
        BYTE    unitstat;               /* Device status             */
        BYTE    chanstat;               /* Subchannel status         */
        HWORD   residual;               /* Residual byte count       */
        BYTE    lpm;                    /* Logical path mask         */
        BYTE    resv3[5];               /* Reserved bytes, must be 0 */
        HWORD   sensecount;             /* Number of sense bytes     */
        BYTE    resv4[24];              /* Reserved bytes, must be 0 */
        BYTE    sense[32];              /* Sense bytes               */
    } HCPSGIOP;

/* Bit definitions for flags */
#define HCPSGIOP_FORMAT1_CCW  0x80      /* 1=Format-1 CCW            */
#define HCPSGIOP_FLAG_RESV    0x7F      /* Reserved bits, must be 0  */

/*-------------------------------------------------------------------*/
/* DIAGNOSE X'24' and DIAGNOSE X'210' Structures and Table           */
/*-------------------------------------------------------------------*/

/* VM Device Class Definitions */
#define DC_TERM 0x80
#define DC_GRAF 0x40
#define DC_URI  0x20
#define DC_URO  0x10
#define DC_TAPE 0x08
#define DC_DASD 0x04
#define DC_SPEC 0x02
#define DC_FBA  0x01

/* VM Device Type Definitions */
#define DT_CTCA 0x80
#define DT_FBA  0x00
#define DT_OSA  0x20 /* Not yet supported */
#define DT_UNKN 0x01
#define DT_0671 0x20
#define DT_1052 0x00
#define DT_1403 0x41
#define DT_1442 0x88
#define DT_2305 0x02
#define DT_2311 0x80
#define DT_2314 0x40
#define DT_2501 0x81
#define DT_2703 0x40
#define DT_3211 0x42
#define DT_3215 0x00
#define DT_3277 0x04
#define DT_3287 0x02
#define DT_3310 0x01
#define DT_3330 0x10
#define DT_3340 0x01
#define DT_3350 0x08
#define DT_3370 0x02
#define DT_3375 0x04
#define DT_3380 0x20
#define DT_3390 0x82
#define DT_3410 0x08
#define DT_3420 0x10
#define DT_3422 0x82
#define DT_3430 0x02
#define DT_3480 0x01
#define DT_3490 0x81
#define DT_3505 0x84
#define DT_3525 0x84
#define DT_3590 0x83
#define DT_370x 0x40
#define DT_8809 0x04
#define DT_9332 0x08
#define DT_9335 0x04
#define DT_9336 0x40
#define DT_9345 0x81
#define DT_9347 0x84

/* VM Virtual Device Status Definitions */
#define DS_DED    0x01    /* Dedicated device          */
#define DS_BUSY   0x20    /* Device is busy            */

/* VM Virtual Device Flag Definitions */
#define DF_ENA     0x80   /* 270x line enabled         */
#define DF_CONN    0x40   /* 270x line connected       */
#define DF_RSRL    0x02   /* Reserve/Release supported */
#define DF_MIDAW   0x01   /* MIDAW's supported         */

/* VM Real Device Features */
#define DRF_RPS    0x80  /* Device has RPS             */
#define DRF_EXTSNS 0x40  /* Extended Sense             */
#define DRF_CTCA   0x40  /* CTCA device                */
#define DRF_35M    0x08  /* 3340 has 35M data module   */
#define DRF_70M    0x04  /* 3340 has 70M data module   */
#define DRF_RSRL   0x02  /* Reserve/Release valid      */

/*-------------------------------------------------------------------*/
/* Hercules-to-VM Device Table                                       */
/*-------------------------------------------------------------------*/
typedef struct _VMDEVTBL {
        U16     vmhtype;                /* Hercules device type      */
        BYTE    vmdevcls;               /* VM Device Class           */
        BYTE    vmdevtyp;               /* VM Device Type            */
        BYTE    vmdiags;                /* DIAGS recognizing device  */
#define VMDIAG024 0x80   /* Device recognized by DIAGNOSE X'24'      */
#define VMDIAG210 0x40   /* Device recognized by DIAGNOSE X'210'     */
    } VMDEVTBL;
#define VMDEV_SIZE sizeof(VMDEVTBL)

static VMDEVTBL vmdev[] = {
   DEV024(0x0671,DC_FBA, DT_0671),
   DEV024(0x1052,DC_TERM,DT_1052),
   DEV024(0x1403,DC_URO, DT_1403),
   DEV024(0x1442,DC_URI, DT_1442),
   DEV024(0x2305,DC_DASD,DT_2305),
   DEV024(0x2311,DC_DASD,DT_2311),
   DEV024(0x2314,DC_DASD,DT_2314),
   DEV024(0x2501,DC_URI, DT_2501),
   DEV024(0x2703,DC_TERM,DT_2703),
   DEV024(0x3088,DC_SPEC,DT_CTCA),
   DEV024(0x3211,DC_URI, DT_3211),
   DEV024(0x3215,DC_TERM,DT_3215),
   DEV024(0x3270,DC_GRAF,DT_3277),
   DEV024(0x3287,DC_GRAF,DT_3287),
   DEV024(0x3310,DC_FBA, DT_3310),
   DEV024(0x3330,DC_DASD,DT_3330),
   DEV024(0x3340,DC_DASD,DT_3340),
   DEV024(0x3350,DC_DASD,DT_3350),
   DEV024(0x3370,DC_FBA, DT_3370),
   DEV024(0x3375,DC_DASD,DT_3375),
   DEV024(0x3380,DC_DASD,DT_3380),
   DEV210(0x3390,DC_DASD,DT_3390),
   DEV024(0x3410,DC_TAPE,DT_3410),
   DEV024(0x3420,DC_TAPE,DT_3420),
   DEV024(0x3422,DC_TAPE,DT_3422),
   DEV024(0x3430,DC_TAPE,DT_3430),
   DEV024(0x3480,DC_TAPE,DT_3480),
   DEV210(0x3490,DC_TAPE,DT_3490),
   DEV024(0x3505,DC_URI, DT_3505),
   DEV024(0x3525,DC_URO, DT_3525),
   DEV024(0x3590,DC_TAPE,DT_3590),
   DEV024(0x3705,DC_SPEC,DT_370x),
   DEV024(0x8809,DC_TAPE,DT_8809),
   DEV024(0x9332,DC_FBA, DT_9332),
   DEV024(0x9335,DC_FBA, DT_9335),
   DEV024(0x9336,DC_FBA, DT_9336),
   DEV210(0x9345,DC_DASD,DT_9345),
   DEV024(0x9347,DC_TAPE,DT_9347)
};
#define VMDEV_NUM (sizeof(vmdev)/VMDEV_SIZE)

/*-------------------------------------------------------------------*/
/* Virtual Device Data                                               */
/*-------------------------------------------------------------------*/
typedef struct _VRDCVDAT {
        BYTE    vdevcls;                /* Virtual device class      */
        BYTE    vdevtyp;                /* Virtual device type       */
        BYTE    vdevstat;               /* Virtual device status     */
        BYTE    vdevflag;               /* Virtual device flag       */
    } VRDCVDAT;

/*-------------------------------------------------------------------*/
/* Real Device Data                                                  */
/*-------------------------------------------------------------------*/
typedef struct _VRDCRCDT {
        BYTE    rdevcls;                /* Real device class         */
        BYTE    rdevtyp;                /* Real device type          */
        BYTE    rdevmodl;               /* Real device model         */
        BYTE    rdevfeat;               /* Real device features      */
    } VRDCRCDT;

/*-------------------------------------------------------------------*/
/* Virtual/Real Device Characteristics Block                         */
/*-------------------------------------------------------------------*/
typedef struct _VRDCBLOK {
/*00*/  HWORD    vrdcdvno;       /* Device number                    */
/*02*/  HWORD    vrdclen;        /* VRDCBLOK length                  */
/*04*/  VRDCVDAT vrdcvdat;       /* Virtual device data              */
/*08*/  VRDCRCDT vrdcrcdt;       /* Real device data                 */
/*0C*/  BYTE     vrdcundv;       /* Real underlying device           */
/*0D*/  BYTE     vrdcrdaf;       /* Real device additional features  */
#define VRDCEMRD 0x02            /* No emulated real device          */
/*0E*/  HWORD    vrdcrsvd;       /* Reserved - must be zeros         */
/*10*/  BYTE     vrdcrdc[64];    /* READ DEVICE CHARACTERISTICS data */
/*50*/  BYTE     vrdcpgid[11];   /* Path Group Identifier            */
/*5B*/  BYTE     resv5[5];       /* reserved                         */
/*60*/  BYTE     vrdcvers;       /* version                          */
/*61*/  BYTE     vrdcrsio[31];   /* reserved for Input/Output        */
/*80*/  HWORD    vrdcrdev;       /* Real device number               */
/*82*/  BYTE     vrdcrsve[126];  /* reserverd                        */
/*100*/
   } VRDCBLOK;
#define VRDCBLOK_SIZE sizeof(VRDCBLOK)

#endif /*!defined(_VM_C)*/

/*-------------------------------------------------------------------*/
/* Internal Function Prototypes                                      */
/*-------------------------------------------------------------------*/
DEVBLK* ARCH_DEP(vmdevice_data)(int, U16, VRDCVDAT *, VRDCRCDT *);

/*-------------------------------------------------------------------*/
/* Provide VM Virtual and Real Device Data based upon device number  */
/*-------------------------------------------------------------------*/
DEVBLK* ARCH_DEP(vmdevice_data)(int code, U16 devnum, VRDCVDAT *vdat, VRDCRCDT *rdat)
{
U32      i;                      /* loop index                      */
VMDEVTBL *vmentry;               /* -> VMDEVTBL entry found         */
DEVBLK   *dev;                   /* -> DEVBLK                       */

    /* Clear vdat and rdat */
    memset (vdat, 0x00, sizeof(*vdat));
    memset (rdat, 0x00, sizeof(*rdat));

    /* Locate the device block */
    dev = find_device_by_devnum (0,devnum);
    
    /* Return 0 if device is not found */
    if (!dev)
       return 0;
    
    /* Indicate the device is dedicated - all Hercules devices are */
    vdat->vdevstat = DS_DED;

    /* Find the device in the VM table */
    vmentry=NULL;
    for (i = 0; i < (int)VMDEV_NUM; i++)
       {
#if 0
           logmsg ("vmdevice_data: i=%i %4.4X %2.2X %2.2X %2.2X\n",i,
                   vmdev[i].vmhtype,vmdev[i].vmdevcls,vmdev[i].vmdevtyp,vmdev[i].vmdiags);
#endif
           if (dev->devtype == vmdev[i].vmhtype)
           {
               vmentry = &vmdev[i];
               break;
           }
       }
#if 0
    logmsg ("FOUND: %4.4X %2.2X %2.2X %2.2X\n",
            vmentry->vmhtype,vmentry->vmdevcls,vmentry->vmdevtyp,vmentry->vmdiags);
#endif

    /* If device is not in the table or it isn't recognized by DIAG X'24' */
    if ( !vmentry || ( code==0x24 && !(vmentry->vmdiags & VMDIAG024 ) ) )
    {
        /* Set the real and virtual data to an unsupported device */
        vdat->vdevcls = DC_SPEC;
        vdat->vdevtyp = DT_UNKN;
        rdat->rdevcls = DC_SPEC;
        rdat->rdevtyp = DT_UNKN;
        return dev;
    }

    /* Set the virtual and real data to the device's VM class and type */
    vdat->vdevcls = vmentry->vmdevcls;
    vdat->vdevtyp = vmentry->vmdevtyp;
    rdat->rdevcls = vmentry->vmdevcls;
    rdat->rdevtyp = vmentry->vmdevtyp;

    /* Indicate if the device is busy */
    if ( (dev->busy && dev->ioactive == DEV_SYS_LOCAL) || dev->startpending )
        vdat->vdevstat |= DS_BUSY;
    
    /* Set virtual device flags, and real device model and features */
    vdat->vdevflag = 0x00;
    rdat->rdevmodl = 0x00;
    rdat->rdevfeat = 0x00;

    if (dev->hnd->reserve)           /* Indicate if RESERVE/RELEASE supported */
        vdat->vdevflag |= DF_RSRL;
    
#if defined(FEATURE_MIDAW)
    /* If DIAGNOSE X'210', indicate if MIDAW's are supported */ 
    if (code==0x210)
        vdat->vdevflag |= DF_MIDAW;
#endif /* FEATURE_MIDAW */

    switch (rdat->rdevcls) {
    case DC_DASD:
         if (dev->hnd->reserve)
            rdat->rdevfeat |= DRF_RSRL;
         if (dev->numsense==24)
            rdat->rdevfeat |= DRF_EXTSNS;
         if (dev->ckdtab->sectors)
            rdat->rdevfeat |= DRF_RPS;
         if (dev->devtype == 0x3340)
         {
            if (dev->ckdtab->model==0x01)
               rdat->rdevfeat |= DRF_35M;
            else
               rdat->rdevfeat |= DRF_70M;
         }
         if ( dev->devtype == 0x3380  && code == 0x24)
            rdat->rdevmodl = (dev->ckdtab->model & 0x0F) | (dev->ckdcu->model & 0xF0);
         else
            rdat->rdevmodl = dev->ckdtab->model;
         break;
     case DC_FBA:
         rdat->rdevmodl = dev->fbatab->model;
         break;
     case DC_TERM:
         if (dev->devtype==0x3215)
         {
            rdat->rdevfeat = 0x50;
            /* Note: 0x50 is carried forward from the previous version of       */
            /* DIAGNOSE X'24'. The actual meaning was not previously documented */
         }
         else
         {
            if (dev->devtype==0x2703 && dev->commadpt)
            {
                if (dev->commadpt->enabled)
                   vdat->vdevflag |= DF_ENA;
                if (dev->commadpt->connect)
                   vdat->vdevflag |= DF_CONN;
            }
         }
         break;
     case DC_SPEC:
         if (rdat->rdevtyp==DT_CTCA)
            rdat->rdevfeat = DRF_CTCA;
     }
     
     /* Return the located DEVBLK to the caller */
     return dev;

} /* end function vmdevice_data */

/*-------------------------------------------------------------------*/
/* Device Type and Features (Function code 0x024)                    */
/*-------------------------------------------------------------------*/
int ARCH_DEP(diag_devtype) (int r1, int r2, REGS *regs)
{
DEVBLK         *dev;                    /* -> Device block           */
U16             devnum;                 /* Device number             */
VRDCVDAT        vdat;                   /* Virtual device data       */
VRDCRCDT        rdat;                   /* Real device data          */

#if defined(FEATURE_ESAME)
     /* Program check if 64-bit addressing is being used. */
     if (regs->psw.amode64)
     {
         ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
     }
#endif /* FEATURE_ESAME */
    
    /* Return console information if R1 register is all ones */
    if (regs->GR_L(r1) == 0xFFFFFFFF)
    {
        for (dev = sysblk.firstdev; dev != NULL; dev = dev->nextdev)
            if ( dev->allocated 
                 && ( dev->devtype == 0x3215 || dev->devtype == 0x1503 )
               )
            {
                regs->GR_L(r1) = dev->devnum;
                break;
            }
    }

    /* Extract the device number from the R1 register */
    devnum = regs->GR_L(r1);

    /* Locate the device block and set the virtual and real device information */
    dev = ARCH_DEP(vmdevice_data) (0x24,devnum,&vdat,&rdat);

    /* Return condition code 3 if device does not exist */
    if (!dev) 
        return 3;

    /* Return virtual device information in the R2 register */
    FETCH_FW(regs->GR_L(r2),&vdat);

    /* Return real device information in the R2+1 register */
    if (r2 != 15)
        FETCH_FW(regs->GR_L(r2+1),&rdat);
#if 0
    logmsg ("Diagnose X\'024\':"
            "devnum=%4.4X VRDCVDAT=%8.8X VRDCRCDT=%8.8X\n",
            devnum, vdat, rdat);
#endif

    /* Return condition code 0 */
    return 0;

} /* end function diag_devtype */

/*-------------------------------------------------------------------*/
/* Process Synchronous Fixed Block I/O call (Function code 0x0A4)    */
/*-------------------------------------------------------------------*/
int ARCH_DEP(syncblk_io) (int r1, int r2, REGS *regs)
{
U32             i;                      /* Array subscript           */
U32             numsense;               /* Number of sense bytes     */
U32             iopaddr;                /* Address of HCPSBIOP       */
HCPSBIOP        ioparm;                 /* I/O parameter list        */
DEVBLK         *dev;                    /* -> Device block           */
U16             devnum;                 /* Device number             */
U16             residual;               /* Residual byte count       */
U32             blksize;                /* Fixed block size          */
U32             sbiaddr;                /* Addr of SBILIST           */
U32             sbicount;               /* Number of SBILIST entries */
U32             blkcount;               /* Number of blocks processed*/
U32             blknum;                 /* Block number              */
U32             absadr;                 /* Absolute storage address  */
BYTE            accum;                  /* Work area                 */
BYTE            unitstat = 0;           /* Device status             */
BYTE            chanstat = 0;           /* Subchannel status         */
BYTE            skey1, skey2;           /* Storage keys of first and
                                           last byte of I/O buffer   */
//FIXME: code not right for shared devices

    UNREFERENCED(r2);

    /* Register R1 contains the real address of the parameter list */
    iopaddr = regs->GR_L(r1);

    /* Program check if parameter list not on fullword boundary */
    if (iopaddr & 0x00000003)
    {
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        return 0;
    }

    /* Ensure that parameter list operand is addressable */
    ARCH_DEP(validate_operand) (iopaddr, USE_REAL_ADDR, sizeof(ioparm)-1,
                        ACCTYPE_WRITE, regs);

    /* Fetch the parameter list from real storage */
    ARCH_DEP(vfetchc) (&ioparm, sizeof(ioparm)-1, iopaddr, USE_REAL_ADDR, regs);

    /* Load numeric fields from the parameter list */
    devnum = (ioparm.devnum[0] << 8) | ioparm.devnum[1];
    blksize = (ioparm.blksize[0] << 24)
                | (ioparm.blksize[1] << 16)
                | (ioparm.blksize[2] << 8)
                | ioparm.blksize[3];
    sbiaddr = (ioparm.sbiaddr[0] << 24)
                | (ioparm.sbiaddr[1] << 16)
                | (ioparm.sbiaddr[2] << 8)
                | ioparm.sbiaddr[3];
    sbicount = (ioparm.sbicount[0] << 24)
                | (ioparm.sbicount[1] << 16)
                | (ioparm.sbicount[2] << 8)
                | ioparm.sbicount[3];

    /* Locate the device block */
    dev = find_device_by_devnum (0,devnum);

    /* Set return code 2 and cond code 1 if device does not exist
       or does not support the synchronous I/O call */
    if (dev == NULL || dev->devtype != 0x3370)
    {
        regs->GR_L(15) = 2;
        return 1;
    }

    /* Program check if protect key bits 4-7 are not zero
       or if I/O request type is not read or write */
    if ((ioparm.akey & 0x0F)
        || !(ioparm.type == HCPSBIOP_WRITE
            || ioparm.type == HCPSBIOP_READ))
    {
        ARCH_DEP(program_interrupt) (regs, PGM_OPERAND_EXCEPTION);
        return 0;
    }

    /* Set return code 8 and cond code 2 if blocksize is invalid */
    if (!(blksize == 512 || blksize == 1024
            || blksize == 2048 || blksize == 4096))
    {
        regs->GR_L(15) = 8;
        return 2;
    }

    /* Program check if SBILIST is not on a doubleword boundary */
    if (sbiaddr & 0x00000007)
    {
        ARCH_DEP(program_interrupt) (regs, PGM_OPERAND_EXCEPTION);
        return 0;
    }

    /* Program check if reserved fields are not zero */
    for (accum = 0, i = 0; i < sizeof(ioparm.resv1); i++)
        accum |= ioparm.resv1[i];
    for (i = 0; i < sizeof(ioparm.resv2); i++)
        accum |= ioparm.resv2[i];
    if (accum != 0)
    {
        ARCH_DEP(program_interrupt) (regs, PGM_OPERAND_EXCEPTION);
        return 0;
    }

    /* Set return code 11 and cond code 2 if SBI count is invalid */
    if (sbicount < 1 || sbicount > 500)
    {
        regs->GR_L(15) = 11;
        return 2;
    }

    /* Obtain the device lock */
    obtain_lock (&dev->lock);

#ifdef FEATURE_CHANNEL_SUBSYSTEM
    /* Return code 5 and condition code 1 if status pending */
    if ((dev->scsw.flag3 & SCSW3_SC_PEND)
        || (dev->pciscsw.flag3 & SCSW3_SC_PEND))
    {
        release_lock (&dev->lock);
        regs->GR_L(15) = 5;
        return 1;
    }
#endif /*FEATURE_CHANNEL_SUBSYSTEM*/

    /* Return code 5 and condition code 1 if device is busy */
    if (dev->busy || IOPENDING(dev))
    {
        release_lock (&dev->lock);
        regs->GR_L(15) = 5;
        return 1;
    }

    /* Set the device busy indicator */
    dev->busy = 1;

    /* Release the device lock */
    release_lock (&dev->lock);

    /* Process each entry in the SBILIST */
    for (blkcount = 0; blkcount < sbicount; blkcount++)
    {
        /* Return code 10 and cond code 2 if SBILIST entry
           is outside main storage or is fetch protected.
           Note that the SBI address is an absolute address
           and is not subject to fetch-protection override
           or storage-protection override mechanisms, and
           an SBILIST entry cannot cross a page boundary */
        if (sbiaddr > regs->mainlim
            || ((STORAGE_KEY(sbiaddr, regs) & STORKEY_FETCH)
                && (STORAGE_KEY(sbiaddr, regs) & STORKEY_KEY) != ioparm.akey
                && ioparm.akey != 0))
        {
            regs->GR_L(15) = 10;
            return 2;
        }

        /* Load block number and data address from SBILIST */
        blknum = ARCH_DEP(fetch_fullword_absolute)(sbiaddr, regs);
        absadr = ARCH_DEP(fetch_fullword_absolute)(sbiaddr+4, regs);

        if (dev->ccwtrace || dev->ccwstep)
        {
            logmsg ("%4.4X:Diagnose X\'0A4\':%s "
                    "blk=%8.8X adr=%8.8X len=%8.8X\n",
                    dev->devnum,
                    (ioparm.type == HCPSBIOP_WRITE ? "WRITE" : "READ"),
                    blknum, absadr, blksize);
        }

        /* Return code 12 and cond code 2 if buffer exceeds storage */
        if (absadr > regs->mainlim - blksize)
        {
            regs->GR_L(15) = 12;
            return 2;
        }

        /* Channel protection check if access key does not match
           storage keys of buffer.  Note that the buffer address is
           an absolute address, the buffer cannot span more than two
           pages, and the access is not subject to fetch-protection
           override, storage-protection override, or low-address
           protection */
        skey1 = STORAGE_KEY(absadr, regs);
        skey2 = STORAGE_KEY(absadr + blksize - 1, regs);
        if (ioparm.akey != 0
            && (
                   ((skey1 & STORKEY_KEY) != ioparm.akey
                    && ((skey1 & STORKEY_FETCH)
                        || ioparm.type == HCPSBIOP_READ))
                || ((skey2 & STORKEY_KEY) != ioparm.akey
                    && ((skey2 & STORKEY_FETCH)
                        || ioparm.type == HCPSBIOP_READ))
            ))
        {
            chanstat |= CSW_PROTC;
            break;
        }

        /* Call device handler to read or write one block */
        fbadasd_syncblk_io (dev, ioparm.type, blknum, blksize,
                            regs->mainstor + absadr,
                            &unitstat, &residual);

        /* Set incorrect length if residual count is non-zero */
        if (residual != 0)
            chanstat |= CSW_IL;

        /* Exit if any unusual status */
        if (unitstat != (CSW_CE | CSW_DE) || chanstat != 0)
            break;

        /* Point to next SBILIST entry */
        sbiaddr += 8;

    } /* end for(blkcount) */

    /* Reset the device busy indicator */
    dev->busy = 0;

    /* Store the block count in the parameter list */
    ioparm.blkcount[0] = (blkcount >> 24) & 0xFF;
    ioparm.blkcount[1] = (blkcount >> 16) & 0xFF;
    ioparm.blkcount[2] = (blkcount >> 8) & 0xFF;
    ioparm.blkcount[3] = blkcount & 0xFF;

    /* Store the device and subchannel status in the parameter list */
    ioparm.unitstat = unitstat;
    ioparm.chanstat = chanstat;

    /* Store the residual byte count in the parameter list */
    ioparm.residual[0] = (residual >> 8) & 0xFF;
    ioparm.residual[1] = residual & 0xFF;

    /* Return sense data if unit check occurred */
    if (unitstat & CSW_UC)
    {
        numsense = dev->numsense;
        if (numsense > sizeof(ioparm.sense))
            numsense = sizeof(ioparm.sense);
        ioparm.sensecount[0] = (numsense >> 8) & 0xFF;
        ioparm.sensecount[1] = numsense & 0xFF;
        memcpy (ioparm.sense, dev->sense, numsense);
    }

    /* Store the updated parameter list in real storage */
    ARCH_DEP(vstorec) (&ioparm, sizeof(ioparm)-1, iopaddr, USE_REAL_ADDR, regs);

    /* If I/O error occurred, set return code 13 and cond code 3 */
    if (unitstat != (CSW_CE | CSW_DE) || chanstat != 0)
    {
        regs->GR_L(15) = 13;
        return 3;
    }

    /* Set return code 0 and cond code 0 */
    regs->GR_L(15) = 0;
    return 0;

} /* end function syncblk_io */

/*-------------------------------------------------------------------*/
/* Process Synchronous General I/O call (Function code 0x0A8)        */
/*-------------------------------------------------------------------*/
int ARCH_DEP(syncgen_io) (int r1, int r2, REGS *regs)
{
U32             i;                      /* Array subscript           */
U32             numsense;               /* Number of sense bytes     */
U32             iopaddr;                /* Address of HCPSGIOP       */
HCPSGIOP        ioparm;                 /* I/O parameter list        */
DEVBLK         *dev;                    /* -> Device block           */
U16             devnum;                 /* Device number             */
U16             residual;               /* Residual byte count       */
U32             ccwaddr;                /* Address of channel program*/
U32             lastccw;                /* CCW address at interrupt  */
BYTE            accum;                  /* Work area                 */
BYTE            unitstat = 0;           /* Device status             */
BYTE            chanstat = 0;           /* Subchannel status         */

//FIXME: code not right for shared devices

    UNREFERENCED(r2);

    /* Register R1 contains the real address of the parameter list */
    iopaddr = regs->GR_L(r1);

    /* Program check if parameter list not on fullword boundary */
    if (iopaddr & 0x00000003)
    {
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        return 0;
    }

    /* Ensure that parameter list operand is addressable */
    ARCH_DEP(validate_operand) (iopaddr, USE_REAL_ADDR, sizeof(ioparm)-1,
                        ACCTYPE_WRITE, regs);

    /* Fetch the parameter list from real storage */
    ARCH_DEP(vfetchc) (&ioparm, sizeof(ioparm)-1, iopaddr, USE_REAL_ADDR, regs);

    /* Load numeric fields from the parameter list */
    devnum = (ioparm.devnum[0] << 8) | ioparm.devnum[1];
    ccwaddr = (ioparm.ccwaddr[0] << 24)
                | (ioparm.ccwaddr[1] << 16)
                | (ioparm.ccwaddr[2] << 8)
                | ioparm.ccwaddr[3];

    /* Locate the device block */
    dev = find_device_by_devnum (0,devnum);

    /* Set return code 1 and cond code 1 if device does not exist */
    if (dev == NULL)
    {
        regs->GR_L(15) = 1;
        return 1;
    }

    /* Program check if protect key bits 4-7 are not zero
       or if the reserved bits in the flag byte are not zero */
    if ((ioparm.akey & 0x0F) || (ioparm.flag & HCPSGIOP_FLAG_RESV))
    {
        ARCH_DEP(program_interrupt) (regs, PGM_OPERAND_EXCEPTION);
        return 0;
    }

#ifdef FEATURE_S370_CHANNEL
    /* Program check if flag byte specifies format-1 CCW */
    if (ioparm.flag & HCPSGIOP_FORMAT1_CCW)
    {
        ARCH_DEP(program_interrupt) (regs, PGM_OPERAND_EXCEPTION);
        return 0;
    }
#endif /*FEATURE_S370_CHANNEL*/

    /* Program check if CCW is not on a doubleword boundary,
       or if CCW address exceeds maximum according to CCW format */
    if ((ccwaddr & 0x00000007) || ccwaddr >
           ((ioparm.flag & HCPSGIOP_FORMAT1_CCW) ?
                        (U32)0x7FFFFFFF : (U32)0x00FFFFFF))
    {
        ARCH_DEP(program_interrupt) (regs, PGM_OPERAND_EXCEPTION);
        return 0;
    }

    /* Program check if reserved fields are not zero */
    for (accum = 0, i = 0; i < sizeof(ioparm.resv1); i++)
        accum |= ioparm.resv1[i];
    for (i = 0; i < sizeof(ioparm.resv2); i++)
        accum |= ioparm.resv2[i];
    for (i = 0; i < sizeof(ioparm.resv3); i++)
        accum |= ioparm.resv3[i];
    for (i = 0; i < sizeof(ioparm.resv4); i++)
        accum |= ioparm.resv4[i];
    if (accum != 0)
    {
        ARCH_DEP(program_interrupt) (regs, PGM_OPERAND_EXCEPTION);
        return 0;
    }

    /* Obtain the interrupt lock */
    obtain_lock (&dev->lock);

#ifdef FEATURE_CHANNEL_SUBSYSTEM
    /* Return code 5 and condition code 1 if status pending */
    if ((dev->scsw.flag3 & SCSW3_SC_PEND)
        || (dev->pciscsw.flag3 & SCSW3_SC_PEND))
    {
        release_lock (&dev->lock);
        regs->GR_L(15) = 5;
        return 1;
    }
#endif /*FEATURE_CHANNEL_SUBSYSTEM*/

    /* Return code 5 and condition code 1 if device is busy */
    if (dev->busy || IOPENDING(dev))
    {
        release_lock (&dev->lock);
        regs->GR_L(15) = 5;
        return 1;
    }

    /* Set the device busy indicator */
    dev->busy = 1;

    /* Release the device lock */
    release_lock (&dev->lock);

    /* Build the operation request block */                    /*@IWZ*/
    memset (&dev->orb, 0, sizeof(ORB));                        /*@IWZ*/
    STORE_FW(dev->orb.ccwaddr, ccwaddr);                       /*@IWZ*/
    dev->orb.flag4 = ioparm.akey & ORB4_KEY;                   /*@IWZ*/
    if (ioparm.flag & HCPSGIOP_FORMAT1_CCW)                    /*@IWZ*/
        dev->orb.flag5 |= ORB5_F;                              /*@IWZ*/

    /* Execute the channel program synchronously */
    ARCH_DEP(execute_ccw_chain) (dev);

    /* Obtain status, CCW address, and residual byte count */
#ifdef FEATURE_S370_CHANNEL
    lastccw = (dev->csw[1] << 16) || (dev->csw[2] << 8)
                || dev->csw[3];
    unitstat = dev->csw[4];
    chanstat = dev->csw[5];
    residual = (dev->csw[6] << 8) || dev->csw[7];
#endif /*FEATURE_S370_CHANNEL*/

#ifdef FEATURE_CHANNEL_SUBSYSTEM
    lastccw = (dev->scsw.ccwaddr[0] << 24)
                || (dev->scsw.ccwaddr[1] << 16)
                || (dev->scsw.ccwaddr[2] << 8)
                || dev->scsw.ccwaddr[3];
    unitstat = dev->scsw.unitstat;
    chanstat = dev->scsw.chanstat;
    residual = (dev->scsw.count[0] << 8) || dev->scsw.count[1];
#endif /*FEATURE_CHANNEL_SUBSYSTEM*/

    /* Clear the interrupt pending and device busy conditions */
    obtain_lock (&dev->lock);
    dev->busy = dev->pending = 0;
    dev->scsw.flag2 = 0;
    dev->scsw.flag3 = 0;
    release_lock (&dev->lock);

    /* Store the last CCW address in the parameter list */
    ioparm.lastccw[0] = (lastccw >> 24) & 0xFF;
    ioparm.lastccw[1] = (lastccw >> 16) & 0xFF;
    ioparm.lastccw[2] = (lastccw >> 8) & 0xFF;
    ioparm.lastccw[3] = lastccw & 0xFF;

    /* Store the device and subchannel status in the parameter list */
    ioparm.unitstat = unitstat;
    ioparm.chanstat = chanstat;

    /* Store the residual byte count in the parameter list */
    ioparm.residual[0] = (residual >> 8) & 0xFF;
    ioparm.residual[1] = residual & 0xFF;

    /* Return sense data if unit check occurred */
    if (unitstat & CSW_UC)
    {
        numsense = dev->numsense;
        if (numsense > sizeof(ioparm.sense))
            numsense = sizeof(ioparm.sense);
        ioparm.sensecount[0] = (numsense >> 8) & 0xFF;
        ioparm.sensecount[1] = numsense & 0xFF;
        memcpy (ioparm.sense, dev->sense, numsense);
    }

    /* Store the updated parameter list in real storage */
    ARCH_DEP(vstorec) (&ioparm, sizeof(ioparm)-1, iopaddr, USE_REAL_ADDR, regs);

    /* If I/O error occurred, set return code 13 and cond code 3 */
    if (unitstat != (CSW_CE | CSW_DE) || chanstat != 0)
    {
        regs->GR_L(15) = 13;
        return 3;
    }

    /* Return with condition code 0 and register 15 unchanged */
    return 0;

} /* end function syncgen_io */

/*-------------------------------------------------------------------*/
/* Store Extended Identification Code (Function code 0x000)          */
/*-------------------------------------------------------------------*/
void ARCH_DEP(extid_call) (int r1, int r2, REGS *regs)
{
int        i;                           /* Array subscript           */
int        ver, rel;                    /* Version and release number*/
U32        idaddr;                      /* Address of storage operand*/
U32        idlen;                       /* Length of storage operand */
BYTE       buf[40];                     /* Extended identification   */
#if defined( HAVE_GETLOGIN_R )
  #if !defined(LOGIN_NAME_MAX)  
    #define LOGIN_NAME_MAX 100
  #endif
char       unam[LOGIN_NAME_MAX+1];      /* User name                 */
#endif
char      *puser;                       /* Pointer to user name      */
BYTE       c;                           /* Character work area       */

    /* Load storage operand address from R1 register */
    idaddr = regs->GR_L(r1);

    /* Program check if operand is not on a doubleword boundary */
    if (idaddr & 0x00000007)
    {
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        return;
    }

    /* Load storage operand length from R2 register */
    idlen = regs->GR_L(r2);

    /* Program check if operand length is invalid */
    if (idlen < 1)
    {
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        return;
    }

    /* Bytes 0-7 contain the system name ("HERCULES" in EBCDIC) */
    get_lparname(buf);

    /* Bytes 8-9 contain the execution environment bits */
    buf[8] = 0x00;
    buf[9] = 0x00;

    /* Byte 10 contains the system product version number */
    sscanf (MSTRING(VERSION), "%d.%d", &ver, &rel);
    buf[10] = ver;

    /* Byte 11 contains version number from STIDP */
    buf[11] = sysblk.cpuid >> 56;

    /* Bytes 12-13 contain MCEL length from STIDP */
    buf[12] = (sysblk.cpuid >> 8) & 0xFF;
    buf[13] = sysblk.cpuid & 0xFF;

    /* Bytes 14-15 contain the CP address */
    buf[14] = (regs->cpuad >> 8) & 0xFF;
    buf[15] = regs->cpuad & 0xFF;

    /* Bytes 16-23 contain the userid in EBCDIC */
#if defined( HAVE_GETLOGIN_R )
    memset( unam, 0, sizeof(unam) );
    VERIFY( getlogin_r ( unam, sizeof(unam) ) == 0 );
    puser = unam;
#else
    puser = "";
#endif
    for (i = 0; i < 8; i++)
    {
        c = (*puser == '\0' ? SPACE : *(puser++));
        buf[16+i] = host_to_guest(toupper(c));
    }

    /* Bytes 24-31 contain the program product bitmap */
    memcpy (buf+24, "\x7F\xFE\x00\x00\x00\x00\x00\x00", 8);

    /* Bytes 32-35 contain the time zone differential */
    memset (buf+32, '\0', 4);

    /* Bytes 36-39 contain version, level, and service level */
    buf[36] = ver;
    buf[37] = rel;
    buf[38] = 0x00;
    buf[39] = 0x00;

#if 0
    logmsg ("Diagnose X\'000\':"
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X "
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X\n\t\t"
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X "
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X\n\t\t"
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X\n",
            buf[0], buf[1], buf[2], buf[3],
            buf[4], buf[5], buf[6], buf[7],
            buf[8], buf[9], buf[10], buf[11],
            buf[12], buf[13], buf[14], buf[15],
            buf[16], buf[17], buf[18], buf[19],
            buf[20], buf[21], buf[22], buf[23],
            buf[24], buf[25], buf[26], buf[27],
            buf[28], buf[29], buf[30], buf[31],
            buf[32], buf[33], buf[34], buf[35],
            buf[36], buf[37], buf[38], buf[39]);
#endif

    /* Enforce maximum length to store */
    if (idlen > sizeof(buf))
        idlen = sizeof(buf);

    /* Store the extended identification code at operand address */
    ARCH_DEP(vstorec) (buf, idlen-1, idaddr, USE_REAL_ADDR, regs);

    /* Deduct number of bytes from the R2 register */
    regs->GR_L(r2) -= idlen;

} /* end function extid_call */

/*-------------------------------------------------------------------*/
/* Process CP command (Function code 0x008)                          */
/*-------------------------------------------------------------------*/
int ARCH_DEP(cpcmd_call) (int r1, int r2, REGS *regs)
{
U32     i;                              /* Array subscript           */
U32     cc = 0;                         /* Condition code            */
U32     cmdaddr;                        /* Address of command string */
U32     cmdlen;                         /* Length of command string  */
U32     respadr;                        /* Address of response buffer*/
U32     maxrlen;                        /* Length of response buffer */
U32     resplen;                        /* Length of actual response */
BYTE    cmdflags;                       /* Command flags             */
#define CMDFLAGS_REJPASSW       0x80    /* Reject password in command*/
#define CMDFLAGS_RESPONSE       0x40    /* Return response in buffer */
#define CMDFLAGS_REQPASSW       0x20    /* Prompt for password       */
#define CMDFLAGS_RESERVED       0x1F    /* Reserved bits, must be 0  */
char    bufi[256];                      /* Command buffer (ASCIIZ)   */
char    bufo[257];                      /* Command buffer (ASCIIZ)   */
char    resp[256];                      /* Response buffer (ASCIIZ)  */
char    *dresp;                         /* Default response (ASCIIZ) */
int     freeresp;                       /* Flag to free resp bfr     */
U32     j,k;

    /* Obtain command address from R1 register */
    cmdaddr = regs->GR_L(r1);

    /* Obtain command length and flags from R2 register */
    cmdflags = regs->GR_L(r2) >> 24;
    cmdlen = regs->GR_L(r2) & 0x00FFFFFF;

    /* Program check if invalid flags, or if command string
       is too long, or if response buffer is specified and
       registers are consecutive or either register
       specifies register 15 */
    if ((cmdflags & CMDFLAGS_RESERVED) || cmdlen > sizeof(bufi)-1
        || ((cmdflags & CMDFLAGS_RESPONSE)
            && (r1 == 15 || r2 == 15 || r1 == r2 + 1 || r2 == r1 + 1)))
    {
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        return 0;
    }

    /* Put machine into stopped state if command length is zero */
    if (cmdlen == 0)
    {
        regs->opinterv = 0;
        regs->cpustate = CPUSTATE_STOPPED;
        ON_IC_INTERRUPT(regs);
        return 0;
    }

    /* Obtain the command string from storage */
    ARCH_DEP(vfetchc) (bufi, cmdlen-1, cmdaddr, USE_REAL_ADDR, regs);

    /* Prepend '-' if noecho is requested */
    i=0;
    if(!(sysblk.diag8cmd & DIAG8CMD_ECHO))
    {
        bufo[0]='-';
        i=1;
    }
    /* Translate EBCDIC command to ASCII */
    for (j=0; j < cmdlen; i++,j++)
    {
        bufo[i] = guest_to_host(bufi[j]);
    }
    bufo[i] = '\0';
    dresp="";
    freeresp=0;

    if(*bufo)
    {
#ifdef FEATURE_HERCULES_DIAGCALLS
        int shcmd = 0;
        {
            char* p = bufo;
            while (*p && isspace(*p)) p++;
            if ((*(p+0) == 's' || *(p+0) == 'S') &&
                (*(p+1) == 'h' || *(p+1) == 'H') && 
                isspace(*(p+2))) shcmd = 1;
        }
        if ((sysblk.diag8cmd & DIAG8CMD_ENABLE)
            && (!shcmd || !(sysblk.shcmdopt & (SHCMDOPT_DISABLE | SHCMDOPT_NODIAG8)))
        )
        {
            if(sysblk.diag8cmd & DIAG8CMD_ECHO)
                logmsgp (_("HHCVM001I *%s* panel command issued by guest\n"), bufo);
            if (cmdflags & CMDFLAGS_RESPONSE)
            {
                dresp=log_capture(panel_command,bufo);
                if(dresp!=NULL)
                {
                    freeresp=1;
                }
                else
                {
                    dresp="";
                }
            }
            else
            {
                panel_command(bufo);
                if(sysblk.diag8cmd & DIAG8CMD_ECHO)
                    logmsgp (_("HHCVM002I *%s* command complete\n"), bufo);
            }
        }
        else
        {
            if(sysblk.diag8cmd & DIAG8CMD_ECHO)
            {
                logmsgp (_("HHCVM005W *%s* panel command issued by guest (but disabled)\n"), bufo);
            }
            dresp=_("HHCVM003I Host command processing disabled by configuration statement");
        }
#else
            dresp=_("HHCVM004E Host command processing not included in engine build");
#endif
    }

    /* Store the response and set length if response requested */
    if (cmdflags & CMDFLAGS_RESPONSE)
    {
        if(!freeresp)
        {
                strlcpy (resp, dresp, sizeof(resp));
                dresp=resp;
        }
        resplen = strlen(dresp);
        for (i = 0; i < resplen; i++)
            dresp[i] = host_to_guest(dresp[i]);

        respadr = regs->GR_L(r1+1);
        maxrlen = regs->GR_L(r2+1);

        i=(resplen<=maxrlen) ? resplen : maxrlen;
        j=0;
        while(i>0)
        {
            k=(i<255 ? i : 255);
            ARCH_DEP(vstorec) (&dresp[j], k-1 , respadr+j, USE_REAL_ADDR, regs);
            i-=k;
            j+=k;
        }
        regs->GR_L(r2+1) = (resplen<=maxrlen) ? resplen : resplen-maxrlen;
        cc = (resplen<=maxrlen) ? 0 : 1;
    }
    if(freeresp)
    {
        free(dresp);
    }

    /* Set R2 register to CP completion code */
    regs->GR_L(r2) = 0;

    /* Return condition code */
    return cc;

} /* end function cpcmd_call */

/*-------------------------------------------------------------------*/
/* Access Re-IPL data (Function code 0x0B0)                          */
/*-------------------------------------------------------------------*/
void ARCH_DEP(access_reipl_data) (int r1, int r2, REGS *regs)
{
U32     bufadr;                         /* Real addr of data buffer  */
U32     buflen;                         /* Length of data buffer     */

    /* Obtain buffer address and length from R1 and R2 registers */
    bufadr = regs->GR_L(r1);
    buflen = regs->GR_L(r2);

    /* Program check if buffer length is negative */
    if ((S32)buflen < 0)
    {
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        return;
    }

    /* Store IPL information if buffer length is non-zero */
    if (buflen > 0)
    {
        /* Store one byte of zero to indicate no IPL information */
        ARCH_DEP(vstoreb) (0, bufadr, USE_REAL_ADDR, regs);
    }

    PTT(PTT_CL_ERR,"*DIAG0B0",regs->GR_L(r1),regs->GR_L(r2),regs->psw.IA_L);

    /* Return code 4 means no re-IPL information available */
    regs->GR_L(r2) = 4;

} /* end function access_reipl_data */

/*-------------------------------------------------------------------*/
/* Access Device Information (Function code 0x210)                   */
/*-------------------------------------------------------------------*/
/* Note: This implementation emulates z/VM 5.4                       */
int  ARCH_DEP(device_info) (int r1, int r2, REGS *regs)
{
DEVBLK   *dev;             /* -> Device block                        */
VRDCBLOK vrdc;             /* VRDCBLOK                               */
RADR     blokaddr;         /* Location of the VRDCBLOK               */
U16      bloklen;          /* Length from the VRDCBLOK               */
#if 0 
/* Only required if implementation is for the z/VM 5.3 level */
U16      reserved;         /* Bytes 14 and 15                        */
#endif 
U16      devnum;           /* Device number from the VRDCBLOK        */


    UNREFERENCED(r2);

    if (regs->GR_L(r1) & 0x3
#if defined(FEATURE_ESAME)
        || (regs->psw.amode64)
#endif /* FEATURE_ESAME */
       )
    {
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
    }
    
    blokaddr = regs->GR_L(r1);

    /* Fetch the first 4 bytes of the VRDCBLOK */
    ARCH_DEP(vfetchc) (&vrdc, 3, blokaddr, USE_REAL_ADDR, regs);

    /* Get the VRDCBLOK length from the working VRDC */
    FETCH_HW(bloklen,&vrdc.vrdclen);

    /* VRDCBLOK length must be at least 8 bytes */
    if (bloklen<8)
    {
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
    }

    /* Fetch remainder of supplied VRDCBLOK, but no more */
    if (bloklen>VRDCBLOK_SIZE)
       bloklen=VRDCBLOK_SIZE;
    ARCH_DEP(vfetchc) (&vrdc.vrdcvdat,bloklen-5,blokaddr+4, USE_REAL_ADDR, regs);

#if 0
    /* If length is 16 or greater, bytes 14 and 15 must be zero on z/VM 5.3.0 or earlier */
    if ( bloklen>=16)
    {
         FETCH_HW(reserved,&vrdc.vrdcrsvd);
         if (reserved != 0)
         {
              ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
         }
    }
#endif

    /* Get the device number from the working VRDC */
    FETCH_HW(devnum,&vrdc.vrdcdvno);

    /* Locate the device block and set the virtual and real device information */
    dev = ARCH_DEP(vmdevice_data) (0x210,devnum,&vrdc.vrdcvdat,&vrdc.vrdcrcdt);

    /* Return condition code 3 if device does not exist */
    if (!dev)
    {
        PTT(PTT_CL_ERR,"*DIAG210",regs->GR_L(r1),regs->GR_L(r2),regs->psw.IA_L);
        return 3;
    }
    
    /* Set the underlying device and real device features */
    vrdc.vrdcundv=0x00;
    vrdc.vrdcrdaf=0x00;

    /* Create device dependent mappings */
    if (vrdc.vrdcvdat.vdevcls == DC_DASD)
    {
        memcpy(&vrdc.vrdcrdc,dev->devchar,42);
        switch (dev->devtype)
        {
             case 0x2311:
             case 0x2314:
             case 0x2305:
             case 0x3330:
             case 0x3340:
             case 0x3350:
                  /* Set non-keyed overhead */
                  STORE_HW(&vrdc.vrdcrdc[0x18],dev->ckdtab->f2);
                  /* Set keyed overhead */
                  STORE_HW(&vrdc.vrdcrdc[0x1A],dev->ckdtab->f1);
             /* Note: for all other DASD devices these fields contain bytes 24-27 of the RDC */
        }
        /* Set Control Unit ID */
        vrdc.vrdcrdc[0x2A]=dev->devchar[56];
    }
    else if (vrdc.vrdcvdat.vdevcls == DC_FBA)
        memcpy(&vrdc.vrdcrdc,dev->devchar,32);
    
    /* Set Path Group ID */
    memcpy(&vrdc.vrdcpgid,dev->pgid,11);

    /* Set version */
    if (bloklen>0x60)
       vrdc.vrdcvers=0x01;

    /* Set underlying real device */
    if (!(vrdc.vrdcrdaf & VRDCEMRD))
       memcpy(&vrdc.vrdcrdev,&vrdc.vrdcdvno,2);

    /* Update the VRDC in main storage */
    ARCH_DEP(vstorec) (&vrdc, bloklen-1, blokaddr, USE_REAL_ADDR, regs);

    /* Return condition code 0 for success */
    return 0;

} /* end function device_info */


/*-------------------------------------------------------------------*/
/* Access Certain Virtual Machine Information (Function code 0x260)  */
/*-------------------------------------------------------------------*/
/* Note: This implementation emulates z/VM 5.4                       */
void ARCH_DEP(vm_info) (int r1, int r2, REGS *regs)
{
DEVBLK  *dev;                          /* -> Device block            */
U16     devnum;                        /* Device number              */
#if defined(FEATURE_ESAME)
RADR    stgarea;                       /* Storage extent area        */
S64     stglen;                        /* Storage extent area length */
#endif /* FEATURE_ESAME */

    /* Ry contains the subcode */
    switch(regs->GR_L(r2))
    {
    case 0x00000000: /* Highest addressable byte */
#if defined(FEATURE_ESAME)

        /* Program check if running in z/Architecture mode and */
        /* 64-bit addressing is being used.                    */
        if (regs->psw.amode64)
        {
            ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        }
#endif /* FEATURE_ESAME */
        regs->GR_L(r1) = regs->mainlim; /* provide highest addressable byte */
        return;

    case 0x00000004: /* Provide BYUSER ID value */
            
        /* Program check if Rx and Ry are the same registers or        */
        /* or Ry is not an even register or the address provided       */
        /* in Rx is not on a doubleword boundary or if running         */
        /* in z/Architecture mode and 64-bit addressing is being used. */
        if ( r1 == r2 || r2 & 0x1 || regs->GR_L(r1) & 0x7
#if defined(FEATURE_ESAME)
             || (regs->psw.amode64)
#endif /* FEATURE_ESAME */
           )
        {
            ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        }
        regs->GR_L(r2+1)=0x4; /* Indicate no BYUSER ID for Hercules */
        return;
        
    case 0x00000008: /* Return number of lines per page */
#if defined(FEATURE_ESAME)

        /* Program check if running in z/Architecture mode and */
        /* 64-bit addressing is being used.                    */
        if (regs->psw.amode64)
        {
            ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        }
#endif /* FEATURE_ESAME */

        /* Get the device number from the Rx register */
        devnum=regs->GR_LHL(r1);
       
        /* Locate the device block */
        dev = find_device_by_devnum(0,devnum);

        /* Set 0 lines per page for a valid printer or console (meaning SPOOL is OFF) */
        if (dev != NULL &&
              (dev->devtype == 0x1403 ||
               dev->devtype == 0x3211 ||
               dev->devtype == 0x1052 ||
               dev->devtype == 0x3215 )
            )
        {
           regs->GR_L(r1) = 0; /* Set zero lines per page */
           regs->GR_L(r2) = 0; /* Set return code to indicate a valid device */
        }
        else
        {
           regs->GR_L(r2) = 4; /* Set return code to indicate an invalid device */
        }
        return;
        
#if defined(FEATURE_ESAME)
    case 0x0000000C: /* Return highest addressable byte for z/Architecture machine */
         regs->GR_G(r1) = regs->mainlim;
         regs->GR_G(r2) = regs->mainlim;
         return;

    case 0x00000010: /* Set storage extent */
            
         /* Obtain the storage extent area real address from Rx */
         /* and its length from Rx+1                            */
         stgarea=regs->GR_G(r1);
         stglen=regs->GR_G(r1+1); /* Length is treated as a signed value */
         
         /* Program check if Rx is not an even register or the address */
         /* provided in Rx is not on a quadword boundary or the length */
         /* provided in Rx+1 is not positive or not a multiple of 16   */
         if ( r1 & 1 || stgarea & 0xF || stglen <= 0 || stglen & 0xF )
         {
             ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
         }
         
         /* Convert real addres to absolute address */
         stgarea=APPLY_PREFIXING(stgarea,regs->PX );
         
         /* Check to ensure extent information can be stored */
         if (stgarea > regs->mainlim - 16)
         {
             regs->program_interrupt (regs, PGM_ADDRESSING_EXCEPTION);
         }
         /* Set start of storage extent to zero */
         ARCH_DEP(store_doubleword_absolute)(0,stgarea,regs); 
         /* Set end of storage extent to last addressable byte of main storage */
         ARCH_DEP(store_doubleword_absolute)(regs->mainlim,stgarea+8,regs);
         /* Set number of extents to 1 in Ry */
         regs->GR_G(r2) = 1;
         /* Indicate all extents returned */
         regs->psw.cc = 0;
         return;
#endif /* FEATURE_ESAME */

    default: /* Invalid subcode */
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
    }
}


/*-------------------------------------------------------------------*/
/* Pseudo Timer Extended (Function code 0x270)                       */
/* Pseudo Timer (Function code 0x00C)                                */
/*-------------------------------------------------------------------*/
void ARCH_DEP(pseudo_timer) (U32 code, int r1, int r2, REGS *regs)
{
int     i;                              /* Array subscript           */
time_t  timeval;                        /* Current time              */
struct  tm *tmptr;                      /* -> Current time structure */
U32     bufadr;                         /* Real addr of data buffer  */
U32     buflen;                         /* Length of data buffer     */
char    buf[64];                        /* Response buffer           */
BYTE    dattim[64];                     /* Date and time (EBCDIC)    */
#define DIAG_DATEFMT_SHORT      0x80    /* Date format mm/dd/yy      */
#define DIAG_DATEFMT_FULL       0x40    /* Date format mm/dd/yyyy    */
#define DIAG_DATEFMT_ISO        0x20    /* Date format yyyy-mm-dd    */
#define DIAG_DATEFMT_SYSDFLT    0x10    /* System-wide default format*/
static  char timefmt[]="%m/%d/%y%H:%M:%S%m/%d/%Y%Y-%m-%d";

    /* Get the current date and time in EBCDIC */
    timeval = time(NULL);
    tmptr = localtime(&timeval);
    strftime((char *)dattim, sizeof(dattim), timefmt, tmptr);
    for (i = 0; dattim[i] != '\0'; i++)
        dattim[i] = host_to_guest(dattim[i]);

    /* Obtain buffer address and length from R1 and R2 registers */
    bufadr = regs->GR_L(r1);
    buflen = regs->GR_L(r2);

    /* Use length 32 if R2 is zero or function code is 00C */
    if (r2 == 0 || code == 0x00C)
        buflen = 32;

    /* Program check if R1 and R2 specify the same non-zero
       register number, or if buffer length is less than or
       equal to zero, or if buffer address is zero, or if
       buffer is not on a doubleword boundary */
    if ((r2 != 0 && r2 == r1)
        || (S32)buflen <= 0
        || bufadr == 0
        || (bufadr & 0x00000007))
    {
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        return;
    }

    /* Build the response buffer */
    memset (buf, 0x00, sizeof(buf));
    /* Bytes 0-7 contain the date as EBCDIC MM/DD/YY */
    memcpy (buf, dattim, 8);
    /* Bytes 8-15 contain the time as EBCDIC HH:MM:SS */
    memcpy (buf+8, dattim+8, 8);
    /* Bytes 16-23 contain the virtual CPU time used in microseconds */
    /* Bytes 24-31 contain the total CPU time used in microseconds */
    /* Bytes 32-41 contain the date as EBCDIC MM/DD/YYYY */
    memcpy (buf+32, dattim+16, 10);
    /* Bytes 42-47 contain binary zeroes */
    /* Bytes 48-57 contain the date as EBCDIC YYYY-MM-DD */
    memcpy (buf+48, dattim+26, 10);
    /* Byte 58 contains the diagnose 270 version code */
    buf[58] = 0x01;
    /* Byte 59 contains the user's default date format */
    buf[59] = DIAG_DATEFMT_ISO;
    /* Byte 60 contains the system default date format */
    buf[60] = DIAG_DATEFMT_ISO;
    /* Bytes 61-63 contain binary zeroes */

#if 0
    logmsg ("Diagnose X\'%3.3X\':"
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X "
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X\n\t\t"
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X "
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X\n\t\t"
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X "
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X\n\t\t"
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X "
            "%2.2X%2.2X%2.2X%2.2X %2.2X%2.2X%2.2X%2.2X\n",
            code, buf[0], buf[1], buf[2], buf[3],
            buf[4], buf[5], buf[6], buf[7],
            buf[8], buf[9], buf[10], buf[11],
            buf[12], buf[13], buf[14], buf[15],
            buf[16], buf[17], buf[18], buf[19],
            buf[20], buf[21], buf[22], buf[23],
            buf[24], buf[25], buf[26], buf[27],
            buf[28], buf[29], buf[30], buf[31],
            buf[32], buf[33], buf[34], buf[35],
            buf[36], buf[37], buf[38], buf[39],
            buf[40], buf[41], buf[42], buf[43],
            buf[44], buf[45], buf[46], buf[47],
            buf[48], buf[49], buf[50], buf[51],
            buf[52], buf[53], buf[54], buf[55],
            buf[56], buf[57], buf[58], buf[59],
            buf[60], buf[61], buf[63], buf[63]);
#endif

    /* Enforce maximum length to store */
    if (buflen > sizeof(buf))
        buflen = sizeof(buf);

    /* Store the response buffer at the operand location */
    ARCH_DEP(vstorec) (buf, buflen-1, bufadr, USE_REAL_ADDR, regs);

} /* end function pseudo_timer */

/*-------------------------------------------------------------------*/
/* Pending Page Release (Function code 0x214)                        */
/*-------------------------------------------------------------------*/
int ARCH_DEP(diag_ppagerel) (int r1, int r2, REGS *regs)
{
U32     abs, start, end;                /* Absolute frame addresses  */
BYTE    skey;                           /* Specified storage key     */
BYTE    func;                           /* Function code...          */
#define DIAG214_EPR             0x00    /* Establish pending release */
#define DIAG214_CPR             0x01    /* Cancel pending release    */
#define DIAG214_CAPR            0x02    /* Cancel all pending release*/
#define DIAG214_CPRV            0x03    /* Cancel and validate       */

    /* Program check if R1 is not an even-numbered register */
    if (r1 & 1)
    {
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        return 0;
    }

    /* Extract the function code from R1+1 register bits 24-31 */
    func = regs->GR_L(r1+1) & 0xFF;

    /* Extract the start/end addresses from R1 and R1+1 registers */
    start = regs->GR_L(r1) & STORAGE_KEY_PAGEMASK;
    end = regs->GR_L(r1+1) & STORAGE_KEY_PAGEMASK;

    /* Validate start/end addresses if function is not CAPR */
    if (func != DIAG214_CAPR
        && (start > end || end > regs->mainlim))
    {
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        return 0;
    }

    /* Process depending on function code */
    switch (func)
    {
    case DIAG214_EPR:  /* Establish Pending Release */
        break;

    case DIAG214_CPR:  /* Cancel Pending Release */
    case DIAG214_CPRV: /* Cancel Pending Release and Validate */

        /* Do not set storage keys if R2 is register 0 */
        if (r2 == 0) break;

        /* Obtain key from R2 register bits 24-28 */
        skey = regs->GR_L(r2) & (STORKEY_KEY | STORKEY_FETCH);

        /* Set storage key for each frame within specified range */
        for (abs = start; abs <= end; abs += STORAGE_KEY_PAGESIZE)
        {
            STORAGE_KEY(abs, regs) &= ~(STORKEY_KEY | STORKEY_FETCH);
            STORAGE_KEY(abs, regs) |= skey;
        } /* end for(abs) */

        break;

    case DIAG214_CAPR:  /* Cancel All Pending Releases */
        break;

    default:            /* Invalid function code */
        ARCH_DEP(program_interrupt) (regs, PGM_SPECIFICATION_EXCEPTION);
        return 0;
    } /* end switch(func) */

    /* Return condition code zero */
    return 0;

} /* end function diag_ppagerel */


/*-------------------------------------------------------------------*/
/* B2F0 IUCV  - Inter User Communications Vehicle                [S] */
/*-------------------------------------------------------------------*/
DEF_INST(inter_user_communication_vehicle)
{
int     b2;                             /* Effective addr base       */
VADR    effective_addr2;                /* Effective address         */

    S(inst, regs, b2, effective_addr2);
#if defined(FEATURE_ECPSVM)
    if(ecpsvm_doiucv(regs,b2,effective_addr2)==0)
    {
        return;
    }
#endif


    /* Program check if in problem state,
       the IUCV instruction generates an operation exception
       rather then a priviliged operation exception when
       executed in problem state                                 *JJ */
    if ( PROBSTATE(&regs->psw) )
        ARCH_DEP(program_interrupt) (regs, PGM_OPERATION_EXCEPTION);

    SIE_INTERCEPT(regs);

    if( HDC3(debug_iucv, b2, effective_addr2, regs) )
        return;

    PTT(PTT_CL_ERR,"*IUCV",b2,effective_addr2,regs->psw.IA_L);

    /* Set condition code to indicate IUCV not available */
    regs->psw.cc = 3;

}

#endif /*FEATURE_EMULATE_VM*/


#if !defined(_GEN_ARCH)

#if defined(_ARCHMODE2)
 #define  _GEN_ARCH _ARCHMODE2
 #include "vm.c"
#endif

#if defined(_ARCHMODE3)
 #undef   _GEN_ARCH
 #define  _GEN_ARCH _ARCHMODE3
 #include "vm.c"
#endif

#endif /*!defined(_GEN_ARCH)*/