arm-wince-tdep.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* Target-dependent code for Windows CE running on ARM processors,
  2. for GDB.
  3. Copyright (C) 2007-2022 Free Software Foundation, Inc.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include "defs.h"
  16. #include "osabi.h"
  17. #include "gdbcore.h"
  18. #include "target.h"
  19. #include "frame.h"
  20. #include "arch/arm.h"
  21. #include "arm-tdep.h"
  22. #include "windows-tdep.h"
  23. static const gdb_byte arm_wince_le_breakpoint[] = { 0x10, 0x00, 0x00, 0xe6 };
  24. static const gdb_byte arm_wince_thumb_le_breakpoint[] = { 0xfe, 0xdf };
  25. /* Description of the longjmp buffer. */
  26. #define ARM_WINCE_JB_ELEMENT_SIZE ARM_INT_REGISTER_SIZE
  27. #define ARM_WINCE_JB_PC 10
  28. static CORE_ADDR
  29. arm_pe_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
  30. {
  31. struct gdbarch *gdbarch = get_frame_arch (frame);
  32. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  33. ULONGEST indirect;
  34. struct bound_minimal_symbol indsym;
  35. const char *symname;
  36. CORE_ADDR next_pc;
  37. /* The format of an ARM DLL trampoline is:
  38. ldr ip, [pc]
  39. ldr pc, [ip]
  40. .dw __imp_<func>
  41. */
  42. if (pc == 0
  43. || read_memory_unsigned_integer (pc + 0, 4, byte_order) != 0xe59fc000
  44. || read_memory_unsigned_integer (pc + 4, 4, byte_order) != 0xe59cf000)
  45. return 0;
  46. indirect = read_memory_unsigned_integer (pc + 8, 4, byte_order);
  47. if (indirect == 0)
  48. return 0;
  49. indsym = lookup_minimal_symbol_by_pc (indirect);
  50. if (indsym.minsym == NULL)
  51. return 0;
  52. symname = indsym.minsym->linkage_name ();
  53. if (symname == NULL || !startswith (symname, "__imp_"))
  54. return 0;
  55. next_pc = read_memory_unsigned_integer (indirect, 4, byte_order);
  56. if (next_pc != 0)
  57. return next_pc;
  58. /* Check with the default arm gdbarch_skip_trampoline. */
  59. return arm_skip_stub (frame, pc);
  60. }
  61. /* GCC emits a call to __gccmain in the prologue of main.
  62. The function below examines the code pointed at by PC and checks to
  63. see if it corresponds to a call to __gccmain. If so, it returns
  64. the address of the instruction following that call. Otherwise, it
  65. simply returns PC. */
  66. static CORE_ADDR
  67. arm_wince_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
  68. {
  69. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  70. ULONGEST this_instr;
  71. this_instr = read_memory_unsigned_integer (pc, 4, byte_order);
  72. /* bl offset <__gccmain> */
  73. if ((this_instr & 0xfff00000) == 0xeb000000)
  74. {
  75. #define sign_extend(V, N) \
  76. (((long) (V) ^ (1L << ((N) - 1))) - (1L << ((N) - 1)))
  77. long offset = sign_extend (this_instr & 0x000fffff, 23) << 2;
  78. CORE_ADDR call_dest = (pc + 8 + offset) & 0xffffffffU;
  79. struct bound_minimal_symbol s = lookup_minimal_symbol_by_pc (call_dest);
  80. if (s.minsym != NULL
  81. && s.minsym->linkage_name () != NULL
  82. && strcmp (s.minsym->linkage_name (), "__gccmain") == 0)
  83. pc += 4;
  84. }
  85. return pc;
  86. }
  87. static void
  88. arm_wince_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  89. {
  90. arm_gdbarch_tdep *tdep = (arm_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  91. windows_init_abi (info, gdbarch);
  92. tdep->arm_breakpoint = arm_wince_le_breakpoint;
  93. tdep->arm_breakpoint_size = sizeof (arm_wince_le_breakpoint);
  94. tdep->thumb_breakpoint = arm_wince_thumb_le_breakpoint;
  95. tdep->thumb_breakpoint_size = sizeof (arm_wince_thumb_le_breakpoint);
  96. tdep->struct_return = pcc_struct_return;
  97. tdep->fp_model = ARM_FLOAT_SOFT_VFP;
  98. tdep->jb_pc = ARM_WINCE_JB_PC;
  99. tdep->jb_elt_size = ARM_WINCE_JB_ELEMENT_SIZE;
  100. /* On ARM WinCE char defaults to signed. */
  101. set_gdbarch_char_signed (gdbarch, 1);
  102. /* Shared library handling. */
  103. set_gdbarch_skip_trampoline_code (gdbarch, arm_pe_skip_trampoline_code);
  104. /* Single stepping. */
  105. set_gdbarch_software_single_step (gdbarch, arm_software_single_step);
  106. /* Skip call to __gccmain that gcc places in main. */
  107. set_gdbarch_skip_main_prologue (gdbarch, arm_wince_skip_main_prologue);
  108. }
  109. static enum gdb_osabi
  110. arm_wince_osabi_sniffer (bfd *abfd)
  111. {
  112. const char *target_name = bfd_get_target (abfd);
  113. if (strcmp (target_name, "pei-arm-wince-little") == 0)
  114. return GDB_OSABI_WINCE;
  115. return GDB_OSABI_UNKNOWN;
  116. }
  117. void _initialize_arm_wince_tdep ();
  118. void
  119. _initialize_arm_wince_tdep ()
  120. {
  121. gdbarch_register_osabi_sniffer (bfd_arch_arm, bfd_target_coff_flavour,
  122. arm_wince_osabi_sniffer);
  123. gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_WINCE,
  124. arm_wince_init_abi);
  125. }