No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / amd64nbsd-nat.c
blobbd1dc4ee761d47a30a59358bbec4ca0c907fb22c
1 /* Native-dependent code for NetBSD/amd64.
3 Copyright (C) 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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #include "defs.h"
23 #include "target.h"
25 #include "gdb_assert.h"
27 #include "nbsd-nat.h"
28 #include "amd64-tdep.h"
29 #include "amd64-nat.h"
31 #include <machine/frame.h>
32 #include <machine/pcb.h>
34 /* Mapping between the general-purpose registers in NetBSD/amd64
35 `struct reg' format and GDB's register cache layout for
36 NetBSD/i386.
38 Note that most (if not all) NetBSD/amd64 registers are 64-bit,
39 while the NetBSD/i386 registers are all 32-bit, but since we're
40 little-endian we get away with that. */
42 /* From <machine/reg.h>. */
43 static int amd64nbsd32_r_reg_offset[] =
45 14 * 8, /* %eax */
46 3 * 8, /* %ecx */
47 2 * 8, /* %edx */
48 13 * 8, /* %ebx */
49 24 * 8, /* %esp */
50 12 * 8, /* %ebp */
51 1 * 8, /* %esi */
52 0 * 8, /* %edi */
53 21 * 8, /* %eip */
54 23 * 8, /* %eflags */
55 22 * 8, /* %cs */
56 25 * 8, /* %ss */
57 18 * 8, /* %ds */
58 17 * 8, /* %es */
59 16 * 8, /* %fs */
60 15 * 8 /* %gs */
64 static int
65 amd64nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
67 struct switchframe sf;
68 int regnum;
70 /* The following is true for NetBSD/amd64:
72 The pcb contains the stack pointer at the point of the context
73 switch in cpu_switchto(). At that point we have a stack frame as
74 described by `struct switchframe', which for NetBSD/amd64 has the
75 following layout:
77 interrupt level
78 %r15
79 %r14
80 %r13
81 %r12
82 %rbx
83 return address
85 Together with %rsp in the pcb, this accounts for all callee-saved
86 registers specified by the psABI. From this information we
87 reconstruct the register state as it would look when we just
88 returned from cpu_switchto().
90 For kernel core dumps, dumpsys() builds a fake switchframe for us. */
92 /* The stack pointer shouldn't be zero. */
93 if (pcb->pcb_rsp == 0)
94 return 0;
96 /* Read the stack frame, and check its validity. */
97 read_memory (pcb->pcb_rsp, (gdb_byte *) &sf, sizeof sf);
98 pcb->pcb_rsp += sizeof (struct switchframe);
99 regcache_raw_supply (regcache, 12, &sf.sf_r12);
100 regcache_raw_supply (regcache, 13, &sf.sf_r13);
101 regcache_raw_supply (regcache, 14, &sf.sf_r14);
102 regcache_raw_supply (regcache, 15, &sf.sf_r15);
103 regcache_raw_supply (regcache, AMD64_RBX_REGNUM, &sf.sf_rbx);
104 regcache_raw_supply (regcache, AMD64_RIP_REGNUM, &sf.sf_rip);
106 regcache_raw_supply (regcache, AMD64_RSP_REGNUM, &pcb->pcb_rsp);
107 regcache_raw_supply (regcache, AMD64_RBP_REGNUM, &pcb->pcb_rbp);
108 regcache_raw_supply (regcache, AMD64_FS_REGNUM, &pcb->pcb_fs);
109 regcache_raw_supply (regcache, AMD64_GS_REGNUM, &pcb->pcb_gs);
111 return 1;
113 /* Provide a prototype to silence -Wmissing-prototypes. */
114 void _initialize_amd64nbsd_nat (void);
116 void
117 _initialize_amd64nbsd_nat (void)
119 struct target_ops *t;
121 amd64_native_gregset32_reg_offset = amd64nbsd32_r_reg_offset;
122 amd64_native_gregset32_num_regs = ARRAY_SIZE (amd64nbsd32_r_reg_offset);
123 amd64_native_gregset64_reg_offset = amd64nbsd_r_reg_offset;
125 /* Add some extra features to the common *BSD/amd64 target. */
126 t = amd64bsd_target ();
127 t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
128 add_target (t);
130 /* Support debugging kernel virtual memory images. */
131 bsd_kvm_add_target (amd64nbsd_supply_pcb);