1 /* Native-dependent code for OpenBSD/amd64.
3 Copyright 2003, 2004 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
26 #include "gdb_assert.h"
28 #include "amd64-tdep.h"
29 #include "amd64-nat.h"
31 /* Mapping between the general-purpose registers in OpenBSD/amd64
32 `struct reg' format and GDB's register cache layout for
35 Note that most (if not all) OpenBSD/amd64 registers are 64-bit,
36 while the OpenBSD/i386 registers are all 32-bit, but since we're
37 little-endian we get away with that. */
39 /* From <machine/reg.h>. */
40 static int amd64obsd32_r_reg_offset[] =
61 /* Support for debugging kernel virtual memory images. */
63 #include <sys/types.h>
64 #include <machine/frame.h>
65 #include <machine/pcb.h>
70 amd64obsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
72 struct switchframe sf;
75 /* The following is true for OpenBSD 3.5:
77 The pcb contains the stack pointer at the point of the context
78 switch in cpu_switch(). At that point we have a stack frame as
79 described by `struct switchframe', which for OpenBSD 3.5 has the
91 Together with %rsp in the pcb, this accounts for all callee-saved
92 registers specified by the psABI. From this information we
93 reconstruct the register state as it would look when we just
94 returned from cpu_switch().
96 For core dumps the pcb is saved by savectx(). In that case the
97 stack frame only contains the return address, and there is no way
98 to recover the other registers. */
100 /* The stack pointer shouldn't be zero. */
101 if (pcb->pcb_rsp == 0)
104 /* Read the stack frame, and check its validity. */
105 read_memory (pcb->pcb_rsp, (char *) &sf, sizeof sf);
106 if (sf.sf_rbp == pcb->pcb_rbp)
108 /* Yes, we have a frame that matches cpu_switch(). */
109 pcb->pcb_rsp += sizeof (struct switchframe);
110 regcache_raw_supply (regcache, 12, &sf.sf_r12);
111 regcache_raw_supply (regcache, 13, &sf.sf_r13);
112 regcache_raw_supply (regcache, 14, &sf.sf_r14);
113 regcache_raw_supply (regcache, 15, &sf.sf_r15);
114 regcache_raw_supply (regcache, AMD64_RBX_REGNUM, &sf.sf_rbx);
115 regcache_raw_supply (regcache, AMD64_RIP_REGNUM, &sf.sf_rip);
119 /* No, the pcb must have been last updated by savectx(). */
121 regcache_raw_supply (regcache, AMD64_RIP_REGNUM, &sf);
124 regcache_raw_supply (regcache, AMD64_RSP_REGNUM, &pcb->pcb_rsp);
125 regcache_raw_supply (regcache, AMD64_RBP_REGNUM, &pcb->pcb_rbp);
131 /* Provide a prototype to silence -Wmissing-prototypes. */
132 void _initialize_amd64obsd_nat (void);
135 _initialize_amd64obsd_nat (void)
137 amd64_native_gregset32_reg_offset = amd64obsd32_r_reg_offset;
138 amd64_native_gregset32_num_regs = ARRAY_SIZE (amd64obsd32_r_reg_offset);
139 amd64_native_gregset64_reg_offset = amd64obsd_r_reg_offset;
141 /* Support debugging kernel virtual memory images. */
142 bsd_kvm_add_target (amd64obsd_supply_pcb);