* configure.ac: Switch license to GPLv3.
[deliverable/binutils-gdb.git] / gdb / i386obsd-nat.c
CommitLineData
baadce09 1/* Native-dependent code for OpenBSD/i386.
5d93ae8c 2
6aba47ca 3 Copyright (C) 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
baadce09
MK
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
197e01b6
EZ
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
baadce09
MK
21
22#include "defs.h"
5d0fc17b
MK
23#include "gdbcore.h"
24#include "regcache.h"
25#include "target.h"
baadce09
MK
26
27#include <sys/param.h>
28#include <sys/sysctl.h>
5d0fc17b
MK
29#include <machine/frame.h>
30#include <machine/pcb.h>
baadce09 31
e2dbbd2d 32#include "i386-tdep.h"
5d0fc17b
MK
33#include "i386bsd-nat.h"
34#include "bsd-kvm.h"
35
36static int
37i386obsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
38{
39 struct switchframe sf;
40
41 /* The following is true for OpenBSD 3.6:
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 OpenBSD 3.6 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 the stack frame, and check its validity. We do this by
62 checking if the saved interrupt priority level in the stack frame
63 looks reasonable.. */
64 read_memory (pcb->pcb_esp, (char *) &sf, sizeof sf);
65 if ((unsigned int) sf.sf_ppl < 0x100 && (sf.sf_ppl & 0xf) == 0)
66 {
67 /* Yes, we have a frame that matches cpu_switch(). */
68 pcb->pcb_esp += sizeof (struct switchframe);
69 regcache_raw_supply (regcache, I386_EDI_REGNUM, &sf.sf_edi);
70 regcache_raw_supply (regcache, I386_ESI_REGNUM, &sf.sf_esi);
71 regcache_raw_supply (regcache, I386_EBX_REGNUM, &sf.sf_ebx);
72 regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip);
73 }
74 else
75 {
76 /* No, the pcb must have been last updated by savectx(). */
77 pcb->pcb_esp += 4;
78 regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf);
79 }
80
81 regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp);
82 regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp);
83
84 return 1;
85}
86\f
e2dbbd2d 87
baadce09 88/* Prevent warning from -Wmissing-prototypes. */
e5e4acad 89void _initialize_i386obsd_nat (void);
baadce09
MK
90
91void
92_initialize_i386obsd_nat (void)
93{
5d0fc17b
MK
94 /* We've got nothing to add to the common *BSD/i386 target. */
95 add_target (i386bsd_target ());
96
97 /* Support debugging kernel virtual memory images. */
98 bsd_kvm_add_target (i386obsd_supply_pcb);
99
baadce09
MK
100 /* OpenBSD provides a vm.psstrings sysctl that we can use to locate
101 the sigtramp. That way we can still recognize a sigtramp if its
102 location is changed in a new kernel. This is especially
103 important for OpenBSD, since it uses a different memory layout
104 than NetBSD, yet we cannot distinguish between the two.
105
106 Of course this is still based on the assumption that the sigtramp
107 is placed directly under the location where the program arguments
108 and environment can be found. */
109#ifdef VM_PSSTRINGS
110 {
111 struct _ps_strings _ps;
112 int mib[2];
113 size_t len;
114
baadce09
MK
115 mib[0] = CTL_VM;
116 mib[1] = VM_PSSTRINGS;
117 len = sizeof (_ps);
118 if (sysctl (mib, 2, &_ps, &len, NULL, 0) == 0)
119 {
57ac95b8
MK
120 i386obsd_sigtramp_start_addr = (u_long) _ps.val - 128;
121 i386obsd_sigtramp_end_addr = (u_long) _ps.val;
baadce09
MK
122 }
123 }
124#endif
125}
This page took 0.492113 seconds and 4 git commands to generate.