aarch64.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Gprof -c option support for AArch64.
  2. Copyright 2013 Linaro Ltd.
  3. Based upon gprof/i386.c.
  4. Copyright (c) 1983, 1993, 2001
  5. The Regents of the University of California. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions
  8. are met:
  9. 1. Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. 2. Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in the
  13. documentation and/or other materials provided with the distribution.
  14. 3. Neither the name of the University nor the names of its contributors
  15. may be used to endorse or promote products derived from this software
  16. without specific prior written permission.
  17. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  18. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. SUCH DAMAGE. */
  28. #include "gprof.h"
  29. #include "search_list.h"
  30. #include "source.h"
  31. #include "symtab.h"
  32. #include "cg_arcs.h"
  33. #include "corefile.h"
  34. #include "hist.h"
  35. #define BRANCH_MASK 0x7c000000
  36. #define BRANCH_PATTERN 0x14000000
  37. void aarch64_find_call (Sym *, bfd_vma, bfd_vma);
  38. void
  39. aarch64_find_call (Sym *parent, bfd_vma p_lowpc, bfd_vma p_highpc)
  40. {
  41. bfd_vma pc, dest_pc, offset;
  42. unsigned int insn;
  43. Sym *child;
  44. DBG (CALLDEBUG, printf ("[find_call] %s: 0x%lx to 0x%lx\n",
  45. parent->name, (unsigned long) p_lowpc,
  46. (unsigned long) p_highpc));
  47. for (pc = p_lowpc; pc < p_highpc; pc += 4)
  48. {
  49. insn = bfd_get_32 (core_bfd, ((unsigned char *) core_text_space
  50. + pc - core_text_sect->vma));
  51. if ((insn & BRANCH_MASK) == BRANCH_PATTERN)
  52. {
  53. DBG (CALLDEBUG,
  54. printf ("[find_call] 0x%lx: bl", (unsigned long) pc));
  55. /* Regular pc relative addressing check that this is the
  56. address of a function. */
  57. offset = ((((bfd_vma) insn & 0x3ffffff) ^ 0x2000000) - 0x2000000) << 2;
  58. dest_pc = pc + offset;
  59. if (hist_check_address (dest_pc))
  60. {
  61. child = sym_lookup (&symtab, dest_pc);
  62. if (child)
  63. {
  64. DBG (CALLDEBUG,
  65. printf ("\tdest_pc=0x%lx, (name=%s, addr=0x%lx)\n",
  66. (unsigned long) dest_pc, child->name,
  67. (unsigned long) child->addr));
  68. if (child->addr == dest_pc)
  69. {
  70. /* a hit. */
  71. arc_add (parent, child, (unsigned long) 0);
  72. continue;
  73. }
  74. }
  75. }
  76. /* Something funny going on. */
  77. DBG (CALLDEBUG, printf ("\tbut it's a botch\n"));
  78. }
  79. }
  80. }