test: basic c99 vla tests for C primitives
[platform/upstream/binutils.git] / gdb / arm-wince-tdep.c
1 /* Target-dependent code for Windows CE running on ARM processors,
2    for GDB.
3
4    Copyright (C) 2007-2014 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 #include "frame.h"
26
27 #include <string.h>
28
29 #include "arm-tdep.h"
30 #include "windows-tdep.h"
31
32 static const gdb_byte arm_wince_le_breakpoint[] = { 0x10, 0x00, 0x00, 0xe6 };
33 static const gdb_byte arm_wince_thumb_le_breakpoint[] = { 0xfe, 0xdf };
34
35 /* Description of the longjmp buffer.  */
36 #define ARM_WINCE_JB_ELEMENT_SIZE       INT_REGISTER_SIZE
37 #define ARM_WINCE_JB_PC                 10
38
39 static CORE_ADDR
40 arm_pe_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
41 {
42   struct gdbarch *gdbarch = get_frame_arch (frame);
43   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
44   ULONGEST indirect;
45   struct bound_minimal_symbol indsym;
46   const char *symname;
47   CORE_ADDR next_pc;
48
49   /* The format of an ARM DLL trampoline is:
50        ldr  ip, [pc]
51        ldr  pc, [ip]
52        .dw __imp_<func>  */
53
54   if (pc == 0
55       || read_memory_unsigned_integer (pc + 0, 4, byte_order) != 0xe59fc000
56       || read_memory_unsigned_integer (pc + 4, 4, byte_order) != 0xe59cf000)
57     return 0;
58
59   indirect = read_memory_unsigned_integer (pc + 8, 4, byte_order);
60   if (indirect == 0)
61     return 0;
62
63   indsym = lookup_minimal_symbol_by_pc (indirect);
64   if (indsym.minsym == NULL)
65     return 0;
66
67   symname = MSYMBOL_LINKAGE_NAME (indsym.minsym);
68   if (symname == NULL || strncmp (symname, "__imp_", 6) != 0)
69     return 0;
70
71   next_pc = read_memory_unsigned_integer (indirect, 4, byte_order);
72   if (next_pc != 0)
73     return next_pc;
74
75   /* Check with the default arm gdbarch_skip_trampoline.  */
76   return arm_skip_stub (frame, pc);
77 }
78
79 /* GCC emits a call to __gccmain in the prologue of main.
80
81    The function below examines the code pointed at by PC and checks to
82    see if it corresponds to a call to __gccmain.  If so, it returns
83    the address of the instruction following that call.  Otherwise, it
84    simply returns PC.  */
85
86 static CORE_ADDR
87 arm_wince_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
88 {
89   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
90   ULONGEST this_instr;
91
92   this_instr = read_memory_unsigned_integer (pc, 4, byte_order);
93
94   /* bl offset <__gccmain> */
95   if ((this_instr & 0xfff00000) == 0xeb000000)
96     {
97 #define sign_extend(V, N) \
98   (((long) (V) ^ (1L << ((N) - 1))) - (1L << ((N) - 1)))
99
100       long offset = sign_extend (this_instr & 0x000fffff, 23) << 2;
101       CORE_ADDR call_dest = (pc + 8 + offset) & 0xffffffffU;
102       struct bound_minimal_symbol s = lookup_minimal_symbol_by_pc (call_dest);
103
104       if (s.minsym != NULL
105           && MSYMBOL_LINKAGE_NAME (s.minsym) != NULL
106           && strcmp (MSYMBOL_LINKAGE_NAME (s.minsym), "__gccmain") == 0)
107         pc += 4;
108     }
109
110   return pc;
111 }
112
113 static void
114 arm_wince_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
115 {
116   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
117
118   windows_init_abi (info, gdbarch);
119
120   tdep->arm_breakpoint = arm_wince_le_breakpoint;
121   tdep->arm_breakpoint_size = sizeof (arm_wince_le_breakpoint);
122   tdep->thumb_breakpoint = arm_wince_thumb_le_breakpoint;
123   tdep->thumb_breakpoint_size = sizeof (arm_wince_thumb_le_breakpoint);
124   tdep->struct_return = pcc_struct_return;
125
126   tdep->fp_model = ARM_FLOAT_SOFT_VFP;
127
128   tdep->jb_pc = ARM_WINCE_JB_PC;
129   tdep->jb_elt_size = ARM_WINCE_JB_ELEMENT_SIZE;
130
131   /* On ARM WinCE char defaults to signed.  */
132   set_gdbarch_char_signed (gdbarch, 1);
133
134   /* Shared library handling.  */
135   set_gdbarch_skip_trampoline_code (gdbarch, arm_pe_skip_trampoline_code);
136
137   /* Single stepping.  */
138   set_gdbarch_software_single_step (gdbarch, arm_software_single_step);
139
140   /* Skip call to __gccmain that gcc places in main.  */
141   set_gdbarch_skip_main_prologue (gdbarch, arm_wince_skip_main_prologue);
142 }
143
144 static enum gdb_osabi
145 arm_wince_osabi_sniffer (bfd *abfd)
146 {
147   const char *target_name = bfd_get_target (abfd);
148
149   if (strcmp (target_name, "pei-arm-wince-little") == 0)
150     return GDB_OSABI_WINCE;
151
152   return GDB_OSABI_UNKNOWN;
153 }
154
155 /* Provide a prototype to silence -Wmissing-prototypes.  */
156 void _initialize_arm_wince_tdep (void);
157
158 void
159 _initialize_arm_wince_tdep (void)
160 {
161   gdbarch_register_osabi_sniffer (bfd_arch_arm, bfd_target_coff_flavour,
162                                   arm_wince_osabi_sniffer);
163
164   gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_WINCE,
165                           arm_wince_init_abi);
166 }