Mercurial > hg > forks > dxa
annotate scan.c @ 9:987c90810883
Fix a warning.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 27 Jun 2018 11:37:08 +0300 |
parents | ec2f8f6f1dc9 |
children | fe4d840c13eb |
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 } | |
9 | 189 return 0; |
190 | |
0 | 191 case S_BRA: |
192 case S_RTS: | |
193 case S_RTI: | |
194 return 0; | |
195 | |
196 case S_BRK: | |
197 case S_STP: | |
198 return (Options & M_DATA_BLOCKS) == O_DBL_STRICT && | |
199 Options & B_BRK_REJECT; | |
200 } | |
201 | |
202 if (instr->admode == rel) { | |
203 if ((ADDR_T)(addr - scanstart) >= (ADDR_T)(address - scanstart) | |
204 || GetMemType (addr) != MEM_INSTRUCTION) { | |
205 if (GetMemType (address + size) != MEM_INSTRUCTION) | |
206 AddEntry (address + size, scanstart, RTN_POTENTIAL); | |
207 | |
208 return 0; | |
209 } | |
210 | |
211 continue; | |
212 } | |
213 | |
214 if (instr->mnemonic == S_JSR) { | |
215 if (!(Options & B_STK_BALANCE)) { | |
216 if (GetMemType (address + size) != MEM_INSTRUCTION) | |
217 AddEntry (address + size, scanstart, RTN_POTENTIAL); | |
218 | |
219 return 0; | |
220 } | |
221 | |
222 continue; | |
223 } | |
224 | |
225 switch (size) { | |
226 case 2: | |
227 addr = Memory[(ADDR_T)(address + 1)]; | |
228 break; | |
229 case 3: | |
230 addr = Memory[(ADDR_T)(address + 1)] + | |
231 (Memory[(ADDR_T)(address + 2)] << 8); | |
232 break; | |
233 } | |
234 | |
235 if (types[instr->admode] != impimm && GetMemFlag (addr) && | |
236 GetMemType (addr) == MEM_UNPROCESSED) | |
237 return (Options & M_DATA_BLOCKS) == O_DBL_STRICT; | |
238 | |
239 if (types[instr->admode] != impimm && | |
240 ((ADDR_T)(addr - StartAddress) < | |
241 (ADDR_T)(EndAddress - StartAddress) || | |
242 Options & B_LBL_ALWAYS)) { | |
243 PutLabel (addr); | |
244 PutLowByte (addr); | |
245 PutHighByte (addr); | |
246 } | |
247 | |
248 if (types[instr->admode] != other && types[instr->admode] != impimm) { | |
249 if ((ADDR_T)(addr - StartAddress) < | |
250 (ADDR_T)(EndAddress - StartAddress)) { | |
251 switch (GetMemType (addr)) { | |
252 case MEM_UNPROCESSED: | |
253 SetMemType (addr, MEM_DATA); | |
254 break; | |
255 case MEM_INSTRUCTION: | |
256 AddEntry (addr, scanstart, WRN_INSTR_WRITTEN_TO); | |
257 break; | |
258 case MEM_PARAMETER: | |
259 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO); | |
260 break; | |
261 } | |
262 | |
263 if (types[instr->admode] == absindir) { /* indirect mode */ | |
264 addr++; /* set flags for upper vector byte */ | |
265 | |
266 if ((ADDR_T)(addr - StartAddress) < | |
267 (ADDR_T)(EndAddress - StartAddress)) | |
268 switch (GetMemType (addr)) { | |
269 case MEM_UNPROCESSED: | |
270 SetMemType (addr, MEM_DATA); | |
271 break; | |
272 case MEM_INSTRUCTION: | |
273 AddEntry (addr, scanstart, WRN_INSTR_WRITTEN_TO); | |
274 break; | |
275 case MEM_PARAMETER: | |
276 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO); | |
277 break; | |
278 } | |
279 } | |
280 } | |
281 } | |
282 } | |
283 | |
284 /* end of program (unexpectedly) encountered */ | |
285 | |
286 if (Options & O_DBL_STRICT) return 1; | |
287 | |
288 AddEntry (EndAddress, scanstart, WRN_RTN_TRUNCATED); | |
289 return 0; | |
290 } | |
291 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
292 |
0 | 293 int ScanPotential (ADDR_T scanstart) |
294 { | |
295 ADDR_T address, addr; | |
296 opcodes *instr; | |
297 | |
298 unsigned int size, counter; | |
299 | |
300 for (address = scanstart;; address += size) { | |
301 if (GetMemFlag (address)) /* rest of routine not valid */ | |
302 return 1; | |
303 | |
304 instr = &opset[Memory[address]]; | |
305 | |
306 if (!instr->mnemonic) { /* invalid opcode */ | |
307 SetMemFlag (address); | |
308 | |
309 if (GetMemType (address) == MEM_UNPROCESSED) | |
310 SetMemType (address, MEM_DATA); | |
311 return 1; | |
312 } | |
313 | |
314 size = sizes[instr->admode]; | |
315 if ((ADDR_T)(address + size - StartAddress) > | |
316 (ADDR_T)(EndAddress - StartAddress)) | |
317 break; /* end of program code encountered */ | |
318 | |
319 if (GetMemType (address) == MEM_INSTRUCTION) | |
320 return 0; /* The rest of the routine has already been processed. */ | |
321 | |
322 if (instr->admode == zrel) { | |
323 addr = Memory[(ADDR_T)(address + 1)]; | |
324 | |
325 if (GetMemFlag (addr) && GetMemType (addr) == MEM_UNPROCESSED) | |
326 goto Failure; | |
327 | |
328 if (((ADDR_T)(addr - StartAddress) < | |
329 (ADDR_T)(EndAddress - StartAddress) || | |
330 Options & B_LBL_ALWAYS)) | |
331 AddEntry (addr, scanstart, WRN_I_LABEL_NEEDED | WRN_B_TEMPORARY); | |
332 | |
333 addr = (ADDR_T)((int)(char)Memory[(ADDR_T)(address + 1)] + | |
334 address + size); | |
335 | |
336 goto IsJump; | |
337 } | |
338 | |
339 if (instr->admode == rel) { | |
340 addr = (ADDR_T)((int)(char)Memory[(ADDR_T)(address + 1)] + | |
341 address + size); | |
342 | |
343 goto IsJump; | |
344 } | |
345 | |
346 switch (size) { | |
347 case 2: | |
348 addr = Memory[(ADDR_T)(address + 1)]; | |
349 break; | |
350 case 3: | |
351 addr = Memory[(ADDR_T)(address + 1)] + | |
352 (Memory[(ADDR_T)(address + 2)] << 8); | |
353 break; | |
354 default: | |
355 addr = address; | |
356 } | |
357 | |
358 if (types[instr->admode] != impimm && GetMemFlag (addr) && | |
359 GetMemType (addr) == MEM_UNPROCESSED) { | |
360 Failure: | |
361 SetMemFlag (address); | |
362 | |
363 if (GetMemType (address) == MEM_UNPROCESSED) | |
364 SetMemType (address, MEM_DATA); | |
365 return 1; | |
366 } | |
367 | |
368 if ((instr->mnemonic == S_JSR || instr->mnemonic == S_JMP) && | |
369 instr->admode == abso) { | |
370 IsJump: | |
371 if (GetMemFlag (addr)) { | |
372 SetMemFlag (address); | |
373 | |
374 if (GetMemType (address) == MEM_UNPROCESSED) | |
375 SetMemType (address, MEM_DATA); | |
376 return 1; | |
377 } | |
378 | |
379 if ((ADDR_T)(addr - StartAddress) < | |
380 (ADDR_T)(EndAddress - StartAddress)) | |
381 AddEntry (addr, scanstart, Options & B_SCEPTIC && | |
382 instr->admode == rel && instr->mnemonic != S_BRA ? | |
383 RTN_SUSP_POT : RTN_SUSPECTED); | |
384 else if (Options & B_LBL_ALWAYS) | |
385 AddEntry (addr, scanstart, WRN_I_LABEL_NEEDED | WRN_B_TEMPORARY); | |
386 | |
387 if (Options & B_JMP_STRICT && addr == address && | |
388 instr->mnemonic != S_BVC) { | |
389 SetMemFlag (address); | |
390 | |
391 if (GetMemType (address) == MEM_UNPROCESSED) | |
392 SetMemType (address, MEM_DATA); | |
393 return 1; | |
394 } | |
395 } | |
396 | |
397 switch (instr->mnemonic) { | |
398 case S_BRK: | |
399 case S_STP: | |
400 if (Options & B_BRK_REJECT) { | |
401 SetMemFlag (address); | |
402 | |
403 if (GetMemType (address) == MEM_UNPROCESSED) | |
404 SetMemType (address, MEM_DATA); | |
405 return 1; | |
406 } | |
407 } | |
408 | |
409 if (!GetMemFlag (address)) | |
410 switch (GetMemType (address)) { | |
411 case MEM_DATA: | |
412 AddEntry (address, scanstart, WRN_INSTR_WRITTEN_TO | WRN_B_TEMPORARY); | |
413 break; | |
414 | |
415 case MEM_PARAMETER: | |
416 AddEntry (address, scanstart, WRN_PARAM_JUMPED_TO | WRN_B_TEMPORARY); | |
417 } | |
418 | |
419 SetMemType (address, MEM_INSTRUCTION); | |
420 | |
421 for (counter = size, addr = address + 1; --counter; addr++) | |
422 switch (GetMemType (addr)) { | |
423 case MEM_INSTRUCTION: | |
424 AddEntry (addr, scanstart, WRN_PARAM_JUMPED_TO | WRN_B_TEMPORARY); | |
425 break; | |
426 case MEM_DATA: | |
427 if (!GetMemFlag (addr)) | |
428 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO | WRN_B_TEMPORARY); | |
429 break; | |
430 default: | |
431 SetMemType (addr, MEM_PARAMETER); | |
432 } | |
433 | |
434 switch (instr->mnemonic) { | |
435 case S_BRK: | |
436 case S_STP: | |
437 case S_RTS: | |
438 case S_BRA: | |
439 case S_RTI: | |
440 return 0; | |
441 | |
442 case S_JMP: | |
443 addr = Memory[(ADDR_T)(address + 1)] + | |
444 (Memory[(ADDR_T)(address + 2)] << 8); | |
445 | |
446 if (instr->admode == iabs && (ADDR_T)(addr - StartAddress) < | |
447 (ADDR_T)(EndAddress - StartAddress)) { | |
448 AddEntry (addr, scanstart, WRN_I_LABEL_NEEDED | WRN_B_TEMPORARY); | |
449 | |
450 /* Mark pointer as data. */ | |
451 switch (GetMemType (addr)) { | |
452 case MEM_UNPROCESSED: | |
453 AddEntry (addr, scanstart, WRN_I_ACCESSED | WRN_B_TEMPORARY); | |
454 break; | |
455 case MEM_INSTRUCTION: | |
456 AddEntry (addr, scanstart, WRN_INSTR_WRITTEN_TO | WRN_B_TEMPORARY); | |
457 break; | |
458 case MEM_PARAMETER: | |
459 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO | WRN_B_TEMPORARY); | |
460 break; | |
461 } | |
462 | |
463 addr++; | |
464 | |
465 if ((ADDR_T)(addr - StartAddress) < | |
466 (ADDR_T)(EndAddress - StartAddress)) | |
467 switch (GetMemType (addr)) { | |
468 case MEM_UNPROCESSED: | |
469 AddEntry (addr, scanstart, WRN_I_ACCESSED | WRN_B_TEMPORARY); | |
470 break; | |
471 case MEM_INSTRUCTION: | |
472 AddEntry (addr, scanstart, | |
473 WRN_INSTR_WRITTEN_TO | WRN_B_TEMPORARY); | |
474 break; | |
475 case MEM_PARAMETER: | |
476 AddEntry (addr, scanstart, | |
477 WRN_PARAM_WRITTEN_TO | WRN_B_TEMPORARY); | |
478 break; | |
479 } | |
480 } | |
481 else if (Options & B_LBL_ALWAYS) | |
482 AddEntry (addr, scanstart, WRN_I_LABEL_NEEDED | WRN_B_TEMPORARY); | |
483 | |
484 return 0; | |
485 } | |
486 | |
487 if (instr->admode == rel && | |
488 GetMemType (address + size) != MEM_INSTRUCTION) { | |
489 AddEntry (address + size, scanstart, RTN_SUSP_POT); | |
490 | |
491 return 0; | |
492 } | |
493 | |
494 if (instr->mnemonic == S_JSR) { | |
495 if (!(Options & B_STK_BALANCE)) { | |
496 if (GetMemType (address + size) != MEM_INSTRUCTION) | |
497 AddEntry (address + size, scanstart, RTN_SUSP_POT); | |
498 | |
499 return 0; | |
500 } | |
501 | |
502 continue; | |
503 } | |
504 | |
505 switch (size) { | |
506 case 2: | |
507 addr = Memory[(ADDR_T)(address + 1)]; | |
508 break; | |
509 case 3: | |
510 addr = Memory[(ADDR_T)(address + 1)] + | |
511 (Memory[(ADDR_T)(address + 2)] << 8); | |
512 break; | |
513 } | |
514 | |
515 if (types[instr->admode] != impimm && | |
516 ((ADDR_T)(addr - StartAddress) < | |
517 (ADDR_T)(EndAddress - StartAddress) || | |
518 Options & B_LBL_ALWAYS)) | |
519 AddEntry (addr, scanstart, WRN_I_LABEL_NEEDED | WRN_B_TEMPORARY); | |
520 | |
521 if (types[instr->admode] != other && types[instr->admode] != impimm) { | |
522 if ((ADDR_T)(addr - StartAddress) < | |
523 (ADDR_T)(EndAddress - StartAddress)) { | |
524 switch (GetMemType (addr)) { | |
525 case MEM_UNPROCESSED: | |
526 AddEntry (addr, scanstart, WRN_I_ACCESSED | WRN_B_TEMPORARY); | |
527 break; | |
528 case MEM_INSTRUCTION: | |
529 AddEntry (addr, scanstart, WRN_INSTR_WRITTEN_TO | WRN_B_TEMPORARY); | |
530 break; | |
531 case MEM_PARAMETER: | |
532 AddEntry (addr, scanstart, WRN_PARAM_WRITTEN_TO | WRN_B_TEMPORARY); | |
533 break; | |
534 } | |
535 | |
536 if (types[instr->admode] == absindir) { /* indirect mode */ | |
537 addr++; /* set flags for upper vector byte */ | |
538 | |
539 if ((ADDR_T)(addr - StartAddress) < | |
540 (ADDR_T)(EndAddress - StartAddress)) | |
541 switch (GetMemType (addr)) { | |
542 case MEM_UNPROCESSED: | |
543 AddEntry (addr, scanstart, WRN_I_ACCESSED | WRN_B_TEMPORARY); | |
544 break; | |
545 case MEM_INSTRUCTION: | |
546 AddEntry (addr, scanstart, | |
547 WRN_INSTR_WRITTEN_TO | WRN_B_TEMPORARY); | |
548 break; | |
549 case MEM_PARAMETER: | |
550 AddEntry (addr, scanstart, | |
551 WRN_PARAM_WRITTEN_TO | WRN_B_TEMPORARY); | |
552 break; | |
553 } | |
554 } | |
555 } | |
556 } | |
557 } | |
558 | |
559 /* end of program (unexpectedly) encountered */ | |
560 | |
561 return 1; | |
562 } | |
563 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
564 |
0 | 565 int ScanSpecified (void) |
566 { | |
567 table *entry; | |
568 | |
569 if (fVerbose) | |
570 fprintf (stderr, "%s: scanning the routines at specified address(es)", | |
571 prog); | |
572 | |
573 while ((entry = FindNextEntryType (NULL, ~0, RTN_SURE))) { | |
574 PutLabel (entry->address); | |
575 PutLowByte (entry->address); | |
576 PutHighByte (entry->address); | |
577 | |
578 if (ScanSure (entry->address)) { | |
579 fprintf(stderr,"For routine specified at %i:", | |
580 (unsigned int)entry->address); | |
581 return 1; | |
582 } | |
1 | 583 entry = FindNextEntryType (NULL, ~0, RTN_SURE); |
0 | 584 DeleteEntry (entry); |
585 } | |
586 | |
587 return 0; | |
588 } | |
589 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
590 |
0 | 591 void UnDoScan (ADDR_T scanstart) |
592 { | |
593 opcodes *instr; | |
594 unsigned counter; | |
595 ADDR_T address; | |
596 | |
597 for (address = scanstart; address != EndAddress; address++) { | |
598 if (GetMemFlag (address)) return; | |
599 | |
600 switch (GetMemType (address)) { | |
601 case MEM_UNPROCESSED: | |
602 return; | |
603 | |
604 case MEM_INSTRUCTION: | |
605 SetMemFlag (address); | |
606 SetMemType (address, MEM_DATA); /* This could cause WRN_PARAM_WRITTEN_TO | |
607 in vain. */ | |
608 instr = &opset[Memory[address++]]; | |
609 for (counter = sizes[instr->admode]; --counter; address++) | |
610 if (GetMemType (address) == MEM_PARAMETER) | |
611 SetMemType (address, MEM_UNPROCESSED); | |
612 else if (GetMemType (address) == MEM_INSTRUCTION) | |
613 break; | |
614 | |
615 if (instr->mnemonic == S_STP || instr->mnemonic == S_BRK || | |
616 instr->mnemonic == S_RTI || instr->mnemonic == S_RTS || | |
617 instr->mnemonic == S_JMP || instr->admode == rel) | |
618 return; | |
619 | |
620 address--; | |
621 break; | |
622 | |
623 case MEM_PARAMETER: | |
624 SetMemType (address, MEM_UNPROCESSED); | |
625 } | |
626 } | |
627 } | |
628 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
629 |
0 | 630 void DeleteSuspectedParents (ADDR_T child) |
631 { | |
632 table *entry = NULL; | |
633 | |
634 while ((entry = FindNextEntry (entry, child, ~(RTN_B_PROCESSED | | |
635 RTN_B_TEMPORARY), | |
636 RTN_SUSPECTED))) { | |
637 if (entry->type & RTN_B_PROCESSED && entry->parent != child) | |
638 DeleteSuspectedParents (entry->parent); | |
639 | |
640 DeleteEntry (entry); | |
641 } | |
642 | |
643 entry = NULL; | |
644 | |
645 while ((entry = FindNextEntryTypeParent (entry, child, ~0, RTN_SUSP_POT))) | |
646 DeleteEntry (entry); | |
647 | |
648 entry = NULL; | |
649 | |
650 while ((entry = FindNextEntryTypeParent (entry, child, | |
651 MASK_ANY | WRN_B_TEMPORARY, | |
652 WRN_ANY | WRN_B_TEMPORARY))) { | |
653 if (entry->type == (WRN_PARAM_JUMPED_TO | WRN_B_TEMPORARY)) | |
654 SetMemType (entry->address, MEM_PARAMETER); | |
655 | |
656 DeleteEntry (entry); | |
657 } | |
658 | |
659 UnDoScan (child); | |
660 } | |
661 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
662 |
0 | 663 void ScanPotentials (void) |
664 { | |
665 table *entry; | |
666 ADDR_T address; | |
667 | |
668 if (fVerbose) | |
669 fprintf (stderr, "\n%s: scanning potential routines\n", prog); | |
670 | |
671 while ((entry = FindNextEntryType (NULL, ~0, RTN_POTENTIAL))) { | |
672 address = entry->address; | |
673 DeleteEntry (entry); | |
674 | |
675 if (!ScanPotential (address)) { | |
676 while ((entry = FindNextEntryType (NULL, ~RTN_B_TEMPORARY, | |
677 RTN_SUSPECTED))) { | |
678 entry->type |= RTN_B_PROCESSED; | |
679 | |
680 if (ScanPotential (entry->address) && | |
681 (Options & M_DATA_BLOCKS) != O_DBL_IGNORE) { | |
682 DeleteSuspectedParents (entry->address); | |
683 SetMemType (address, MEM_DATA); | |
684 } | |
685 } | |
686 | |
687 if (GetMemType (address) != MEM_DATA) { | |
688 PutLabel (address); | |
689 PutLowByte (address); | |
690 PutHighByte (address); | |
691 } | |
692 | |
693 entry = NULL; | |
694 | |
695 while ((entry = FindNextEntryType (entry, ~0, RTN_B_TEMPORARY | | |
696 RTN_SUSPECTED | RTN_B_PROCESSED))) | |
697 DeleteEntry (entry); | |
698 | |
699 entry = NULL; | |
700 | |
701 while ((entry = FindNextEntryType (entry, ~0, | |
702 RTN_SUSPECTED | RTN_B_PROCESSED))) { | |
703 PutLabel (entry->address); | |
704 PutLowByte (entry->address); | |
705 PutHighByte (entry->address); | |
706 DeleteEntry (entry); | |
707 } | |
708 | |
709 entry = NULL; | |
710 | |
711 while ((entry = FindNextEntryType (entry, ~0, RTN_SUSP_POT))) | |
712 entry->type = RTN_POTENTIAL; | |
713 | |
714 entry = NULL; | |
715 | |
716 while ((entry = FindNextEntryType (entry, MASK_ANY | WRN_B_TEMPORARY, | |
717 WRN_ANY | WRN_B_TEMPORARY))) { | |
718 switch (entry->type & ~WRN_B_TEMPORARY) { | |
719 case WRN_PARAM_WRITTEN_TO: | |
720 if (GetMemType (entry->address) == MEM_DATA) | |
721 SetMemType (entry->address, MEM_PARAMETER); | |
722 entry->type &= ~WRN_B_TEMPORARY; | |
723 break; | |
724 | |
725 case WRN_INSTR_WRITTEN_TO: | |
726 if (GetMemType (entry->address) == MEM_DATA) | |
727 SetMemType (entry->address, MEM_INSTRUCTION); | |
728 entry->type &= ~WRN_B_TEMPORARY; | |
729 break; | |
730 | |
731 case WRN_I_ACCESSED: | |
732 SetMemType (entry->address, MEM_DATA); | |
733 /* fall through */ | |
734 case WRN_I_LABEL_NEEDED: | |
735 PutLabel (entry->address); | |
736 PutLowByte (entry->address); | |
737 PutHighByte (entry->address); | |
738 DeleteEntry (entry); | |
739 break; | |
740 | |
741 default: | |
742 entry->type &= ~WRN_B_TEMPORARY; | |
743 } | |
744 } | |
745 } | |
746 else { | |
747 DeleteSuspectedParents (address); | |
748 SetMemType (address, MEM_DATA); | |
749 } | |
750 } | |
751 } | |
752 | |
2
ec2f8f6f1dc9
Cleanup pass #1: Get rid of some ancient K&R-isms.
Matti Hamalainen <ccr@tnsp.org>
parents:
1
diff
changeset
|
753 |
0 | 754 void ScanTheRest (void) |
755 { | |
756 ADDR_T address; | |
757 table *entry; | |
758 unsigned int fPotentials; | |
759 | |
760 if ((Options & M_DATA_BLOCKS) == O_DBL_NOSCAN) { | |
761 for (address = StartAddress; address != EndAddress; address++) | |
762 if (GetMemType (address) == MEM_UNPROCESSED) | |
763 SetMemType (address, MEM_DATA); | |
764 | |
765 return; | |
766 } | |
767 | |
768 if (fVerbose) | |
769 fprintf (stderr, "%s: scanning the remaining bytes for routines\n", prog); | |
770 | |
771 for (address = StartAddress; address != EndAddress; address++) { | |
772 if (GetMemType (address) || GetMemFlag (address)) | |
773 continue; /* scan only unprocessed bytes */ | |
774 | |
775 if (Options & B_RSC_STRICT) | |
776 switch (opset[Memory[address]].mnemonic) { | |
777 case S_RTI: | |
778 case S_RTS: | |
779 case S_BRK: | |
780 case S_STP: | |
781 continue; | |
782 | |
783 case S_BRA: | |
784 break; | |
785 | |
786 default: | |
787 if (opset[Memory[address]].admode == rel && | |
788 GetMemType (address + sizes[rel]) != MEM_INSTRUCTION) | |
789 AddEntry (address + sizes[rel], address, | |
790 RTN_SUSPECTED | RTN_B_TEMPORARY); | |
791 } | |
792 | |
793 if (fVerbose) | |
794 fprintf (stderr, "\r%s: scanning at %X", prog, address); | |
795 | |
796 if (!ScanPotential (address)) { | |
797 while ((entry = FindNextEntryType (NULL, ~RTN_B_TEMPORARY, | |
798 RTN_SUSPECTED))) { | |
799 entry->type |= RTN_B_PROCESSED; | |
800 | |
801 if (ScanPotential (entry->address) && | |
802 (Options & M_DATA_BLOCKS) != O_DBL_IGNORE) { | |
803 DeleteSuspectedParents (entry->address); | |
804 SetMemType (address, MEM_DATA); | |
805 } | |
806 } | |
807 | |
808 if (GetMemType (address) != MEM_DATA) { | |
809 PutLabel (address); | |
810 PutLowByte (address); | |
811 PutHighByte (address); | |
812 } | |
813 | |
814 fPotentials = FALSE; | |
815 entry = NULL; | |
816 | |
817 while ((entry = FindNextEntryType (entry, ~0, RTN_SUSP_POT))) { | |
818 fPotentials = TRUE; | |
819 entry->type = RTN_POTENTIAL; | |
820 } | |
821 | |
822 entry = NULL; | |
823 | |
824 while ((entry = FindNextEntryType (entry, ~0, RTN_B_TEMPORARY | | |
825 RTN_SUSPECTED | RTN_B_PROCESSED))) | |
826 DeleteEntry (entry); | |
827 | |
828 entry = NULL; | |
829 | |
830 while ((entry = FindNextEntryType (entry, ~0, | |
831 RTN_SUSPECTED | RTN_B_PROCESSED))) { | |
832 PutLabel (entry->address); | |
833 PutLowByte (entry->address); | |
834 PutHighByte (entry->address); | |
835 DeleteEntry (entry); | |
836 } | |
837 | |
838 entry = NULL; | |
839 | |
840 while ((entry = FindNextEntryType (entry, MASK_ANY | WRN_B_TEMPORARY, | |
841 WRN_ANY | WRN_B_TEMPORARY))) { | |
842 switch (entry->type & ~WRN_B_TEMPORARY) { | |
843 case WRN_PARAM_WRITTEN_TO: | |
844 if (GetMemType (entry->address) == MEM_DATA) | |
845 SetMemType (entry->address, MEM_PARAMETER); | |
846 entry->type &= ~WRN_B_TEMPORARY; | |
847 break; | |
848 | |
849 case WRN_INSTR_WRITTEN_TO: | |
850 if (GetMemType (entry->address) == MEM_DATA) | |
851 SetMemType (entry->address, MEM_INSTRUCTION); | |
852 entry->type &= ~WRN_B_TEMPORARY; | |
853 break; | |
854 | |
855 case WRN_I_ACCESSED: | |
856 SetMemType (entry->address, MEM_DATA); | |
857 /* fall through */ | |
858 case WRN_I_LABEL_NEEDED: | |
859 PutLabel (entry->address); | |
860 PutLowByte (entry->address); | |
861 PutHighByte (entry->address); | |
862 DeleteEntry (entry); | |
863 break; | |
864 | |
865 default: | |
866 entry->type &= ~WRN_B_TEMPORARY; | |
867 } | |
868 } | |
869 | |
870 if (fPotentials) ScanPotentials (); | |
871 } | |
872 else { | |
873 DeleteSuspectedParents (address); | |
874 SetMemType (address, MEM_DATA); | |
875 } | |
876 } | |
877 | |
878 if (fVerbose) | |
879 fprintf (stderr, "\n"); | |
880 | |
881 for (address = StartAddress; address != EndAddress; address++) | |
882 if (GetMemType (address) == MEM_UNPROCESSED) { | |
883 fPotentials = GetMemFlag (address) ? MEM_PARAMETER : MEM_DATA; | |
884 SetMemType (address, fPotentials); | |
885 } | |
886 } |