home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / local / include / mach-o / hppa / reloc.h next >
Encoding:
C/C++ Source or Header  |  2001-09-14  |  4.6 KB  |  109 lines

  1. /*
  2.  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
  3.  *
  4.  * @APPLE_LICENSE_HEADER_START@
  5.  * 
  6.  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
  7.  * Reserved.  This file contains Original Code and/or Modifications of
  8.  * Original Code as defined in and that are subject to the Apple Public
  9.  * Source License Version 1.1 (the "License").  You may not use this file
  10.  * except in compliance with the License.  Please obtain a copy of the
  11.  * License at http://www.apple.com/publicsource and read it before using
  12.  * this file.
  13.  * 
  14.  * The Original Code and all software distributed under the License are
  15.  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  16.  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  17.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
  19.  * License for the specific language governing rights and limitations
  20.  * under the License.
  21.  * 
  22.  * @APPLE_LICENSE_HEADER_END@
  23.  */
  24. /*    reloc.h   -  assemble for HP-PA    */
  25. /*    Defines machine specific relocation entries */
  26.  
  27. #ifndef HPPA_RELOC_INCLUDED
  28. #define HPPA_RELOC_INCLUDED
  29.  
  30. /*
  31.  * Relocation types used in the hppa implementation.  Relocation entries for
  32.  * things other than instructions use the same generic relocation as discribed
  33.  * in <mach-o/reloc.h> and their r_type is HPPA_RELOC_VANILLA.  The rest of the
  34.  * relocation types are for instructions.  Since they are for instructions the
  35.  * r_address field indicates the 32 bit instruction that the relocation is to
  36.  * be preformed on.  The field r_pcrel is set only for the HPPA_RELOC_BR17.
  37.  * And r_length is set to long for all non-RELOC_VANILLA r_types.
  38.  */
  39. enum reloc_type_hppa
  40. {
  41.     HPPA_RELOC_VANILLA,    /* generic relocation as discribed in <mach-o/reloc.h>*/
  42.     HPPA_RELOC_PAIR,    /* the second relocation entry of a pair */
  43.     HPPA_RELOC_HI21,    /* a PAIR follows with the low part */
  44.     HPPA_RELOC_LO14,    /* a PAIR follows with the high part */
  45.     HPPA_RELOC_BR17,    /* 17 bit branch displacement (to a word address)
  46.                a PAIR follows with the high part */
  47.     HPPA_RELOC_BL17,    /* a bl instruction (overlow causes an error) */
  48.     HPPA_RELOC_JBSR,     /* a bl instruction that is targeted at a long branch
  49.                stub, a PAIR follows with the high part */
  50.     HPPA_RELOC_SECTDIFF,    /* a PAIR follows with subtract symbol value */
  51.     HPPA_RELOC_HI21_SECTDIFF,    /* a PAIR follows with subtract symbol value */
  52.     HPPA_RELOC_LO14_SECTDIFF,    /* a PAIR follows with subtract symbol value */
  53.     HPPA_RELOC_PB_LA_PTR    /* prebound lazy pointer */
  54. };
  55.  
  56. /*
  57.  * For the HI and LO relocation types the two parts of the relocated expression
  58.  * (symbol + offset) are calculated as follows:
  59.  *
  60.  *    rounded = round(offset, 0x2000);
  61.  *    left21 =   (symbol + rounded) & 0xfffff800;
  62.  *    right14 = ((symbol + rounded) & 0x000007ff) + (offset - rounded);
  63.  *
  64.  * This allows the left part to be shared between references with different
  65.  * offsets as long as the rounded offsets are the same.
  66.  *
  67.  * The HPPA_RELOC_BR17 r_type also uses the above calculation and the right14
  68.  * bits, sign extened to fill the displacement, and converted to a word
  69.  * displacement by droping the low bits (after checking they are zero).
  70.  */
  71.  
  72. /*
  73.  * For relocation types that use pairs the part of the relocated expression that
  74.  * is not stored in the instruction is stored in the r_address feild of the
  75.  * PAIR's entry.
  76.  *
  77.  * All low parts are stored as sign extened byte addressed values in the PAIR's
  78.  * r_address field as 32 bit values.  This allows the HI21 not to have to know
  79.  * which type of low it is used with.
  80.  *
  81.  * The high parts are left justified 21 bit values zero filled to 32 bits and 
  82.  * stored in the PAIR's r_address field.
  83.  */
  84.  
  85. /*
  86.  * The instructions that use the non-RELOC_VANILLA r_types are and the r_types
  87.  * they use are as follows:
  88.  *    instructions    r_type
  89.  *
  90.  *    LDIL,ADDIL    HPPA_RELOC_HI21
  91.  *    LDx, STx, LDO    HPPA_RELOC_LO14
  92.  *    BE, BLE        HPPA_RELOC_BR17
  93.  *    BL        HPPA_RELOC_BL17
  94.  *
  95.  * For the HPPA_RELOC_JBSR the BL instruction must be targeted at a long branch
  96.  * stub that can be reached with 17 bits of signed word displacement.  Also the
  97.  * stub must be in the same block as the BL instruction so that scattered
  98.  * loading done by the link editor will not move them apart.  For example in
  99.  * assembly code:
  100.  *    jbsr    foo,%r2,L1    ; creates a bl inst with a HPPA_RELOC_JBSR
  101.  *                ;  relocation entry for the symbol foo and the
  102.  *                ;  instruction is targeted to L1
  103.  *    ...
  104.  * L1:    ldil    L'foo,%r1    ; a HPPA_RELOC_HI21 entry for symbol foo
  105.  *    ble,n    R'foo(%sr4,%r1)    ; a HPPA_RELOC_BR17 entry for symbol foo
  106.  */
  107.  
  108. #endif    /* HPPA_RELOC_INCLUDED */
  109.