13842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz/* libunwind - a platform-independent unwind library
23842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz   Copyright (C) 2008 CodeSourcery
33842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
43842dac7333e42aa44531eda34ba55200b99ccf8Daniel JacobowitzThis file is part of libunwind.
53842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
63842dac7333e42aa44531eda34ba55200b99ccf8Daniel JacobowitzPermission is hereby granted, free of charge, to any person obtaining
73842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitza copy of this software and associated documentation files (the
83842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz"Software"), to deal in the Software without restriction, including
93842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzwithout limitation the rights to use, copy, modify, merge, publish,
103842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzdistribute, sublicense, and/or sell copies of the Software, and to
113842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzpermit persons to whom the Software is furnished to do so, subject to
123842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzthe following conditions:
133842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
143842dac7333e42aa44531eda34ba55200b99ccf8Daniel JacobowitzThe above copyright notice and this permission notice shall be
153842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzincluded in all copies or substantial portions of the Software.
163842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
173842dac7333e42aa44531eda34ba55200b99ccf8Daniel JacobowitzTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
183842dac7333e42aa44531eda34ba55200b99ccf8Daniel JacobowitzEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
193842dac7333e42aa44531eda34ba55200b99ccf8Daniel JacobowitzMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
203842dac7333e42aa44531eda34ba55200b99ccf8Daniel JacobowitzNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
213842dac7333e42aa44531eda34ba55200b99ccf8Daniel JacobowitzLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
223842dac7333e42aa44531eda34ba55200b99ccf8Daniel JacobowitzOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
233842dac7333e42aa44531eda34ba55200b99ccf8Daniel JacobowitzWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
243842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
253842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#ifndef LIBUNWIND_H
263842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#define LIBUNWIND_H
273842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
283842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#if defined(__cplusplus) || defined(c_plusplus)
293842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzextern "C" {
303842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#endif
313842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
323842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include <inttypes.h>
333842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include <ucontext.h>
343842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
353842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#ifdef mips
363842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz# undef mips
373842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#endif
383842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
393842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#define UNW_TARGET	mips
403842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#define UNW_TARGET_MIPS	1
413842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
423842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#define _U_TDEP_QP_TRUE	0	/* see libunwind-dynamic.h  */
433842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
443842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz/* This needs to be big enough to accommodate "struct cursor", while
453842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz   leaving some slack for future expansion.  Changing this value will
463842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz   require recompiling all users of this library.  Stack allocation is
473842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz   relatively cheap and unwind-state copying is relatively rare, so we
483842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz   want to err on making it rather too big than too small.  */
493842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
503842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz/* FIXME for MIPS. Too big?  What do other things use for similar tasks?  */
513842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#define UNW_TDEP_CURSOR_LEN	4096
523842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
533842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz/* The size of a "word" varies on MIPS.  This type is used for memory
543842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz   addresses and register values.  To allow a single library to support
553842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz   multiple ABIs, and to support N32 at all, we must use a 64-bit type
563842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz   even when addresses are only 32 bits.  */
573842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitztypedef uint64_t unw_word_t;
583842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitztypedef int32_t unw_sword_t;
593842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
603842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz/* FIXME: MIPS ABIs.  */
613842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitztypedef long double unw_tdep_fpreg_t;
623842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
633842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitztypedef enum
643842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz  {
653842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R0,
663842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R1,
673842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R2,
683842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R3,
693842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R4,
703842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R5,
713842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R6,
723842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R7,
733842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R8,
743842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R9,
753842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R10,
763842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R11,
773842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R12,
783842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R13,
793842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R14,
803842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R15,
813842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R16,
823842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R17,
833842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R18,
843842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R19,
853842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R20,
863842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R21,
873842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R22,
883842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R23,
893842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R24,
903842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R25,
913842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R26,
923842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R27,
933842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R28,
943842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R29,
953842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R30,
963842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_R31,
973842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
9879c2c254a74ca850aefe2c49b973dea1fa2934c2Tommi Rantala    UNW_MIPS_PC = 34,
9979c2c254a74ca850aefe2c49b973dea1fa2934c2Tommi Rantala
1003842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    /* FIXME: Other registers!  */
1013842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1023842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    /* For MIPS, the CFA is the value of SP (r29) at the call site in the
1033842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz       previous frame.  */
1043842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_CFA,
1053842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1063842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_TDEP_LAST_REG = UNW_MIPS_R31,
1073842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1083842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_TDEP_IP = UNW_MIPS_R31,
1093842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_TDEP_SP = UNW_MIPS_R29,
1103842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_TDEP_EH = UNW_MIPS_R0   /* FIXME.  */
1113842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz  }
1123842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzmips_regnum_t;
1133842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1143842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitztypedef enum
1153842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz  {
1163842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_ABI_O32,
1173842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_ABI_N32,
1183842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    UNW_MIPS_ABI_N64
1193842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz  }
1203842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzmips_abi_t;
1213842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1223842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#define UNW_TDEP_NUM_EH_REGS	2	/* FIXME for MIPS.  */
1233842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1243842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitztypedef struct unw_tdep_save_loc
1253842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz  {
1263842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    /* Additional target-dependent info on a save location.  */
1273842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz  }
1283842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzunw_tdep_save_loc_t;
1293842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1303842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz/* On x86, we can directly use ucontext_t as the unwind context.  FIXME for
1313842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz   MIPS.  */
1323842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitztypedef ucontext_t unw_tdep_context_t;
1333842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1343842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include "libunwind-dynamic.h"
1353842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1363842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitztypedef struct
1373842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz  {
1383842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz    /* no mips-specific auxiliary proc-info */
1393842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz  }
1403842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzunw_tdep_proc_info_t;
1413842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1423842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#include "libunwind-common.h"
1433842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1443842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz/* There is no getcontext() on MIPS.  Use a stub version which only saves GP
1453842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz   registers.  FIXME: Not ideal, may not be sufficient for all libunwind
1463842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz   use cases.  */
1473842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#define unw_tdep_getcontext UNW_ARCH_OBJ(getcontext)
1483842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzextern int unw_tdep_getcontext (ucontext_t *uc);
1493842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1503842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#define unw_tdep_is_fpreg		UNW_ARCH_OBJ(is_fpreg)
1513842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitzextern int unw_tdep_is_fpreg (int);
1523842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1533842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#if defined(__cplusplus) || defined(c_plusplus)
1543842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz}
1553842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#endif
1563842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz
1573842dac7333e42aa44531eda34ba55200b99ccf8Daniel Jacobowitz#endif /* LIBUNWIND_H */
158