]> git.sur5r.net Git - cc65/blob - doc/da65.sgml
Doc for new comment attribute
[cc65] / doc / da65.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4 <title>da65 Users Guide
5 <author>Ullrich von Bassewitz, <htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">
6 <date>2003-08-08
7
8 <abstract>
9 da65 is a 6502/65C02 disassembler that is able to read user supplied
10 information about its input data for better results. The output is ready for
11 feeding into ca65, the macro assembler supplied with the cc65 C compiler.
12 </abstract>
13
14 <!-- Table of contents -->
15 <toc>
16
17 <!-- Begin the document -->
18
19 <sect>Overview<p>
20
21 da65 is a disassembler for 6502/65C02 code. It is supplied as a utility with
22 the cc65 C compiler and generates output that is suitable for the ca65
23 macro assembler.
24
25 Besides generating output for ca65, one of the design goals was that the user
26 is able to feed additional information about the code into the disassembler
27 for improved results. This information may include the location and size of
28 tables, and their format.
29
30 One nice advantage of this concept is that disassembly of copyrighted binaries
31 may be handled without problems: One can just pass the information file for
32 disassembling the binary, so everyone with a legal copy of the binary can
33 generate a nicely formatted disassembly with readable labels and other
34 information.
35
36
37 <sect>Usage<p>
38
39
40 <sect1>Command line option overview<p>
41
42 The assembler accepts the following options:
43
44 <tscreen><verb>
45 ---------------------------------------------------------------------------
46 Usage: da65 [options] [inputfile]
47 Short options:
48   -g                    Add debug info to object file
49   -h                    Help (this text)
50   -i name               Specify an info file
51   -o name               Name the output file
52   -v                    Increase verbosity
53   -F                    Add formfeeds to the output
54   -S addr               Set the start/load address
55   -V                    Print the disassembler version
56
57 Long options:
58   --comments n          Set the comment level for the output
59   --cpu type            Set cpu type
60   --debug-info          Add debug info to object file
61   --formfeeds           Add formfeeds to the output
62   --help                Help (this text)
63   --info name           Specify an info file
64   --pagelength n        Set the page length for the listing
65   --start-addr addr     Set the start/load address
66   --verbose             Increase verbosity
67   --version             Print the disassembler version
68 ---------------------------------------------------------------------------
69 </verb></tscreen>
70
71
72 <sect1>Command line options in detail<p>
73
74 Here is a description of all the command line options:
75
76 <descrip>
77
78   <label id="option--comments">
79   <tag><tt>--comments n</tt></tag>
80
81   Set the comment level for the output. Valid arguments are 0..4. Greater
82   values will increase the level of additional information written to the
83   output file in form of comments.
84
85
86   <label id="option--cpu">
87   <tag><tt>--cpu type</tt></tag>
88
89   Set the CPU type. The option takes a parameter, which may be one of
90
91         6502, 65SC02, 65C02
92
93   Support for the 65816 is currently not available.
94
95
96   <label id="option--formfeeds">
97   <tag><tt>-F, --formfeeds</tt></tag>
98
99   Add formfeeds to the generated output. This feature is useful together
100   with the <tt><ref id="option--pagelength" name="--pagelength"></tt> option.
101   If <tt/--formfeeds/ is given, a formfeed is added to the output after each
102   page.
103
104
105   <tag><tt>-g, --debug-info</tt></tag>
106
107   This option adds the <tt/.DEBUGINFO/ command to the output file, so the
108   assembler will generate debug information when reassembling the generated
109   output.
110
111
112   <tag><tt>-h, --help</tt></tag>
113
114   Print the short option summary shown above.
115
116
117   <label id="option--info">
118   <tag><tt>-i name, --info name</tt></tag>
119
120   Specify an info file. The info file contains global options that may
121   override or replace command line options plus informations about the code
122   that has to be disassembled. See the separate section <ref id="infofile"
123   name="Info File Format">.
124
125
126   <label id="option-o">
127   <tag><tt>-o name</tt></tag>
128
129   Specify a name for an output file. The default is to use <tt/stdout/, so
130   without this switch or the corresponding <ref id="global-options"
131   name="global option"> <tt><ref id="OUTPUTNAME" name="OUTPUTNAME"></tt>,
132   the output will go to the terminal.
133
134
135   <label id="option--pagelength">
136   <tag><tt>--pagelength n</tt></tag>
137
138   Sets the length of a listing page in lines. After this number of lines, a
139   new page header is generated. If the <tt><ref id="option--formfeeds"
140   name="--formfeeds"></tt> is also given, a formfeed is inserted before
141   generating the page header.
142
143   A value of zero for the page length will disable paging of the output.
144
145
146   <label id="option--start-addr">
147   <tag><tt>-S addr, --start-addr addr</tt></tag>
148
149   Specify the start/load address of the binary code that is going to be
150   disassembled. The given address is interpreted as an octal value if
151   preceeded with a '0' digit, as a hexadecimal value if preceeded with '0x',
152   '0X', or '$', and as a decimal value in all other cases. If no start address
153   is specified, $10000 minus the size of the input file is used.
154
155
156   <tag><tt>-v, --verbose</tt></tag>
157
158   Increase the disassembler verbosity. Usually only needed for debugging
159   purposes. You may use this option more than one time for even more
160   verbose output.
161
162
163   <tag><tt>-V, --version</tt></tag>
164
165   Print the version number of the assembler. If you send any suggestions
166   or bugfixes, please include the version number.
167
168 </descrip>
169 <p>
170
171
172 <sect>Detailed workings<p>
173
174 <sect1>Supported CPUs<p>
175
176 The default (no CPU given on the command line or in the <tt/GLOBAL/ section of
177 the info file) is the 6502 CPU. The disassembler knows all "official" opcodes
178 for this CPU. Invalid opcodes are translated into <tt/.byte/ commands.
179
180 With the command line option <tt><ref id="option--cpu" name="--cpu"></tt>, the
181 disassembler may be told to recognize either the 65SC02 or 65C02 CPUs. The
182 latter understands the same opcodes as the former, plus 16 additional bit
183 manipulation and bit test-and-branch commands.
184
185 While there is some code for the 65816 in the sources, it is currently
186 unsupported.
187
188
189 <sect1>Attribute map<p>
190
191 The disassembler works by creating an attribute map for the whole address
192 space ($0000 - $FFFF). Initially, all attributes are cleared. Then, an
193 external info file (if given) is read. Disassembly is done in several passes.
194 In all passes with the exception of the last one, information about the
195 disassembled code is gathered and added to the symbol and attribute maps. The
196 last pass generates output using the information from the maps.
197
198 <sect1>Labels<p>
199
200 Some instructions may generate labels in the first pass, while most other
201 instructions do not generate labels, but use them if they are available. Among
202 others, the branch and jump instructions will generate labels for the target
203 of the branch in the first pass. External labels (taken from the info file)
204 have precedence over internally generated ones, They must be valid identifiers
205 as specified for the ca65 assembler. Internal labels (generated by the
206 disassembler) have the form <tt/Labcd/, where <tt/abcd/ is the hexadecimal
207 address of the label in upper case letters. You should probably avoid using
208 such label names for external labels.
209
210
211 <sect1>Info File<p>
212
213 The info file is used to pass additional information about the input code to
214 the disassembler. This includes label names, data areas or tables, and global
215 options like input and output file names. See the <ref id="infofile"
216 name="next section"> for more information.
217
218
219
220 <sect>Info File Format<label id="infofile"><p>
221
222 The info file contains lists of specifications grouped together. Each group
223 directive has an identifying token and an attribute list enclosed in curly
224 braces. Attributes have a name followed by a value. The syntax of the value
225 depends on the type of the attribute. String attributes are places in double
226 quotes, numeric attributes may be specified as decimal numbers or hexadecimal
227 with a leading dollar sign. There are also attributes where the attribute
228 value is a keyword, in this case the keyword is given as is (without quotes or
229 anything). Each attribute is terminated by a semicolon.
230
231 <tscreen><verb>
232         group-name { attribute1 attribute-value; attribute2 attribute-value; }
233 </verb></tscreen>
234
235
236 <sect1>Comments<p>
237
238 Comments start with a hash mark (<tt/#/)  and extend from the position of
239 the mark to the end of the current line. Hash marks inside of strings will
240 of course <em/not/ start a comment.
241
242
243 <sect1>Specifying global options<label id="global-options"><p>
244
245 Global options may be specified in a group with the name <tt/GLOBAL/. The
246 following attributes are recognized:
247
248 <descrip>
249
250   <tag><tt>COMMENTS</tt></tag>
251   This attribute may be used instead of the <tt><ref id="option--comments"
252   name="--comments"></tt> option on the command line. It takes a numerical
253   parameter between 0 and 4. Higher values increase the amount of information
254   written to the output file in form of comments.
255
256
257   <tag><tt>CPU</tt></tag>
258   This attribute may be used instead of the <tt><ref id="option--cpu"
259   name="--cpu"></tt> option on the command line. It takes a string parameter.
260
261
262   <tag><tt>INPUTNAME</tt></tag>
263   The attribute is followed by a string value, which gives the name of the
264   input file to read. If it is present, the disassembler does not accept an
265   input file name on the command line.
266
267
268   <tag><tt>INPUTOFFS</tt></tag>
269   The attribute is followed by a numerical value that gives an offset into
270   the input file which is skipped before reading data. The attribute may be
271   used to skip headers or unwanted code sections in the input file.
272
273
274   <tag><tt>INPUTSIZE</tt></tag>
275   <tt/INPUTSIZE/ is followed by a numerical value that gives the amount of
276   data to read from the input file. Data beyond <tt/INPUTOFFS + INPUTSIZE/
277   is ignored.
278
279
280   <label id="OUTPUTNAME">
281   <tag><tt>OUTPUTNAME</tt></tag>
282   The attribute is followed by string value, which gives the name of the
283   output file to write. If it is present, specification of an output file on
284   the command line using the <tt><ref id="option-o" name="-o"></tt> option is
285   not allowed.
286
287   The default is to use <tt/stdout/ for output, so without this attribute or
288   the corresponding command line option <tt/<ref id="option-o" name="-o">/
289   the output will go to the terminal.
290
291
292   <tag><tt>PAGELENGTH</tt></tag>
293   This attribute may be used instead of the <tt><ref id="option--pagelength"
294   name="--pagelength"></tt> option on the command line. It takes a numerical
295   parameter. Using zero as page length (which is the default) means that no
296   pages are generated.
297
298
299   <tag><tt>STARTADDR</tt></tag>
300   This attribute may be used instead of the <tt><ref id="option--start-addr"
301   name="--start-addr"></tt> option on the command line. It takes a numerical
302   parameter. The default for the start address is $10000 minus the size of
303   the input file (this assumes that the input file is a ROM that contains the
304   reset and irq vectors).
305
306 </descrip>
307
308
309 <sect1>Specifying Ranges<p>
310
311 The <tt/RANGE/ directive is used to give information about address ranges. The
312 following attributes are recognized:
313
314 <descrip>
315
316   <tag><tt>COMMENT</tt></tag>
317   This attribute is only allowed if a label is also given. It takes a string
318   as argument. See the description of the <tt><ref id="infofile-label"
319   name="LABEL"></tt> directive for an explanation.
320
321   <tag><tt>END</tt></tag>
322   This gives the end address of the range. The end address is inclusive, that
323   means, it is part of the range. Of course, it may not be smaller than the
324   start address.
325
326   <tag><tt>NAME</tt></tag>
327   This is a convenience attribute. It takes a string argument and will cause
328   the disassembler to define a label for the start of the range with the
329   given name. So a separate <tt><ref id="infofile-label" name="LABEL"></tt>
330   directive is not needed.
331
332   <tag><tt>START</tt></tag>
333   This gives the start address of the range.
334
335   <tag><tt>TYPE</tt></tag>
336   This attribute specifies the type of data within the range. The attribute
337   value is one of the following keywords:
338
339   <descrip>
340     <tag><tt>ADDRTABLE</tt></tag>
341     The range consists of data and is disassembled as a table of words
342     (16 bit values). The difference to the <tt/WORDTABLE/ type is that
343     a label is defined for each entry in the table.
344
345     <tag><tt>BYTETABLE</tt></tag>
346     The range consists of data and is disassembled as a byte table.
347
348     <tag><tt>CODE</tt></tag>
349     The range consists of code.
350
351     <tag><tt>DBYTETABLE</tt></tag>
352     The range consists of data and is disassembled as a table of dbytes
353     (double byte values, 16 bit values with the low byte containing the
354     most significant byte of the 16 bit value).
355
356     <tag><tt>DWORDTABLE</tt></tag>
357     The range consists of data and is disassembled as a table of double
358     words (32 bit values).
359
360     <tag><tt>RTSTABLE</tt></tag>
361     The range consists of data and is disassembled as a table of words (16 bit
362     values). The values are interpreted as words that are pushed onto the
363     stack and jump to it via <tt/RTS/. This means that they contain
364     <tt/address-1/ of a function, for which a label will get defined by the
365     disassembler.
366
367     <tag><tt>SKIP</tt></tag>
368     The range is simply ignored when generating the output file. Please note
369     that this means that reassembling the output file will <em/not/ generate
370     the original file, not only because the missing piece in between, but also
371     because the following code will be located on wrong addresses. Output
372     generated with <tt/SKIP/ ranges will need manual rework.
373
374     <tag><tt>TEXTTABLE</tt></tag>
375     The range consists of readable text.
376
377     <tag><tt>WORDTABLE</tt></tag>
378     The range consists of data and is disassembled as a table of words
379     (16 bit values).
380
381   </descrip>
382
383 </descrip>
384
385
386 <sect1>Specifying Labels<label id="infofile-label"><p>
387
388 The <tt/LABEL/ directive is used to give names for labels in the disassembled
389 code. The following attributes are recognized:
390
391 <descrip>
392
393   <tag><tt>ADDR</tt></tag>
394   Followed by a numerical value. Specifies the value of the label.
395
396   <tag><tt>COMMENT</tt></tag>
397   Attribute argument is a string. The comment will show up in a separate line
398   before the label, if the label is within code or data range, or after the
399   label if it is outside.
400
401   Example output:
402
403 <tscreen><verb>
404         foo     := $0001        ; Comment for label named "foo"
405
406         ; Comment for label named "bar"
407         bar:
408 </verb></tscreen>
409
410   <tag><tt>NAME</tt></tag>
411   The attribute is followed by a string value which gives the name of the
412   label.
413
414   <tag><tt>SIZE</tt></tag>
415   This attribute is optional and may be used to specifiy the size of the data
416   that follows. If a size greater than 1 is specified, the disassembler will
417   create labels in the form <tt/label+offs/ for all bytes within the given
418   range, where <tt/label/ is the label name given with the <tt/NAME/
419   attribute, and <tt/offs/ is the offset within the data.
420
421 </descrip>
422
423
424 <sect1>Specifying Assembler Includes<label id="infofile-asminc"><p>
425
426 The <tt/ASMINC/ directive is used to give the names of input files containing
427 symbol assignments in assembler syntax:
428
429 <tscreen><verb>
430         Name = value
431         Name := value
432 </verb></tscreen>
433
434 The usual conventions apply for symbol names. Values may be specified as hex
435 (leading &dollar;), binary (leading %) or decimal. The values may optionally
436 be signed.
437
438 NOTE: The include file parser is very simple. Expressions are not allowed, and
439 anything but symbol assignments is flagged as an error (but see the
440 <tt/IGNOREUNKNOWN/ directive below).
441
442 The following attributes are recognized:
443
444 <descrip>
445
446   <tag><tt>FILE</tt></tag>
447   Followed by a string value. Specifies the name of the file to read.
448
449   <tag><tt>COMMENTSTART</tt></tag>
450   The optional attribute is followed by a character constant. It specifies the
451   character that starts a comment. The default value is a semicolon. This
452   value is ignored if <tt/IGNOREUNKNOWN/ is true.
453
454   <tag><tt>IGNOREUNKNOWN</tt></tag>
455   This attribute is optional and is followed by a boolean value. It allows to
456   ignore input lines that don't have a valid syntax. This allows to read in
457   assembler include files that contain more than just symbol assignments.
458   Note: When this attribute is used, the disassembler will ignore any errors
459   in the given include file. This may have undesired side effects.
460
461 </descrip>
462
463
464 <sect1>An Info File Example<p>
465
466 The following is a short example for an info file that contains most of the
467 directives explained above:
468
469 <tscreen><verb>
470         # This is a comment. It extends to the end of the line
471         GLOBAL {
472             OUTPUTNAME      "kernal.s";
473             INPUTNAME       "kernal.bin";
474             STARTADDR       $E000;
475             PAGELENGTH      0;                  # No paging
476             CPU             "6502";
477         };
478
479
480         RANGE { START $E612;    END   $E631; TYPE Code;      };
481         RANGE { START $E632;    END   $E640; TYPE ByteTable; };
482         RANGE { START $EA51;    END   $EA84; TYPE RtsTable;  };
483         RANGE { START $EC6C;    END   $ECAB; TYPE RtsTable;  };
484         RANGE { START $ED08;    END   $ED11; TYPE AddrTable; };
485
486         # Zero page variables
487         LABEL { NAME "fnadr";   ADDR  $90;   SIZE 3;    };
488         LABEL { NAME "sal";     ADDR  $93;   };
489         LABEL { NAME "sah";     ADDR  $94;   };
490         LABEL { NAME "sas";     ADDR  $95;   };
491
492         # Stack
493         LABEL { NAME "stack";   ADDR  $100;  SIZE 255;  };
494
495         # Indirect vectors
496         LABEL { NAME "cinv";    ADDR  $300;  SIZE 2;    };      # IRQ
497         LABEL { NAME "cbinv";   ADDR  $302;  SIZE 2;    };      # BRK
498         LABEL { NAME "nminv";   ADDR  $304;  SIZE 2;    };      # NMI
499
500         # Jump table at end of kernal ROM
501         LABEL { NAME "kscrorg"; ADDR  $FFED; };
502         LABEL { NAME "kplot";   ADDR  $FFF0; };
503         LABEL { NAME "kiobase"; ADDR  $FFF3; };
504         LABEL { NAME "kgbye";   ADDR  $FFF6; };
505
506         # Hardware vectors
507         LABEL { NAME "hanmi";   ADDR  $FFFA; };
508         LABEL { NAME "hares";   ADDR  $FFFC; };
509         LABEL { NAME "hairq";   ADDR  $FFFE; };
510 </verb></tscreen>
511
512
513
514
515
516 <sect>Bugs/Feedback<p>
517
518 If you have problems using the disassembler, if you find any bugs, or if
519 you're doing something interesting with the assembler, I would be glad to hear
520 from you. Feel free to contact me by email (<htmlurl url="mailto:uz@cc65.org"
521 name="uz@cc65.org">).
522
523
524
525 <sect>Copyright<p>
526
527 da65 (and all cc65 binutils) are (C) Copyright 1998-2003 Ullrich von
528 Bassewitz. For usage of the binaries and/or sources the following
529 conditions do apply:
530
531 This software is provided 'as-is', without any expressed or implied
532 warranty.  In no event will the authors be held liable for any damages
533 arising from the use of this software.
534
535 Permission is granted to anyone to use this software for any purpose,
536 including commercial applications, and to alter it and redistribute it
537 freely, subject to the following restrictions:
538
539 <enum>
540 <item>  The origin of this software must not be misrepresented; you must not
541         claim that you wrote the original software. If you use this software
542         in a product, an acknowledgment in the product documentation would be
543         appreciated but is not required.
544 <item>  Altered source versions must be plainly marked as such, and must not
545         be misrepresented as being the original software.
546 <item>  This notice may not be removed or altered from any source
547         distribution.
548 </enum>
549
550
551
552 </article>
553
554
555
556