Share fork_inferior et al with gdbserver
[external/binutils.git] / gdb / gdbserver / nto-x86-low.c
1 /* QNX Neutrino specific low level interface, for the remote server
2    for GDB.
3    Copyright (C) 2009-2017 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 3 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, see <http://www.gnu.org/licenses/>.  */
19
20 #include "server.h"
21 #include "nto-low.h"
22 #include "regdef.h"
23 #include "regcache.h"
24
25 #include <x86/context.h>
26
27
28 /* Defined in auto-generated build-time file gdb/gdbserver/i386.c.  */
29 extern void init_registers_i386 ();
30 extern struct reg *regs_i386;
31 extern const struct target_desc *tdesc_i386;
32
33 const unsigned char x86_breakpoint[] = { 0xCC };
34 #define x86_breakpoint_len 1
35
36 /* Returns offset in appropriate Neutrino's context structure.
37    Defined in x86/context.h.
38    GDBREGNO is index into regs_i386 array.  It is autogenerated and
39    hopefully doesn't change.  */
40 static int
41 nto_x86_register_offset (int gdbregno)
42 {
43   if (gdbregno >= 0 && gdbregno < 16)
44     {
45       X86_CPU_REGISTERS *dummy = (void*)0;
46       /* GPRs  */
47       switch (gdbregno)
48         {
49         case 0: 
50           return (int)&(dummy->eax);
51         case 1:
52           return (int)&(dummy->ecx);
53         case 2:
54           return (int)&(dummy->edx);
55         case 3:
56           return (int)&(dummy->ebx);
57         case 4:
58           return (int)&(dummy->esp);
59         case 5:
60           return (int)&(dummy->ebp);
61         case 6:
62           return (int)&(dummy->esi);
63         case 7:
64           return (int)&(dummy->edi);
65         case 8:
66           return (int)&(dummy->eip);
67         case 9:
68           return (int)&(dummy->efl);
69         case 10:
70           return (int)&(dummy->cs);
71         case 11:
72           return (int)&(dummy->ss);
73 #ifdef __SEGMENTS__
74         case 12:
75           return (int)&(dummy->ds);
76         case 13:
77           return (int)&(dummy->es);
78         case 14:
79           return (int)&(dummy->fs);
80         case 15:
81           return (int)&(dummy->gs);
82 #endif
83         default:
84           return -1;
85         }
86     }
87   return -1;
88 }
89
90 static void
91 nto_x86_arch_setup (void)
92 {
93   init_registers_i386 ();
94   the_low_target.num_regs = 16;
95   nto_tdesc = tdesc_i386;
96 }
97
98 struct nto_target_ops the_low_target =
99 {
100   nto_x86_arch_setup,
101   0, /* num_regs */
102   nto_x86_register_offset,
103   x86_breakpoint,
104   x86_breakpoint_len
105 };
106
107
108