linux-unwind.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* DWARF2 EH unwinding support for Alpha Linux.
  2. Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #ifndef inhibit_libc
  20. /* Do code reading to identify a signal frame, and set the frame
  21. state data appropriately. See unwind-dw2.c for the structs. */
  22. #include <signal.h>
  23. #include <sys/ucontext.h>
  24. #define MD_FALLBACK_FRAME_STATE_FOR alpha_fallback_frame_state
  25. static _Unwind_Reason_Code
  26. alpha_fallback_frame_state (struct _Unwind_Context *context,
  27. _Unwind_FrameState *fs)
  28. {
  29. unsigned int *pc = context->ra;
  30. struct sigcontext *sc;
  31. long new_cfa;
  32. int i;
  33. if (pc[0] != 0x47fe0410 /* mov $30,$16 */
  34. || pc[2] != 0x00000083) /* callsys */
  35. return _URC_END_OF_STACK;
  36. if (context->cfa == 0)
  37. return _URC_END_OF_STACK;
  38. if (pc[1] == 0x201f0067) /* lda $0,NR_sigreturn */
  39. sc = context->cfa;
  40. else if (pc[1] == 0x201f015f) /* lda $0,NR_rt_sigreturn */
  41. {
  42. struct rt_sigframe {
  43. siginfo_t info;
  44. ucontext_t uc;
  45. } *rt_ = context->cfa;
  46. /* The void * cast is necessary to avoid an aliasing warning.
  47. The aliasing warning is correct, but should not be a problem
  48. because it does not alias anything. */
  49. sc = (struct sigcontext *) (void *) &rt_->uc.uc_mcontext;
  50. }
  51. else
  52. return _URC_END_OF_STACK;
  53. new_cfa = sc->sc_regs[30];
  54. fs->regs.cfa_how = CFA_REG_OFFSET;
  55. fs->regs.cfa_reg = 30;
  56. fs->regs.cfa_offset = new_cfa - (long) context->cfa;
  57. for (i = 0; i < 30; ++i)
  58. {
  59. fs->regs.reg[i].how = REG_SAVED_OFFSET;
  60. fs->regs.reg[i].loc.offset
  61. = (long) &sc->sc_regs[i] - new_cfa;
  62. }
  63. for (i = 0; i < 31; ++i)
  64. {
  65. fs->regs.reg[i+32].how = REG_SAVED_OFFSET;
  66. fs->regs.reg[i+32].loc.offset
  67. = (long) &sc->sc_fpregs[i] - new_cfa;
  68. }
  69. fs->regs.reg[64].how = REG_SAVED_OFFSET;
  70. fs->regs.reg[64].loc.offset = (long)&sc->sc_pc - new_cfa;
  71. fs->retaddr_column = 64;
  72. fs->signal_frame = 1;
  73. return _URC_NO_REASON;
  74. }
  75. #define MD_FROB_UPDATE_CONTEXT alpha_frob_update_context
  76. /* Fix up for signal handlers that don't have S flag set. */
  77. static void
  78. alpha_frob_update_context (struct _Unwind_Context *context,
  79. _Unwind_FrameState *fs ATTRIBUTE_UNUSED)
  80. {
  81. unsigned int *pc = context->ra;
  82. if (pc[0] == 0x47fe0410 /* mov $30,$16 */
  83. && pc[2] == 0x00000083 /* callsys */
  84. && (pc[1] == 0x201f0067 /* lda $0,NR_sigreturn */
  85. || pc[1] == 0x201f015f)) /* lda $0,NR_rt_sigreturn */
  86. _Unwind_SetSignalFrame (context, 1);
  87. }
  88. #endif