Copyright updates for 2007.
[platform/upstream/binutils.git] / gdb / i386nbsd-nat.c
1 /* Native-dependent code for NetBSD/i386.
2
3    Copyright (C) 2004, 2005, 2007 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., 51 Franklin Street, Fifth Floor,
20    Boston, MA 02110-1301, USA.  */
21
22 #include "defs.h"
23 #include "gdbcore.h"
24 #include "regcache.h"
25 #include "target.h"
26
27 #include "i386-tdep.h"
28 #include "i386bsd-nat.h"
29
30 /* Support for debugging kernel virtual memory images.  */
31
32 #include <sys/types.h>
33 #include <machine/frame.h>
34 #include <machine/pcb.h>
35
36 #include "nbsd-nat.h"
37 #include "bsd-kvm.h"
38
39 static int
40 i386nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
41 {
42   struct switchframe sf;
43
44   /* The following is true for NetBSD 1.6.2:
45
46      The pcb contains %esp and %ebp at the point of the context switch
47      in cpu_switch().  At that point we have a stack frame as
48      described by `struct switchframe', which for NetBSD 1.6.2 has the
49      following layout:
50
51      interrupt level
52      %edi
53      %esi
54      %ebx
55      %eip
56
57      we reconstruct the register state as it would look when we just
58      returned from cpu_switch().  */
59
60   /* The stack pointer shouldn't be zero.  */
61   if (pcb->pcb_esp == 0)
62     return 0;
63
64   read_memory (pcb->pcb_esp, (gdb_byte *)&sf, sizeof sf);
65   pcb->pcb_esp += sizeof (struct switchframe);
66   regcache_raw_supply (regcache, I386_EDI_REGNUM, &sf.sf_edi);
67   regcache_raw_supply (regcache, I386_ESI_REGNUM, &sf.sf_esi);
68   regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp);
69   regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp);
70   regcache_raw_supply (regcache, I386_EBX_REGNUM, &sf.sf_ebx);
71   regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip);
72
73   return 1;
74 }
75 \f
76
77 /* Provide a prototype to silence -Wmissing-prototypes.  */
78 void _initialize_i386nbsd_nat (void);
79
80 void
81 _initialize_i386nbsd_nat (void)
82 {
83   struct target_ops *t;
84
85   /* Add some extra features to the common *BSD/i386 target.  */
86   t = i386bsd_target ();
87   t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
88   add_target (t);
89  
90   /* Support debugging kernel virtual memory images.  */
91   bsd_kvm_add_target (i386nbsd_supply_pcb);
92 }