Home | History | Annotate | Download | only in include
      1 /* libunwind - a platform-independent unwind library
      2    Copyright (C) 2006-2007 IBM
      3    Contributed by
      4      Corey Ashford <cjashfor (at) us.ibm.com>
      5      Jose Flavio Aguilar Paulino <jflavio (at) br.ibm.com> <joseflavio (at) gmail.com>
      6 
      7    Copied from libunwind-x86_64.h, modified slightly for building
      8    frysk successfully on ppc64, by Wu Zhou <woodzltc (at) cn.ibm.com>
      9    Will be replaced when libunwind is ready on ppc64 platform.
     10 
     11 This file is part of libunwind.
     12 
     13 Permission is hereby granted, free of charge, to any person obtaining
     14 a copy of this software and associated documentation files (the
     15 "Software"), to deal in the Software without restriction, including
     16 without limitation the rights to use, copy, modify, merge, publish,
     17 distribute, sublicense, and/or sell copies of the Software, and to
     18 permit persons to whom the Software is furnished to do so, subject to
     19 the following conditions:
     20 
     21 The above copyright notice and this permission notice shall be
     22 included in all copies or substantial portions of the Software.
     23 
     24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     25 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     26 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     27 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     28 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     29 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     30 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
     31 
     32 #ifndef LIBUNWIND_H
     33 #define LIBUNWIND_H
     34 
     35 #if defined(__cplusplus) || defined(c_plusplus)
     36 extern "C" {
     37 #endif
     38 
     39 #include <inttypes.h>
     40 #include <ucontext.h>
     41 
     42 #define UNW_TARGET		ppc32
     43 #define UNW_TARGET_PPC32	1
     44 
     45 #define _U_TDEP_QP_TRUE	0	/* see libunwind-dynamic.h  */
     46 
     47 /*
     48  * This needs to be big enough to accommodate "struct cursor", while
     49  * leaving some slack for future expansion.  Changing this value will
     50  * require recompiling all users of this library.  Stack allocation is
     51  * relatively cheap and unwind-state copying is relatively rare, so we want
     52  * to err on making it rather too big than too small.
     53  *
     54  * To simplify this whole process, we are at least initially taking the
     55  * tack that UNW_PPC32_* map straight across to the .eh_frame column register
     56  * numbers.  These register numbers come from gcc's source in
     57  * gcc/config/rs6000/rs6000.h
     58  *
     59  * UNW_TDEP_CURSOR_LEN is in terms of unw_word_t size.  Since we have 115
     60  * elements in the loc array, each sized 2 * unw_word_t, plus the rest of
     61  * the cursor struct, this puts us at about 2 * 115 + 40 = 270.  Let's
     62  * round that up to 280.
     63  */
     64 
     65 #define UNW_TDEP_CURSOR_LEN 280
     66 
     67 #if __WORDSIZE==32
     68 typedef uint32_t unw_word_t;
     69 typedef int32_t unw_sword_t;
     70 #else
     71 typedef uint64_t unw_word_t;
     72 typedef int64_t unw_sword_t;
     73 #endif
     74 
     75 typedef long double unw_tdep_fpreg_t;
     76 
     77 typedef enum
     78   {
     79     UNW_PPC32_R0,
     80     UNW_PPC32_R1, /* called STACK_POINTER in gcc */
     81     UNW_PPC32_R2,
     82     UNW_PPC32_R3,
     83     UNW_PPC32_R4,
     84     UNW_PPC32_R5,
     85     UNW_PPC32_R6,
     86     UNW_PPC32_R7,
     87     UNW_PPC32_R8,
     88     UNW_PPC32_R9,
     89     UNW_PPC32_R10,
     90     UNW_PPC32_R11, /* called STATIC_CHAIN in gcc */
     91     UNW_PPC32_R12,
     92     UNW_PPC32_R13,
     93     UNW_PPC32_R14,
     94     UNW_PPC32_R15,
     95     UNW_PPC32_R16,
     96     UNW_PPC32_R17,
     97     UNW_PPC32_R18,
     98     UNW_PPC32_R19,
     99     UNW_PPC32_R20,
    100     UNW_PPC32_R21,
    101     UNW_PPC32_R22,
    102     UNW_PPC32_R23,
    103     UNW_PPC32_R24,
    104     UNW_PPC32_R25,
    105     UNW_PPC32_R26,
    106     UNW_PPC32_R27,
    107     UNW_PPC32_R28,
    108     UNW_PPC32_R29,
    109     UNW_PPC32_R30,
    110     UNW_PPC32_R31, /* called HARD_FRAME_POINTER in gcc */
    111 
    112     /* Count Register */
    113     UNW_PPC32_CTR = 32,
    114     /* Fixed-Point Status and Control Register */
    115     UNW_PPC32_XER = 33,
    116     /* Condition Register */
    117     UNW_PPC32_CCR = 34,
    118     /* Machine State Register */
    119     //UNW_PPC32_MSR = 35,
    120     /* MQ or SPR0, not part of generic Power, part of MPC601 */
    121     //UNW_PPC32_MQ = 36,
    122     /* Link Register */
    123     UNW_PPC32_LR = 36,
    124     /* Floating Pointer Status and Control Register */
    125     UNW_PPC32_FPSCR = 37,
    126 
    127     UNW_PPC32_F0 = 48,
    128     UNW_PPC32_F1,
    129     UNW_PPC32_F2,
    130     UNW_PPC32_F3,
    131     UNW_PPC32_F4,
    132     UNW_PPC32_F5,
    133     UNW_PPC32_F6,
    134     UNW_PPC32_F7,
    135     UNW_PPC32_F8,
    136     UNW_PPC32_F9,
    137     UNW_PPC32_F10,
    138     UNW_PPC32_F11,
    139     UNW_PPC32_F12,
    140     UNW_PPC32_F13,
    141     UNW_PPC32_F14,
    142     UNW_PPC32_F15,
    143     UNW_PPC32_F16,
    144     UNW_PPC32_F17,
    145     UNW_PPC32_F18,
    146     UNW_PPC32_F19,
    147     UNW_PPC32_F20,
    148     UNW_PPC32_F21,
    149     UNW_PPC32_F22,
    150     UNW_PPC32_F23,
    151     UNW_PPC32_F24,
    152     UNW_PPC32_F25,
    153     UNW_PPC32_F26,
    154     UNW_PPC32_F27,
    155     UNW_PPC32_F28,
    156     UNW_PPC32_F29,
    157     UNW_PPC32_F30,
    158     UNW_PPC32_F31,
    159 
    160     UNW_TDEP_LAST_REG = UNW_PPC32_F31,
    161 
    162     UNW_TDEP_IP = UNW_PPC32_LR,
    163     UNW_TDEP_SP = UNW_PPC32_R1,
    164     UNW_TDEP_EH = UNW_PPC32_R12
    165   }
    166 ppc32_regnum_t;
    167 
    168 /*
    169  * According to David Edelsohn, GNU gcc uses R3, R4, R5, and maybe R6 for
    170  * passing parameters to exception handlers.
    171  */
    172 
    173 #define UNW_TDEP_NUM_EH_REGS	4
    174 
    175 typedef struct unw_tdep_save_loc
    176   {
    177     /* Additional target-dependent info on a save location.  */
    178     /* ANDROID support update. */
    179     char __reserved;
    180     /* End of ANDROID update. */
    181   }
    182 unw_tdep_save_loc_t;
    183 
    184 /* On ppc, we can directly use ucontext_t as the unwind context.  */
    185 typedef ucontext_t unw_tdep_context_t;
    186 
    187 /* XXX this is not ideal: an application should not be prevented from
    188    using the "getcontext" name just because it's using libunwind.  We
    189    can't just use __getcontext() either, because that isn't exported
    190    by glibc...  */
    191 #define unw_tdep_getcontext(uc)		(getcontext (uc), 0)
    192 
    193 #include "libunwind-dynamic.h"
    194 
    195 typedef struct
    196   {
    197     /* no ppc32-specific auxiliary proc-info */
    198     /* ANDROID support update. */
    199     char __reserved;
    200     /* End of ANDROID update. */
    201   }
    202 unw_tdep_proc_info_t;
    203 
    204 #include "libunwind-common.h"
    205 
    206 #define unw_tdep_is_fpreg		UNW_ARCH_OBJ(is_fpreg)
    207 extern int unw_tdep_is_fpreg (int);
    208 
    209 #if defined(__cplusplus) || defined(c_plusplus)
    210 }
    211 #endif
    212 
    213 #endif /* LIBUNWIND_H */
    214