home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer) / NeXT_Developer-3.3.iso / NextDeveloper / Headers / mach-o / hppa / reloc.h next >
C/C++ Source or Header  |  1993-10-20  |  4KB  |  85 lines

  1. /*    reloc.h   -  assemble for HP-PA    */
  2. /*    Defines machine specific relocation entries */
  3.  
  4. #ifndef HPPA_RELOC_INCLUDED
  5. #define HPPA_RELOC_INCLUDED
  6.  
  7. /*
  8.  * Relocation types used in the hppa implementation.  Relocation entries for
  9.  * things other than instructions use the same generic relocation as discribed
  10.  * in <mach-o/reloc.h> and their r_type is HPPA_RELOC_VANILLA.  The rest of the
  11.  * relocation types are for instructions.  Since they are for instructions the
  12.  * r_address field indicates the 32 bit instruction that the relocation is to
  13.  * be preformed on.  The field r_pcrel is set only for the HPPA_RELOC_BR17.
  14.  * And r_length is set to long for all non-RELOC_VANILLA r_types.
  15.  */
  16. enum reloc_type_hppa
  17. {
  18.     HPPA_RELOC_VANILLA,    /* generic relocation as discribed in <mach-o/reloc.h>*/
  19.     HPPA_RELOC_PAIR,    /* the second relocation entry of a pair */
  20.     HPPA_RELOC_HI21,    /* a PAIR follows with the low part */
  21.     HPPA_RELOC_LO14,    /* a PAIR follows with the high part */
  22.     HPPA_RELOC_BR17,    /* 17 bit branch displacement (to a word address)
  23.                a PAIR follows with the high part */
  24.     HPPA_RELOC_BL17,    /* a bl instruction (overlow causes an error) */
  25.     HPPA_RELOC_JBSR,     /* a bl instruction that is targeted at a long branch
  26.                stub, a PAIR follows with the high part */
  27.     HPPA_RELOC_SECTDIFF,    /* a PAIR follows with subtract symbol value */
  28.     HPPA_RELOC_HI21_SECTDIFF,    /* a PAIR follows with subtract symbol value */
  29.     HPPA_RELOC_LO14_SECTDIFF    /* a PAIR follows with subtract symbol value */
  30. };
  31.  
  32. /*
  33.  * For the HI and LO relocation types the two parts of the relocated expression
  34.  * (symbol + offset) are calculated as follows:
  35.  *
  36.  *    rounded = round(offset, 0x2000);
  37.  *    left21 =   (symbol + rounded) & 0xfffff800;
  38.  *    right14 = ((symbol + rounded) & 0x000007ff) + (offset - rounded);
  39.  *
  40.  * This allows the left part to be shared between references with different
  41.  * offsets as long as the rounded offsets are the same.
  42.  *
  43.  * The HPPA_RELOC_BR17 r_type also uses the above calculation and the right14
  44.  * bits, sign extened to fill the displacement, and converted to a word
  45.  * displacement by droping the low bits (after checking they are zero).
  46.  */
  47.  
  48. /*
  49.  * For relocation types that use pairs the part of the relocated expression that
  50.  * is not stored in the instruction is stored in the r_address feild of the
  51.  * PAIR's entry.
  52.  *
  53.  * All low parts are stored as sign extened byte addressed values in the PAIR's
  54.  * r_address field as 32 bit values.  This allows the HI21 not to have to know
  55.  * which type of low it is used with.
  56.  *
  57.  * The high parts are left justified 21 bit values zero filled to 32 bits and 
  58.  * stored in the PAIR's r_address field.
  59.  */
  60.  
  61. /*
  62.  * The instructions that use the non-RELOC_VANILLA r_types are and the r_types
  63.  * they use are as follows:
  64.  *    instructions    r_type
  65.  *
  66.  *    LDIL,ADDIL    HPPA_RELOC_HI21
  67.  *    LDx, STx, LDO    HPPA_RELOC_LO14
  68.  *    BE, BLE        HPPA_RELOC_BR17
  69.  *    BL        HPPA_RELOC_BL17
  70.  *
  71.  * For the HPPA_RELOC_JBSR the BL instruction must be targeted at a long branch
  72.  * stub that can be reached with 17 bits of signed word displacement.  Also the
  73.  * stub must be in the same block as the BL instruction so that scattered
  74.  * loading done by the link editor will not move them apart.  For example in
  75.  * assembly code:
  76.  *    jbsr    foo,%r2,L1    ; creates a bl inst with a HPPA_RELOC_JBSR
  77.  *                ;  relocation entry for the symbol foo and the
  78.  *                ;  instruction is targeted to L1
  79.  *    ...
  80.  * L1:    ldil    L'foo,%r1    ; a HPPA_RELOC_HI21 entry for symbol foo
  81.  *    ble,n    R'foo(%sr4,%r1)    ; a HPPA_RELOC_BR17 entry for symbol foo
  82.  */
  83.  
  84. #endif    /* HPPA_RELOC_INCLUDED */
  85.