forked from larsbrinkhoff/pdp10-its-disassembler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstantinople.c
131 lines (112 loc) · 3.05 KB
/
constantinople.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
/* Copyright (C) 2021 Lars Brinkhoff <[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/>. */
/* Given a memory range (inclusive), list all references to each
location in that range. If a reference is from the left half, put
parentheses around the address. If a reference isn't in ascending
order, put exclamation marks after. */
#include <stdio.h>
#include <getopt.h>
#include "dis.h"
#include "memory.h"
#include "opcode/pdp10.h"
static int ascending = 0;
static int
reference (const char *format, int first, int address)
{
printf (format, address);
if (first)
{
if (address > ascending)
ascending = address;
else
printf ("!!!");
}
return 0;
}
static void
check (struct pdp10_memory *memory, int address)
{
int first = 1;
word_t data;
int i;
for (i = 0; i <= 0777777; i++)
{
data = get_word_at (memory, i);
if (data == -1)
continue;
if ((data & 0777777) == address)
first = reference (" %06o", first, i);
if (((data >> 18) & 0777777) == address)
first = reference (" (%06o)", first, i);
}
}
static void
analyse_consta (struct pdp10_memory *memory, int start, int end)
{
word_t data;
int i;
for (i = start; i <= end; i++)
{
data = get_word_at (memory, i);
if (data == -1)
continue;
printf ("%06o/%012llo: ", i, data);
check (memory, i);
printf ("\n");
}
}
static void
usage (char **argv)
{
fprintf (stderr, "Usage: %s <start> <end> [file]\n\n", argv[0]);
exit (1);
}
int
main (int argc, char **argv)
{
int opt;
int cpu_model = PDP10_KA10_ITS;
struct pdp10_memory memory;
FILE *file = stdin;
int start, end;
input_file_format = &sblk_file_format;
while ((opt = getopt (argc, argv, "F:W:")) != -1)
{
switch (opt)
{
case 'F':
if (parse_input_file_format (optarg))
usage (argv);
break;
case 'W':
if (parse_input_word_format (optarg))
usage (argv);
break;
}
}
if (optind < argc)
start = strtoul (argv[optind++], NULL, 8);
else
usage (argv);
if (optind < argc)
end = strtoul (argv[optind++], NULL, 8);
else
usage (argv);
if (optind < argc)
file = fopen (argv[optind++], "rb");
if (optind != argc)
usage (argv);
output_file = fopen ("/dev/null", "w");
init_memory (&memory);
input_file_format->read (file, &memory, cpu_model);
analyse_consta (&memory, start, end);
}