-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathinfo.c
701 lines (614 loc) · 16.4 KB
/
info.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
/* Copyright (C) 2013, 2019 Lars Brinkhoff <[email protected]>
Copyright (C) 2018, 2020 Adam Sampson <[email protected]>
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 2 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/>. */
#include <stdio.h>
#include <string.h>
#include "dis.h"
#include "memory.h"
#include "symbols.h"
#include "jobdat.h"
#define SQUOZE_MASK 0037777777777
#define SYHKL 0400000000000
#define SYKIL 0200000000000
#define SYLCL 0100000000000
#define SYGBL 0040000000000
#define SYFLG 0740000000000 /* all flags mask */
/* Information block types */
#define STBDEF 0
#define STBUND 1
#define STBFIL 2
#define STBINF 3
/* Most metadata is not valid if all zeros or all ones. */
#define GOOD(WORD) ((WORD) != -1 && \
(WORD) != 0 && \
(WORD) != 0777777LL && \
(WORD) != 0777777777777LL)
word_t start_instruction;
FILE *output_file;
word_t
ascii_to_sixbit (const char *ascii)
{
int i;
char c;
word_t w;
int zero = 0;
w = 0;
for (i = 0; i < 6; i++)
{
if (zero)
c = ' ';
else
{
c = *ascii++;
if (c == 0)
{
c = ' ';
zero = 1;
}
}
w <<= 6;
if (c >= 'a' && c <= 'z')
c -= 32;
w += (c - 040);
}
return w;
}
void
sixbit_to_ascii (word_t sixbit, char *ascii)
{
int i;
for (i = 0; i < 6; i++)
{
ascii[i] = 040 + ((sixbit >> (6 * (5 - i))) & 077);
}
ascii[6] = 0;
}
word_t
ascii_to_squoze (const char *ascii)
{
int i;
word_t word = 0;
for (i = 0; i < 6; i++)
{
word *= 40;
switch (*ascii)
{
default:
case ' ': word += 000; break;
case '0': word += 001; break;
case '1': word += 002; break;
case '2': word += 003; break;
case '3': word += 004; break;
case '4': word += 005; break;
case '5': word += 006; break;
case '6': word += 007; break;
case '7': word += 010; break;
case '8': word += 011; break;
case '9': word += 012; break;
case 'A':
case 'a': word += 013; break;
case 'B':
case 'b': word += 014; break;
case 'C':
case 'c': word += 015; break;
case 'D':
case 'd': word += 016; break;
case 'E':
case 'e': word += 017; break;
case 'F':
case 'f': word += 020; break;
case 'G':
case 'g': word += 021; break;
case 'H':
case 'h': word += 022; break;
case 'I':
case 'i': word += 023; break;
case 'J':
case 'j': word += 024; break;
case 'K':
case 'k': word += 025; break;
case 'L':
case 'l': word += 026; break;
case 'M':
case 'm': word += 027; break;
case 'N':
case 'n': word += 030; break;
case 'O':
case 'o': word += 031; break;
case 'P':
case 'p': word += 032; break;
case 'Q':
case 'q': word += 033; break;
case 'R':
case 'r': word += 034; break;
case 'S':
case 's': word += 035; break;
case 'T':
case 't': word += 036; break;
case 'U':
case 'u': word += 037; break;
case 'V':
case 'v': word += 040; break;
case 'W':
case 'w': word += 041; break;
case 'X':
case 'x': word += 042; break;
case 'Y':
case 'y': word += 043; break;
case 'Z':
case 'z': word += 044; break;
case '.': word += 045; break;
case '$': word += 046; break;
case '%': word += 047; break;
}
if (*ascii != 0)
ascii++;
}
return word;
}
void
squoze_to_ascii (word_t squoze, char *ascii)
{
static char table[] =
{
' ', '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z', '.', '$', '%'
};
int i;
squoze &= SQUOZE_MASK;
for (i = 0; i < 6; i++)
{
ascii[5-i] = table[squoze % 40];
squoze /= 40;
}
ascii[6] = 0;
}
int supress_warning = 0;
void
print_date (FILE *f, word_t t)
{
/* Bits 3.1-3.5 are the day, bits 3.6-3.9 are the month, and bits
4.1-4.7 are the year. */
int date = (t >> 18);
int day = (date & 037);
int month = (date & 0740);
int year = (date & 0777000);
fprintf (f, "%u-%02u-%02u", (year >> 9) + 1900, (month >> 5), day);
if ((year & 0600000) && !supress_warning)
fprintf (output_file, " [WARNING: overflowed year field]");
}
void
print_time (FILE *f, word_t t)
{
/* The right half of this word is the time of day since midnight in
half-seconds. */
int seconds = (t & 0777777) / 2;
int minutes = (seconds / 60);
int hours = (minutes / 60);
fprintf (f, "%02u:%02u:%02u", hours, (minutes % 60), (seconds % 60));
}
void
print_datime (FILE *f, word_t t)
{
print_date (f, t);
fputc (' ', f);
print_time (f, t);
}
static void
print_symbol (word_t word1, word_t word2)
{
char str[7], *p;
int flags = 0;
squoze_to_ascii (word1, str);
for (p = str; *p == ' '; p++)
;
fprintf (output_file, " Symbol %s = ", p);
fprintf (output_file, "%llo (", word2);
if (word1 & SYHKL)
{
fprintf (output_file, " halfkilled");
flags |= SYMBOL_HALFKILLED;
}
if (word1 & SYKIL)
{
fprintf (output_file, " killed");
flags |= SYMBOL_KILLED;
}
if (word1 & SYLCL)
fprintf (output_file, " local");
if (word1 & SYGBL)
{
fprintf (output_file, " global");
flags |= SYMBOL_GLOBAL;
}
fprintf (output_file, ")\n");
add_symbol (p, word2, flags);
}
void
sblk_info (FILE *f, word_t word0, int cpu_model)
{
int block_length;
word_t word;
int i;
fprintf (output_file, "Start instruction:\n");
disassemble_word (NULL, word0, -1, cpu_model);
while ((word = get_word (f)) & SIGNBIT)
{
fprintf (output_file, "\n");
reset_checksum (word);
block_length = -((word >> 18) | ((-1) & ~0777777));
switch ((int)word & 0777777)
{
case STBDEF:
{
char str[7];
fprintf (output_file, "Symbol table:\n");
for (i = 0; i < block_length; i += 2)
{
word_t word1, word2;
word1 = get_checksummed_word (f);
word2 = get_checksummed_word (f);
if (word1 == -1 || word2 == -1) {
fprintf (output_file, " [WARNING: early end of file]\n");
goto end;
}
if (word1 & SYFLG)
{
print_symbol (word1, word2);
}
else
{
squoze_to_ascii (word1, str);
fprintf (output_file, " Header: %s\n", str);
}
}
goto checksum;
}
case STBUND:
fprintf (output_file, "Undefined symbol table:\n");
break;
case STBFIL:
{
char str[7];
fprintf (output_file, "Indirect symbol table pointer:\n");
if (block_length != 4)
{
fprintf (output_file, " (unknown table format)\n");
break;
}
sixbit_to_ascii (get_checksummed_word (f), str);
fprintf (output_file, " Device name: %s\n", str);
sixbit_to_ascii (get_checksummed_word (f), str);
fprintf (output_file, " File name 1: %s\n", str);
sixbit_to_ascii (get_checksummed_word (f), str);
fprintf (output_file, " File name 2: %s\n", str);
sixbit_to_ascii (get_checksummed_word (f), str);
fprintf (output_file, " File sname: %s\n", str);
goto checksum;
}
case STBINF:
{
int subblock_length;
char str[7];
word = get_checksummed_word (f);
subblock_length = -((word >> 18) | ((-1) & ~0777777));
switch ((int)word & 0777777)
{
case 1:
fprintf (output_file, "Assembly info:\n");
sixbit_to_ascii (get_checksummed_word (f), str);
fprintf (output_file, " User name: %s\n", str);
fprintf (output_file, " Creation time: ");
print_datime (output_file, get_checksummed_word (f));
fputc ('\n', output_file);
sixbit_to_ascii (get_checksummed_word (f), str);
fprintf (output_file, " Source file device: %s\n", str);
sixbit_to_ascii (get_checksummed_word (f), str);
fprintf (output_file, " Source file name 1: %s\n", str);
sixbit_to_ascii (get_checksummed_word (f), str);
fprintf (output_file, " Source file name 2: %s\n", str);
sixbit_to_ascii (get_checksummed_word (f), str);
fprintf (output_file, " Source file sname: %s\n", str);
for (i = 0; i < block_length - subblock_length - 1; i++)
{
fprintf (output_file, " (%012llo)\n", get_checksummed_word(f));
}
goto checksum;
case 2:
fprintf (output_file, "Debugging info:\n");
break;
default:
fprintf (output_file, "Unknown miscellaneous info:\n");
break;
}
fprintf (output_file, " (%d words)\n", subblock_length);
for (i = 0; i < subblock_length; i++)
{
get_checksummed_word (f);
}
goto checksum;
}
default:
fprintf (output_file, "Unknown information:\n");
break;
}
fprintf (output_file, "(%d words)\n", block_length);
for (i = 0; i < block_length; i++)
{
get_checksummed_word (f);
}
checksum:
word = get_word (f);
if (word == -1LL)
return;
check_checksum (word);
}
fprintf (output_file, "\nDuplicate start instruction:\n");
disassemble_word (NULL, word, -1, cpu_model);
end:
return;
}
static char *
unpad (char *str)
{
for (; *str == ' '; str++)
;
return str;
}
static void
print_sail_symbol (word_t word, word_t block, word_t value)
{
char *str, str1[7], str2[7];
int flags = word >> 32;
squoze_to_ascii (word, str1);
/* Remove space padding. */
str = unpad (str1);
switch (flags)
{
case 000: /* Program name. */
if (*str != 0)
fprintf (output_file, " Program: %s\n", str);
break;
case 003: /* Block name. */
fprintf (output_file, " Block: %s\n", str);
break;
default:
fprintf (output_file, " Symbol %s ", str);
squoze_to_ascii (block, str2);
if (block != 0)
fprintf (output_file, "[%s] ", unpad (str2));
fprintf (output_file, "= %llo (%02o)\n", value, flags);
add_symbol (str, value, 0); /* Don't know what flags mean. */
}
}
void
dmp_new_symbols (struct pdp10_memory *memory, int table)
{
word_t word1, word2, block, value;
int bname, class1, class2, class3, class4, lastv;
int i;
bname = get_word_at (memory, table + 1);
class1 = get_word_at (memory, table + 5);
class2 = get_word_at (memory, table + 6);
class3 = get_word_at (memory, table + 7);
class4 = get_word_at (memory, table + 8);
lastv = get_word_at (memory, table + 9);
fprintf (output_file, "\nSymbol table:\n");
for (i = class1; i < class2; i += 2)
{
word1 = get_word_at (memory, table + i);
word2 = get_word_at (memory, table + i + 1);
block = get_word_at (memory, table + bname + (word2 >> 23));
print_sail_symbol (word1, block, word2 & 0777777LL);
}
for (i = class2; i < class3; i += 2)
{
word1 = get_word_at (memory, table + i);
word2 = get_word_at (memory, table + i + 1);
block = get_word_at (memory, table + bname + (word2 >> 23));
print_sail_symbol (word1, block, word2 & 0777777LL);
}
for (i = class3; i < class4; i += 2)
{
word1 = get_word_at (memory, table + i);
word2 = get_word_at (memory, table + i + 1);
block = get_word_at (memory, table + bname + (word2 >> 23));
print_sail_symbol (word1, block, (word2 & 0777777LL) << 18);
}
for (i = class4; i < lastv; i += 2)
{
word1 = get_word_at (memory, table + i);
word2 = get_word_at (memory, table + i + 1);
block = get_word_at (memory, table + bname + (word2 >> 23));
value = get_word_at (memory, table + (word2 & 0777777LL));
print_sail_symbol (word1, block, value);
}
}
void
dmp_info (struct pdp10_memory *memory, int cpu_model)
{
word_t jbsa, jbda, jbsym;
int p;
(void)cpu_model;
/* For the PDP-6 monitor, JBSA is the start address. */
jbsa = get_word_at (memory, 0120);
fprintf (output_file, "Start address (PDP-6): %06llo\n", jbsa & 0777777);
start_instruction = JRST + (jbsa & 0777777);
/* For WAITS, JBDA is a JRST to the start address. */
jbda = get_word_at (memory, 0140);
fprintf (output_file, "Start address (WAITS): %06llo\n", jbda & 0777777);
/* .JBSYM is an AOBJN pointer to DDT's symbol table. If the
executable doesn't have one, it may be an pointer past the end of
the executable. */
jbsym = get_word_at (memory, 0116);
p = jbsym & 0777777;
if (jbsym == -1 || p == 0 || get_word_at (memory, p) == -1)
return;
if (get_word_at (memory, p) == 0777777777777LL)
dmp_new_symbols (memory, p);
else
{
int i;
int length = 01000000 - (jbsym >> 18);
fprintf (output_file, "\nSymbol table:\n");
for (i = length - 2; i >= 0; i -= 2)
{
word_t word1 = get_word_at (memory, p + i);
word_t word2 = get_word_at (memory, p + i + 1);
print_sail_symbol (word1, 0LL, word2);
}
}
}
void
dec_symbols (struct pdp10_memory *memory, int address, int length)
{
fprintf (output_file, "Symbol table:\n");
while (length > 0)
{
word_t word1, word2;
word1 = get_word_at (memory, address++);
word2 = get_word_at (memory, address++);
print_symbol (word1, word2);
length -= 2;
}
}
void
dec_info (struct pdp10_memory *memory,
word_t entry_vec_len, word_t entry_vec_addr,
int cpu_model)
{
word_t word;
if (entry_vec_addr == -1 || entry_vec_len == 0254000)
{
word = get_word_at (memory, JBREL);
if (word != -1 && (word & 0777777) != 0)
fprintf (output_file, "Highest lowseg location: %llo\n",
word & 0777777);
word = get_word_at (memory, JBREL);
if (GOOD (word))
fprintf (output_file, "DDT from %llo to %llo\n",
word & 0777777, (word >> 18) & 0777777);
word = get_word_at (memory, JBHRL);
if (word != -1 && (word & 0777777) != 0)
fprintf (output_file, "Highest hiseg location: %llo\n",
word & 0777777);
if (entry_vec_addr != 0)
word = entry_vec_addr;
else
word = get_word_at (memory, JBSA);
if (GOOD (word))
{
word &= 0777777;
fprintf (output_file, "Start address: %06llo\n", word);
start_instruction = JRST + word;
}
word = get_word_at (memory, JBREN);
if (GOOD (word))
fprintf (output_file, "Reentry address: %06llo\n", word & 0777777);
word = get_word_at (memory, JBVER);
if (GOOD (word))
fprintf (output_file, "Version: %012llo\n", word);
}
else
{
fprintf (output_file, "Entry vector at %06llo length %llo:\n",
entry_vec_addr, entry_vec_len);
if (entry_vec_len == 1)
{
fprintf (output_file, "Start address: %06llo\n", entry_vec_addr);
}
else if (entry_vec_len == 3)
{
int addr;
fprintf (output_file, "Start instruction:\n");
addr = entry_vec_addr;
disassemble_word (memory, get_word_at (memory, addr),
addr, cpu_model);
word = get_word_at (memory, ++addr);
if (GOOD (word))
{
fprintf (output_file, "Reentry instruction:\n");
disassemble_word (memory, word, addr, cpu_model);
}
word = get_word_at (memory, ++addr);
if (GOOD (word))
{
fprintf (output_file, "Version: %012llo\n", word);
}
}
}
word = get_word_at (memory, 0116);
if (GOOD (word))
dec_symbols (memory, word & 0777777,
01000000 - ((word >> 18) & 0777777));
}
int
byte_size (int code, int *leftovers)
{
if (code <= 17)
{
*leftovers = 0;
return 044 - code;
}
else if (code <= 111)
{
*leftovers = (code & 3);
return (code - 044) >> 2;
}
else if (code <= 248)
{
*leftovers = (code & 013);
return (code - 0200) >> 4;
}
else
{
*leftovers = (code & 077);
return (code - 0400) >> 6;
}
}
void
ntsddt_info (struct pdp10_memory *memory, int ddt)
{
char name[7];
word_t a, w, v;
int i, syms;
a = get_word_at (memory, ddt - 1);
if (a == -1LL)
{
fprintf (stderr, "No DDT symbol table.\n");
return;
}
/* The word at DDT-1 points to an AOBJ pointer. */
a = get_word_at (memory, a);
syms = a >> 18;
if (syms & 0400000)
syms |= ~0U << 18;
syms = -syms;
a &= 0777777;
fprintf (output_file, "Symbol table:\n");
for (i = 0; i < syms; i += 2)
{
w = get_word_at (memory, a);
v = get_word_at (memory, a + 1);
if (w >> 32)
print_symbol (w, v);
else
{
squoze_to_ascii (w, name);
fprintf (output_file, " Header: %s (%012llo)\n", name, v);
}
a += 2;
}
}