annotate lwdisasm/do_raw.c @ 423:079d43b6967b 3.0-beta2 3.0-beta2

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