comparison lwdisasm/do_raw.c @ 409:cba03436c720

Checkpoint disassembler
author lost@l-w.ca
date Mon, 02 Aug 2010 18:07:04 -0600
parents
children
comparison
equal deleted inserted replaced
408:2a94b2e64621 409:cba03436c720
1 /*
2 do_raw.c
3
4 Copyright © 2010 William Astle
5
6 This file is part of LWTOOLS.
7
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation, either version 3 of the License, or (at your option) any later
11 version.
12
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 more details.
17
18 You should have received a copy of the GNU General Public License along with
19 this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <config.h>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 #include "lwdisasm.h"
28
29 void do_disasm_raw(disasmstate_t *as)
30 {
31 linedata_t *l;
32 symbol_t *s;
33 char bytebuf[11];
34 int i;
35
36 // initialize disassembly
37 as -> curoff = as -> entry;
38 as -> crange = lookup_range(as, as -> curoff);
39
40
41 while (l = disasm_insn(as))
42 {
43 if (!as -> ltail)
44 as -> lhead = l;
45 else
46 as -> ltail -> next = l;
47 l -> prev = as -> ltail;
48 as -> ltail = l;
49
50 if (l -> target != -1)
51 {
52 s = register_symbol(as, l -> target, l -> sectionref, NULL);
53 l -> symbol = s;
54 }
55 }
56
57 attach_symbols(as);
58
59 for (l = as -> lhead; l; l = l -> next)
60 {
61 if (l -> target != -1)
62 redisasm_insn(as, l);
63 }
64
65 for (l = as -> lhead; l; l = l -> next)
66 {
67 bytebuf[0] = 0;
68 for (i = 0; i < l -> length; i++)
69 {
70 sprintf(bytebuf, "%s%02X", bytebuf, l -> bytes[i]);
71 }
72 printf("%04X %-10s %-15s %s\n", l -> address, bytebuf, l -> isref ? l -> symbol -> symbol : "", l -> disasm);
73 }
74 }