408
|
1 /*
|
|
2 lwdisasm.h
|
|
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 #ifndef ____lwdisasm_h_seen____
|
|
23 #define ____lwdisasm_h_seen____
|
|
24
|
|
25 #include <stdint.h>
|
|
26
|
|
27 enum
|
|
28 {
|
|
29 INPUT_RAW = 0,
|
|
30 INPUT_DECB,
|
|
31 INPUT_OBJ,
|
|
32 INPUT_OS9
|
|
33 };
|
|
34
|
|
35 enum
|
|
36 {
|
|
37 TARGET_6809 = 0,
|
|
38 TARGET_6309
|
|
39 };
|
|
40
|
|
41 enum
|
|
42 {
|
|
43 ADDR_DIR = 0,
|
|
44 ADDR_EXT,
|
|
45 ADDR_IND,
|
|
46 ADDR_IMM8,
|
|
47 ADDR_IMM16,
|
|
48 ADDR_IMM32,
|
|
49 ADDR_INH,
|
|
50 ADDR_RTOR,
|
409
|
51 ADDR_PSHPULS,
|
|
52 ADDR_PSHPULU,
|
408
|
53 ADDR_IMM8DIR,
|
|
54 ADDR_IMM8IND,
|
|
55 ADDR_IMM8EXT,
|
|
56 ADDR_BITBIT,
|
|
57 ADDR_REL8,
|
|
58 ADDR_REL16,
|
|
59 ADDR_PAGE1,
|
|
60 ADDR_PAGE2,
|
|
61 ADDR_TFMPP,
|
|
62 ADDR_TFMMM,
|
|
63 ADDR_TFMPC,
|
|
64 ADDR_TFMCP
|
|
65 };
|
|
66
|
409
|
67
|
|
68 typedef struct rangedata_s rangedata_t;
|
|
69 struct rangedata_s
|
|
70 {
|
|
71 int min;
|
|
72 int max;
|
|
73 int type;
|
|
74 rangedata_t *next;
|
|
75 rangedata_t *prev;
|
|
76 };
|
|
77
|
|
78 typedef struct symbol_s symbol_t;
|
|
79 struct symbol_s
|
|
80 {
|
|
81 int address;
|
|
82 int section;
|
|
83 char *symbol;
|
|
84 symbol_t *next;
|
|
85 };
|
|
86
|
|
87 typedef struct linedata_s linedata_t;
|
|
88 struct linedata_s
|
|
89 {
|
|
90 int address;
|
|
91 int sectionref;
|
|
92 int length;
|
|
93 int type;
|
|
94 int target;
|
|
95 char *disasm;
|
|
96 uint8_t *bytes;
|
|
97 int isref;
|
|
98 symbol_t *symbol;
|
|
99 linedata_t *next;
|
|
100 linedata_t *prev;
|
|
101 };
|
|
102 typedef struct instab_s
|
|
103 {
|
|
104 char *op; // mneumonic
|
|
105 int addrmode; // addressing mode
|
|
106 } instab_t;
|
|
107
|
408
|
108 typedef struct disasmstate_s
|
|
109 {
|
|
110 int input_type;
|
|
111 int debug_level;
|
|
112 char *output_file;
|
|
113 char *input_file;
|
|
114 int target;
|
|
115 uint8_t *filedata; // the file data
|
|
116 long filelen; // length of the file data
|
|
117 int base; // base address (raw)
|
|
118 int entry; // entry address
|
409
|
119 int dpval; // DP value
|
|
120 linedata_t *lhead; // start of lines table
|
|
121 linedata_t *ltail; // end of lines table
|
|
122 rangedata_t *rhead; // start of range table
|
|
123 rangedata_t *rtail; // end of range table
|
|
124
|
|
125 instab_t *page0; // instruction table 0
|
|
126 instab_t *page1; // instruction table 1
|
|
127 instab_t *page2; // instruction table 2
|
|
128
|
|
129 int curoff; // current disassembly point
|
|
130 rangedata_t *crange; // current range
|
|
131
|
|
132 symbol_t *symbols; // symbol tables
|
408
|
133 } disasmstate_t;
|
|
134
|
|
135
|
|
136
|
|
137 extern instab_t page0_6809[];
|
|
138 extern instab_t page1_6809[];
|
|
139 extern instab_t page2_6809[];
|
|
140
|
|
141 extern instab_t page0_6309[];
|
|
142 extern instab_t page1_6309[];
|
|
143 extern instab_t page2_6309[];
|
|
144
|
409
|
145 enum
|
|
146 {
|
|
147 type_code = 0,
|
|
148 type_data = 1
|
|
149 };
|
|
150
|
|
151 extern void register_range(disasmstate_t *as, int min, int max, int type);
|
|
152 extern rangedata_t *lookup_range(disasmstate_t *as, int addr);
|
|
153 extern int fetch_byte(disasmstate_t *as);
|
|
154 extern linedata_t *disasm_insn(disasmstate_t *as);
|
|
155 extern symbol_t *register_symbol(disasmstate_t *as, int addr, int section, char *symbol);
|
|
156 extern void attach_symbols(disasmstate_t *as);
|
|
157 extern void redisasm_insn(disasmstate_t *as, linedata_t *l);
|
|
158 extern symbol_t *find_symbol(disasmstate_t *as, int addr, int section);
|
408
|
159 #endif // ____lwdisasm_h_seen____
|