Commit | Line | Data |
---|---|---|
005328e3 | 1 | /* Target-dependent code for OpenBSD/i386. |
4be87837 | 2 | Copyright 1988, 1989, 1991, 1992, 1994, 1996, 2000, 2001, 2002, 2003 |
005328e3 MK |
3 | Free Software Foundation, Inc. |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "defs.h" | |
23 | #include "arch-utils.h" | |
24 | #include "gdbcore.h" | |
25 | #include "regcache.h" | |
4be87837 | 26 | #include "osabi.h" |
005328e3 MK |
27 | |
28 | #include "i386-tdep.h" | |
29 | #include "i387-tdep.h" | |
30 | ||
31 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
32 | void _initialize_i386obsd_tdep (void); | |
33 | ||
34 | #define SIZEOF_STRUCT_REG (16 * 4) | |
35 | ||
36 | static void | |
37 | i386obsd_supply_reg (char *regs, int regno) | |
38 | { | |
39 | int i; | |
40 | ||
41 | for (i = 0; i <= 15; i++) | |
42 | if (regno == i || regno == -1) | |
43 | supply_register (i, regs + i * 4); | |
44 | } | |
45 | ||
46 | static void | |
47 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, int which, | |
48 | CORE_ADDR ignore) | |
49 | { | |
50 | char *regs, *fsave; | |
51 | ||
52 | /* We get everything from one section. */ | |
53 | if (which != 0) | |
54 | return; | |
55 | ||
56 | if (core_reg_size < (SIZEOF_STRUCT_REG + 108)) | |
57 | { | |
58 | warning ("Wrong size register set in core file."); | |
59 | return; | |
60 | } | |
61 | ||
62 | regs = core_reg_sect; | |
63 | fsave = core_reg_sect + SIZEOF_STRUCT_REG; | |
64 | ||
65 | /* Integer registers. */ | |
66 | i386obsd_supply_reg (regs, -1); | |
67 | ||
68 | /* Floating point registers. */ | |
41d041d6 | 69 | i387_supply_fsave (current_regcache, -1, fsave); |
005328e3 MK |
70 | } |
71 | ||
72 | static struct core_fns i386obsd_core_fns = | |
73 | { | |
74 | bfd_target_unknown_flavour, /* core_flavour */ | |
75 | default_check_format, /* check_format */ | |
76 | default_core_sniffer, /* core_sniffer */ | |
77 | fetch_core_registers, /* core_read_registers */ | |
78 | NULL /* next */ | |
79 | }; | |
80 | \f | |
81 | ||
82 | CORE_ADDR i386obsd_sigtramp_start = 0xbfbfdf20; | |
83 | CORE_ADDR i386obsd_sigtramp_end = 0xbfbfdff0; | |
84 | ||
85 | /* From <machine/signal.h>. */ | |
a3386186 MK |
86 | int i386obsd_sc_reg_offset[I386_NUM_GREGS] = |
87 | { | |
88 | 10 * 4, /* %eax */ | |
89 | 9 * 4, /* %ecx */ | |
90 | 8 * 4, /* %edx */ | |
91 | 7 * 4, /* %ebx */ | |
92 | 14 * 4, /* %esp */ | |
93 | 6 * 4, /* %ebp */ | |
94 | 5 * 4, /* %esi */ | |
95 | 4 * 4, /* %edi */ | |
96 | 11 * 4, /* %eip */ | |
97 | 13 * 4, /* %eflags */ | |
98 | 12 * 4, /* %cs */ | |
99 | 15 * 4, /* %ss */ | |
100 | 3 * 4, /* %ds */ | |
101 | 2 * 4, /* %es */ | |
102 | 1 * 4, /* %fs */ | |
103 | 0 * 4 /* %gs */ | |
104 | }; | |
005328e3 MK |
105 | |
106 | static void | |
107 | i386obsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
108 | { | |
109 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
110 | ||
111 | /* Obviously OpenBSD is BSD-based. */ | |
112 | i386bsd_init_abi (info, gdbarch); | |
113 | ||
114 | /* OpenBSD uses -freg-struct-return by default. */ | |
115 | tdep->struct_return = reg_struct_return; | |
116 | ||
117 | /* OpenBSD uses a different memory layout. */ | |
118 | tdep->sigtramp_start = i386obsd_sigtramp_start; | |
119 | tdep->sigtramp_end = i386obsd_sigtramp_end; | |
120 | ||
121 | /* OpenBSD has a `struct sigcontext' that's different from the | |
122 | origional 4.3 BSD. */ | |
a3386186 MK |
123 | tdep->sc_reg_offset = i386obsd_sc_reg_offset; |
124 | tdep->sc_num_regs = I386_NUM_GREGS; | |
005328e3 MK |
125 | } |
126 | ||
127 | void | |
128 | _initialize_i386obsd_tdep (void) | |
129 | { | |
130 | add_core_fns (&i386obsd_core_fns); | |
131 | ||
132 | /* FIXME: kettenis/20021020: Since OpenBSD/i386 binaries are | |
133 | indistingushable from NetBSD/i386 a.out binaries, building a GDB | |
134 | that should support both these targets will probably not work as | |
135 | expected. */ | |
136 | #define GDB_OSABI_OPENBSD_AOUT GDB_OSABI_NETBSD_AOUT | |
137 | ||
05816f70 | 138 | gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_OPENBSD_AOUT, |
005328e3 MK |
139 | i386obsd_init_abi); |
140 | } |