ia64.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
  2. 2000 Free Software Foundation, Inc.
  3. This file is part of GNU CC.
  4. GNU CC 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 2, or (at your option)
  7. any later version.
  8. GNU CC 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. You should have received a copy of the GNU General Public License
  13. along with GNU CC; see the file COPYING. If not, write to
  14. the Free Software Foundation, 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. /* As a special exception, if you link this library with other files,
  17. some of which are compiled with GCC, to produce an executable,
  18. this library does not by itself cause the resulting executable
  19. to be covered by the GNU General Public License.
  20. This exception does not however invalidate any other reasons why
  21. the executable file might be covered by the GNU General Public License. */
  22. #include <stddef.h>
  23. #include <memory.h>
  24. #define IA64_UNWIND_INFO
  25. #include "ia64-frame.h"
  26. static int
  27. ia64_backtrace_helper (void **array, void *throw_pc,
  28. ia64_frame_state *throw_frame,
  29. ia64_frame_state *frame, void *bsp, int size)
  30. {
  31. void *pc = NULL;
  32. int frame_count = 0;
  33. unwind_info_ptr *info;
  34. asm volatile ("flushrs"); /* Make the local register stacks available. */
  35. /* Start at our stack frame, get our state. */
  36. info = build_ia64_frame_state (throw_pc, throw_frame, bsp, NULL);
  37. memcpy (frame, throw_frame, sizeof (*frame));
  38. while (info && frame_count < size)
  39. {
  40. pc = array[frame_count++] = get_real_reg_value (&frame->rp);
  41. --pc;
  42. bsp = calc_caller_bsp
  43. ((long)get_real_reg_value (&frame->pfs), frame->my_bsp);
  44. info = build_ia64_frame_state (pc, frame, bsp, NULL);
  45. if (frame->rp.loc_type == IA64_UNW_LOC_TYPE_NONE) /* We've finished. */
  46. break;
  47. }
  48. return frame_count;
  49. }
  50. int
  51. _Jv_ia64_backtrace (void **array, int size)
  52. {
  53. ia64_frame_state my_frame;
  54. ia64_frame_state originator; /* For the context handler is in. */
  55. void *bsp;
  56. /* Do any necessary initialization to access arbitrary stack frames.
  57. This forces gcc to save memory in our stack frame for saved
  58. registers. */
  59. __builtin_unwind_init ();
  60. label_ia64:
  61. bsp = __builtin_ia64_bsp ();
  62. return ia64_backtrace_helper (array, &&label_ia64, &my_frame,
  63. &originator, bsp, size);
  64. }