home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / XSRVDIS.C < prev    next >
Text File  |  1995-04-14  |  7KB  |  101 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   xsrvdis.c                                                            822*/
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*  some x-server disassembly functions.                                     */
  8. /*                                                                           */
  9. /* History:                                                                  */
  10. /*                                                                           */
  11. /*   05/04/93 Created.                                                       */
  12. /*                                                                           */
  13. /*...                                                                        */
  14. /*... 06/04/93  827   Joe       Add remote debug support.                    */
  15. /*...                                                                        */
  16. /*****************************************************************************/
  17. #include "all.h"
  18.  
  19. /*****************************************************************************/
  20. /* _InstLength()                                                             */
  21. /*                                                                           */
  22. /* Description:                                                              */
  23. /*   Gets the length of an assembler instruction.                            */
  24. /*                                                                           */
  25. /* Parameters:                                                               */
  26. /*   addr        input - address of instruction.                             */
  27. /*                                                                           */
  28. /* Return:                                                                   */
  29. /*                                                                           */
  30. /*               length of instruction.                                      */
  31. /*                                                                           */
  32. /* Assumptions:                                                              */
  33. /*                                                                           */
  34. /*   addr is flat.                                                           */
  35. /*                                                                           */
  36. /*****************************************************************************/
  37. UCHAR _InstLength( ULONG addr )
  38. {
  39.  DTIF    InstrPacket;
  40.  int     PacketSize;
  41.  UCHAR   type;
  42.  UCHAR   bitness;
  43.  
  44.  PacketSize = sizeof(InstrPacket);
  45.  memset(&InstrPacket,0,PacketSize );
  46.  bitness = _GetBitness( addr );
  47.  type = (bitness==BIT16)?USE16:USE32;
  48.  InstrPacket.Flags.Use32bit = type;
  49.  _GetInstrPacket( addr, (DTIF*)&InstrPacket );
  50.  return(InstrPacket.retInstLen);
  51. }
  52.  
  53. /*****************************************************************************/
  54. /* GetInstrPacket                                                            */
  55. /*                                                                           */
  56. /* Description:                                                              */
  57. /*   Get the disassembler packet for an instruction.                         */
  58. /*                                                                           */
  59. /* Parameters:                                                               */
  60. /*   addr        input - address of instruction.                             */
  61. /*   packet      input - -> to instruction packet.                           */
  62. /*                       gets filled in by this function.                    */
  63. /*                                                                           */
  64. /* Return:                                                                   */
  65. /*                                                                           */
  66. /* Assumptions:                                                              */
  67. /*                                                                           */
  68. /*  addr is valid.                                                           */
  69. /*                                                                           */
  70. /*****************************************************************************/
  71. #define BLEN 15                         /* bytes of debuggee code to read 107*/
  72.                                         /* for call instruction disassembl   */
  73.  void                                   /*                                   */
  74. _GetInstrPacket( uint addr, DTIF *InstrPacket ) /*                     101*/
  75. {                                       /*                                   */
  76.  uchar    hexbuffer[HEXBUFFSIZE];       /* where disassembler puts hex.   108*/
  77.  char     mnebuffer[MNEMBUFFSIZE];      /* where disassembler puts mne.   108*/
  78.  uchar    textbuffer[TEXTBUFFSIZE];     /* where disassembler puts text.  108*/
  79.  uchar   *tempptr;                      /* ->DBGet allocated memory.         */
  80.  uint     read;                         /* bytes read in by Getnbytes.       */
  81.                                         /*                                   */
  82.  /****************************************************************************/
  83.  /* tempptr allocate and free is managed by Getnbytes which allocates the    */
  84.  /* buffer and just holds on to it until the next call by any caller.        */
  85.  /****************************************************************************/
  86.  tempptr =  Getnbytes(addr,BLEN,&read); /* read BLEN bytes from debuggee. 101*/
  87.  InstrPacket->InstPtr = tempptr;        /* ->read in hex from user app       */
  88.  InstrPacket->InstEIP  = 0xffffffff;    /* EIP value for this instr->        */
  89.  InstrPacket->Flags.MASMbit=1;          /* 1 for masm disassembly.           */
  90.  InstrPacket->Flags.N387bit  = 1;       /* not a 80x87 processor instr       */
  91.  InstrPacket->Flags.Unused1 = 0;        /* make zero due to possible futur   */
  92.  /****************************************************************************/
  93.  /* We don't really care about these buffers at this time. We put them       */
  94.  /* in to satisfy the disassembler.                                          */
  95.  /****************************************************************************/
  96.  InstrPacket->HexBuffer = hexbuffer;    /* hexbuffer will have instr strea   */
  97.  InstrPacket->MneBuffer = mnebuffer;    /* -> disassembled mnemonic.         */
  98.  InstrPacket->TextBuffer = textbuffer;  /* for disasembly text               */
  99.  DisAsm( InstrPacket );                 /* disassemble current instruction   */
  100. }                                       /* end GetInstrPacket.               */
  101.