freebsd-unwind.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* DWARF2 EH unwinding support for PowerPC64 FreeBSD.
  2. Copyright (C) 2012-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  11. 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. #define R_LR 65
  20. #define MD_FROB_UPDATE_CONTEXT frob_update_context
  21. static void
  22. frob_update_context (struct _Unwind_Context *context,
  23. _Unwind_FrameState *fs ATTRIBUTE_UNUSED)
  24. {
  25. const unsigned int *pc = (const unsigned int *) context->ra;
  26. #ifdef __powerpc64__
  27. if (fs->regs.reg[2].how == REG_UNSAVED)
  28. {
  29. /* If the current unwind info (FS) does not contain explicit info
  30. saving R2, then we have to do a minor amount of code reading to
  31. figure out if it was saved. The big problem here is that the
  32. code that does the save/restore is generated by the linker, so
  33. we have no good way to determine at compile time what to do. */
  34. if (pc[0] == 0xF8410028
  35. || ((pc[0] & 0xFFFF0000) == 0x3D820000
  36. && pc[1] == 0xF8410028))
  37. {
  38. /* We are in a plt call stub or r2 adjusting long branch stub,
  39. before r2 has been saved. Keep REG_UNSAVED. */
  40. }
  41. else
  42. {
  43. unsigned int *insn
  44. = (unsigned int *) _Unwind_GetGR (context, R_LR);
  45. if (insn && *insn == 0xE8410028)
  46. _Unwind_SetGRPtr (context, 2, context->cfa + 40);
  47. else if (pc[0] == 0x4E800421
  48. && pc[1] == 0xE8410028)
  49. {
  50. /* We are at the bctrl instruction in a call via function
  51. pointer. gcc always emits the load of the new R2 just
  52. before the bctrl so this is the first and only place
  53. we need to use the stored R2. */
  54. _Unwind_Word sp = _Unwind_GetGR (context, 1);
  55. _Unwind_SetGRPtr (context, 2, (void *)(sp + 40));
  56. }
  57. }
  58. }
  59. #endif
  60. }