Rename gdb/ChangeLog to gdb/ChangeLog-2021
[binutils-gdb.git] / gdb / i386-netbsd-nat.c
blobee3abb43394478d0bad6cf6503c8c24fda093f7a
1 /* Native-dependent code for NetBSD/i386.
3 Copyright (C) 2004-2021 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "defs.h"
21 #include "gdbcore.h"
22 #include "regcache.h"
23 #include "target.h"
25 #include "i386-tdep.h"
26 #include "i386-bsd-nat.h"
28 /* Support for debugging kernel virtual memory images. */
30 #include <sys/types.h>
31 #include <machine/frame.h>
32 #include <machine/pcb.h>
34 #include "netbsd-nat.h"
35 #include "bsd-kvm.h"
37 static int
38 i386nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
40 struct switchframe sf;
42 /* The following is true for NetBSD 1.6.2:
44 The pcb contains %esp and %ebp at the point of the context switch
45 in cpu_switch(). At that point we have a stack frame as
46 described by `struct switchframe', which for NetBSD 1.6.2 has the
47 following layout:
49 interrupt level
50 %edi
51 %esi
52 %ebx
53 %eip
55 we reconstruct the register state as it would look when we just
56 returned from cpu_switch(). */
58 /* The stack pointer shouldn't be zero. */
59 if (pcb->pcb_esp == 0)
60 return 0;
62 read_memory (pcb->pcb_esp, (gdb_byte *)&sf, sizeof sf);
63 pcb->pcb_esp += sizeof (struct switchframe);
64 regcache->raw_supply (I386_EDI_REGNUM, &sf.sf_edi);
65 regcache->raw_supply (I386_ESI_REGNUM, &sf.sf_esi);
66 regcache->raw_supply (I386_EBP_REGNUM, &pcb->pcb_ebp);
67 regcache->raw_supply (I386_ESP_REGNUM, &pcb->pcb_esp);
68 regcache->raw_supply (I386_EBX_REGNUM, &sf.sf_ebx);
69 regcache->raw_supply (I386_EIP_REGNUM, &sf.sf_eip);
71 return 1;
74 static i386_bsd_nat_target<nbsd_nat_target> the_i386_nbsd_nat_target;
76 void _initialize_i386nbsd_nat ();
77 void
78 _initialize_i386nbsd_nat ()
80 add_inf_child_target (&the_i386_nbsd_nat_target);
82 /* Support debugging kernel virtual memory images. */
83 bsd_kvm_add_target (i386nbsd_supply_pcb);