Mercurial > hg > forks > dxa
annotate scan.c @ 2:ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 24 Feb 2015 20:28:57 +0200 |
parents | cfcae2ef1c2b |
children | 987c90810883 |
rev | line source |
---|---|
0 | 1 /*\ |
2 * dxa v0.1.1 -- symbolic 65xx disassembler | |
3 * | |
4 * Copyright (C) 1993, 1994 Marko M\"akel\"a | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 * | |
20 * Contacting the author: | |
21 * | |
22 * Via Internet E-mail: | |
23 * <Marko.Makela@FTP.FUNET.FI> | |
24 * | |
25 * Via Snail Mail: | |
26 * Marko M\"akel\"a | |
27 * Sillitie 10 A | |
28 * FIN-01480 VANTAA | |
29 * Finland | |
30 \*/ | |
31 | |
32 #define _SCAN_C_ | |
33 #include <stdio.h> | |
34 #include "proto.h" | |
35 #include "opcodes.h" | |
36 #include "options.h" | |
37 | |
38 | |
39 int ScanSure (ADDR_T scanstart) | |
40 { | |
41 ADDR_T address, addr; | |
42 opcodes *instr; | |
43 | |
44 unsigned int size, counter; | |
45 | |
46 for (address = scanstart;; address += size) { | |
47 if (GetMemFlag (address)) /* rest of routine not valid */ | |
48 return ((Options & M_DATA_BLOCKS) == O_DBL_STRICT); | |
49 | |
50 instr = &opset[Memory[address]]; | |
51 | |
52 if (!instr->mnemonic) /* invalid opcode */ | |
53 return ((Options & M_DATA_BLOCKS) == O_DBL_STRICT); | |
54 | |
55 size = sizes[instr->admode]; | |
56 if ((ADDR_T)(address + size - StartAddress) > | |
57 (ADDR_T)(EndAddress - StartAddress)) | |
58 break; /* end of program code encountered */ | |
59 | |
60 switch (GetMemType (address)) { | |
61 case MEM_INSTRUCTION: | |
62 return 0; /* The rest of the routine has already been processed. */ | |
63 | |
64 case MEM_DATA: | |
65 AddEntry (address, scanstart, WRN_INSTR_WRITTEN_TO); | |
66 break; | |
67 | |
68 case MEM_PARAMETER: | |
69 AddEntry (address, scanstart, WRN_PARAM_JUMPED_TO); | |
70 } | |
71 | |
72 SetMemType (address, MEM_INSTRUCTION); | |
73 | |
74 for (counter = size, addr = address + 1; --counter; addr++) | |
75 switch GetMemType(addr) { | |
76 case MEM_INSTRUCTION: | |
77 AddEntry (addr, scanstart, WRN_PARAM_JUMPED_TO); | |
78 break; | |
79 case MEM_DATA: | |
80 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO); | |
81 /* fall through */ | |
82 default: | |
83 SetMemType (addr, MEM_PARAMETER); | |
84 } | |
85 | |
86 if (instr->admode == zrel) { | |
87 addr = Memory[(ADDR_T)(address + 1)]; | |
88 | |
89 if (GetMemFlag (addr) && GetMemType (addr) == MEM_UNPROCESSED) | |
90 return (Options & M_DATA_BLOCKS) == O_DBL_STRICT; | |
91 | |
92 if (((ADDR_T)(addr - StartAddress) < | |
93 (ADDR_T)(EndAddress - StartAddress) || | |
94 Options & B_LBL_ALWAYS)) { | |
95 PutLabel (addr); | |
96 PutLowByte (addr); | |
97 PutHighByte (addr); | |
98 } | |
99 | |
100 addr = (ADDR_T)((int)(char)Memory[(ADDR_T)(address + 2)] + | |
101 address + size); | |
102 goto IsJump; | |
103 } | |
104 | |
105 if (instr->admode == rel) { | |
106 addr = (ADDR_T)((int)(char)Memory[(ADDR_T)(address + 1)] + | |
107 address + size); | |
108 | |
109 goto IsJump; | |
110 } | |
111 if ((instr->mnemonic == S_JSR || instr->mnemonic == S_JMP) && | |
112 instr->admode == abso) { | |
113 addr = Memory[(ADDR_T)(address + 1)] + | |
114 (Memory[(ADDR_T)(address + 2)] << 8); | |
115 | |
116 IsJump: | |
117 if (GetMemFlag (addr)) | |
118 return ((Options & M_DATA_BLOCKS) == O_DBL_STRICT); | |
119 | |
120 if ((ADDR_T)(addr - StartAddress) < | |
121 (ADDR_T)(EndAddress - StartAddress)) { | |
122 if (GetMemType (addr) == MEM_INSTRUCTION) { | |
123 PutLabel (addr); | |
124 PutLowByte (addr); | |
125 PutHighByte (addr); | |
126 } | |
127 else | |
128 AddEntry (addr, scanstart, Options & B_SCEPTIC && | |
129 instr->admode == rel && instr->mnemonic != S_BRA ? | |
130 RTN_POTENTIAL : RTN_SURE); | |
131 } | |
132 else if (Options & B_LBL_ALWAYS) { | |
133 PutLabel (addr); | |
134 PutLowByte (addr); | |
135 PutHighByte (addr); | |
136 } | |
137 | |
138 if ((Options & M_DATA_BLOCKS) == O_DBL_STRICT && | |
139 Options & B_JMP_STRICT && | |
140 addr == address && instr->mnemonic != S_BVC) | |
141 return 1; | |
142 } | |
143 | |
144 switch (instr->mnemonic) { | |
145 case S_JMP: | |
146 addr = Memory[(ADDR_T)(address + 1)] + | |
147 (Memory[(ADDR_T)(address + 2)] << 8); | |
148 | |
149 if (instr->admode == iabs && (ADDR_T)(addr - StartAddress) < | |
150 (ADDR_T)(EndAddress - StartAddress)) { | |
151 PutLabel (addr); | |
152 PutLowByte (addr); | |
153 PutHighByte (addr); | |
154 | |
155 /* Mark pointer as data. */ | |
156 switch (GetMemType (addr)) { | |
157 case MEM_UNPROCESSED: | |
158 SetMemType (addr, MEM_DATA); | |
159 break; | |
160 case MEM_INSTRUCTION: | |
161 AddEntry (addr, scanstart, WRN_INSTR_WRITTEN_TO); | |
162 break; | |
163 case MEM_PARAMETER: | |
164 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO); | |
165 break; | |
166 } | |
167 | |
168 addr++; | |
169 | |
170 if ((ADDR_T)(addr - StartAddress) < | |
171 (ADDR_T)(EndAddress - StartAddress)) | |
172 switch (GetMemType (addr)) { | |
173 case MEM_UNPROCESSED: | |
174 SetMemType (addr, MEM_DATA); | |
175 break; | |
176 case MEM_INSTRUCTION: | |
177 AddEntry (addr, scanstart, WRN_INSTR_WRITTEN_TO); | |
178 break; | |
179 case MEM_PARAMETER: | |
180 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO); | |
181 break; | |
182 } | |
183 } | |
184 else if (Options & B_LBL_ALWAYS) { | |
185 PutLabel (addr); | |
186 PutLowByte (addr); | |
187 PutHighByte (addr); | |
188 } | |
189 case S_BRA: | |
190 case S_RTS: | |
191 case S_RTI: | |
192 return 0; | |
193 | |
194 case S_BRK: | |
195 case S_STP: | |
196 return (Options & M_DATA_BLOCKS) == O_DBL_STRICT && | |
197 Options & B_BRK_REJECT; | |
198 } | |
199 | |
200 if (instr->admode == rel) { | |
201 if ((ADDR_T)(addr - scanstart) >= (ADDR_T)(address - scanstart) | |
202 || GetMemType (addr) != MEM_INSTRUCTION) { | |
203 if (GetMemType (address + size) != MEM_INSTRUCTION) | |
204 AddEntry (address + size, scanstart, RTN_POTENTIAL); | |
205 | |
206 return 0; | |
207 } | |
208 | |
209 continue; | |
210 } | |
211 | |
212 if (instr->mnemonic == S_JSR) { | |
213 if (!(Options & B_STK_BALANCE)) { | |
214 if (GetMemType (address + size) != MEM_INSTRUCTION) | |
215 AddEntry (address + size, scanstart, RTN_POTENTIAL); | |
216 | |
217 return 0; | |
218 } | |
219 | |
220 continue; | |
221 } | |
222 | |
223 switch (size) { | |
224 case 2: | |
225 addr = Memory[(ADDR_T)(address + 1)]; | |
226 break; | |
227 case 3: | |
228 addr = Memory[(ADDR_T)(address + 1)] + | |
229 (Memory[(ADDR_T)(address + 2)] << 8); | |
230 break; | |
231 } | |
232 | |
233 if (types[instr->admode] != impimm && GetMemFlag (addr) && | |
234 GetMemType (addr) == MEM_UNPROCESSED) | |
235 return (Options & M_DATA_BLOCKS) == O_DBL_STRICT; | |
236 | |
237 if (types[instr->admode] != impimm && | |
238 ((ADDR_T)(addr - StartAddress) < | |
239 (ADDR_T)(EndAddress - StartAddress) || | |
240 Options & B_LBL_ALWAYS)) { | |
241 PutLabel (addr); | |
242 PutLowByte (addr); | |
243 PutHighByte (addr); | |
244 } | |
245 | |
246 if (types[instr->admode] != other && types[instr->admode] != impimm) { | |
247 if ((ADDR_T)(addr - StartAddress) < | |
248 (ADDR_T)(EndAddress - StartAddress)) { | |
249 switch (GetMemType (addr)) { | |
250 case MEM_UNPROCESSED: | |
251 SetMemType (addr, MEM_DATA); | |
252 break; | |
253 case MEM_INSTRUCTION: | |
254 AddEntry (addr, scanstart, WRN_INSTR_WRITTEN_TO); | |
255 break; | |
256 case MEM_PARAMETER: | |
257 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO); | |
258 break; | |
259 } | |
260 | |
261 if (types[instr->admode] == absindir) { /* indirect mode */ | |
262 addr++; /* set flags for upper vector byte */ | |
263 | |
264 if ((ADDR_T)(addr - StartAddress) < | |
265 (ADDR_T)(EndAddress - StartAddress)) | |
266 switch (GetMemType (addr)) { | |
267 case MEM_UNPROCESSED: | |
268 SetMemType (addr, MEM_DATA); | |
269 break; | |
270 case MEM_INSTRUCTION: | |
271 AddEntry (addr, scanstart, WRN_INSTR_WRITTEN_TO); | |
272 break; | |
273 case MEM_PARAMETER: | |
274 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO); | |
275 break; | |
276 } | |
277 } | |
278 } | |
279 } | |
280 } | |
281 | |
282 /* end of program (unexpectedly) encountered */ | |
283 | |
284 if (Options & O_DBL_STRICT) return 1; | |
285 | |
286 AddEntry (EndAddress, scanstart, WRN_RTN_TRUNCATED); | |
287 return 0; | |
288 } | |
289 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
290 |
0 | 291 int ScanPotential (ADDR_T scanstart) |
292 { | |
293 ADDR_T address, addr; | |
294 opcodes *instr; | |
295 | |
296 unsigned int size, counter; | |
297 | |
298 for (address = scanstart;; address += size) { | |
299 if (GetMemFlag (address)) /* rest of routine not valid */ | |
300 return 1; | |
301 | |
302 instr = &opset[Memory[address]]; | |
303 | |
304 if (!instr->mnemonic) { /* invalid opcode */ | |
305 SetMemFlag (address); | |
306 | |
307 if (GetMemType (address) == MEM_UNPROCESSED) | |
308 SetMemType (address, MEM_DATA); | |
309 return 1; | |
310 } | |
311 | |
312 size = sizes[instr->admode]; | |
313 if ((ADDR_T)(address + size - StartAddress) > | |
314 (ADDR_T)(EndAddress - StartAddress)) | |
315 break; /* end of program code encountered */ | |
316 | |
317 if (GetMemType (address) == MEM_INSTRUCTION) | |
318 return 0; /* The rest of the routine has already been processed. */ | |
319 | |
320 if (instr->admode == zrel) { | |
321 addr = Memory[(ADDR_T)(address + 1)]; | |
322 | |
323 if (GetMemFlag (addr) && GetMemType (addr) == MEM_UNPROCESSED) | |
324 goto Failure; | |
325 | |
326 if (((ADDR_T)(addr - StartAddress) < | |
327 (ADDR_T)(EndAddress - StartAddress) || | |
328 Options & B_LBL_ALWAYS)) | |
329 AddEntry (addr, scanstart, WRN_I_LABEL_NEEDED | WRN_B_TEMPORARY); | |
330 | |
331 addr = (ADDR_T)((int)(char)Memory[(ADDR_T)(address + 1)] + | |
332 address + size); | |
333 | |
334 goto IsJump; | |
335 } | |
336 | |
337 if (instr->admode == rel) { | |
338 addr = (ADDR_T)((int)(char)Memory[(ADDR_T)(address + 1)] + | |
339 address + size); | |
340 | |
341 goto IsJump; | |
342 } | |
343 | |
344 switch (size) { | |
345 case 2: | |
346 addr = Memory[(ADDR_T)(address + 1)]; | |
347 break; | |
348 case 3: | |
349 addr = Memory[(ADDR_T)(address + 1)] + | |
350 (Memory[(ADDR_T)(address + 2)] << 8); | |
351 break; | |
352 default: | |
353 addr = address; | |
354 } | |
355 | |
356 if (types[instr->admode] != impimm && GetMemFlag (addr) && | |
357 GetMemType (addr) == MEM_UNPROCESSED) { | |
358 Failure: | |
359 SetMemFlag (address); | |
360 | |
361 if (GetMemType (address) == MEM_UNPROCESSED) | |
362 SetMemType (address, MEM_DATA); | |
363 return 1; | |
364 } | |
365 | |
366 if ((instr->mnemonic == S_JSR || instr->mnemonic == S_JMP) && | |
367 instr->admode == abso) { | |
368 IsJump: | |
369 if (GetMemFlag (addr)) { | |
370 SetMemFlag (address); | |
371 | |
372 if (GetMemType (address) == MEM_UNPROCESSED) | |
373 SetMemType (address, MEM_DATA); | |
374 return 1; | |
375 } | |
376 | |
377 if ((ADDR_T)(addr - StartAddress) < | |
378 (ADDR_T)(EndAddress - StartAddress)) | |
379 AddEntry (addr, scanstart, Options & B_SCEPTIC && | |
380 instr->admode == rel && instr->mnemonic != S_BRA ? | |
381 RTN_SUSP_POT : RTN_SUSPECTED); | |
382 else if (Options & B_LBL_ALWAYS) | |
383 AddEntry (addr, scanstart, WRN_I_LABEL_NEEDED | WRN_B_TEMPORARY); | |
384 | |
385 if (Options & B_JMP_STRICT && addr == address && | |
386 instr->mnemonic != S_BVC) { | |
387 SetMemFlag (address); | |
388 | |
389 if (GetMemType (address) == MEM_UNPROCESSED) | |
390 SetMemType (address, MEM_DATA); | |
391 return 1; | |
392 } | |
393 } | |
394 | |
395 switch (instr->mnemonic) { | |
396 case S_BRK: | |
397 case S_STP: | |
398 if (Options & B_BRK_REJECT) { | |
399 SetMemFlag (address); | |
400 | |
401 if (GetMemType (address) == MEM_UNPROCESSED) | |
402 SetMemType (address, MEM_DATA); | |
403 return 1; | |
404 } | |
405 } | |
406 | |
407 if (!GetMemFlag (address)) | |
408 switch (GetMemType (address)) { | |
409 case MEM_DATA: | |
410 AddEntry (address, scanstart, WRN_INSTR_WRITTEN_TO | WRN_B_TEMPORARY); | |
411 break; | |
412 | |
413 case MEM_PARAMETER: | |
414 AddEntry (address, scanstart, WRN_PARAM_JUMPED_TO | WRN_B_TEMPORARY); | |
415 } | |
416 | |
417 SetMemType (address, MEM_INSTRUCTION); | |
418 | |
419 for (counter = size, addr = address + 1; --counter; addr++) | |
420 switch (GetMemType (addr)) { | |
421 case MEM_INSTRUCTION: | |
422 AddEntry (addr, scanstart, WRN_PARAM_JUMPED_TO | WRN_B_TEMPORARY); | |
423 break; | |
424 case MEM_DATA: | |
425 if (!GetMemFlag (addr)) | |
426 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO | WRN_B_TEMPORARY); | |
427 break; | |
428 default: | |
429 SetMemType (addr, MEM_PARAMETER); | |
430 } | |
431 | |
432 switch (instr->mnemonic) { | |
433 case S_BRK: | |
434 case S_STP: | |
435 case S_RTS: | |
436 case S_BRA: | |
437 case S_RTI: | |
438 return 0; | |
439 | |
440 case S_JMP: | |
441 addr = Memory[(ADDR_T)(address + 1)] + | |
442 (Memory[(ADDR_T)(address + 2)] << 8); | |
443 | |
444 if (instr->admode == iabs && (ADDR_T)(addr - StartAddress) < | |
445 (ADDR_T)(EndAddress - StartAddress)) { | |
446 AddEntry (addr, scanstart, WRN_I_LABEL_NEEDED | WRN_B_TEMPORARY); | |
447 | |
448 /* Mark pointer as data. */ | |
449 switch (GetMemType (addr)) { | |
450 case MEM_UNPROCESSED: | |
451 AddEntry (addr, scanstart, WRN_I_ACCESSED | WRN_B_TEMPORARY); | |
452 break; | |
453 case MEM_INSTRUCTION: | |
454 AddEntry (addr, scanstart, WRN_INSTR_WRITTEN_TO | WRN_B_TEMPORARY); | |
455 break; | |
456 case MEM_PARAMETER: | |
457 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO | WRN_B_TEMPORARY); | |
458 break; | |
459 } | |
460 | |
461 addr++; | |
462 | |
463 if ((ADDR_T)(addr - StartAddress) < | |
464 (ADDR_T)(EndAddress - StartAddress)) | |
465 switch (GetMemType (addr)) { | |
466 case MEM_UNPROCESSED: | |
467 AddEntry (addr, scanstart, WRN_I_ACCESSED | WRN_B_TEMPORARY); | |
468 break; | |
469 case MEM_INSTRUCTION: | |
470 AddEntry (addr, scanstart, | |
471 WRN_INSTR_WRITTEN_TO | WRN_B_TEMPORARY); | |
472 break; | |
473 case MEM_PARAMETER: | |
474 AddEntry (addr, scanstart, | |
475 WRN_PARAM_WRITTEN_TO | WRN_B_TEMPORARY); | |
476 break; | |
477 } | |
478 } | |
479 else if (Options & B_LBL_ALWAYS) | |
480 AddEntry (addr, scanstart, WRN_I_LABEL_NEEDED | WRN_B_TEMPORARY); | |
481 | |
482 return 0; | |
483 } | |
484 | |
485 if (instr->admode == rel && | |
486 GetMemType (address + size) != MEM_INSTRUCTION) { | |
487 AddEntry (address + size, scanstart, RTN_SUSP_POT); | |
488 | |
489 return 0; | |
490 } | |
491 | |
492 if (instr->mnemonic == S_JSR) { | |
493 if (!(Options & B_STK_BALANCE)) { | |
494 if (GetMemType (address + size) != MEM_INSTRUCTION) | |
495 AddEntry (address + size, scanstart, RTN_SUSP_POT); | |
496 | |
497 return 0; | |
498 } | |
499 | |
500 continue; | |
501 } | |
502 | |
503 switch (size) { | |
504 case 2: | |
505 addr = Memory[(ADDR_T)(address + 1)]; | |
506 break; | |
507 case 3: | |
508 addr = Memory[(ADDR_T)(address + 1)] + | |
509 (Memory[(ADDR_T)(address + 2)] << 8); | |
510 break; | |
511 } | |
512 | |
513 if (types[instr->admode] != impimm && | |
514 ((ADDR_T)(addr - StartAddress) < | |
515 (ADDR_T)(EndAddress - StartAddress) || | |
516 Options & B_LBL_ALWAYS)) | |
517 AddEntry (addr, scanstart, WRN_I_LABEL_NEEDED | WRN_B_TEMPORARY); | |
518 | |
519 if (types[instr->admode] != other && types[instr->admode] != impimm) { | |
520 if ((ADDR_T)(addr - StartAddress) < | |
521 (ADDR_T)(EndAddress - StartAddress)) { | |
522 switch (GetMemType (addr)) { | |
523 case MEM_UNPROCESSED: | |
524 AddEntry (addr, scanstart, WRN_I_ACCESSED | WRN_B_TEMPORARY); | |
525 break; | |
526 case MEM_INSTRUCTION: | |
527 AddEntry (addr, scanstart, WRN_INSTR_WRITTEN_TO | WRN_B_TEMPORARY); | |
528 break; | |
529 case MEM_PARAMETER: | |
530 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO | WRN_B_TEMPORARY); | |
531 break; | |
532 } | |
533 | |
534 if (types[instr->admode] == absindir) { /* indirect mode */ | |
535 addr++; /* set flags for upper vector byte */ | |
536 | |
537 if ((ADDR_T)(addr - StartAddress) < | |
538 (ADDR_T)(EndAddress - StartAddress)) | |
539 switch (GetMemType (addr)) { | |
540 case MEM_UNPROCESSED: | |
541 AddEntry (addr, scanstart, WRN_I_ACCESSED | WRN_B_TEMPORARY); | |
542 break; | |
543 case MEM_INSTRUCTION: | |
544 AddEntry (addr, scanstart, | |
545 WRN_INSTR_WRITTEN_TO | WRN_B_TEMPORARY); | |
546 break; | |
547 case MEM_PARAMETER: | |
548 AddEntry (addr, scanstart, | |
549 WRN_PARAM_WRITTEN_TO | WRN_B_TEMPORARY); | |
550 break; | |
551 } | |
552 } | |
553 } | |
554 } | |
555 } | |
556 | |
557 /* end of program (unexpectedly) encountered */ | |
558 | |
559 return 1; | |
560 } | |
561 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
562 |
0 | 563 int ScanSpecified (void) |
564 { | |
565 table *entry; | |
566 | |
567 if (fVerbose) | |
568 fprintf (stderr, "%s: scanning the routines at specified address(es)", | |
569 prog); | |
570 | |
571 while ((entry = FindNextEntryType (NULL, ~0, RTN_SURE))) { | |
572 PutLabel (entry->address); | |
573 PutLowByte (entry->address); | |
574 PutHighByte (entry->address); | |
575 | |
576 if (ScanSure (entry->address)) { | |
577 fprintf(stderr,"For routine specified at %i:", | |
578 (unsigned int)entry->address); | |
579 return 1; | |
580 } | |
1 | 581 entry = FindNextEntryType (NULL, ~0, RTN_SURE); |
0 | 582 DeleteEntry (entry); |
583 } | |
584 | |
585 return 0; | |
586 } | |
587 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
588 |
0 | 589 void UnDoScan (ADDR_T scanstart) |
590 { | |
591 opcodes *instr; | |
592 unsigned counter; | |
593 ADDR_T address; | |
594 | |
595 for (address = scanstart; address != EndAddress; address++) { | |
596 if (GetMemFlag (address)) return; | |
597 | |
598 switch (GetMemType (address)) { | |
599 case MEM_UNPROCESSED: | |
600 return; | |
601 | |
602 case MEM_INSTRUCTION: | |
603 SetMemFlag (address); | |
604 SetMemType (address, MEM_DATA); /* This could cause WRN_PARAM_WRITTEN_TO | |
605 in vain. */ | |
606 instr = &opset[Memory[address++]]; | |
607 for (counter = sizes[instr->admode]; --counter; address++) | |
608 if (GetMemType (address) == MEM_PARAMETER) | |
609 SetMemType (address, MEM_UNPROCESSED); | |
610 else if (GetMemType (address) == MEM_INSTRUCTION) | |
611 break; | |
612 | |
613 if (instr->mnemonic == S_STP || instr->mnemonic == S_BRK || | |
614 instr->mnemonic == S_RTI || instr->mnemonic == S_RTS || | |
615 instr->mnemonic == S_JMP || instr->admode == rel) | |
616 return; | |
617 | |
618 address--; | |
619 break; | |
620 | |
621 case MEM_PARAMETER: | |
622 SetMemType (address, MEM_UNPROCESSED); | |
623 } | |
624 } | |
625 } | |
626 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
627 |
0 | 628 void DeleteSuspectedParents (ADDR_T child) |
629 { | |
630 table *entry = NULL; | |
631 | |
632 while ((entry = FindNextEntry (entry, child, ~(RTN_B_PROCESSED | | |
633 RTN_B_TEMPORARY), | |
634 RTN_SUSPECTED))) { | |
635 if (entry->type & RTN_B_PROCESSED && entry->parent != child) | |
636 DeleteSuspectedParents (entry->parent); | |
637 | |
638 DeleteEntry (entry); | |
639 } | |
640 | |
641 entry = NULL; | |
642 | |
643 while ((entry = FindNextEntryTypeParent (entry, child, ~0, RTN_SUSP_POT))) | |
644 DeleteEntry (entry); | |
645 | |
646 entry = NULL; | |
647 | |
648 while ((entry = FindNextEntryTypeParent (entry, child, | |
649 MASK_ANY | WRN_B_TEMPORARY, | |
650 WRN_ANY | WRN_B_TEMPORARY))) { | |
651 if (entry->type == (WRN_PARAM_JUMPED_TO | WRN_B_TEMPORARY)) | |
652 SetMemType (entry->address, MEM_PARAMETER); | |
653 | |
654 DeleteEntry (entry); | |
655 } | |
656 | |
657 UnDoScan (child); | |
658 } | |
659 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
660 |
0 | 661 void ScanPotentials (void) |
662 { | |
663 table *entry; | |
664 ADDR_T address; | |
665 | |
666 if (fVerbose) | |
667 fprintf (stderr, "\n%s: scanning potential routines\n", prog); | |
668 | |
669 while ((entry = FindNextEntryType (NULL, ~0, RTN_POTENTIAL))) { | |
670 address = entry->address; | |
671 DeleteEntry (entry); | |
672 | |
673 if (!ScanPotential (address)) { | |
674 while ((entry = FindNextEntryType (NULL, ~RTN_B_TEMPORARY, | |
675 RTN_SUSPECTED))) { | |
676 entry->type |= RTN_B_PROCESSED; | |
677 | |
678 if (ScanPotential (entry->address) && | |
679 (Options & M_DATA_BLOCKS) != O_DBL_IGNORE) { | |
680 DeleteSuspectedParents (entry->address); | |
681 SetMemType (address, MEM_DATA); | |
682 } | |
683 } | |
684 | |
685 if (GetMemType (address) != MEM_DATA) { | |
686 PutLabel (address); | |
687 PutLowByte (address); | |
688 PutHighByte (address); | |
689 } | |
690 | |
691 entry = NULL; | |
692 | |
693 while ((entry = FindNextEntryType (entry, ~0, RTN_B_TEMPORARY | | |
694 RTN_SUSPECTED | RTN_B_PROCESSED))) | |
695 DeleteEntry (entry); | |
696 | |
697 entry = NULL; | |
698 | |
699 while ((entry = FindNextEntryType (entry, ~0, | |
700 RTN_SUSPECTED | RTN_B_PROCESSED))) { | |
701 PutLabel (entry->address); | |
702 PutLowByte (entry->address); | |
703 PutHighByte (entry->address); | |
704 DeleteEntry (entry); | |
705 } | |
706 | |
707 entry = NULL; | |
708 | |
709 while ((entry = FindNextEntryType (entry, ~0, RTN_SUSP_POT))) | |
710 entry->type = RTN_POTENTIAL; | |
711 | |
712 entry = NULL; | |
713 | |
714 while ((entry = FindNextEntryType (entry, MASK_ANY | WRN_B_TEMPORARY, | |
715 WRN_ANY | WRN_B_TEMPORARY))) { | |
716 switch (entry->type & ~WRN_B_TEMPORARY) { | |
717 case WRN_PARAM_WRITTEN_TO: | |
718 if (GetMemType (entry->address) == MEM_DATA) | |
719 SetMemType (entry->address, MEM_PARAMETER); | |
720 entry->type &= ~WRN_B_TEMPORARY; | |
721 break; | |
722 | |
723 case WRN_INSTR_WRITTEN_TO: | |
724 if (GetMemType (entry->address) == MEM_DATA) | |
725 SetMemType (entry->address, MEM_INSTRUCTION); | |
726 entry->type &= ~WRN_B_TEMPORARY; | |
727 break; | |
728 | |
729 case WRN_I_ACCESSED: | |
730 SetMemType (entry->address, MEM_DATA); | |
731 /* fall through */ | |
732 case WRN_I_LABEL_NEEDED: | |
733 PutLabel (entry->address); | |
734 PutLowByte (entry->address); | |
735 PutHighByte (entry->address); | |
736 DeleteEntry (entry); | |
737 break; | |
738 | |
739 default: | |
740 entry->type &= ~WRN_B_TEMPORARY; | |
741 } | |
742 } | |
743 } | |
744 else { | |
745 DeleteSuspectedParents (address); | |
746 SetMemType (address, MEM_DATA); | |
747 } | |
748 } | |
749 } | |
750 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
751 |
0 | 752 void ScanTheRest (void) |
753 { | |
754 ADDR_T address; | |
755 table *entry; | |
756 unsigned int fPotentials; | |
757 | |
758 if ((Options & M_DATA_BLOCKS) == O_DBL_NOSCAN) { | |
759 for (address = StartAddress; address != EndAddress; address++) | |
760 if (GetMemType (address) == MEM_UNPROCESSED) | |
761 SetMemType (address, MEM_DATA); | |
762 | |
763 return; | |
764 } | |
765 | |
766 if (fVerbose) | |
767 fprintf (stderr, "%s: scanning the remaining bytes for routines\n", prog); | |
768 | |
769 for (address = StartAddress; address != EndAddress; address++) { | |
770 if (GetMemType (address) || GetMemFlag (address)) | |
771 continue; /* scan only unprocessed bytes */ | |
772 | |
773 if (Options & B_RSC_STRICT) | |
774 switch (opset[Memory[address]].mnemonic) { | |
775 case S_RTI: | |
776 case S_RTS: | |
777 case S_BRK: | |
778 case S_STP: | |
779 continue; | |
780 | |
781 case S_BRA: | |
782 break; | |
783 | |
784 default: | |
785 if (opset[Memory[address]].admode == rel && | |
786 GetMemType (address + sizes[rel]) != MEM_INSTRUCTION) | |
787 AddEntry (address + sizes[rel], address, | |
788 RTN_SUSPECTED | RTN_B_TEMPORARY); | |
789 } | |
790 | |
791 if (fVerbose) | |
792 fprintf (stderr, "\r%s: scanning at %X", prog, address); | |
793 | |
794 if (!ScanPotential (address)) { | |
795 while ((entry = FindNextEntryType (NULL, ~RTN_B_TEMPORARY, | |
796 RTN_SUSPECTED))) { | |
797 entry->type |= RTN_B_PROCESSED; | |
798 | |
799 if (ScanPotential (entry->address) && | |
800 (Options & M_DATA_BLOCKS) != O_DBL_IGNORE) { | |
801 DeleteSuspectedParents (entry->address); | |
802 SetMemType (address, MEM_DATA); | |
803 } | |
804 } | |
805 | |
806 if (GetMemType (address) != MEM_DATA) { | |
807 PutLabel (address); | |
808 PutLowByte (address); | |
809 PutHighByte (address); | |
810 } | |
811 | |
812 fPotentials = FALSE; | |
813 entry = NULL; | |
814 | |
815 while ((entry = FindNextEntryType (entry, ~0, RTN_SUSP_POT))) { | |
816 fPotentials = TRUE; | |
817 entry->type = RTN_POTENTIAL; | |
818 } | |
819 | |
820 entry = NULL; | |
821 | |
822 while ((entry = FindNextEntryType (entry, ~0, RTN_B_TEMPORARY | | |
823 RTN_SUSPECTED | RTN_B_PROCESSED))) | |
824 DeleteEntry (entry); | |
825 | |
826 entry = NULL; | |
827 | |
828 while ((entry = FindNextEntryType (entry, ~0, | |
829 RTN_SUSPECTED | RTN_B_PROCESSED))) { | |
830 PutLabel (entry->address); | |
831 PutLowByte (entry->address); | |
832 PutHighByte (entry->address); | |
833 DeleteEntry (entry); | |
834 } | |
835 | |
836 entry = NULL; | |
837 | |
838 while ((entry = FindNextEntryType (entry, MASK_ANY | WRN_B_TEMPORARY, | |
839 WRN_ANY | WRN_B_TEMPORARY))) { | |
840 switch (entry->type & ~WRN_B_TEMPORARY) { | |
841 case WRN_PARAM_WRITTEN_TO: | |
842 if (GetMemType (entry->address) == MEM_DATA) | |
843 SetMemType (entry->address, MEM_PARAMETER); | |
844 entry->type &= ~WRN_B_TEMPORARY; | |
845 break; | |
846 | |
847 case WRN_INSTR_WRITTEN_TO: | |
848 if (GetMemType (entry->address) == MEM_DATA) | |
849 SetMemType (entry->address, MEM_INSTRUCTION); | |
850 entry->type &= ~WRN_B_TEMPORARY; | |
851 break; | |
852 | |
853 case WRN_I_ACCESSED: | |
854 SetMemType (entry->address, MEM_DATA); | |
855 /* fall through */ | |
856 case WRN_I_LABEL_NEEDED: | |
857 PutLabel (entry->address); | |
858 PutLowByte (entry->address); | |
859 PutHighByte (entry->address); | |
860 DeleteEntry (entry); | |
861 break; | |
862 | |
863 default: | |
864 entry->type &= ~WRN_B_TEMPORARY; | |
865 } | |
866 } | |
867 | |
868 if (fPotentials) ScanPotentials (); | |
869 } | |
870 else { | |
871 DeleteSuspectedParents (address); | |
872 SetMemType (address, MEM_DATA); | |
873 } | |
874 } | |
875 | |
876 if (fVerbose) | |
877 fprintf (stderr, "\n"); | |
878 | |
879 for (address = StartAddress; address != EndAddress; address++) | |
880 if (GetMemType (address) == MEM_UNPROCESSED) { | |
881 fPotentials = GetMemFlag (address) ? MEM_PARAMETER : MEM_DATA; | |
882 SetMemType (address, fPotentials); | |
883 } | |
884 } |