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