home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 2: Collection B / 17Bit_Collection_B.iso / files / 2032.dms / in.adf / dis.docs < prev    next >
Encoding:
Text File  |  1978-01-10  |  12.0 KB  |  239 lines

  1.            Dis - an AmigaDOS File Disassembler/Dumper
  2.  
  3.  
  4.     General
  5.  
  6.     Dis is a program which will symbolically disassemble AmigaDOS object
  7.     files, whether unlinked or fully linked. It can also operate in a non-
  8.     disassembly mode and just dump the hunks in the files, or even just
  9.     list which hunks are found. It uses my 'disassemble.library' as the
  10.     disassembler, so it has all of the features of that library, including
  11.     support for the full MC68000 family, label generation, controllable
  12.     output format, etc. It also has special support for the case/switch
  13.     constructs generated by several compilers, and hooks to allow better
  14.     disassembly of AmigaDOS libraries and devices. 'Dis' will also generate
  15.     appropriate output for data and bss hunks.
  16.  
  17.     This simplest way to use Dis is as in:
  18.  
  19.     Dis <object-file>
  20.  
  21.     Dis itself has been compiled with symbolic information left in, so a
  22.     good sample of what it does can be seen by having it disassemble
  23.     itself, as in
  24.  
  25.     Dis Dis
  26.  
  27.     Some interesting things can be seen from the disassembly. First, it was
  28.     linked with an old version of BLink, since the first hunk is an extra
  29.     text hunk added to just branch to the actual starting point. Second, it
  30.     was not linked with 'smalldata', since there are multiple bss sections.
  31.     Third, it was linked with 'smallcode', since there is only one text
  32.     hunk (other than the one BLink added). The first few hunks are bss
  33.     hunks that correspond to file level variables in the source files for
  34.     Dis. Symbolic information for them was present, so Dis was able to show
  35.     the individual variables. (This symbolic information is, unfortunately,
  36.     only available with my Beta 1.3 version of Draco, and not with any
  37.     version that has been distributed.)
  38.  
  39.     Hunk #1 is the space used by the run-time system to save the contents
  40.     of registers D0 and A0, so that the command-line parameters can be
  41.     accessed. Hunks 2, 3, 4, 5, and 6 are file-level storage for the
  42.     various source files of Dis. Hunks 7 and 8 come from the interface
  43.     libraries for dos.library and exec.library. Hunk 9 is the main code
  44.     hunk. It will take a while to disassemble.
  45.  
  46.     The lines reading "Loop 1: 594 new labels.", etc. need some
  47.     explanation. They are to show that Dis is actually working and hasn't
  48.     gone away somehow. In its default mode of operation, it takes multiple
  49.     passes through each text hunk, initially assuming that only the first
  50.     part is code. It runs through all parts known to be code, identifying
  51.     all branches, jumps, calls, etc. The branch and jump targets are
  52.     identified, and the data there is taken to be code, and, if the branch
  53.     is unconditional or is a jump, the code immediately after it is not
  54.     assumed to be code unless some other instruction branches to it. This
  55.     process is repeated for the entire hunk, until no more targets are
  56.     defined. A final pass is then used to produce the actual output. See
  57.     below for methods of altering this behavior. Similar special cases are
  58.     made for subroutine returns of various forms. The goal behind this
  59.     special handling is to accurately distinguish between actual
  60.     instructions in a text hunk and non-instructions in the hunk. Other
  61.     things that can be in a text hunk are constants of various types,
  62.     tables of labels used for switch/case statements, etc.
  63.  
  64.     As you can see, symbolic information is used to provide labels, which
  65.     here are procedure names, and symbolic addresses of variables. This
  66.     type of information can be produced by various compilers - see the
  67.     instructions for the compiler for how to do it. Often, however, fully
  68.     linked object files have little or no symbolic information left in
  69.     them. In these cases Dis will not be able to show symbolic labels and
  70.     variable names. It will still be able to generate labels for referenced
  71.     locations, however. Variable or data references (or references to code
  72.     in another hunk) will be shown as a hunk-number/offset pair.
  73.  
  74.     Since unlinked object files contain references, by name, to symbols
  75.     defined elsewhere, Dis is able to produce symbolic information in a
  76.     disassembly even though explicit HUNK_SYMBOLs are not present. This
  77.     type of disassembly is one of my main uses for Dis - to see what code
  78.     my compiler is generating in test cases.
  79.  
  80.     There are many more special cases in Dis. Those interested in the gory
  81.     details are invited to examine the source, which is included here.
  82.     In particular, special handling is done for two types of Draco case
  83.     statements, two types of Lattice C switch statements, one type of Aztec
  84.     C switch statement, and a switch statement from some other compiler,
  85.     which I assume is the GreenHills compiler used by Commodore.
  86.  
  87.     Dis can be stopped at any time by typing control-C. It may take a few
  88.     seconds to stop if it is in the initial phase of processing symbolic
  89.     and relocation information for a large text hunk. Those who get
  90.     impatient with this phase are invited to rewrite the code to make it
  91.     quicker. Perhaps a binary tree of relocation offsets would work. The
  92.     culprit routines are 'insertRelocs' and 'mergeRelocs' in 'symbol.d'.
  93.  
  94.  
  95.     Dis Options
  96.  
  97.     Several flags can be given to Dis to control how it works. A brief
  98.     summary of them can be obtained by entering
  99.  
  100.     Dis -?
  101.  
  102.     In more detail, the flags are:
  103.  
  104.     -h - show all hunks. Some hunks, such as HUNK_NAME, HUNK_UNIT,
  105.     HUNK_END, are of interest only to those who have to deal with
  106.     object files directly, so Dis does not normally show them.
  107.     Specifying '-h' will force it to do so.
  108.  
  109.     -x - raw dump of hunks. In this mode of operation, no disassembly or
  110.     symbolic output is done. Instead, each hunk is dumped in a raw
  111.     form. Data and text hunks are dumped in hexadecimal and ascii.
  112.     Again, this form is probably only of use to those who need to know
  113.     the details of AmigaDOS object files.
  114.  
  115.     -a - absolute. By default, Dis will use relative addresses on
  116.     disassembly. This flag forces it to use absolute (hunk-relative)
  117.     addresses. For text hunks with symbolic information, typically
  118.     generated by a compiler, Dis will display position information and
  119.     branch labels as relative to the most recent symbolic label, which
  120.     means, for high-level languages, relative to the current function.
  121.     With '-a' specified, all addresses and labels are expanded to 32
  122.     bits and are relative to the beginning of the text hunk.
  123.  
  124.     -s - show hex addresses. If Dis can find a symbolic value to show for
  125.     an address, it will use that, rather than a hex value. '-s' forces
  126.     it to show both. This can be useful if Dis is getting confused by
  127.     some symbolic information, and is using it in inappropriate places.
  128.  
  129.     -f - force disassembly of all code. As explained previously, Dis by
  130.     default only disassembles those parts of text hunks that it thinks
  131.     are "reachable" from the initial code in the hunk. This method can
  132.     miss parts of the code if those parts are not referenced directly.
  133.     This is sometimes because a function is not being called, but can
  134.     also be because parts of the code are only referenced indirectly,
  135.     through a function table or jump table of some kind. Specifying
  136.     flag '-f' forces Dis to treat the entire text hunk as code. This
  137.     can lead to a mess, however, since most strings and constants don't
  138.     disassemble very well.
  139.  
  140.     -n - Dis normally tries to generate labels for all branch and jump
  141.     targets, and to use those labels at the branch points. Specifying
  142.     '-n' tells it to not do that. Branches will then display both the
  143.     hex form of the target and, as appropriate, the PC-relative form.
  144.  
  145.     -w - the previously mentioned technique of doing multiple scans of the
  146.     code to find out what is code and what is data can be quite time
  147.     consuming. Flag '-w' tells Dis to not work so hard. If '-n' is not
  148.     specified, it will do a single pre-pass to identify labels, and
  149.     then disassemble with what it has found by then. This will often
  150.     work, but is confused by switch/case statements. If '-n' is
  151.     specified along with '-w', then Dis will do no prescans, but will
  152.     just disassemble in one pass. This can cut down on the time quite a
  153.     bit, but can also miss a lot. Adding '-f' to the flag list gives a
  154.     raw, non-labelled disassembly of the entire text hunk.
  155.  
  156.     -l - AmigaDOS libraries (in LIBS:) and devices (in DEVS:) have a very
  157.     specific format, with a couple of header sections which point to
  158.     the routines of the library/device. Flag '-l' tells Dis that it is
  159.     looking at one of these. With this flag, it will try to find the
  160.     special parts, and treat them separately. The code to do this works
  161.     well for libraries generated by my 'fdCompile' program, but
  162.     sometimes has trouble with other libraries/devices. (The difficulty
  163.     seems to be that they put parts of the special stuff a long way
  164.     down in the code, so that Dis doesn't find it early enough. Also,
  165.     it seems that some of the Commodore-supplied ones don't follow the
  166.     form layed out in the ROM Kernel Manuals.)
  167.  
  168.     -r - this flag tells Dis to show the relative form of branches and data
  169.     references as well as a symbolic or label form.
  170.  
  171.     -p - by default, Dis shows a hexadecimal offset to the left of the
  172.     disassembly it generates. This flag suppresses that part, which
  173.     makes the output closer to something that an assembler will like.
  174.  
  175.     -c - by default, Dis will capitalize any non-MC68000 instructions or
  176.     addressing forms that it finds. This is useful for people with
  177.     compilers that can handle the MC68020/MC68881, etc. Specifying '-c'
  178.     will suppress that capitalization.
  179.  
  180.     -q - this flag enables a quick summary mode. A single line only is
  181.     printed for each hunk found in the object file.
  182.  
  183.     -d - a fully linked object file with no symbolic information has jumps
  184.     and branches within it - to subroutines, run-time library routines,
  185.     interface stubs, etc. One of the special cases in Dis is for a type
  186.     of case statement in Draco which JMPs to a run-time routine to do a
  187.     binary search through a sorted table. If no symbolic information is
  188.     present, Dis has no way to distinguish this JMP from others. Flag
  189.     '-d' tells Dis to treat all such JMPs as JMPs to those special run-
  190.     time system routines. If you know that an object file is not fully
  191.     linked, isn't compiled by Draco, or has symbolic information, this
  192.     flag will not be needed.
  193.  
  194.     -k - problems similar to the above can occur in other object files with
  195.     "unusual" code. Flag '-k' tells Dis to assume that the entire text
  196.     hunk is code when doing prepasses to find labels. The normal checks
  197.     for code v.s. data will be done when the actual disassembly is
  198.     produced. The disadvantage of this flag is that spurious labels can
  199.     be produced, and occasionally, data will be treated as code.
  200.  
  201.  
  202.     Some Sample Disassemblies to Try
  203.  
  204.     dis dis
  205.     dis -dl libs:disassemble.library
  206.     dis -lkf libs:mathieeedoubtrans.library
  207.         if you have enough patience, you can see the FPU
  208.         instructions start at offset 0x385c
  209.     dis c:format
  210.         What? you don't have format copied to your C: directory so
  211.         you can use it from CLI? Note the empty code and data hunks
  212.         - must be a funny compiler Commodore uses.
  213.     dis -q c:format
  214.     dis -x c:format
  215.         So does the trashcan icon look like a trashcan in hex?
  216.  
  217.  
  218.     Expansion
  219.  
  220.     My original need was for a disassembler that would just nicely
  221.     disassemble the object files my compiler produces for small test files.
  222.     Dis has grown considerably from that initial requirement. As with any
  223.     program like this, there is still much that could be done:
  224.  
  225.     - better heuristics for distinguishing code from data in text hunks
  226.     - better handling of libraries and devices that don't follow the
  227.         model that Dis likes
  228.     - flags to allow some hunks to be skipped
  229.     - flags to force certain regions to be treated as code or data
  230.     - an interactive mode
  231.     - intuition interface
  232.     - flags to force output to be directly acceptable to assemblers
  233.  
  234.     I don't plan to do any of these things myself. Some minor changes may
  235.     get done if something becomes a nuisance. Since the full source to Dis
  236.     is included, however, others are invited to try their hand at some of
  237.     them. I would especially be interested in improvements to the code/data
  238.     distinguishing code.
  239.