annotate lwdisasm/main.c @ 434:b8bf63962a99 3.0

Added various generated files for release
author lost@l-w.ca
date Fri, 29 Oct 2010 19:20:39 -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 main.c
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 #include <config.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
23
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
24 #include <argp.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
25 #include <stdio.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
26 #include <stdlib.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
27
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
28 #include <lw_alloc.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
29 #include <lw_string.h>
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
30
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
31 #include "lwdisasm.h"
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
32
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
33 /* command line option handling */
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
34 const char *argp_program_version = "lwdisasmasm from " PACKAGE_STRING;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
35 const char *argp_program_bug_address = PACKAGE_BUGREPORT;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
36 char *program_name;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
37
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
38 static struct argp_option options[] =
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 { "output", 'o', "FILE", 0, "Output to FILE"},
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
41 { "debug", 'd', "LEVEL", OPTION_ARG_OPTIONAL, "Set debug mode"},
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
42 { "format", 'f', "TYPE", 0, "Select input format: decb, raw, obj, os9"},
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
43 { "decb", 'b', 0, 0, "Read DECB .bin format input, equivalent of --format=decb"},
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
44 { "raw", 'r', 0, 0, "Read raw binary format input, equivalent of --format=raw"},
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
45 { "obj", 0x100, 0, 0, "Read proprietary object file format, equivalent of --format=obj" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
46 { "6809", '9', 0, 0, "Set disassembler to 6809 only mode" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
47 { "6309", '3', 0, 0, "Set disassembler to 6309 mode (default)" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
48 { "data", 0x101, "RANGE", 0, "Set an address range as data" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
49 { "code", 0x102, "RANGE", 0, "Set an address range as code" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
50 { "entry", 0x103, "ADDR", 0, "Start disassembling at ADDR" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
51 { "base", 0x104, "ADDR", 0, "Set the base address of a raw file" },
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
52 { 0 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
53 };
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
54
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
55
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
56 static error_t parse_opts(int key, char *arg, struct argp_state *state)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
57 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
58 disasmstate_t *as = state -> input;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
59 int rangelow, rangehigh;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
60 char *e;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
61
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
62 switch (key)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
63 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
64
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
65 case 0x101: // data range
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
66 rangelow = strtol(arg, &e, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
67 if (*e != ':')
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
68 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
69 fprintf(stderr, "Invalid range: %s\n", arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
70 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
71 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
72 rangehigh = strtol(e + 1, NULL, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
73 if (rangelow < 0 || rangehigh < 0 || rangehigh < rangelow)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
74 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
75 fprintf(stderr, "Invalid range: %s\n", arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
76 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
77 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
78 // register the range as data
409
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
79 register_range(as, rangelow, rangehigh, type_data);
408
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
80 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
81
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
82 case 0x102: // code range
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
83 rangelow = strtol(arg, &e, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
84 if (*e != ':')
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
85 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
86 fprintf(stderr, "Invalid range: %s\n", arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
87 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
88 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
89 rangehigh = strtol(e + 1, NULL, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
90 if (rangelow < 0 || rangehigh < 0 || rangehigh < rangelow)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
91 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
92 fprintf(stderr, "Invalid range: %s\n", arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
93 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
94 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
95 // register the range as code
409
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
96 register_range(as, rangelow, rangehigh, type_code);
408
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
97 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
98
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
99 case 0x103: // entry
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
100 as -> entry = strtol(arg, NULL, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
101 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
102
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
103 case 0x104: // base
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
104 as -> base = strtol(arg, NULL, 0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
105 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
106
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
107 case 'o':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
108 if (as -> output_file)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
109 lw_free(as -> output_file);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
110 as -> output_file = lw_strdup(arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
111 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
112
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
113 case 'd':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
114 if (!arg)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
115 as -> debug_level = 50;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
116 else
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
117 as -> debug_level = atoi(arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
118 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
119
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
120 case 'b':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
121 as -> input_type = INPUT_DECB;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
122 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
123
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
124 case 'r':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
125 as -> input_type = INPUT_RAW;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
126 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
127
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
128 case 0x100:
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
129 as -> input_type = INPUT_OBJ;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
130 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
131
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
132 case 'f':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
133 if (!strcasecmp(arg, "decb"))
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
134 as -> input_type = INPUT_DECB;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
135 else if (!strcasecmp(arg, "raw"))
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
136 as -> input_type = INPUT_RAW;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
137 else if (!strcasecmp(arg, "obj"))
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
138 as -> input_type = INPUT_OBJ;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
139 else if (!strcasecmp(arg, "os9"))
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
140 as -> input_type = INPUT_OS9;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
141 else
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
142 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
143 fprintf(stderr, "Invalid input format: %s\n", arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
144 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
145 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
146 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
147
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
148 case '9':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
149 as -> target = TARGET_6809;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
150 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
151
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
152 case '3':
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
153 as -> target = TARGET_6309;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
154 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
155
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
156 case ARGP_KEY_END:
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
157 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
158
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
159 case ARGP_KEY_ARG:
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
160 if (as -> input_file)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
161 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
162 fprintf(stderr, "Only one input file allowed\n");
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
163 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
164 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
165 as -> input_file = lw_strdup(arg);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
166 break;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
167
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
168 default:
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
169 return ARGP_ERR_UNKNOWN;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
170 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
171 return 0;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
172 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
173
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
174 static struct argp argp =
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
175 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
176 options,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
177 parse_opts,
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
178 "<input file>",
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
179 "LWDISASM, a HD6309 and MC6809 disassembler"
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
180 };
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
181
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
182 /*
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
183 main function; parse command line, set up disassembler state, and run the
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
184 disassembler on the first file
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
185 */
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
186
409
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
187 void do_disasm_raw(disasmstate_t *as);
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
188
408
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
189 int main(int argc, char **argv)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
190 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
191 disasmstate_t as = { 0 };
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
192 FILE *fp;
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
193
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
194 /* assembler state */
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
195 program_name = argv[0];
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
196
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
197 /* parse command line arguments */
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
198 argp_parse(&argp, argc, argv, 0, 0, &as);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
199
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
200 if (as.input_file == NULL)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
201 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
202 fprintf(stderr, "No input files specified.\n");
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
203 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
204 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
205
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
206 fp = fopen(as.input_file, "rb");
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
207 if (!fp)
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
208 {
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
209 perror("Cannot open input file");
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
210 exit(1);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
211 }
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
212
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
213 fseek(fp, 0, SEEK_END);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
214 as.filelen = ftell(fp);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
215 rewind(fp);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
216
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
217 as.filedata = lw_alloc(as.filelen);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
218 0 == fread(as.filedata, as.filelen, 1, fp);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
219
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
220 fclose(fp);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
221
409
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
222 switch (as.target)
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
223 {
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
224 case TARGET_6309:
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
225 as.page0 = page0_6309;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
226 as.page1 = page1_6309;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
227 as.page2 = page2_6309;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
228 break;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
229
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
230 case TARGET_6809:
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
231 as.page0 = page0_6809;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
232 as.page1 = page1_6809;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
233 as.page2 = page2_6809;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
234 break;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
235
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
236 default:
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
237 as.page0 = page0_6809;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
238 as.page1 = page1_6809;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
239 as.page2 = page2_6809;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
240 break;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
241
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
242 }
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
243
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
244 switch (as.input_type)
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
245 {
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
246 case INPUT_RAW:
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
247 do_disasm_raw(&as);
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
248 break;
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
249
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
250 default:
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
251 fprintf(stderr, "Input type is not currently implemented\n");
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
252 exit(1);
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
253 }
cba03436c720 Checkpoint disassembler
lost@l-w.ca
parents: 408
diff changeset
254
408
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
255 exit(0);
2a94b2e64621 Started creation of lwdisasm
lost@l-w.ca
parents:
diff changeset
256 }