Commit | Line | Data |
---|---|---|
9062529b MK |
1 | /* Native-dependent code for NetBSD/i386. |
2 | ||
3 | Copyright 2004 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 "gdbcore.h" | |
24 | #include "regcache.h" | |
25 | ||
26 | #include "i386-tdep.h" | |
27 | ||
28 | /* Support for debugging kernel virtual memory images. */ | |
29 | ||
30 | #include <sys/types.h> | |
31 | #include <machine/frame.h> | |
32 | #include <machine/pcb.h> | |
33 | ||
34 | #include "bsd-kvm.h" | |
35 | ||
36 | static int | |
37 | i386nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb) | |
38 | { | |
39 | struct switchframe sf; | |
40 | ||
41 | /* The following is true for NetBSD 1.6.2: | |
42 | ||
43 | The pcb contains %esp and %ebp at the point of the context switch | |
44 | in cpu_switch(). At that point we have a stack frame as | |
45 | described by `struct switchframe', which for NetBSD 1.6.2 has the | |
46 | following layout: | |
47 | ||
48 | interrupt level | |
49 | %edi | |
50 | %esi | |
51 | %ebx | |
52 | %eip | |
53 | ||
54 | we reconstruct the register state as it would look when we just | |
55 | returned from cpu_switch(). */ | |
56 | ||
57 | /* The stack pointer shouldn't be zero. */ | |
58 | if (pcb->pcb_esp == 0) | |
59 | return 0; | |
60 | ||
61 | read_memory (pcb->pcb_esp, (char *) &sf, sizeof sf); | |
62 | pcb->pcb_esp += sizeof (struct switchframe); | |
63 | regcache_raw_supply (regcache, I386_EDI_REGNUM, &sf.sf_edi); | |
64 | regcache_raw_supply (regcache, I386_ESI_REGNUM, &sf.sf_esi); | |
65 | regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp); | |
66 | regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp); | |
67 | regcache_raw_supply (regcache, I386_EBX_REGNUM, &sf.sf_ebx); | |
68 | regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip); | |
69 | ||
70 | return 1; | |
71 | } | |
72 | \f | |
73 | ||
74 | /* Provide a prototype to silence -Wmissing-prototypes. */ | |
75 | void _initialize_i386nbsd_nat (void); | |
76 | ||
77 | void | |
78 | _initialize_i386nbsd_nat (void) | |
79 | { | |
80 | /* Support debugging kernel virtual memory images. */ | |
81 | bsd_kvm_add_target (i386nbsd_supply_pcb); | |
82 | } |