home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Source / GNU / cctools / include / mach-o / m88k / disasm.h next >
Encoding:
C/C++ Source or Header  |  1992-06-25  |  11.4 KB  |  248 lines

  1. /*
  2.  * This file discribes the 88k disassember functions and structures.
  3.  */
  4. #import <mach-o/nlist.h>
  5. #import <mach-o/reloc.h>
  6. #import "stuff/ofile.h"
  7. #import <mach-o/m88k/parseinst.h>
  8.  
  9. /* This is the structure that is filled in by the get_reg() routine */
  10. union m88k_reg_value {
  11.     struct {
  12.     unsigned long w[4]; /* big endian, most significant word in w[0] */
  13.     } words;
  14.     float f;
  15.     double d;
  16. };
  17.  
  18. /*
  19.  * This is the block of parameters for the disassembler.  The block itself and
  20.  * all fields are optional (must be 0 if not specified).  The disassembler
  21.  * routine never writes any of these fields.
  22.  */
  23. struct m88k_disassembler_params {
  24.     char *string_before_mnemonic;    /* if NULL then "\t" is used */
  25.     char *string_after_mnemonic;    /* if NULL then "\t" is used */
  26.  
  27.     /* These are arrays of register names */
  28.     char **general_registers;    /* if NULL then "r0"..."r31" is used */
  29.     char **extended_registers;    /* if NULL then "x0"..."x31" is used */
  30.     char **control_registers;    /* if NULL then "cr0"..."cr63" is used */
  31.     char **fp_control_registers;/* if NULL then "fcr0"..."fcr63" is used */
  32.  
  33.     /*
  34.      * If the current_address parameter of m88k_disassembler() is not NULL and
  35.      * the value it is pointing at is an address of an instruction that is
  36.      * being disassembled then this function is used to get the values of the
  37.      * register operands and they are added to that line as a comment.  The
  38.      * parameter num is the register's number, type is one of the four register
  39.      * type m88k_operand_type enumeration constants, format is one of the
  40.      * m88k_operand_format enumeration constants which describes the format and
  41.      * width of the operand to be returned in the value parameter.
  42.      */
  43.     void (*get_reg)(unsigned long num,
  44.             enum m88k_operand_type type,
  45.             enum m88k_operand_format format,
  46.             union m88k_reg_value *value);
  47.  
  48.     /* The default for all of these is flags is FALSE (0) */
  49.     unsigned long
  50.      /*
  51.       * This causes the first thing on the line to be the 8 digit hex
  52.       * address of the instruction (no leading 0x).
  53.       */
  54.          output_instruction_address:1,
  55.      /*
  56.       * This causes the next thing on the line to be the 8 digit hex
  57.       * opcode of the instruction (no leading 0x).
  58.       */
  59.      output_instruction_opcode:1,
  60.      /*
  61.       * These next three are mutually exclusive and are order here is the
  62.       * precedence if more than one is set.  They provide different ways to
  63.       * produce labels for instructions and operands of branches.  When
  64.       * output_manufactured_instruction_labels is set then targets of
  65.       * branches that don't have symbols have labels of the form "Ln" (when
  66.       * n is a number) are manufactured and only symbols names without an
  67.       * offset are printed.  If output_instruction_labels_and_offsets is
  68.       * set then each instruction which has a symbol before it's address is
  69.       * output with the previous symbol plus it's offset.  If
  70.       * output_instruction_labels is set then only instructions that have
  71.       * symbols at their addresses are output as labels.
  72.       */
  73.      output_manufactured_instruction_labels:1,
  74.      output_instruction_labels_and_offsets:1,
  75.      output_instruction_labels:1,
  76.      /* this allows for no partial lines to be placed in the buffer */
  77.      output_nopartial_lines:1,
  78.      /*
  79.       * This forces the output to include the next instruction if the last
  80.       * instruction in the range will cause the next instruction to be
  81.       * executed.
  82.       */
  83.      output_execute_next_instructions:1,
  84.      /*
  85.       * This forces the disassembler to not guess a symbolic name for a
  86.       * "symbol+value" operand when all it has is the resulting expression
  87.       * value and not external relocation entries.
  88.       */
  89.      output_noguessed_operands:1,
  90.      output_reserved_flags:24;
  91.  
  92.     /*
  93.      * To get a symbol name for an address the function get_symbol() is used if
  94.      * not NULL, or if NULL the symbol is searched for in the sorted_symbols,
  95.      * nsorted_symbols, string_table and string_table_size if their values are
  96.      * not NULL.  The array of sorted_symbols should be sorted by the n_value
  97.      * field and should contain only those symbols that should be considered
  98.      * labels (things like stab entries should not appear).  Then the n_strx
  99.      * field of the symbol table entry is used as an index in to the
  100.      * string_table.  The function get_symbol() should return the name and
  101.      * value of the symbol that is closest but not greater than addr.  It
  102.      * returns -1 if it can't find a symbol before that address and zero
  103.      * otherwise.  If get_symbol() is set it can use the field user_data
  104.      * to get at any data it needs.
  105.      */
  106.     long (*get_symbol)(unsigned long addr, /* in */
  107.                const struct m88k_disassembler_params *params, /* in */
  108.                char **name, /* out */
  109.                unsigned long *value); /* out */
  110.     struct nlist *sorted_symbols;
  111.     unsigned long nsorted_symbols;
  112.     char *string_table;
  113.     unsigned long string_table_size;
  114.  
  115.     /*
  116.      * To get a "symbol+value" for an operand of an instruction the function
  117.      * get_reloc() is used if not NULL, or if NULL the symbol is searched for
  118.      * in the original_relocs, noriginal_relocs, original_symbols,
  119.      * noriginal_symbols, as well as sorted_symbols, nsorted_symbols,
  120.      * string_table, and string_table_size (from above) if their values are not
  121.      * NULL.  If the tables are used the r_address field of the relocation
  122.      * entries must be changed to a true address and not left as an offset from
  123.      * the start of a section.  In the case of disassembling code from the first
  124.      * section of a relocatable object that is linked at zero nothing has to be
  125.      * done to the r_address field for this section's relocation entries.  Since
  126.      * the (__TEXT,__text) section is typically first and where disassembly is
  127.      * typically done from and only relocatable objects tend to have relocation
  128.      * entries this works without changing the r_address field.  The relocation
  129.      * entries must have their M88K_RELOC_PAIR entries following their
  130.      * M88K_RELOC_{HI16,LO16} entries.  The function get_reloc() should return
  131.      * the name, value and type of the "symbol+value" expression for the
  132.      * instruction at addr who opcodeis passed.  The name can be returned as
  133.      * NULL if no symbol name can be found and then only the value will be
  134.      * output.  The type returned should be one of the M88K_RELOC_* defined in
  135.      * <reloc.h> for an instruction.  Only the hi/lo types are used to print
  136.      * the "hi16(symbol+value)" around the operand.  Get_reloc() returns -1 if
  137.      * it can't find a symbol/value/type for the address and zero otherwise.
  138.      * If get_reloc() is set it can use the field user_data to get at any data
  139.      * it needs.
  140.      */
  141.     long (*get_reloc)(unsigned long addr, /* in */
  142.               unsigned long opcode, /* in */
  143.               const struct m88k_disassembler_params *params, /* in */
  144.               char **name, /* out */
  145.               long *value, /* out */
  146.               unsigned long *type); /* out */
  147.     struct relocation_info *original_relocs;
  148.     unsigned long noriginal_relocs;
  149.     struct nlist *original_symbols;
  150.     unsigned long noriginal_symbols;
  151.  
  152.     /* This is intended for the user and not used by m88k_disassembler() */
  153.     void *user_data;
  154. };
  155.  
  156. /*
  157.  * m88k_disassembler() returns the numbers of bytes of the instructions it
  158.  * disassembles or -1 for errors which prevent it from doing disassembly.
  159.  * Non-fatal errors are just ignored and the best that can be done is done.
  160.  * The range of addresses between start_addr through end_addr (exclusive) is
  161.  * disassembled into the buffer of buffer_size.  For one instruction start_addr
  162.  * is equal end_addr.  The function get_word() is called to get 32 bit words
  163.  * for the address it is passed and sets word to the value of the 32 bit word.
  164.  * The parameter get_word_data is passed to the function get_word() when called.
  165.  * Get_word returns -1 when it can't get the word at the specified address and
  166.  * zero otherwise.  All other parameter are optional and must be NULL if not
  167.  * specified.  Params is a pointer to block of options (described above).
  168.  * Current_address is use only for printing register values of the currently
  169.  * executing instruction (see get_reg above).  If number_of_instructions is not
  170.  * NULL it is set to the count of instructions disassembled into the buffer.
  171.  * If buffer_size_needed is not NULL it is set the size that is needed to fully
  172.  * disassembled the instructions in the specified range into the buffer.
  173.  */
  174. extern long m88k_disassembler(
  175.     /* required parameters */
  176.     unsigned long start_addr, /* in */
  177.     unsigned long end_addr, /* in */
  178.     char *buffer, /* in */
  179.     unsigned long buffer_size, /* in */
  180.     long (*get_word)(unsigned long addr /* in */,
  181.              unsigned long *word /* out */,
  182.              void *get_word_data /* in */), /* in */
  183.     void *get_word_data, /* in */
  184.  
  185.     /* optional parameters, must be NULL if not specified */
  186.     const struct m88k_disassembler_params *params, /* in */
  187.     const unsigned long *current_address, /* in */
  188.     unsigned long *number_of_instructions, /* out */
  189.     unsigned long *buffer_size_needed); /* out */
  190.  
  191. /*
  192.  * m88k_disassemble_routine() returns a a pointer to a buffer that contains the
  193.  * disassembled routine, routine_name, from the object file, object_name, in
  194.  * the archive library, archive_name (or if archive_name is NULL from the named
  195.  * object file).  The buffer is created with malloc(3).  The argument params is
  196.  * used as the option to the disassembler routine m88k_disassembler() and maybe
  197.  * NULL.  This routine causes the symbolic tables in params to be set and then
  198.  * cleared.  If m88k_disassemble_routine() can't do it's job NULL is returned.
  199.  */
  200. extern char * m88k_disassemble_routine(
  201.     const char *archive_name,
  202.     const char *object_name,
  203.     const char *routine_name,
  204.     struct m88k_disassembler_params *params);
  205.  
  206. /*
  207.  * m88k_disassembler_setup() sets up the symbolic tables that it can from the
  208.  * ofile into the params for the object file (in the archive if archive_name is
  209.  * not NULL).  It returns -1 for failure and 0 for success.
  210.  */
  211. extern long m88k_disassembler_setup(
  212.     const char *archive_name,
  213.     const char *object_name,
  214.     struct m88k_disassembler_params *params,
  215.     struct ofile *ofile);
  216.  
  217. /*
  218.  * m88k_disassembler_cleanup() cleans up the symbolic tables in param and closes
  219.  * the ofile.  It returns -1 for failure and 0 for success.
  220.  */
  221. extern long m88k_disassembler_cleanup(
  222.     struct m88k_disassembler_params *params,
  223.     struct ofile *ofile);
  224.  
  225. /*
  226.  * m88k_disassembler_dbgmon_setup() sets up the debug monitor's disassembler.
  227.  * Specifily it set up the sorted symbol table and the string table feilds
  228.  * in to params.  It also set the register names to the kernel register names.
  229.  * It is passed the address of the mach_header of the co-loaded program it is
  230.  * going to disassemble.  This program must have a mapped LINKEDIT segment and
  231.  * the symbol table must be stripped to only those symbols used for lables and
  232.  * operand values and must be sorted by their n_value field.  This routine does
  233.  * no checking of the header or the load commands.  It only returns failure if
  234.  * there is no LC_SYMTAB load command or LINKEDIT segment.  It returns -1 for
  235.  * failure and 0 for success.
  236.  */
  237. extern long m88k_disassembler_dbgmon_setup(
  238.     struct mach_header *mh,
  239.     struct m88k_disassembler_params *params);
  240.  
  241. /*
  242.  * These are arrays of the conventional kernel coding names of the registers.
  243.  */
  244. extern const char * const kernel_general_register_names[];
  245. extern const char * const kernel_extended_register_names[];
  246. extern const char * const kernel_control_register_names[];
  247. extern const char * const kernel_fp_control_register_names[];
  248.