Next: Disassembly
of Other Sections Up: Implementation
Details of the Previous: First
Pass of Disassembly
Second Pass of Disassembly
The objective of this pass is to generate assembly language instruction
from their binary counterpart. Since the address ranges of valid code have
been identified in the first pass, we only need to disassemble the instructions
in each address range. The instruction disassembly is carried out in the
following steps.
-
Symbol Generation : To perform the symbolic disassembly, at the
beginning of the disassembly of an instruction, it is checked whether a
symbol is associated with the address of the current instruction and if
so, the symbol type (function name or just a label) is also extracted.
If the symbol refers to a function, further information regarding the type
and size of the function is also extracted.
-
Instruction Generation : An instruction is matched using the instruction
matching algorithm (as described in section
) and corresponding assembly language instruction is output with appropriate
parameters. If the instruction is a control transfer instruction, a symbol
is found from the symbol table constructed during the first pass and corresponding
symbol name is used in the disassembled instruction. Further, memory references
to the .data, .rodata and other such sections are found. In case
of such a reference, we try to resolve the address. The size of the operand
and the symbol name is stored for the reference.
This procedure is repeated for each instruction in all address ranges.
The gaps within the .text section are overlooked for the purpose
of text disassembly. One possibility is to simply ignore the bytes in the
gaps and change the current location counter so that it reaches the beginning
of the next valid address range. However, it is possible that these gaps
contain initialized data (which are not referenced by the normal methods,
for instance using register indirection instead of symbols, otherwise it
would have been discovered during the first pass). In such a case,
ignoring them might break the intended equivalence between the relocatable
object file and the generated assembly code. Therefore, we simply output
bytes in the gaps as data and generate appropriate pseudo-ops to glue the
code.
Next: Disassembly
of Other Sections Up: Implementation
Details of the Previous: First
Pass of Disassembly
Nihal chand Jain (9711113)
Fri Jan 15 11:17:08 IST 1999