annotate lwdisasm/lwdisasm.h @ 417:f792faf877bb

Fixed minor layout glitch in listing code
author lost@l-w.ca
date Tue, 10 Aug 2010 23:08:07 -0600
parents cba03436c720
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
408
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
1 /*
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
2 lwdisasm.h
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
3
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
4 Copyright © 2010 William Astle
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
5
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
6 This file is part of LWTOOLS.
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
7
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
11 version.
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
12
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
16 more details.
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
17
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
20 */
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
21
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
22 #ifndef ____lwdisasm_h_seen____
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
23 #define ____lwdisasm_h_seen____
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
24
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
25 #include <stdint.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
26
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
27 enum
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
28 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
29 INPUT_RAW = 0,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
30 INPUT_DECB,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
31 INPUT_OBJ,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
32 INPUT_OS9
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
33 };
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
34
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
35 enum
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
36 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
37 TARGET_6809 = 0,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
38 TARGET_6309
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
39 };
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
40
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
41 enum
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
42 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
43 ADDR_DIR = 0,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
44 ADDR_EXT,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
45 ADDR_IND,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
46 ADDR_IMM8,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
47 ADDR_IMM16,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
48 ADDR_IMM32,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
49 ADDR_INH,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
50 ADDR_RTOR,
409
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
51 ADDR_PSHPULS,
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
52 ADDR_PSHPULU,
408
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
53 ADDR_IMM8DIR,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
54 ADDR_IMM8IND,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
55 ADDR_IMM8EXT,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
56 ADDR_BITBIT,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
57 ADDR_REL8,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
58 ADDR_REL16,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
59 ADDR_PAGE1,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
60 ADDR_PAGE2,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
61 ADDR_TFMPP,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
62 ADDR_TFMMM,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
63 ADDR_TFMPC,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
64 ADDR_TFMCP
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
65 };
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
66
409
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
67
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
68 typedef struct rangedata_s rangedata_t;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
69 struct rangedata_s
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
70 {
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
71 int min;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
72 int max;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
73 int type;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
74 rangedata_t *next;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
75 rangedata_t *prev;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
76 };
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
77
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
78 typedef struct symbol_s symbol_t;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
79 struct symbol_s
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
80 {
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
81 int address;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
82 int section;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
83 char *symbol;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
84 symbol_t *next;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
85 };
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
86
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
87 typedef struct linedata_s linedata_t;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
88 struct linedata_s
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
89 {
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
90 int address;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
91 int sectionref;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
92 int length;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
93 int type;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
94 int target;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
95 char *disasm;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
96 uint8_t *bytes;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
97 int isref;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
98 symbol_t *symbol;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
99 linedata_t *next;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
100 linedata_t *prev;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
101 };
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
102 typedef struct instab_s
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
103 {
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
104 char *op; // mneumonic
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
105 int addrmode; // addressing mode
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
106 } instab_t;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
107
408
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
108 typedef struct disasmstate_s
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
109 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
110 int input_type;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
111 int debug_level;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
112 char *output_file;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
113 char *input_file;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
114 int target;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
115 uint8_t *filedata; // the file data
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
116 long filelen; // length of the file data
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
117 int base; // base address (raw)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
118 int entry; // entry address
409
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
119 int dpval; // DP value
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
120 linedata_t *lhead; // start of lines table
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
121 linedata_t *ltail; // end of lines table
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
122 rangedata_t *rhead; // start of range table
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
123 rangedata_t *rtail; // end of range table
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
124
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
125 instab_t *page0; // instruction table 0
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
126 instab_t *page1; // instruction table 1
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
127 instab_t *page2; // instruction table 2
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
128
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
129 int curoff; // current disassembly point
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
130 rangedata_t *crange; // current range
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
131
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
132 symbol_t *symbols; // symbol tables
408
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
133 } disasmstate_t;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
134
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
135
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
136
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
137 extern instab_t page0_6809[];
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
138 extern instab_t page1_6809[];
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
139 extern instab_t page2_6809[];
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
140
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
141 extern instab_t page0_6309[];
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
142 extern instab_t page1_6309[];
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
143 extern instab_t page2_6309[];
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
144
409
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
145 enum
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
146 {
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
147 type_code = 0,
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
148 type_data = 1
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
149 };
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
150
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
151 extern void register_range(disasmstate_t *as, int min, int max, int type);
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
152 extern rangedata_t *lookup_range(disasmstate_t *as, int addr);
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
153 extern int fetch_byte(disasmstate_t *as);
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
154 extern linedata_t *disasm_insn(disasmstate_t *as);
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
155 extern symbol_t *register_symbol(disasmstate_t *as, int addr, int section, char *symbol);
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
156 extern void attach_symbols(disasmstate_t *as);
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
157 extern void redisasm_insn(disasmstate_t *as, linedata_t *l);
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
158 extern symbol_t *find_symbol(disasmstate_t *as, int addr, int section);
408
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
159 #endif // ____lwdisasm_h_seen____