-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathda.rex
6382 lines (6128 loc) · 269 KB
/
da.rex
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
/*REXX*/
/* DA - z/OS Disassembler Edit Macro v3.0
Copyright (c) 2019-2020, Andrew J. Armstrong
All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Author:
Andrew J. Armstrong <androidarmstrong@gmail.com>
*/
/*REXX*****************************************************************
** **
** NAME - DA **
** **
** TITLE - DISASSEMBLER EDIT MACRO **
** **
** FUNCTION - Disassembles the AMBLIST output (or printable hex) **
** that is currently being edited. **
** **
** This is usually an iterative process: **
** **
** 1. Run DA on the AMBLIST output. This will help to **
** identify which areas are data and which are code. **
** **
** If you see a comment in the output like "<-- TODO **
** (not code)" it means that the disassembler was in **
** CODE parsing mode but detected an invalid instruc- **
** tion. You should insert a "." to switch the dis- **
** assembler into DATA parsing mode at that point, and **
** then insert a "," to revert to CODE mode at the end **
** of that block of data. **
** **
** 2. Mark the beginning of areas known to be code with a **
** "," and those known to be data with a "." (i.e. **
** Comma-for-Code, Dot-for-Data). **
** Run DA again until no 'TODO' comments are seen. **
** **
** 3. Tag the AMBLIST output (much more detail below). **
** Run DA again until the result is satisfactory. **
** Tags are enclosed in parentheses and can be used **
** to: **
** **
** - Mark data areas as having particular data types. **
** **
** For example: **
** (F) 00000010 (H) 00220023 (X) 0102(P)19365C (B)8F **
** **
** Generates: **
** DC F'16' **
** DC H'34' **
** DC H'35' **
** DC XL2'0102' **
** DC PL3'19365' **
** DC B'10001111' **
** **
** - Assign a label at an offset into the code. **
** **
** For example: **
** 18CF(myLabel)47F0C010 **
** **
** Generates: **
** LR R12,R15 **
** myLabel B 16(,R12) **
** **
** - Explicitly assign a label to a code offset: **
** **
** For example: **
** (myLabel=2,myData=6)18CF47F0C010.1234 **
** **
** Generates: **
** LR R12,R15 **
** myLabel B 16(,R12) **
** myData DC XL2'1234' **
** **
** - Specify/drop a base register for the subsequent **
** code. **
** **
** For example: **
** (R12)18CF47F0C002(R12=) **
** **
** Generates: **
** USING *,R12 **
** LR R12 **
** L2 B L2 **
** DROP R12 **
** **
** - Specify a base register for a named DSECT. This **
** is very powerful because it causes a DSECT to **
** be built containing fields for each displacement **
** off that base register that is referenced by the **
** code. The name of each field is derived from the **
** displacement. **
** **
** For example: **
** (R13=>WA)5810D010 5010D044 (R13=) **
** **
** Generates: **
** USING WA,R13 **
** L R1,WA_10 **
** ST R1,WA_44 **
** DROP R13 **
** WA DSECT **
** DS XL16 **
** WA_10 DS XL4 **
** DS XL48 **
** WA_44 DS XL4 **
** **
** - Do some other useful things (see below) **
** **
** 4. Assemble the disassembled source file. You will **
** likely see some assembly error messages like: **
** **
** ** ASMA044E Undefined symbol - L12C **
** **
** ...which is easily resolved by going back to the **
** AMBLIST output and inserting a "." (for data) at **
** offset +12C. That will create the missing label **
** (L12C) at that offset. **
** **
** Rerun DA and reassemble the output until all **
** assembly errors are resolved. **
** **
** **
** **
** If DA is invoked outside of the ISPF editor then it **
** will generate and edit an AMBLIST job that you can **
** submit to produce a module listing that can be read **
** by the DA macro. For example, the following command **
** will generate JCL to list module IEFBR14: **
** **
** TSO DA SYS1.LPALIB(IEFBR14) **
** **
** If DA is invoked in an ISPF edit session with the TEST **
** option, e.g. "DA (TEST", then an assembler source file **
** is generated containing one valid assembler statement **
** for each instruction. This can be assembled into a **
** load module, printed with AMBLIST and used to check **
** that DA can disassemble all instructions correctly. **
** **
** SYNTAX - DA [dsn | hex] [(options...] **
** **
** Where, **
** dsn = Load module to be printed using AMBLIST. The **
** dataset name must be fully qualified and **
** include the module name in parentheses. **
** **
** hex = Hex to be disassembled. If this is omitted **
** then the hex is read from the file being **
** edited. **
** **
** **
** options = **
** **
** STAT - Generate instruction format and mnemonic **
** usage statistics. **
** **
** TEST - Generate a source file to exercise the **
** assembler. When assembled into a module, the **
** result can be used to test the disassembler. **
** **
** ASM - Generate an assembly job that you can submit **
** to verify the disassembled source is valid. **
** **
** 360 - Disassemble using the System/360 instruction **
** set. **
** **
** 370 - Disassemble using the System/370 instruction **
** set. **
** **
** 390 - Disassemble using the System/390 instruction **
** set. **
** **
** Z - Disassemble using the z/Architecture **
** instruction set (this is the default). **
** **
** **
** LOGIC - 1. Read the hex input file and extract the hex and any **
** tags describing the hex. Create tags to label each **
** CSECT name found (if any). **
** **
** 2. Disassemble the hex producing a list of machine **
** instructions (code) or Define Constant (DC) **
** directives (data) - along with the corresponding **
** hex offset of each. If the user has specified tags **
** of the format (Rnn=>dsect) then build a DSECT for **
** each offset from the associated base register(s). **
** **
** 3. Build a list of references to storage locations **
** with the data type and length either inferred from **
** the machine instruction, or explicitly specified by **
** the user having supplied a tag for that location. **
** **
** 4. Cycle through the statement list and apply a label **
** if a statement is referenced. The label can be **
** either explicitly specified by the user via a tag, **
** or automatically generated based on the location. **
** **
** 5. Cycle through the storage reference list, and for **
** each referenced location that has no label, emit a **
** comment saying that an undefined label was detect- **
** ed and insert a (.xxx) tag in the original hex **
** input file to account for the missing label. Warn **
** the user to rerun DA to pick up the extra inserted **
** tags. **
** **
** 6. For labels that cannot be assigned by this process, **
** for example self-modifying code, emit an EQU **
** statement for each undefined label in order to **
** avoid assembly errors. **
** **
** **
** **
** NOTES - 1. As new instructions are added to the z/Series inst- **
** ruction set, it will be necessary to define them in **
** the comments below marked by BEGIN-xxx and END-xxx **
** comments. Otherwise the new instructions will be **
** treated as data. **
** **
** 2. A handy way to initially tag the AMBLIST output is **
** to issue the following EDIT commands: **
** **
** C 90EC ("")90EC ALL; C 07FE 07FE('') ALL **
** **
** This will highlight subroutines bounded by the **
** usual STM R14,R12,12(R13) and BR R14 instructions. **
** **
** **
** **
** USAGE - **
** **
BEGIN-JCL-COMMENTS
** To disassemble a load module: **
** **
** 0. Run TSO DA to generate and edit an AMBLIST job. For example: **
** TSO DA SYS1.LPALIB(IEFBR14) **
** **
** 1. Submit the AMBLIST job to print a dump of the selected module **
** **
** 2. Edit the SYSPRINT output (e.g. issue SE in SDSF) **
** **
** 3. Optionally, exclude areas that you do not want disassembled. **
** That may help speed up disassembly of large modules. **
** **
** 4. Optionally, mark blocks of hex using action markers. **
** **
** Action markers are a quick way to mark blocks of hex as being **
** either CODE or DATA. **
** **
** The following action markers can be inserted: **
** **
** Action Meaning **
** --------- ---------------------------------------------------- **
** , Scan following hex as CODE. **
** Remember: Comma=Code **
** **
** . Scan following hex as DATA. **
** Remember: Dot=Data **
** **
** / Reset to automatic data type detection and scan the **
** following hex as DATA. This is equivalent to speci- **
** fying a null tag () but saves a keystroke. **
** **
** 5. Optionally, tag the hex more rigorously: **
** **
** Tags are a way to further clarify how CODE or DATA blocks **
** should be interpreted. The syntax for a tag is: **
** **
** (tag,...) One or more case sensitive tags separated by commas **
** and enclosed in parentheses. For example: **
** **
** (MYCSECT,R12) **
** **
** ...means label the data following MYCSECT and assume **
** that R12 points to it at runtime. **
** **
** (R12=,F) **
** **
** ...means that R12 no longer points to anything and **
** that the data following should be interpreted as **
** fullword constants. **
** **
** The following tags can be inserted: **
** **
** (tag) Meaning **
** --------- ---------------------------------------------------- **
** **
** ('comment') Inserts a comment into the generated source file **
** with the format: **
** **
** *--------------------------------------------------* **
** * comment **
** *--------------------------------------------------* **
** **
** A good use for this is to mark the end of subrout- **
** ines by making a global change to the hex input data **
** as follows: **
** C 07FE 07FE('') ALL **
** ...which will cause an empty comment to be inserted **
** after every BR R14 instruction. **
** **
** **
** ("comment") Inserts a comment into the generated source file **
** with the format: **
** **
** **************************************************** **
** * * **
** * comment * **
** * * **
** **************************************************** **
** **
** A good use for this is to mark the start of subrout- **
** ines by making a global change to the hex input data **
** as follows: **
** C 90EC ("")90EC ALL **
** ...which will cause an empty section heading to be **
** inserted before each STM R14,R12,x(Rn) instruction. **
** **
** **
** (t) Converts the following data to data type t, where **
** t can be one of the following: **
** **
** t Type Length Generates (for example) **
** -- ------- ------ ------------------------ **
** A Address 4 AL4(L304) **
** AD Address (Long) 8 AD(L304) **
** B Binary 1 B'10110011' **
** C Character n CL9'Some text' **
** CA Character (ASCII) n CL9'Some ASCII text' **
** D Long Hex Float 8 D'3.141592653589793' **
** DH Long Hex Float 8 DH'3.141592653589793' **
** DB Long Bin Float 8 DB'3.141592653589793' **
** DD Long Dec Float 8 DD'3.141592653589793' **
** E Short Hex Float 4 E'3.1415926' **
** EH Short Hex Float 4 EH'3.1415926' **
** EB Short Bin Float 4 EB'3.1415926' **
** ED Short Dec Float 4 ED'3.1415926' **
** FD Doubleword Binary 8 FD'304' **
** F Fullword Binary 4 F'304' **
** H Halfword Binary 2 H'304' **
** P Packed Decimal n PL2'304' **
** S Storage Reference 2 S(X'020'(R12)) **
** X Hexadecimal n XL2'0304' **
** **
** (%formatspec) **
** **
** Parses the subsequent hex as formatted rows of table **
** data. The end of the table data is indicated by **
** either a "/" action marker, or an empty tag list (), **
** or an empty formatspec tag: (%). Each row of table **
** data is parsed according to the formatspec. The **
** formatspec consists of zero or more space delimited **
** assembler storage type declarations each having the **
** format: **
** <duplication_factor><type><length_modifier> **
** or: <type><length_modifier>=<variable_name> **
** or: <type>L<length_expression> **
** **
** ...for example, 4XL3. The default duplication_factor **
** (the repetition count for the field) is 1. The **
** default type is X (hexadecimal). The default length_ **
** modifier depends on the type as follows: **
** **
** t Type Length **
** -- ------- ------ **
** A Address 4 **
** AD Address (long) 8 **
** B Binary 1 **
** C Character 1 **
** CA Character (ASCII) 1 **
** D Long Hex Float 8 **
** DH Long Hex Float 8 **
** DB Long Bin Float 8 **
** DD Long Dec Float 8 **
** E Short Hex Float 4 **
** EH Short Hex Float 4 **
** EB Short Bin Float 4 **
** ED Short Dec Float 4 **
** FD Doubleword Binary 8 **
** F Fullword Binary 4 **
** H Halfword Binary 2 **
** P Packed Decimal 1 **
** S Storage Reference 2 **
** X Hexadecimal 1 **
** **
** If you specify an unsupported data type then the **
** default format of X is used. As a happy side effect, **
** specifying "3 3 3 3" or even just "4x3" (which you **
** could read as "four by three bytes") is equivalent **
** to "4XL3" or "XL3 XL3 XL3 XL3". If you specify **
** just a number then that number is treated as the **
** length of a type X field (e.g. "3" is the same as **
** "XL3"). **
** **
** For example, **
** **
** (%CL3 X PL4). **
** C1C3E3 02 0426709C D5E2E6 01 8089526C / **
** **
** ...(spaces inserted for clarity) will be disassembled**
** as: **
** **
** L0 DC CL3'ACT' <-- Table row 1 **
** DC XL1'02' **
** DC PL4'426709' **
** DC CL3'NSW' <-- Table row 2 **
** DC XL1'01' **
** DC PL4'8089526' **
** **
** By using the =variable_name and length_expression **
** syntax, you can parse variable length data. **
** **
** When =variable_name is specified, a rexx variable is **
** created called $variable_name - to avoid clashes with**
** variables already used by the DA Rexx procedure - **
** containing the contents of the associated field **
** converted to decimal. **
** **
** When length_expression is specified, the expression **
** can be any simple Rexx expression that results in a **
** positive whole number. The expression must not cont- **
** ain parentheses. You should use variable names you **
** created with a $ sign prepended, else the result will**
** be unpredictable. **
** **
** For example, **
** **
** (%AL1=n CL$n+1). **
** 00 C1 01 C1C2 04 C1C2C34040 **
** **
** ...will be disassembled as: **
** **
** L0 DC AL1(0) <-- Variable string 1 **
** DC CL1'A' <-- Length is 0+1 **
** DC AL1(1) <-- Variable string 2 **
** DC CL2'AB' <-- Length is 1+1 **
** DC AL1(4) <-- Variable string 3 **
** DC CL5'ABC' <-- Length is 4+1 **
** **
** () Resets the data type tag so that automatic data type **
** detection is enabled. Automatic data type detection **
** splits the data into either printable text or binary.**
** Binary data is defined as fullwords if aligned on a **
** fullword boundary, as halfwords if aligned on a **
** halfword boundary, or else is output as hexadecimal. **
** Printable text is defined as character constants. **
** You can instead use the "/" action marker to do this.**
** **
** (@xxx) Specifies that the current location counter is to be **
** set to the hex address specified by xxx. **
** By default the initial location counter is 0. **
** The equivalent assembler directive is: **
** ORG @+X'xxx' **
** **
** (Rn) Specifies that register n (where n = 0 to 15) points **
** to the immediately following code or data. **
** The equivalent assembler directive is: **
** USING *,Rn **
** **
** For example: **
** **
** Register 12 points to offset 0 **
** | Code Data **
** | | | **
** V V V **
** (R12)18CF 5820C008 07FE . 0000000A **
** code.............. data.... **
** **
** The above would be disassembled as: **
** **
** USING *,R12 **
** * ----------- **
** L0 LR R12,R15 **
** L R2,L8 **
** BR R14 **
** L8 DC F'10' **
** **
** (Rn+Rm) Specifies that register n points to the immediately **
** following code or data, and that register m points **
** 4096 bytes past register n (for as many registers as **
** you specify - each additional register extends the **
** coverage by a further 4096 bytes). **
** The equivalent assembler directive is: **
** USING *,Rn,Rm **
** **
** (Rn+Rm=Ry) Same as (Rn+Rm) except that Rn+Rm points to the **
** location currently declared for Ry. **
** The equivalent assembler directive is: **
** DROP Ry **
** USING *,Rn,Rm **
** **
** (Rn=>name'desc') **
** Specifies that register n (where n = 0 to 15) points **
** to (=>) a dummy section (DSECT) called "name". **
** Optionally, associate a short description "desc". **
** A DSECT is then built to cover subsequent address **
** references for that base register until a (Rn=) tag **
** is encountered which DROPs that register. **
** All DSECTs so generated will be appended to the end **
** of the disassembled source. **
** The equivalent assembler directive is: **
** USING name,Rn **
** **
** (Rn=xxx) Specifies that register n (where n = 0 to 15) points **
** to location xxx in hexadecimal. **
** The equivalent assembler directive is: **
** USING @+xxx,Rn **
** **
** ...where "@" is the label assigned to offset 0. **
** **
** (Rn=label)Specifies that register n (where n = 0 to 15) points **
** to location identified by label "label". **
** The equivalent assembler directive is: **
** USING label,Rn **
** **
** (Rn=) Resets a base register tag. **
** The equivalent assembler directive is: **
** DROP Rn **
** **
** (label) Assigns an assembler label to the following code or **
** data. You may use it to name a CSECT for example. **
** The label cannot be R0 to R15, or A to F, H, P, S or **
** X as those have special meanings as described above. **
** The maximum length of a label assigned in this way **
** is 8 (for pragmatic reasons). **
** **
** For example: **
** **
** Data Code **
** | Data label | Code label **
** | | | | **
** V V V V **
** 07FE.(nSize)0000000A,(getCVT)58200010 **
** code data.... code.... **
** **
** The above would be disassembled as: **
** **
** BR R14 **
** nSize DC X'0000000A' **
** getCVT L R2,16 **
** **
** (label=x) Assigns an assembler label to the location x in **
** hexadecimal. Use this if you know in advance the **
** offset of particular CSECTs. For example, **
** **
** (MAIN=0,CSECTA=1C0,CSECTB=280) **
** **
** Any address constants encountered will then use the **
** specified name instead of a literal. For example, **
** **
** DC A(448) **
** **
** will be generated as: **
** **
** DC A(CSECTA) X'000001C0' **
** **
** Some labels will be automatically created from the **
** External Symbol Dictionary of the AMBLIST output. **
** **
** (.xxx) Assigns an automatically named assembler label to **
** location xxx in hexadecimal. Use this if you know in **
** advance which locations are referenced by machine **
** instructions so that the location can be represented **
** by a label instead of a displacement off a register. **
** DA will automatically insert one of these tags into **
** the hex input (AMBLIST output) for each location **
** referenced by a machine instruction that does not **
** already have a label defined for it. The inserted **
** tags will be taken into account the next time DA is **
** run. **
** **
** (.xxx=t) Assigns an automatically named assembler label and **
** data type "t" to location xxx. The type can be any **
** of those described above for the (t) tag. **
** **
** 6. Issue DA to disassemble the AMBLIST output being edited. **
** - Spaces in the hex input are not significant (with one **
** exception explained below). **
** - The DA macro will disassemble AMBLIST output that has the **
** following format: **
** **
** Everything after 3 consecutive spaces is ignored **
** (to accommodate a bug in versions of AMBLIST prior **
** to z/OS v2.3 - see APAR OA58170). **
** | **
** V **
** xxxxxxxx xxxxxxxx ... xxxxxxxx *aaaaa...aaaa* **
** |offset| |------hex data-----| |---ignored-----> **
** **
** If AMBLIST output is not detected, then the input is **
** considered to be free form printable hex with no offset. **
** For example: **
** 18CF 5820C008 07FE 0000000A **
** **
** - The first 80 columns of the disassembly are valid assembler **
** statements and can be pasted into an FB80 file to be proc- **
** essed by the HLASM assembler. That is, you can paste all the **
** disassembled lines and ignore the truncation warning. **
** **
** - The remaining columns contain the following information: **
** location counter, instruction in hex, instruction format and **
** the target operand length if any. **
** **
** 7. Examine the "Undefined labels" report at the end of the dis- **
** assembly to help you identify where to insert CODE and DATA **
** action markers. Labels will be created at each location that **
** is referenced by a machine instruction or an address constant. **
** **
** 8. Press F3 to quit editing the disassembly and return to the **
** AMBLIST output - where you can adjust the tags as described **
** above and try again. **
** **
** 9. Submit an assembly job to verify that the disassembled code **
** assembles cleanly. **
** **
** **
** AUTHOR - Andrew J. Armstrong <androidarmstrong@gmail.com> **
** **
END-JCL-COMMENTS
** **
** HISTORY - Date By Reason (most recent at the top please) **
** -------- --- ----------------------------------------- **
** 20220920 AA Added new z16 instructions. **
** 20201106 AA Added System/370 Vector Facility opcodes. **
** 20201106 AA Changed the TEST option output such that **
** the opcode of each instruction is emitted **
** as a label (e.g. LR -> X18 LR). **
** 20201104 AA Added options: 360, 370, 390 and Z **
** to disassemble System/360, System/370, **
** System/390 and z/Architecture modules. **
** z/Architecture is the default. **
** 20201027 AA Added CA tag for ASCII text. **
** 20200825 AA Allowed hex to be supplied on the command **
** line. **
** 20200605 AA Major redesign for version 3.0. **
** 20200525 AA Implemented equates for Element Size and **
** Floating Point Format in vector instruc- **
** tions. **
** 20200522 AA Added ED and DD tags for Decimal Floating **
** Point (DFP) constants. **
** 20200511 AA Major overhaul for version 2.0. **
** Reworked the way that opcodes are deter- **
** mined. **
** Applied storage formats to instruction **
** operands instead of treating them all as **
** type X. **
** 20200508 AA Renamed the hint() function to t() to **
** save space in the definition data. **
** 20200507 AA Added onSyntax trap to help identify the **
** location of the error in the input hex. **
** 20200506 AA Tidied up address handling a little. **
** Extended the '%' tag to handle parsing **
** of variable length table entries. This is **
** useful for parsing error message tables. **
** 20200505 AA Miscellaneous bug fixes. **
** 20200501 AA Emit A(label) if label is known. **
** 20200501 AA Added '(Rnn[+Rnn...]=Rnn) tag. **
** 20200430 AA Handle 31-bit addresses better. **
** 20200429 AA Switch to data parsing mode on % tag. **
** 20200427 AA Emit EQU for each undefined label. **
** 20200424 AA Improved '%' tag parsing. **
** 20200421 AA Added '%' tag for printing formatted **
** table entries. **
** 20200420 AA Insert a blank line before each label **
** more reliably. **
** 20200420 AA TR/TRT now has fixed table length of 256. **
** 20200417 AA Added ASM option to create assembly JCL. **
** 20200407 AA Sort by mnemonic in instruction stats. **
** 20200407 AA Insert only *new* undefined labels in the **
** original AMBLIST output. **
** 20200407 AA Show the target of an EX or EXRL as a **
** comment. **
** 20200401 AA Added '(.=xxx)' tag so that data labels **
** can be applied in advance. Inserted one **
** of these tags for each undefined label **
** into the original AMBLIST output just **
** before the first CSECT. DA will take **
** these into account the next time it is **
** run. This is equivalent to you manually **
** inserting '.' action characters to create **
** labels that are referenced by machine **
** instructions. **
** 20200316 AA Fixed length hints for SS-a/b formats. **
** 20200305 AA Fixed handling of (label) tag that begins **
** with the letter R. For example (Return). **
** 20200106 AA Reworked operand length hints. **
** 20191213 AA Allowed dsn to be specified on DA command.**
** 20191212 AA Added description to the "=>" tag. **
** 20191209 AA Displayed TODO count message. **
** 20191206 AA Added '/' action marker and updated doc. **
** 20191205 AA Fixed processing of tags after the end of **
** the hex input. **
** 20191204 AA Allocated edit dataset based on the size **
** of the input hex to be decoded. **
** 20191203 AA Fixed (Rn=xxx) tag processing. **
** Added reference support for DC A(label). **
** 20191203 AA Fixed implicit operand lengths. **
** 20191202 AA Added length to undefined labels report. **
** 20191125 AA Detected undefined labels. **
** 20191119 AA Added support for S-type addresses. They **
** are commonly used for patch areas. **
** 20191113 AA Set flag 'c' on all instructions that set **
** the condition code. **
** 20191031 AA Added support for DSECTs (Rn=>name) tag **
** AA Added support for comments ('comment') **
** AA Added support for sections ("comment") **
** AA Fixed extended mnemonics **
** 20191023 AA Fixed operand construction by adding **
** "hard" blank translation **
** 20191014 AA Added z/OS SVC descriptions **
** 20191014 AA Added multiple register USING support **
** 20191008 AA Added new z15 instructions **
** 20190625 AA Initial version **
** **
**********************************************************************/
trace o
signal on syntax name onSyntax
parse arg xData'('sOptions
xData = space(xData,0)
if \isHex(xData)
then do
parse arg sDsn sOptions
parse var sDsn sDsn'('sMod')'
parse var sOptions '('sOptions
sDsn = strip(sDSN,'BOTH',"'")
end
parse source . . me .
address ISPEXEC 'CONTROL ERRORS RETURN'
numeric digits 22
g. = ''
parse source t1 t2 t3 t4 t5 t6 t7 t8 t9
g.0ZOS = wordpos(t1,'TSO MVS') > 0
g.0NIX = t1 = 'UNIX' | t8 = 'OMVS'
g.0WIN = pos('WIN',t1) > 0
g.0EBCDIC_ENVIRONMENT = g.0ZOS | t8 = 'OMVS' /* Platform is EBCDIC */
call getOptions sOptions
call prolog
address ISREDIT
'(state) = USER_STATE' /* Save current editor state */
if g.0OPTION.TEST = 1 /* Generate test assembler source? */
then do
call generateTestBed
call epilog
exit 0
end
if g.0OPTION.ASM = 1 /* Generate assembly JCL? */
then do
call generateAsm
call epilog
exit 0
end
call emit '@ START'
call emit '*Label Op Operands 'left('Comment',59),
'Location Hex Format'
/*
*-------------------------------------------------------------------
* 1. Extract the hex input
*-------------------------------------------------------------------
*/
if \isHex(xData) /* If hex not supplied on the command line */
then do
xMeta = readMeta() /* Determine the input format */
if g.0AMBLIST
then do
if g.0PGMOBJ
then xData = readProgramObject()
else xData = readModule()
end
else xData = readRawHex()
end
/*
*-------------------------------------------------------------------
* 2. Disassemble hex
*-------------------------------------------------------------------
*/
g.0ISCODE = 1 /* Set hex parsing mode (1=Code, 0=Data) */
do while xData <> '' /* Disassemble the extracted hex data */
parse var xData xChunk '('sTags')' xData
xChunk = space(xChunk,0)
/* Decode any hex before the next tag */
nPos = verify(xChunk,'.,/','MATCH') /* first action character */
if nPos = 0 /* If no dots, commas or slashes found */
then do
call decodeChunk xChunk
end
else do while xChunk <> ''
nPos = verify(xChunk,'.,/','MATCH') /* next dot, comma or slash */
if nPos > 0
then do /* decode up until the next action character */
sAction = substr(xChunk,nPos,1) /* Get the action character */
parse var xChunk xChunklet (sAction) xChunk
end
else do /* decode the complete chunk */
xChunklet = xChunk
sAction = ''
xChunk = ''
end
if xChunklet <> ''
then call decodeChunk xChunklet
select
when sAction = ',' then do /* If we are switching to code mode */
g.0ISCODE = 1 /* Decode subsequent hex as code */
g.0TYPE = '' /* Reset data type to automatic */
end
when sAction = '.' then do
g.0ISCODE = 0 /* Decode subsequent hex as data */
/* Using the existing data type */
end
when sAction = '/' then do
g.0ISCODE = 0 /* Decode subsequent hex as data */
g.0TYPE = '' /* Reset data type to automatic */
g.0FIELD.0 = 0 /* Reset table entry generation */
end
otherwise nop /* Use existing mode and data type */
end
end
/* Now process the tag, if any */
call handleTags sTags
end
/* The following is a hack to ensure that any tags or action characters
appended to the very end of the hex input data are actually processed */
if pos(sAction,'.,/') > 0 & isReferenced(g.0XLOC) /* If trailing action */
then call saveStmt 'DS','0X' /* Emit a label and any directives */
else call save '' /* Emit only directives for this location */
call nextLoc +1 /* Prevent repeating any directives on the last statement */
if g.0DIAG /* If a DIAGNOSE instruction was encountered */
then do /* Emit a DIAG macro to avoid assembly error */
call emit ' MACRO'
call emit '&label DIAG &O1,&O2'
call emit ' DS 0h'
call emit "&label DC X'83',AL1(&O1*16),S(&O2.)"
call emit ' MEND'
end
/*
*-------------------------------------------------------------------
* 3. Apply labels to all referenced storage locations
*-------------------------------------------------------------------
*/
do n = 1 to g.0LINE
parse var g.0STMT.n sOp sOperand sDesc 100 xLoc8 +8 .
if xLoc8 <> '' /* Only interested in code and data */
then do
xLoc = stripx(xLoc8)
bIsReferenced = isReferenced(xLoc)
if bIsReferenced
then do
call emit '' /* Then insert a blank line before it */
sLabel = getLabel(xLoc)
nLoc = x2d(xLoc)
g.0ASS.nLoc = 1 /* Indicate present in disassembly */
end
else sLabel = ''
/* g.0CLENG.xLoc is the longest length actually used in an instruction
that references this location. If it is longer than the data length
assigned to this location then a 'DC 0XLnn' directive will be
inserted to cover the entire field referenced by the instruction.
*/
select
when sOp = 'DC' &, /* A constant, and... */
g.0CLENG.xLoc <> '' /* An instruction specified its length */
then do
if pos('(',sOperand) > 0
then parse var sOperand sType'('sValue')' /* A() style syntax */
else parse var sOperand sType"'"sValue"'" /* X'' style syntax */
parse var sType sType'L'nLen
nPos = verify(nLen,'0123456789','NOMATCH')
if nPos > 0 /* If a non-numeric is present */
then nLen = left(nLen,nPos-1) /* Keep only length digits */
if nLen = '' /* If length modifier is absent */
then nLen = g.0MAXLEN.sType /* Use default length for this type*/
if g.0CLENG.xLoc \= nLen
then do
/* Use the label from the existing statement */
sLocType = g.0CTYPE.xLoc
if sLocType = '' then sLocType = 'X'
call emitStmt sLabel,'DC 0'tl(sLocType,g.0CLENG.xLoc)
call emitStmt ,substr(g.0STMT.n,10)
end
else do
call emitStmt sLabel,substr(g.0STMT.n,10)
end
end
when inSet(sOp,'EX EXRL') then do /* An Execute instruction */
/* Show the execute target in the comment */
parse var sOperand sReg','sExLabel
xLocInst = getLocation(sExLabel)
nEx = g.0STMT#.xLocInst
parse var g.0STMT.nEx sExOp sExOperand .
sStmt = overlay(strip(sDesc) sExOp sExOperand,g.0STMT.n,40)
call emitStmt sLabel,substr(sStmt,10)
end
when inSet(sOp,'BALR BASSM BASR BAL BAS BAKR PC SVC') then do
call emitStmt sLabel,substr(g.0STMT.n,10)
call emit '' /* Insert a blank line after */
end
otherwise do
call emitStmt sLabel,substr(g.0STMT.n,10)
end
end
end
else call emit g.0STMT.n
end
nHWM = n /* High Water Mark */
/*
*-------------------------------------------------------------------
* 4. Save all non-addressable statements
*-------------------------------------------------------------------
*/
call saveRegisterEquates
call saveDSECTs
if g.0OPTION.STAT then call saveStatistics
/*
*-------------------------------------------------------------------
* 5. Process undefined labels
*-------------------------------------------------------------------
*/
nUndefinedLabels = saveUndefinedLabels()
call save ' END'
do n = nHWM to g.0LINE
call emit g.0STMT.n
end
/*
*-------------------------------------------------------------------
* Termination
*-------------------------------------------------------------------
*/
say 'DIS0009I Generated' g.0LINE 'statements ('g.0INST 'instructions)'
if g.0TODO > 0
then say 'DIS0010W There are' g.0TODO 'lines marked: TODO (not code)'
if nUndefinedLabels > 0
then say 'DIS0011W There are' nUndefinedLabels 'references to undefined',
'labels (see end of listing)'
if g.0NEWDOTS > 0
then say 'DIS0013I Rerun DA to process' g.0NEWDOTS 'new references'
else say 'DIS0014I DA processing complete'
'USER_STATE = (state)' /* Restore editor state */
call epilog
/* Insert tags for any undefined labels before the first CSECT */
if g.0NEWDOTS > 0
then do
do i = sorted.0 to 1 by -1 /* Reverse order so they appear in order! */
n = sorted.i
nLoc = g.0REFLOC.n /* A referenced storage location */
xLoc = d2x(nLoc)
if g.0ASS.nLoc = '', /* Label not in disassembly listing */
& g.0DOTS.xLoc = '' /* Not already in the input (.xxx) tags */
then do
sType = g.0CTYPE.xLoc
if sType = ''
then 'LINE_AFTER' g.0FIRSTCSECT '= "' g.0TAGPREFIX '(.'xLoc')"'
else 'LINE_AFTER' g.0FIRSTCSECT '= "' g.0TAGPREFIX '(.'xLoc'='sType')"'
end
end
end
return 1
saveStatistics: procedure expose g.
call saveCommentBlock 'Statistics'
call save '* Instruction format frequency ('g.0FC.0 'formats used)'
call save '*'
call save '* Format Count Mnemonics'
call save '* ------ ----- ---------'
call sortStem 'g.0FC.',0
do i = 1 to sorted.0
n = sorted.i
sFormat = g.0FN.n
sMnemonics = sortWords(g.0ML.sFormat)
if length(sMnemonics) <= 50