Commit | Line | Data |
---|---|---|
776b287e ML |
1 | /* Copyright (c) 1982 Regents of the University of California */ |
2 | ||
3 | static char sccsid[] = "@(#)printinst.c 1.1 %G%"; | |
4 | ||
5 | /* | |
6 | * decode and print the instructions | |
7 | */ | |
8 | ||
9 | #include "defs.h" | |
10 | #include "machine.h" | |
11 | #include "process.h" | |
12 | #include "pxops.h" | |
13 | #include "optab.h" | |
14 | #include "object.h" | |
15 | ||
16 | LOCAL ADDRESS printop(), docase(); | |
17 | ||
18 | /* | |
19 | * print instructions within the given address range | |
20 | */ | |
21 | ||
22 | printinst(lowaddr, highaddr) | |
23 | ADDRESS lowaddr; | |
24 | ADDRESS highaddr; | |
25 | { | |
26 | register ADDRESS addr; | |
27 | ||
28 | for (addr = lowaddr; addr <= highaddr; ) { | |
29 | addr = printop(addr); | |
30 | } | |
31 | } | |
32 | ||
33 | /* | |
34 | * print count instructions from given address | |
35 | */ | |
36 | ||
37 | printninst(count, addr) | |
38 | int count; | |
39 | ADDRESS addr; | |
40 | { | |
41 | int i; | |
42 | ||
43 | for (i = 0; i < count; i++) { | |
44 | addr = printop(addr); | |
45 | } | |
46 | } | |
47 | ||
48 | /* | |
49 | * print the opcode at the given address, return the address | |
50 | * of the next instruction | |
51 | */ | |
52 | ||
53 | LOCAL ADDRESS printop(addr) | |
54 | register ADDRESS addr; | |
55 | { | |
56 | int i; | |
57 | PXOP op; | |
58 | OPTAB *o; | |
59 | char subop; | |
60 | short arg; | |
61 | long longarg; | |
62 | union { | |
63 | short i; | |
64 | struct { char c1, c2; } opword; | |
65 | } u; | |
66 | ||
67 | iread(&u.i, addr, sizeof(u.i)); | |
68 | op = (PXOP) u.opword.c1; | |
69 | subop = u.opword.c2; | |
70 | o = &optab[op]; | |
71 | printf("%5d %s", addr, o->opname); | |
72 | addr += sizeof(u); | |
73 | for (i = 0; o->argtype[i] != 0; i++) { | |
74 | if (i == 0) { | |
75 | putchar('\t'); | |
76 | } else { | |
77 | putchar(','); | |
78 | } | |
79 | switch(o->argtype[i]) { | |
80 | case ADDR4: | |
81 | case LWORD: | |
82 | iread(&longarg, addr, sizeof(longarg)); | |
83 | printf("%d", longarg); | |
84 | addr += sizeof(long); | |
85 | break; | |
86 | ||
87 | case SUBOP: | |
88 | printf("%d", subop); | |
89 | break; | |
90 | ||
91 | case ADDR2: | |
92 | case DISP: | |
93 | case PSUBOP: | |
94 | case VLEN: | |
95 | case HWORD: | |
96 | if (i != 0 || subop == 0) { | |
97 | iread(&arg, addr, sizeof(arg)); | |
98 | addr += sizeof(short); | |
99 | } else { | |
100 | arg = subop; | |
101 | } | |
102 | printf("%d", arg); | |
103 | break; | |
104 | ||
105 | case STRING: { | |
106 | char c; | |
107 | ||
108 | putchar('\''); | |
109 | while (subop > 0) { | |
110 | iread(&c, addr, sizeof(c)); | |
111 | if (c == '\0') { | |
112 | break; | |
113 | } | |
114 | putchar(c); | |
115 | subop--; | |
116 | addr++; | |
117 | } | |
118 | addr++; | |
119 | putchar('\''); | |
120 | if ((addr&1) != 0) { | |
121 | addr++; | |
122 | } | |
123 | break; | |
124 | } | |
125 | ||
126 | default: | |
127 | panic("bad argtype %d", o->argtype[i]); | |
128 | /*NOTREACHED*/ | |
129 | } | |
130 | } | |
131 | switch(op) { | |
132 | case O_CASE1OP: | |
133 | addr = docase(addr, 1, subop); | |
134 | break; | |
135 | ||
136 | case O_CASE2OP: | |
137 | addr = docase(addr, 2, subop); | |
138 | break; | |
139 | ||
140 | case O_CASE4OP: | |
141 | addr = docase(addr, 4, subop); | |
142 | break; | |
143 | } | |
144 | putchar('\n'); | |
145 | return(addr); | |
146 | } | |
147 | ||
148 | /* | |
149 | * print out the destinations and cases | |
150 | */ | |
151 | ||
152 | LOCAL ADDRESS docase(addr, size, n) | |
153 | ADDRESS addr; | |
154 | int size; | |
155 | int n; | |
156 | { | |
157 | register int i; | |
158 | char c; | |
159 | short arg; | |
160 | long longarg; | |
161 | ||
162 | iread(&arg, addr, sizeof(arg)); | |
163 | printf("\n\t%5d", arg); | |
164 | addr += 2; | |
165 | for (i = 1; i < n; i++) { | |
166 | iread(&arg, addr, sizeof(arg)); | |
167 | printf(", %5d", arg); | |
168 | addr += 2; | |
169 | } | |
170 | printf("\n\t"); | |
171 | for (i = 0; i < n; i++) { | |
172 | switch(size) { | |
173 | case 1: | |
174 | iread(&c, addr, sizeof(c)); | |
175 | printf("%5d", c); | |
176 | break; | |
177 | ||
178 | case 2: | |
179 | iread(&arg, addr, sizeof(arg)); | |
180 | printf("%5d", arg); | |
181 | break; | |
182 | ||
183 | case 4: | |
184 | iread(&longarg, addr, sizeof(longarg)); | |
185 | printf("%5d", longarg); | |
186 | break; | |
187 | } | |
188 | addr += size; | |
189 | if (i < n - 1) { | |
190 | printf(", "); | |
191 | } | |
192 | } | |
193 | if ((addr&01) == 01) { | |
194 | addr++; | |
195 | } | |
196 | return(addr); | |
197 | } |