Commit | Line | Data |
---|---|---|
911bc6ee | 1 | /* Target-dependent code for QNX Neutrino x86. |
1b883d35 | 2 | |
911bc6ee | 3 | Copyright 2003, 2004 Free Software Foundation, Inc. |
1b883d35 KW |
4 | |
5 | Contributed by QNX Software Systems Ltd. | |
6 | ||
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program; if not, write to the Free Software | |
21 | Foundation, Inc., 59 Temple Place - Suite 330, | |
22 | Boston, MA 02111-1307, USA. */ | |
23 | ||
1b883d35 KW |
24 | #include "defs.h" |
25 | #include "frame.h" | |
17ca283a | 26 | #include "osabi.h" |
1b883d35 | 27 | #include "regcache.h" |
17ca283a MK |
28 | #include "target.h" |
29 | ||
30 | #include "gdb_assert.h" | |
31 | #include "gdb_string.h" | |
32 | ||
1b883d35 | 33 | #include "i386-tdep.h" |
1b883d35 | 34 | #include "i387-tdep.h" |
17ca283a MK |
35 | #include "nto-tdep.h" |
36 | #include "solib-svr4.h" | |
1b883d35 KW |
37 | |
38 | #ifndef X86_CPU_FXSR | |
39 | #define X86_CPU_FXSR (1L << 12) | |
40 | #endif | |
41 | ||
42 | /* Why 13? Look in our /usr/include/x86/context.h header at the | |
43 | x86_cpu_registers structure and you'll see an 'exx' junk register | |
44 | that is just filler. Don't ask me, ask the kernel guys. */ | |
45 | #define NUM_GPREGS 13 | |
46 | ||
47 | /* Map a GDB register number to an offset in the reg structure. */ | |
48 | static int regmap[] = { | |
49 | (7 * 4), /* eax */ | |
50 | (6 * 4), /* ecx */ | |
51 | (5 * 4), /* edx */ | |
52 | (4 * 4), /* ebx */ | |
53 | (11 * 4), /* esp */ | |
54 | (2 * 4), /* epb */ | |
55 | (1 * 4), /* esi */ | |
56 | (0 * 4), /* edi */ | |
57 | (8 * 4), /* eip */ | |
58 | (10 * 4), /* eflags */ | |
59 | (9 * 4), /* cs */ | |
60 | (12 * 4), /* ss */ | |
61 | (-1 * 4) /* filler */ | |
62 | }; | |
63 | ||
d737fd7f KW |
64 | static struct nto_target_ops i386_nto_target; |
65 | ||
1b883d35 KW |
66 | /* Given a gdb regno, return the offset into Neutrino's register structure |
67 | or -1 if register is unknown. */ | |
68 | static int | |
69 | nto_reg_offset (int regno) | |
70 | { | |
71 | return (regno >= 0 && regno < NUM_GPREGS) ? regmap[regno] : -1; | |
72 | } | |
73 | ||
74 | static void | |
75 | i386nto_supply_gregset (char *gpregs) | |
76 | { | |
77 | unsigned regno; | |
78 | int empty = 0; | |
79 | ||
f6792ef4 | 80 | for (regno = 0; regno < I386_NUM_GREGS; regno++) |
1b883d35 KW |
81 | { |
82 | int offset = nto_reg_offset (regno); | |
83 | if (offset == -1) | |
23a6d369 | 84 | regcache_raw_supply (current_regcache, regno, (char *) &empty); |
1b883d35 | 85 | else |
23a6d369 | 86 | regcache_raw_supply (current_regcache, regno, gpregs + offset); |
1b883d35 KW |
87 | } |
88 | } | |
89 | ||
90 | static void | |
91 | i386nto_supply_fpregset (char *fpregs) | |
92 | { | |
93 | if (nto_cpuinfo_valid && nto_cpuinfo_flags | X86_CPU_FXSR) | |
41d041d6 | 94 | i387_supply_fxsave (current_regcache, -1, fpregs); |
1b883d35 | 95 | else |
41d041d6 | 96 | i387_supply_fsave (current_regcache, -1, fpregs); |
1b883d35 KW |
97 | } |
98 | ||
99 | static void | |
100 | i386nto_supply_regset (int regset, char *data) | |
101 | { | |
102 | switch (regset) | |
103 | { | |
104 | case NTO_REG_GENERAL: /* QNX has different ordering of GP regs than GDB. */ | |
105 | i386nto_supply_gregset (data); | |
106 | break; | |
107 | case NTO_REG_FLOAT: | |
108 | i386nto_supply_fpregset (data); | |
109 | break; | |
110 | } | |
111 | } | |
112 | ||
113 | static int | |
114 | i386nto_regset_id (int regno) | |
115 | { | |
116 | if (regno == -1) | |
117 | return NTO_REG_END; | |
f6792ef4 | 118 | else if (regno < I386_NUM_GREGS) |
1b883d35 | 119 | return NTO_REG_GENERAL; |
f6792ef4 | 120 | else if (regno < I386_NUM_GREGS + I386_NUM_FREGS) |
1b883d35 KW |
121 | return NTO_REG_FLOAT; |
122 | ||
123 | return -1; /* Error. */ | |
124 | } | |
125 | ||
126 | static int | |
127 | i386nto_register_area (int regno, int regset, unsigned *off) | |
128 | { | |
129 | int len; | |
130 | ||
131 | *off = 0; | |
132 | if (regset == NTO_REG_GENERAL) | |
133 | { | |
134 | if (regno == -1) | |
135 | return NUM_GPREGS * 4; | |
136 | ||
137 | *off = nto_reg_offset (regno); | |
138 | if (*off == -1) | |
139 | return 0; | |
140 | return 4; | |
141 | } | |
142 | else if (regset == NTO_REG_FLOAT) | |
143 | { | |
144 | unsigned off_adjust, regsize, regset_size; | |
145 | ||
146 | if (nto_cpuinfo_valid && nto_cpuinfo_flags | X86_CPU_FXSR) | |
147 | { | |
148 | off_adjust = 32; | |
149 | regsize = 16; | |
150 | regset_size = 512; | |
151 | } | |
152 | else | |
153 | { | |
154 | off_adjust = 28; | |
155 | regsize = 10; | |
156 | regset_size = 128; | |
157 | } | |
158 | ||
159 | if (regno == -1) | |
160 | return regset_size; | |
161 | ||
162 | *off = (regno - FP0_REGNUM) * regsize + off_adjust; | |
163 | return 10; | |
164 | /* Why 10 instead of regsize? GDB only stores 10 bytes per FP | |
165 | register so if we're sending a register back to the target, | |
166 | we only want pdebug to write 10 bytes so as not to clobber | |
167 | the reserved 6 bytes in the fxsave structure. */ | |
168 | } | |
169 | return -1; | |
170 | } | |
171 | ||
172 | static int | |
173 | i386nto_regset_fill (int regset, char *data) | |
174 | { | |
175 | if (regset == NTO_REG_GENERAL) | |
176 | { | |
177 | int regno; | |
178 | ||
179 | for (regno = 0; regno < NUM_GPREGS; regno++) | |
180 | { | |
181 | int offset = nto_reg_offset (regno); | |
182 | if (offset != -1) | |
822c9732 | 183 | regcache_raw_collect (current_regcache, regno, data + offset); |
1b883d35 KW |
184 | } |
185 | } | |
186 | else if (regset == NTO_REG_FLOAT) | |
187 | { | |
188 | if (nto_cpuinfo_valid && nto_cpuinfo_flags | X86_CPU_FXSR) | |
189 | i387_fill_fxsave (data, -1); | |
190 | else | |
191 | i387_fill_fsave (data, -1); | |
192 | } | |
193 | else | |
194 | return -1; | |
195 | ||
196 | return 0; | |
197 | } | |
198 | ||
911bc6ee MK |
199 | /* Return whether the frame preceding NEXT_FRAME corresponds to a QNX |
200 | Neutrino sigtramp routine. */ | |
201 | ||
1b883d35 | 202 | static int |
911bc6ee | 203 | i386nto_sigtramp_p (struct frame_info *next_frame) |
1b883d35 | 204 | { |
911bc6ee MK |
205 | CORE_ADDR pc = frame_pc_unwind (next_frame); |
206 | char *name; | |
207 | ||
208 | find_pc_partial_function (pc, &name, NULL, NULL); | |
1b883d35 KW |
209 | return name && strcmp ("__signalstub", name) == 0; |
210 | } | |
211 | ||
acd5c798 MK |
212 | #define I386_NTO_SIGCONTEXT_OFFSET 136 |
213 | ||
214 | /* Assuming NEXT_FRAME is a frame following a QNX Neutrino sigtramp | |
215 | routine, return the address of the associated sigcontext structure. */ | |
216 | ||
1b883d35 | 217 | static CORE_ADDR |
acd5c798 | 218 | i386nto_sigcontext_addr (struct frame_info *next_frame) |
1b883d35 | 219 | { |
acd5c798 | 220 | char buf[4]; |
89929b45 | 221 | CORE_ADDR sp; |
acd5c798 | 222 | |
911bc6ee | 223 | frame_unwind_register (next_frame, I386_ESP_REGNUM, buf); |
acd5c798 | 224 | sp = extract_unsigned_integer (buf, 4); |
1b883d35 | 225 | |
acd5c798 | 226 | return sp + I386_NTO_SIGCONTEXT_OFFSET; |
1b883d35 KW |
227 | } |
228 | ||
229 | static void | |
47979a4b | 230 | init_i386nto_ops (void) |
1b883d35 | 231 | { |
d737fd7f KW |
232 | i386_nto_target.regset_id = i386nto_regset_id; |
233 | i386_nto_target.supply_gregset = i386nto_supply_gregset; | |
234 | i386_nto_target.supply_fpregset = i386nto_supply_fpregset; | |
235 | i386_nto_target.supply_altregset = nto_dummy_supply_regset; | |
236 | i386_nto_target.supply_regset = i386nto_supply_regset; | |
237 | i386_nto_target.register_area = i386nto_register_area; | |
238 | i386_nto_target.regset_fill = i386nto_regset_fill; | |
239 | i386_nto_target.fetch_link_map_offsets = | |
17ca283a | 240 | svr4_ilp32_fetch_link_map_offsets; |
1b883d35 KW |
241 | } |
242 | ||
243 | static void | |
244 | i386nto_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
245 | { | |
246 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
247 | ||
d737fd7f KW |
248 | /* Deal with our strange signals. */ |
249 | nto_initialize_signals (); | |
250 | ||
1b883d35 KW |
251 | /* NTO uses ELF. */ |
252 | i386_elf_init_abi (info, gdbarch); | |
253 | ||
71bd6bd4 | 254 | /* Neutrino rewinds to look more normal. Need to override the i386 |
d3efc286 | 255 | default which is [unfortunately] to decrement the PC. */ |
1b883d35 KW |
256 | set_gdbarch_decr_pc_after_break (gdbarch, 0); |
257 | ||
258 | /* NTO has shared libraries. */ | |
1b883d35 KW |
259 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); |
260 | ||
911bc6ee | 261 | tdep->sigtramp_p = i386nto_sigtramp_p; |
1b883d35 KW |
262 | tdep->sigcontext_addr = i386nto_sigcontext_addr; |
263 | tdep->sc_pc_offset = 56; | |
264 | tdep->sc_sp_offset = 68; | |
265 | ||
266 | /* Setjmp()'s return PC saved in EDX (5). */ | |
267 | tdep->jb_pc_offset = 20; /* 5x32 bit ints in. */ | |
268 | ||
17ca283a MK |
269 | set_solib_svr4_fetch_link_map_offsets |
270 | (gdbarch, svr4_ilp32_fetch_link_map_offsets); | |
1b883d35 KW |
271 | |
272 | /* Our loader handles solib relocations slightly differently than svr4. */ | |
273 | TARGET_SO_RELOCATE_SECTION_ADDRESSES = nto_relocate_section_addresses; | |
274 | ||
275 | /* Supply a nice function to find our solibs. */ | |
276 | TARGET_SO_FIND_AND_OPEN_SOLIB = nto_find_and_open_solib; | |
277 | ||
d737fd7f KW |
278 | /* Our linker code is in libc. */ |
279 | TARGET_SO_IN_DYNSYM_RESOLVE_CODE = nto_in_dynsym_resolve_code; | |
280 | ||
281 | nto_set_target (&i386_nto_target); | |
1b883d35 KW |
282 | } |
283 | ||
284 | void | |
285 | _initialize_i386nto_tdep (void) | |
286 | { | |
d737fd7f | 287 | init_i386nto_ops (); |
1b883d35 KW |
288 | gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_QNXNTO, |
289 | i386nto_init_abi); | |
d737fd7f KW |
290 | gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour, |
291 | nto_elf_osabi_sniffer); | |
1b883d35 | 292 | } |